/***************************************************************************
 *                              
 *                            -------------------
 *   begin                : Jan 01, 2008 onwards
 *   copyright            : (C) 2007 Creospace
 *   email                : support@creospace.co.uk
 *
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   The dynamically programed parts of this file are copyrighted
 *   You can modify this file under the terms of the Creospace policy but it is 
 *   strictly forbiden to redistribute any or part of this Software file be it  
 *   modified or not to any other domain other than the one/s originally intended. 
 *   
 *
 *	 Creospace is not liable for any damage or misfunction caused as a 
 *	 result of modification in anyway of this file.
 *	 
 *	 This notice must remain in place and intact.
 *  
 *
 ***************************************************************************/ 
 function email(str) {
	    var error = "";
  var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){  
		document.getElementById("email").style.backgroundColor = '#FFDFE3';	
		
		   error = "Invalid E-mail\n";
		   return error;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){  
		document.getElementById("email").style.backgroundColor = '#FFDFE3';	
	
		   error = "Invalid E-mail\n";
		   return error;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		document.getElementById("email").style.backgroundColor = '#FFDFE3';	
	
		       error = "Invalid E-mail\n";
		   return error;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		document.getElementById("email").style.backgroundColor = '#FFDFE3';	

		     error = "Invalid E-mail\n";
		   return error;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){	 
		document.getElementById("email").style.backgroundColor = '#FFDFE3';	

		      error = "Invalid E-mail\n";
		   return error;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){	
		document.getElementById("email").style.backgroundColor = '#FFDFE3';	

		   error = "Invalid E-mail\n";
		   return error;
		 }
		
		 if (str.indexOf(" ")!=-1){
		     error = "Invalid E-mail\n";
		document.getElementById("email").style.backgroundColor = '#FFDFE3';	

		   return error;
		 }

		   return error; 
}
//---------------------------------------------------------------------	
function validate_form() {
var reason = "";

 	reason += validatesubject();
 	reason += validatestudy();
 	reason += validatehelp();
 	reason += validatestandard();
	reason += validatelength();
  	reason += validatedelivery();
	reason += validatetitle();
	reason += email(document.orderForm.email.value);
  	reason += validatefname();
	reason += validatelname();
  	reason += validatecontactNumber();
	reason += validatewheredidyou();
	
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
else
{
   document.orderForm.submit();
   }
}
function validatefname() {
    var error = "";
 
    if (document.orderForm.fname.value == "") 
	{	
		document.getElementById("fname").style.backgroundColor = '#FFDFE3';
        error = "Please specify your first name.\n";
    } 
    return error;  
	
}
function validatelname() {
    var error = "";
 
    if (document.orderForm.lname.value == "") 
	{	
		document.getElementById("lname").style.backgroundColor = '#FFDFE3';
        error = "Please specify your last name.\n";
    } 
    return error;  

}
function validatecontactNumber() {
    var error = "";
 
    if (document.orderForm.contactNumber.value == "") 
	{	
		document.getElementById("contactNumber").style.backgroundColor = '#FFDFE3';
        error = "Please specify your contact number.\n";
    } 
    return error;  
}

function validatesubject() {
    var error = "";
 
 if (document.orderForm.subject.value == "")
    {
        document.getElementById("subject").style.backgroundColor = '#FFDFE3';	
		error= "Your main subject is missing.\n";
   
    } 
    return error;  
}
function validatestudy() {
    var error = "";
 
 if (document.orderForm.study.value == "")
    {
        document.getElementById("study").style.backgroundColor = '#FFDFE3';	
		error= "Your level of study is missing.\n";
   
    } 
    return error;  
}
function validatehelp() {
    var error = "";
 
 if (document.orderForm.help.value == "")
    {
        document.getElementById("help").style.backgroundColor = '#FFDFE3';	
		error= "Type of work you require help with is missing.\n";
   
    } 
    return error;  
}
function validatestandard() {
    var error = "";
 
 if (document.orderForm.standard.value == "")
    {
        document.getElementById("standard").style.backgroundColor = '#FFDFE3';	
		error= "Standard of work you require is missing.\n";
   
    } 
    return error;  
}
function validatelength() {
    var error = "";
 
 if (document.orderForm.wordlength.value == "")
    {
        document.getElementById("wordlength").style.backgroundColor = '#FFDFE3';	
		error= "Length of work you require is missing.\n";
   
    } 
    return error;  
}
function validatedelivery() {
    var error = "";
 
 if (document.orderForm.delivery.value == "")
    {
        document.getElementById("delivery").style.backgroundColor = '#FFDFE3';	
		error= "Delivery of work you require is missing.\n";
   
    } 
    return error; 
} 
function validatewheredidyou() {
    var error = "";
 
 if (document.orderForm.wheredidyou.value == "")
    {
        document.getElementById("wheredidyou").style.backgroundColor = '#FFDFE3';	
		error= "Please tell us how you heard about us.\n";
   
    } 
    return error;  
}	function validatetitle() {
    var error = "";
 
 if (document.orderForm.title.value == "")
    {
        document.getElementById("title").style.backgroundColor = '#FFDFE3';	
		error= "Your title is missing.\n";
   
    } 
    return error;  
}		 
//--------------------------------------------------------------	


