function check_submit(e)
{
	var msg;
	var textAll = "An Error occurred. Please make sure that you have completed this form.";
	var textname="";
	var textemail="";
	var textaddress='';
	var textzip="";
	var textcity='';
	var textphone="";
	var textpassword='';
	var textconfirmation='';

	if ((e.firstname.value == null) || (e.lastname.value == null) || (e.firstname.value == "") || (e.lastname.value == "") || isblank(e.firstname.value) || isblank(e.lastname.value)) { textname = "Customer First Name and Last Name is Required.\n";}
	

	
	if ((e.email.value == null) || (e.email.value == "") || isblank(e.email.value)) { textemail = "E-mail address is Required.\n";}
	
	if (textemail=="") {
	  if (!CheckEmail(e.email.value)) { 
	     textemail = "An Error occurred. Please enter a correct email address. For example: someone@email.com \n";
	  }
	}

	if ((e.address.value == null) || (e.address.value == "") || isblank(e.address.value)) { textaddress = "Street Address is Required.\n";}
	
	if ((e.postcode.value == null) || (e.postcode.value == "") || isblank(e.postcode.value) ) { textzip = "Post Code is Required.\n";}
	
	if ((e.city.value == null) || (e.city.value == "") || isblank(e.city.value) ) { textcity = "City is Required.\n";}
	
	if ((e.telephone.value == null) || (e.telephone.value == "") || isblank(e.telephone.value)) { textphone = "Telephone Number is Required.\n";}
	
	if (textphone=="") {
	  if (!checkphone(e.telephone.value)) { 
	     textphone = "An Error occurred. Please enter a correct phone number. For example: 1-555-555-1212 \n";
	  }
	}
	
	if(e.password.value=='' || e.password.value==null){textpassword='Password is Required.\n';}
	
	if(e.password.value!=e.confirmation.value){textconfirmation='Password and Password Confirmation are different.\n';}

	if (e.firstname.style) e.firstname.style.backgroundColor = textname != "" ? '#FFCC66':'#FFFFFF';
	if (e.lastname.style) e.lastname.style.backgroundColor = textname != "" ? '#FFCC66':'#FFFFFF';
	if (e.email.style) e.email.style.backgroundColor = textemail != "" ? '#FFCC66':'#FFFFFF';
	if (e.address.style) e.address.style.backgroundColor = textaddress != "" ? '#FFCC66':'#FFFFFF';
	if (e.postcode.style) e.postcode.style.backgroundColor = textzip != "" ? '#FFCC66':'#FFFFFF';
	if (e.city.style) e.city.style.backgroundColor = textcity != "" ? '#FFCC66':'#FFFFFF';
	if (e.telephone.style) e.telephone.style.backgroundColor = textphone != "" ? '#FFCC66':'#FFFFFF';
	if (e.password.style){
		e.password.style.backgroundColor = (textpassword != "" || textconfirmation != "") ? '#FFCC66':'#FFFFFF';
		e.confirmation.style.backgroundColor = (textpassword != "" || textconfirmation != "") ? '#FFCC66':'#FFFFFF';
	}

	if ((textname == "") &&  (textemail == "") && (textaddress == "") && (textzip == "") && (textcity == "") && (textphone == "") && (textpassword == "") && (textconfirmation == '')) { return true; }
	
	if (textname &&  textemail && textaddress && textzip && textcity && textphone && textpassword) {
		msg = textAll;
	} else {
		msg = textname +  textemail + textaddress + textzip + textcity + textphone + textpassword + textconfirmation;
	}		
	
	alert(msg);
	return false;
}


function isblank(s)
{
	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

function checkphone(str)
{
    for( var i=0; i < str.length; i++) {
        var ch = str.substring( i, i+1 );
        if( (ch < "0" || ch > "9") && ch != "-" && ch != " " && ch != "(" && ch != ")" && ch != "x" && ch != "X" && ch != "+") 
            return false;              
    }    
    return true;
}

function CheckEmail(strEmail) {
	var i;
	var getChar;

	if ((Left(strEmail, 1) == "@") || (Right(strEmail, 1) == "@") )
		return false;
	
		getChar = 0;
	for (i = 0 ; i < strEmail.length ; i++ ) {
		if (strEmail.charAt(i)=='@'){
			getChar++;
		}
	}	    

	if ( getChar != 1 )
		return false;

	var email1;
	var email2;
	var temail;
	
	temail = strEmail.split('@')
	email1 = temail[0].replace(/\s/g, "");
	email2 = temail[1].replace(/\s/g, "");	
	
	var cemail;
	cemail = strEmail;
	cemail = cemail.replace(/\@/g, "");	
	cemail = cemail.replace(/\./g, "");	
	
	if (cemail.length == 0)
		return false;
	
	var allow;
	allow = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-";
	for(i = 0 ; i < cemail.length; i++ )
		if (allow.indexOf(cemail.charAt(i)) < 0 )
			return false;

	if (Left(email1, 1) == '.')
		return false;

	
	if (Left(email2, 1) == '.' || Right(email2, 1) == '.' || email2.replace(/\./g, "").length == email2.length)
		return false;

	if (email2.indexOf("..") >= 0 )
		return false;

	if (Left(email2, 1) == '-' || Right(email2, 1) == '-')
		return false;

	if (Left(email2, 1) == '_' || Right(email2, 1) == '_')
		return false;
	
	return true;
}

function Left( sourceStr, charIdx ) {
	if((sourceStr==null) || (sourceStr=="")) return "";
	return sourceStr.substring(0, charIdx);
}

function Right( sourceStr, charIdx ) {	
	if((sourceStr==null) || (sourceStr=="")) return "";
	return sourceStr.substring(sourceStr.length-charIdx, sourceStr.length);
}

function strLength(source,start,end){
	if(source.length<start||end.length>end){
		return false;
	}
	return true;
}

function isNumber( source ){
	var Letters = "1234567890";
	for( i = 0; i < d.number.value.length; i ++ ){
		c = d.number.value.charAt( i );
		if (Letters.indexOf( c ) ==-1){
			alert("Credit Card Number must be numeric");
			d.number.focus();
			return false;
		}
	}
	
}
