//Landing page Form validator
function validate_form() {
	
	errors = 0;
	first_name = document.getElementById("first_name").value;
	last_name = document.getElementById("last_name").value;
	//company = document.getElementById("company").value;
	email = document.getElementById("email").value;
	selectedcountry = document.getElementById('country').selectedIndex;
	country = document.getElementById('country')[selectedcountry].value;
	//selectedsolution = document.getElementById('solution').selectedIndex;
	//solution = document.getElementById('country')[selectedsolution].value;
	
	hideAllErrors();
	
	
    if (email == "") {    	
        document.getElementById("email_error").style.display = "block"
        document.getElementById("email").focus();
        errors = 1;
    }
    
	if((email != "") && (!IsEmail(email))){					
	  	document.getElementById("email_invalid").style.display = "block";
	  	document.getElementById("email").focus();	  	
	  	errors = 1;				  	  		  	
	}
	
    
    if (first_name == "") {
        document.getElementById("first_name_error").style.display = "block";
        document.getElementById("first_name").focus();
        errors = 1;
    }

    if (last_name == "") {
        document.getElementById("last_name_error").style.display = "block"
        document.getElementById("last_name").focus();
        errors = 1;
    }
    
//    if (company == "") {
//        document.getElementById("company_error").style.display = "block"
//        document.getElementById("company").focus();
//        errors = 1;
//    }
    
    if (country == "") {
        document.getElementById("country_error").style.display = "block"
        document.getElementById("country").focus();
        errors = 1;
    }
    
//    if (solution == "") {
//        document.getElementById("solution_error").style.display = "block"
//        document.getElementById("solution").focus();
//        errors = 1;
//    }

    
	if(errors == 0){
		document.landing_form.submit();
	}
}

function hideAllErrors() {
    document.getElementById("first_name_error").style.display = "none";
    document.getElementById("last_name_error").style.display = "none";
//    document.getElementById("company_error").style.display = "none";
    document.getElementById("email_error").style.display = "none";
    document.getElementById("email_invalid").style.display = "none";
    document.getElementById("country_error").style.display = "none";
//    document.getElementById("solution_error").style.display = "none";
}

//Email Validator
function IsEmail(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	
	if (str.indexOf(at)==-1){
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
	    return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
	    return false
	}
	if (str.indexOf(" ")!=-1){
	    return false
	}
	return true
}
