//Code Author: Reyco Evangelista


var returningScrollingId="";



function isBlankField(idTextInput){
	temp=document.getElementById(idTextInput).value;
	if(temp==""||temp==null){
		document.getElementById(idTextInput+"Error").innerHTML="*Required";
		document.getElementById(idTextInput+"Error").style.display="";
		returningScrollingId=idTextInput;
		return true;
	}
	return false;
}

function isBlankFieldWithBr(idTextInput){
	temp=document.getElementById(idTextInput).value;
	if(temp==""||temp==null){
		document.getElementById(idTextInput+"Error").innerHTML="<br />*Required";
		document.getElementById(idTextInput+"Error").style.display="";
		returningScrollingId=idTextInput;
		return true;
	}
	return false;
}

function isNotAllNumbers(idTextInput){
	stringLength=document.getElementById(idTextInput).value.length;
	for(ctr=0;ctr<stringLength;ctr++){
		temp=document.getElementById(idTextInput).value.substr(ctr,1);
		if(temp<'0'||temp>'9'){
		
			if(!(temp==' ' || temp=='-')){
				document.getElementById(idTextInput+"Error").innerHTML="*Numbers Only";
				document.getElementById(idTextInput+"Error").style.display="";
				returningScrollingId=idTextInput;
				return true;
			}
		}
	}
	return false;
}

function isNotAllCharacters(idTextInput){
	stringLength=document.getElementById(idTextInput).value.length;
	for(ctr=0;ctr<stringLength;ctr++){
		temp=document.getElementById(idTextInput).value.substr(ctr,1);
		if(!(temp<'0'||temp>'9')){
			document.getElementById(idTextInput+"Error").innerHTML="*Characters Only";
			document.getElementById(idTextInput+"Error").style.display="";
			returningScrollingId=idTextInput;
			return true;
		}
	}
	return false;
}

function isNotValidEmail(idTextInput){
	temp=document.getElementById(idTextInput).value;
	//if( ( temp.indexOf('.') - temp.indexOf('@') ) > 1 ) return false;
	
	if( (temp.indexOf('.')>0)&&(temp.indexOf('@')>0) ){
		return false;
	}
	
	
	document.getElementById(idTextInput+"Error").innerHTML="*Invalid Email";
	document.getElementById(idTextInput+"Error").style.display="";
	
	returningScrollingId=idTextInput;
	return true;
}

function clearErrorMessage(idTextInput){
	document.getElementById(idTextInput+"Error").innerHTML="";
	document.getElementById(idTextInput+"Error").style.display="none";
}


function validateForm(){

	ret=true;
	
	returningScrollingId="";
	
	clearErrorMessage("title");
	clearErrorMessage("firstName");
	clearErrorMessage("lastName");
	clearErrorMessage("companyName");
	
	clearErrorMessage("postalAddress");
	clearErrorMessage("town");
	clearErrorMessage("postcode");
	clearErrorMessage("country");
	
	clearErrorMessage("telephone");
	clearErrorMessage("fax");
	clearErrorMessage("email");
	clearErrorMessage("yourEnquiry");
	
	
	if(isBlankField("yourEnquiry")) ret=false;
	
	
	if(isNotValidEmail("email")) ret=false;
	if(isBlankField("email")) ret=false;
	
	
	if(isNotAllNumbers("fax")) ret=false;
	if(isBlankField("fax")) ret=false;
	
	if(isNotAllNumbers("telephone")) ret=false;
	if(isBlankField("telephone")) ret=false;
		
	
	if(isNotAllCharacters("country")) ret=false;
	if(isBlankField("country")) ret=false;
	
	
	if(isNotAllNumbers("postcode")) ret=false;
	if(isBlankField("postcode")) ret=false;
	
	
	//if(isBlankField("town")) ret=false;
	if(isBlankField("postalAddress")) ret=false;

	//if(isBlankField("companyName")) ret=false;
	
	if(isNotAllCharacters("lastName")) ret=false;
	if(isBlankField("lastName")) ret=false;
	
	
	if(isNotAllCharacters("firstName")) ret=false;
	if(isBlankField("firstName")) ret=false;
	
	

	if(!checkAntiAutomaton()) ret = false;
	

	if(!ret){
		//window.open("#"+returningScrollingId,"_self");
		return false;
	}

}

/*
	clearErrorMessage("password1");
	clearErrorMessage("password2");
	


	if(document.getElementById('password1').value!=document.getElementById('password2').value){ 
		document.getElementById('password1Error').innerHTML="Password Mismatched!";
		document.getElementById('password2Error').innerHTML="Password Mismatched!";
		ret=false;
	}

	if(isBlankField("password2")) ret=false;
	if(isBlankField("password1")) ret=false;
*/

