// JScript File

function ToggleCallback()
{
	var div = document.getElementById("frmCallBackId");
	if (div.style.display == "block")
		{ div.style.display = "none";}
	else
		{ div.style.display = "block";}

}

function Validate_String(string, return_invalid_chars) {
  valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  invalid_chars = '';
  if(string == null || string == '')
     return(true);

  //For every character on the string.   
  for(index = 0; index < string.length; index++) {
    char = string.substr(index, 1);                        
     
    //Is it a valid character?
    if(valid_chars.indexOf(char) == -1) {
      //If not, is it already on the list of invalid characters?
      if(invalid_chars.indexOf(char) == -1) {
        //If it's not, add it.
        if(invalid_chars == '')
          invalid_chars += char;
        else
          invalid_chars += ', ' + char;
      }
    }
  }
            
  //If the string does not contain invalid characters, the function will return true.
  //If it does, it will either return false or a list of the invalid characters used
  //in the string, depending on the value of the second parameter.
  if(return_invalid_chars == true && invalid_chars != '') {
    last_comma = invalid_chars.lastIndexOf(',');
    if(last_comma != -1)
      invalid_chars = invalid_chars.substr(0, $last_comma) + 
      ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
    return(invalid_chars);
    }
  else
    return(invalid_chars == ''); 
}

function echeck(str) {
	if ((str==null)||(str=="")){
		alert("Please Enter your Email")
		return false
	}
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(str.match(emailRegEx)){
		return true;
	}
	else{
		alert('Please enter a valid email address.');
		return false;
	}
}// end of echeck

function checktelephone(str) {
	if ((str==null)||(str=="")){
		alert("Please Enter your Telephone Number")
		return false
	}

	var regEx = /^[0-9 ]+$/;
	if(str.match(regEx)){
		return true;
	}
	else{
		alert('Please enter a just numbers for your telephone number.');
		return false;
	}
}// end of checktelephone

function namecheck(str){
	if ((str==null)||(str=="")){
		return false;
	}
	var regEx = /^[0-9,a-z,A-Z ]+$/;
	if(str.match(regEx)){
		return true;
	}
	else{
		//alert('Characters or number only Please.');
		return false;
	}

}// end of namecheck

function ValidateContactForm(){
 
 	if (checktelephone(document.frmContact.telephone.value)==false) 	
		{return false;}
		
	if (echeck(document.frmContact.email.value)==false) 	
		{return false;}
		
	//-------------------------------------------------------------------------------------
	
	var themessage = "You are required to complete the following fields: ";
	var themessage2 = "Invalid email address";
 
	if (document.frmContact.cbotitle.value=="#") 	
		{themessage = themessage + " - Title";}
		
	if (document.frmContact.forename.value=="") 	
		{themessage = themessage + " - forename";}
		
	if (document.frmContact.surname.value=="") 	
		{themessage = themessage + " - surname";}
		
	if (document.frmContact.telephone.value=="") 	
		{themessage = themessage + " - telephone";}
	
	if (document.frmContact.email.value=="") 	
		{themessage = themessage + " - email";}
		
	if (document.frmContact.address1.value=="") 	
		{themessage = themessage + " - address1";}
		
	if (document.frmContact.address2.value=="") 	
		{themessage = themessage + " - address2";}
		
	if (document.frmContact.Town.value=="") 	
		{themessage = themessage + " - Town";}
		
 	if (document.frmContact.County.value=="#") 	
		{themessage = themessage + " - County";}
		
 	if (document.frmContact.Postcode.value=="") 	
		{themessage = themessage + " - Postcode";}

	//alert if fields are empty and cancel form submit
	if (themessage == "You are required to complete the following fields: ") 
	{	if (echeck(document.frmContact.email.value)) 
		{	document.frmContact.submit();}
		else
		{ 	alert(themessage2); return false; }}
	else 
	{ 	alert(themessage); return false; }
}// validateForm