// JavaScript Document
	var errors = "";
	var emptyStr = /^[" "]*$/;		
	var email = /^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/;
	var phone = /^[0-9\(\)' ']{8,}$/;


function validate_form() {
        var missing = 0;
        var msg = "The following fields need to be filled in: \n";
		
        if (document.form1.title.value == "") {missing = 1; msg += " - Title\n";}
        if (document.form1.fname.value == "") {missing = 1; msg += " - Firstname\n";}
        if (document.form1.lname.value == "") {missing = 1; msg += " - Lastname\n";}
        if (document.form1.company.value == "") {missing = 1; msg += " - Company\n";}
        if (document.form1.city.value == "") {missing = 1; msg += " - City\n";}
        //if (document.form1.country.value == "") {missing = 1; msg += " - Country\n";}
        CheckPhoneNumber(document.form1.phone.value);
        if (document.form1.phone.value == "") {missing = 1; msg += " - Phone\n";}
        if (document.form1.email.value == "") {missing = 1; msg += " - Email\n";}
	if (document.form1.comment.value == "") {missing = 1; msg += " - Comment\n";}

        var msgdte = "";

        //validating the email address
        var emlstr = document.form1.email.value;
        if (emlstr.indexOf("@") == -1) msg += "\nInvalid email address\n";

        if (missing == 1){
                //document.document.form1.write(msg);
		//document.document.form1.value = msg;
		////document.document.form1.write(msg);
		alert("Error! Please enter all Mandatory Fields marked with *");
                return false
        }
        else{return true}
}

function CheckPhoneNumber(TheNumber) {
        var valid = 1;
        var GoodChars = "0123456789()-+ ";
        var i = 0;
        if (TheNumber=="") {
                // Return false if number is empty
                valid = 0;
        }
        for (i =0; i <= TheNumber.length -1; i++) {
                if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
// Note: Remove the comments from the following line to see this
// for loop in action.
// alert(TheNumber.charAt(i) + " is no good.")
                        valid = 0;
                } // End if statement
        } // End for loop
        return valid;
}

function whenLoading(el,w){
	var e = document.getElementById(el); 
	e.innerHTML = ("<table width="+w+"   border='0' cellpadding='0' align='center' valign='top' cellspacing='0' class='text_white'><tr><td>Sending Data...</td></tr></table>");
}

function whenLoaded(el,w){
	var e = document.getElementById(el); 
	e.innerHTML = ("<table width="+w+"   border='0' cellpadding='0' align='center' valign='top' cellspacing='0' class='text_white'><tr><td>Data Sent...</td></tr></table>");
}

function whenInteractive(el,w){
	var e = document.getElementById(el); 
	e.innerHTML = ("<table width="+w+"   border='0' cellpadding='0' align='center' valign='top' cellspacing='0' class='text_white'><tr><td>getting Data...</td></tr></table>");
}
			
	function sendMailAjax(el){
	
		var ajax = new sack();
		ajax.setVar("title", document.form1.title.value); 
		ajax.setVar("fname", document.form1.fname.value); 
		ajax.setVar("lname", document.form1.lname.value); 
		if(!document.form1["position"].value.match(emptyStr))	
		{
			ajax.setVar("position", document.form1.position.value); 
		}
		ajax.setVar("company", document.form1.company.value); 
		ajax.setVar("city", document.form1.city.value); 
		ajax.setVar("country", document.form1.country.value); 
		ajax.setVar("phone", document.form1.phone.value); 
		ajax.setVar("email", document.form1.email.value); 
		
		var radioLength = document.form1.profession.length;
		for(var i = 0; i < radioLength; i++) {
			if(document.form1.profession[i].checked) {
				ajax.setVar("profession", document.form1.profession[i].value); 
			}
		}

		ajax.setVar("comment", document.form1.comment.value); 
		
		ajax.element = el;
		ajax.requestFile = 'contactsForm.php';
		ajax.method = "POST";
		ajax.onLoading = whenLoading(el,200);
		ajax.onLoaded = whenLoaded(el,200); 
		ajax.onInteractive = whenInteractive(el,200);

		ajax.runAJAX();
	}	
