
function validateContactForm(form) {
    if (form.fn.value == "") {
        alert("Please enter your full name.");
        form.fn.focus();
        return false;
    }
    if (form.em.value == "") {
        alert("Please enter your valid email address so we can contact you.");
        form.em.focus();
        return false;
    }
    if (emailcheck(form.em.value)==false){
        form.em.value=""
        form.em.focus();
        return false;
    }

    if (countLineBreaks(form.sites.value) > 10) {
        alert("Sorry - At this time we can only accept maximum 10 links");
        form.sites.focus();
        return false;
    }

    if (form.message.value.length > 2000) {
        alert("Sorry - your message exceeds the maximum length allowed");
        form.message.focus();
        return false;
    }

    if (form.agree.checked == false) {
        alert("Please read and agree with the terms and conditions before you post this form.");
        form.agree.focus();
        return false;
    }

    if (form.humanResponse.value == "") {
        alert("Please write the text what you see in an image at the bottom");
        form.humanResponse.focus();
        return false;
    }

}

function emailcheck(str) {
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
        alert("Invalid E-mail ID")
        return false
    }
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        alert("Invalid E-mail ID")
        return false
    }
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        alert("Invalid E-mail ID")
        return false
    }
    if (str.indexOf(at,(lat+1))!=-1){
        alert("Invalid E-mail ID")
        return false
    }
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert("Invalid E-mail ID")
        return false
    }
    if (str.indexOf(dot,(lat+2))==-1){
        alert("Invalid E-mail ID")
        return false
    }
    if (str.indexOf(" ")!=-1){
        alert("Invalid E-mail ID")
        return false
    }
    return true
}

function countLineBreaks(str){
	try {
		return((str.match(/[^\n]*\n[^\n]*/gi).length));
	} catch(e) {
		return 0;
	}
}
