function bgColor(n,c){
	
	C	=	new Array("FFFFFF","CCCCCC") 
	
	var color	=	C[c];
	
	document.getElementById(n).style.backgroundColor="#"+color;
	
	
	
}
function checkMail(){
	var mail	=	document.getElementById("email").value;
  bgColor("email",0);
  if (echeck(mail)!=0) {
		bgColor("email",1);
		alert("Please provide a valid email adress.");
	}else{
		document.machine.submit();
	}
}


function checkLogin(){
	var l	=	document.getElementById("login").value;
	var p	=	document.getElementById("password2").value;
	var m	=	2;
		
	if(p.length<m || l.length<m){
		
			alert("Please fill the form with at least "+m+" characters on each field.");
		
	}else{
		document.loginForm.submit();
				
	}
	
	
	
	
	
	
}

function echeck(str) {
		var e	=	0;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   
						//alert("1rd")  ;
		    
		   e++;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
					 	//alert("2rd")  ;
		    
		    e++;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    	//alert("3rd")  ;
		    e++;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
							 	//alert("4rd")  ;
		    
		    e++;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
							//alert("5rd")  ;
		    
		    e++;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    e++;
		 }
		 

 	//alert("echeck, num errors :"+e);		
 	return e;
}


/*

var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('myspan').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(obj) {
      var poststr = "mytextarea1=" + encodeURI( document.getElementById("mytextarea1").value ) +
                    "&mytextarea2=" + encodeURI( document.getElementById("mytextarea2").value );
      makePOSTRequest('post.php', poststr);
   }



*/

function checkFormSmall(short_form){
	var error = 0;
  if (!short_form) {
	  TAB	=	new Array("name","mail","tel","nameIT","mailIT","tel2");
  }
  else {
	  TAB	=	new Array("company","name","mail");
  }
	V	=	new Array();
	
	for(i=0;i<(TAB.length);i++){		
		n = TAB[i];		
		bgColor(n,0);
    var v = document.getElementById(n).value;
	  //alert(n+" "+V[i]+" "+V[i].length)           ;
  	
	  if ( (n=="name" || n=="tel" || n=="nameIT" || n=="tel2" || n=="company" ) && v.length<1){
  		bgColor(n,1);	
  		error++;
  	}	
  	
  	if ( (n=="mail" || n=="mailIT") && (v.length<1 || echeck(v)!=0) ) {	
  		bgColor(n,1);
  		error++;
  	}
  	
  } 
		
	
	if(error ==0){ // envoie le formulaire
	
	
		//get(document.getElementById('formContact'));
	
		//alert("send");
		
		document.formContact.submit();
	
	
	}else{
		//
		
		alert("Please fill the "+error+" fields.");
			
	
	}


}

function checkForm(){
	
	var error = 0;
	TAB	=	new Array("name","firstname","mail","address","num","cp","city","countryPtrID","tel","usergenderPtrID","message");
	V	=	new Array();
	
	for(i=0;i<(TAB.length);i++){		
		 
		n = TAB[i];		
		
		bgColor(n,0);
	
		V.push(document.getElementById(n).value);
		
		
	} 
	
	
	if(V[0].length<3){	
		
		bgColor(TAB[0],1);
		error++;
	}	
		if(V[1].length<3){	
		
		bgColor(TAB[1],1);	
		error++;
	}	
	
	if((V[2].length<3) || (echeck(V[2])!=0)){	
		
		bgColor(TAB[2],1);
		
		
		error++;
	}
	
		
	if(V[3].length<4) {	
		
		bgColor(TAB[3],1);	
		error++;
	}
	if((V[4].length<1) ){	
		
		bgColor(TAB[4],1);	
		error++;
	}
	
	if((V[5].length<3) || ((V[5]/V[5])!=1)){	
		
		bgColor(TAB[5],1);	
		error++;
	}
	if((V[6].length<3)){	
		
		bgColor(TAB[6],1);	
		error++;
	}
			
	
	if(V[7].length<1) {	
		
		bgColor(TAB[7],1);
		error++;
	}	
	if(V[8].length<9) {	
		
		bgColor(TAB[8],1);	
		error++;
	}
	if(V[9].length<1) {	
		
		bgColor(TAB[9],1);	
		error++;
	}
	if(V[10].length<5) {	
		
		bgColor(TAB[10],1);	
		error++;
	}
	
	
	//error = 0;
	if(error ==0){ // envoie le formulaire
	
		
		document.formContact.submit();
	
	
	}else{
		//alert("Veuillez compléter les "+error+" champs obligatoires.");
			
	
	}


}

