var $j = jQuery.noConflict();
$j(document).ready(function() {
// is this value a number?
function isNumeric(form_value)
{
    if (form_value.match(/^\d+$/) == null)
        return false;
    else
        return true;
}
// competition form submissions
function validateCompetitionForm(){
	var name = $j("#name").val();
	var email = $j("#email").val();
    var phone = $j("#phone").val();
    var answer = $j("#answer").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 (phone == null || phone == '') {
		errorlist += "A Phone number is required<br>";
		errors++;
	}
    if (answer == null || answer == '') {
		errorlist += "An answer to the question is required<br>";
		errors++;
	}
	if (errors > 0) {
		if (errors == 1) {
        $j.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) {
         $j.facebox("<p class='alert'>Form Error</p><p class='dialogtext'>Errors were found on the form (" + errors + ")</p><p class='dialogtext'>" + errorlist + "</p>");
		}
		$j("#competitionform input").effect("highlight", "#ca2d92", 3000);
        return false;
    }
}
// Tess Daly Submissions
/*function validateDalyForm(){
	var name = $j("#name").val();
	var email = $j("#email").val();
    var phone = $j("#phone").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 (phone == null || phone == '') {
		errorlist += "A Phone number is required<br>";
		errors++;
	}
	if (errors > 0) {
		if (errors == 1) {
        $j.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) {
         $j.facebox("<p class='alert'>Form Error</p><p class='dialogtext'>Errors were found on the form (" + errors + ")</p><p class='dialogtext'>" + errorlist + "</p>");
		}
		$j("#dalyform input").effect("highlight", "#ca2d92", 3000);
        return false; 
    }
}    */
// contact form
function validateContactForm() {
	var name = $j("#name").val();
	var email = $j("#email").val();
    var formtext = $j("#propertydetails").val();
    //alert(formtext);
	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) {
        $j.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) {
         $j.facebox("<p class='alert'>Form Error</p><p class='dialogtext'>Errors were found on the form (" + errors + ")</p><p class='dialogtext'>" + errorlist + "</p>");
		}
        $j("#contactform input").effect("highlight", "#f06011", 2500);
        return false; 
    }
    if (formtext = "We are interested to increase traffic to your website, please get back to us in order to discuss the possibility in further detail.") {
        return false();
        }
}
// contact form
function validateNewsletterSignUpForm() {
	//var origin = $j("#origin").val();
	var email = $j("#email").val();
    //var formtext = $j("#propertydetails").val();
    //alert(formtext);
	var errors = 0;
	var errorlist = "";
	if (email == null || email == '') {
		errorlist += "An Email Address is required<br>"
		errors++;
	}
	/*if (email == null || email == '') {
		errorlist += "An Email Address is required<br>";
		errors++;
	}*/
	if (errors > 0) {
		if (errors == 1) {
        $j.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) {
         $j.facebox("<p class='alert'>Form Error</p><p class='dialogtext'>Errors were found on the form (" + errors + ")</p><p class='dialogtext'>" + errorlist + "</p>");
		}
        $j("#contactform input").effect("highlight", "#f06011", 2500);
        return false;
    }
    /*if (formtext = "We are interested to increase traffic to your website, please get back to us in order to discuss the possibility in further detail.") {
        return false();
        }*/
}
// MyBFB signup form
function validateMyBFBSignUpForm() {
	var name = $j("#name").val();
	var email = $j("#email").val();
    var password = $j("#password").val();
    //var formtext = $j("#propertydetails").val();
    //alert(formtext);
	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 (password == null || password == '') {
		errorlist += "A Password is required<br>";
		errors++;
	}
	if (errors > 0) {
		if (errors == 1) {
        $j.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) {
         $j.facebox("<p class='alert'>Form Error</p><p class='dialogtext'>Errors were found on the form (" + errors + ")</p><p class='dialogtext'>" + errorlist + "</p>");
		}
        $j("#mybfbsignupform input").effect("highlight", "#f06011", 2500);
        return false;
    }
    /*if (formtext = "We are interested to increase traffic to your website, please get back to us in order to discuss the possibility in further detail.") {
        return false();
        }*/
}
$j("#contactsubmit").click(function() {
return validateContactForm();
});
$j("#newslettersignupsubmit").click(function() {
return validateNewsletterSignUpForm();
});
$j("#mybfbsignupsubmit").click(function() {
return validateMyBFBSignUpForm();
});
$j("#dalysubmit").click(function() {
return validateDalyForm();
});
$j("#competitionsubmit").click(function() {
return validateCompetitionForm();
});
// end document.ready
});
