$(document).ready(function() {
//$.facebox("<p class='alert'>Form Error</p><p class='dialogtext'>facebox working</p>");
$("#registersubmit").hide();
$("#contactsubmit").hide();
// is this value a number?
function isNumeric(form_value)
{
    if (form_value.match(/^\d+$/) == null)
        return false;
    else
        return true;
}
// contact form
function validateContactForm() {
	var name = $("#name").val();
	var email = $("#email").val();
	var errors = 0;
	var errorlist = "";
	if (name == null || name == '') {
		errorlist += "A Name is required<br>"
		errors++;
	}
	if (email == null || email == '') {
		errorlist += "An Email Address is required<br>";
		errors++;
	}
	if (errors > 0) {
		if (errors == 1) {
        $.facebox("<p class='alert'>Form Error</p><p class='dialogtext'>An error was found on the form (" + errors + ")</p><p class='dialogtext'>" + errorlist + "</p>");
		} else if(errors > 1) {
         $.facebox("<p class='alert'>Form Error</p><p class='dialogtext'>Errors were found on the form (" + errors + ")</p><p class='dialogtext'>" + errorlist + "</p>");
		}
        //$("#contactform input").effect("highlight", "#f06011", 2500);
        return false; 
    }
$("#contactform").submit();
}

// trade signup form
function validateSignUpForm(){
	var customer_company = $("#customer_company").val();
	var customerName = $("#customerName").val();
	var customer_email = $("#customer_email").val();
	var customer_telephone = $("#customer_telephone").val();

	var errors = 0;
	var errorlist = "";

	if (customerName == null || customerName == '') {
		errorlist += "A Name is required<br>"
		errors++;
	}

	if (customer_email == null || customer_email == '') {
		errorlist += "An Email Address is required<br>";
		errors++;
	}

	if (customer_telephone == null || customer_telephone == '') {
		errorlist += "A Telephone Number is required<br>";
		errors++;
	}
    if (customer_company == null || customer_company == '') {
		errorlist += "A Company Name is required<br>";
		errors++;
	}

	/*if (!isNumeric(customerPhone))
	 {
	 $("#customerPhone_error").show()
	 .append("Phone no. should be numeric");
	 errors++;
	 }*/
	if (errors > 0) {
		if (errors == 1) {
        $.facebox("<p class='alert'>Form Error</p><p class='dialogtext'>An error was found on the form (" + errors + ")</p><p class='dialogtext'>" + errorlist + "</p>");
		} else if(errors > 1) {
         $.facebox("<p class='alert'>Form Error</p><p class='dialogtext'>Errors were found on the form (" + errors + ")</p><p class='dialogtext'>" + errorlist + "</p>");
		}
		//$("#registerdetails input").highlightFade({color:'rgb(255, 0, 0)',speed:2000,iterator:'sinusoidal'});
        return false;
    }
$("#registerdetails").submit();
}
// trade signup form
function validateCheckoutForm(){
	var BillingFirstnames = $("#BillingFirstnames").val();
	var BillingSurname = $("#BillingSurname").val();
	var BillingAddress1 = $("#BillingAddress1").val();
	var BillingCity = $("#BillingCity").val();
	var BillingState = $("#BillingState").val();
    var BillingPostCode = $("#BillingPostCode").val();
    var SelectBillingCountry = $("#SelectBillingCountry").val();
    var CustomerEMail = $("#CustomerEMail").val();
    var BillingPhone = $("#BillingPhone").val();
	var errors = 0;
	var errorlist = "";

	if (BillingFirstnames == null || BillingFirstnames == '') {
		errorlist += "A First Name is required<br>"
		errors++;
	}
	if (BillingSurname == null || BillingSurname == '') {
		errorlist += "A Last Name is required<br>";
		errors++;
	}

	if (BillingAddress1 == null || BillingAddress1 == '') {
		errorlist += "An Address is required<br>";
		errors++;
	}

	if (BillingCity == null || BillingCity == '') {
		errorlist += "A City is required<br>";
		errors++;
	}

    if (BillingState == null || BillingState == '') {
		errorlist += "A Region / County or State is required<br>"
		errors++;
	}
	if (BillingPostCode == null || BillingPostCode == '') {
		errorlist += "A Post Code is required<br>";
		errors++;
	}

	if (SelectBillingCountry == null || SelectBillingCountry == '') {
		errorlist += "A Country is required<br>";
		errors++;
	}

	if (CustomerEMail == null || CustomerEMail == '') {
		errorlist += "An Email Address is required<br>";
		errors++;
	}

    if (BillingPhone == null || BillingPhone == '') {
		errorlist += "A Phone Number is required<br>";
		errors++;
	}

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

$("#contactlink").click(function() {
return validateContactForm();
});
$("a#registerlink").click(function() {
return validateSignUpForm();
//$("#registerdetails").submit();
});
$("#checkoutsubmit").live('click', function() {
return validateCheckoutForm();
});
/*$("#registerlink").click(function() {
$("#registerdetails").submit();
return false;
});*/
// end document.ready
});
