// form processing functions

function validateSignupForm(){
	var customer_company = $("#customer_company").val();
	var customer_first_name = $("#customer_first_name").val();
	var customer_last_name = $("#customer_last_name").val();
	var customer_email = $("#customer_email").val();
	var customer_telephone = $("#customer_telephone").val();
	
	var errors = 0;
	var errorlist = "";
	
	if (customer_first_name == null || customer_first_name == '') {
		errorlist += "A First Name is required\n"
		errors++;
	}
	if (customer_last_name == null || customer_last_name == '') {
		errorlist += "A Last Name is required\n";
		errors++;
	}
	
	if (customer_email == null || customer_email == '') {
		errorlist += "An Email Address is required\n";
		errors++;
	}
	
	if (customer_telephone == null || customer_telephone == '') {
		errorlist += "A Telephone Number is required\n";
		errors++;
	}
	
	/*if (!isNumeric(customerPhone)) 
	 {
	 $("#customerPhone_error").show()
	 .append("Phone no. should be numeric");
	 errors++;
	 }*/
	if (errors > 0) {
		if (errors == 1) {
			alert("An error was found on the form\n");
		} else if(errors > 1) {
			alert("Errors were found on the form (" + errors + ")\n");
		}
		alert(errorlist);
		$("#registerdetails input").highlightFade({color:'rgb(255, 0, 0)',speed:2000,iterator:'sinusoidal'});
        return false; 
    }
}      

function validateCatalogueForm(){
    var name = $("#name").val();
	var address_line_1 = $("#address_line_1").val();
	var address_city = $("#address_city").val();
	var address_county = $("#address_county").val();
	var address_country = $("#address_country").val();
	var address_postcode = $("#address_postcode").val();
	var email = $("#email").val();
	var telephone = $("#telephone").val();
	
	var errors = 0;
	var errorlist = "";

    if (name == null || name == '') {
		errorlist += "A Name is required\n"
		errors++;
	}
	if (address_line_1 == null || address_line_1 == '') {
		errorlist += "A First Line of Address is required\n"
		errors++;
	}
	if (address_city == null || address_city == '') {
		errorlist += "A Town or City is required\n";
		errors++;
	}
	if (address_county == null || address_county == '') {
		errorlist += "A Region, State or County is required\n"
		errors++;
	}
	if (address_country == null || address_country == '') {
		errorlist += "A Country is required\n";
		errors++;
	}
	
	if (email == null || email == '') {
		errorlist += "An Email Address is required\n";
		errors++;
	}
	
	if (telephone == null || telephone == '') {
		errorlist += "A Telephone Number is required\n";
		errors++;
	}
	if (errors > 0) {
		if (errors == 1) {
			alert("An error was found on the form\n");
		} else if(errors > 1) {
			alert("Errors were found on the form (" + errors + ")\n");
		}
		alert(errorlist);
		$("#registerdetails input").highlightFade({color:'rgb(255, 0, 0)',speed:2000,iterator:'sinusoidal'});
        return false; 
    }
}

function validateCallBackForm(){
	var name = $("#name").val();
	var phone = $("#phone").val();
	var callbackText = $("#callbackText").val();
	
	var errors = 0;
	var errorlist = "";
	
	if (name == null || name == '') {
		errorlist += "A Name is required\n"
		errors++;
	}
	if (phone == null || phone == '') {
		errorlist += "A Telephone Number is required\n";
		errors++;
	}
	
	if (callbackText == null || callbackText == '') {
		errorlist += "A brief description of your query is required\n";
		errors++;
	}
	
	/*if (!isNumeric(customerPhone)) 
	 {
	 $("#customerPhone_error").show()
	 .append("Phone no. should be numeric");
	 errors++;
	 }*/
	if (errors > 0) {
		if (errors == 1) {
			alert("An error was found on the form\n");
		} else if(errors > 1) {
			alert("Errors were found on the form (" + errors + ")\n");
		}
		alert(errorlist);
		$("#newdetails input").highlightFade({color:'rgb(255, 0, 0)',speed:2000,iterator:'sinusoidal'});
        return false; 
    }
}

function validateContactForm(){
	var name = $("#name").val();
	var email = $("#email").val();
	var telephone = $("#telephone").val();
	
	var errors = 0;
	var errorlist = "";
	
	if (name == null || name == '') {
		errorlist += "A Name is required\n"
		errors++;
	}
	
	if (email == null || email == '') {
		errorlist += "An Email Address is required\n";
		errors++;
	}
	
	if (telephone == null || telephone == '') {
		errorlist += "A Telephone Number is required\n";
		errors++;
	}
	
	/*if (!isNumeric(customerPhone)) 
	 {
	 $("#customerPhone_error").show()
	 .append("Phone no. should be numeric");
	 errors++;
	 }*/
	if (errors > 0) {
		if (errors == 1) {
			alert("An error was found on the form\n");
		} else if(errors > 1) {
			alert("Errors were found on the form (" + errors + ")\n");
		}
		alert(errorlist);
		$("#contactform input, #registerdetails input").highlightFade({color:'rgb(255, 0, 0)',speed:2000,iterator:'sinusoidal'});
        return false; 
    }
}

function validateEmailCartForm(){
	var name = $("#customer_name").val();
	var email = $("#customer_email").val();
	var telephone = $("#customer_telephone").val();

	var errors = 0;
	var errorlist = "";

	if (name == null || name == '') {
		errorlist += "A Name is required\n"
		errors++;
	}

	if (email == null || email == '') {
		errorlist += "An Email Address is required\n";
		errors++;
	}

	if (telephone == null || telephone == '') {
		errorlist += "A Telephone Number is required\n";
		errors++;
	}

	/*if (!isNumeric(customerPhone))
	 {
	 $("#customerPhone_error").show()
	 .append("Phone no. should be numeric");
	 errors++;
	 }*/
	if (errors > 0) {
		if (errors == 1) {
			alert("An error was found on the form\n");
		} else if(errors > 1) {
			alert("Errors were found on the form (" + errors + ")\n");
		}
		alert(errorlist);
		$("#emailcartform input").highlightFade({color:'rgb(255, 0, 0)',speed:2000,iterator:'sinusoidal'});
        return false;
    }
}

function isNumeric(form_value) 
{ 
    if (form_value.match(/^\d+$/) == null) 
        return false; 
    else 
        return true; 
}