function sendform(obj, failCallback){
	
	var tmpObj = null;
	var msg = 'The following feild(s) are invalid\n';
    var error = false;
	//alert(checkEmail(tmpObj));
	
    tmpObj = obj.elements['firstName'];
    if (!checkField(tmpObj)) {
    	msg = msg + "- First Name\n";
    	error = true;
	}
	
    tmpObj = obj.elements['lastName'];
    if (!checkField(tmpObj)) {
    	msg = msg + "- Last Name\n";
    	error = true;
	}

    tmpObj = obj.elements['company'];
    if (!checkField(tmpObj)) {
    	msg = msg + "- Company\n";
    	error = true;
	}
		
    tmpObj = obj.elements['country'];
    if (tmpObj.options[0].selected) {
    	msg = msg + "- Country of Origin\n";
    	error = true;
	}
		
    tmpObj = obj.elements['phone'];
    if (!IsDigits(tmpObj)) {
    	msg = msg + "- Phone\n";
    	error = true;
	}
			
	tmpObj = obj.elements['email'];		    	
	if (!checkEmail(tmpObj)){
    	msg = msg + "- Email\n";
    	error = true;
	}
	
	if(error){
		alert(msg);
		return false;
	}
	
	// set the country name to be the value
	tmpObj = obj.elements['country'];
	obj.elements['countryname'].value = tmpObj.options[tmpObj.selectedIndex].text;
	
	var isPop = false;
	if(obj.isPop && obj.isPop.value == 1){
		isPop = true;
	}
	
	var result = {
		url: "email.jsp",
		dataType: "json",		  
	    success: function(dataJson) {
			//alert(dataJson);
			if(dataJson){
				//alert(dataJson.status);
				if(isPop){
					window.location="/popup_email-enquiry-sent.html";
				}else{
					window.location="/email-enquiry-sent.html";
				}		
				/*hideForm();		
				$('#sendsuccess').attr("style","");											
				$('#sendfail').attr("style","display:none;");	*/
																	
			}
	    },
    	error: function(o) {
    		if(failCallback){
    			failCallback();    			
    		}else{
	    		hideForm();
	    		$('#sendsuccess').attr("style","display:none;");	
	    		$('#sendfail').attr("style","");			
    		}
			
	    }
	};
	
	$("#emailSubmitBtn").attr("disabled", "true"); 

	$("#ajax_form").ajaxSubmit(result);
}

function checkField(nameObj) {
    return checkFieldValid(nameObj.value);
}

function checkFieldValid(name) {
		//char & space only
		
		if (name == '') {
			return false;
		}
		else {
            pattern= /[a-zA-Z\s]+/;
            return pattern.test(name);
        }
}	

function IsDigits(obj) {
    var pattern = /[0-9\s\-]+/;
    return ((obj.value == '') || (!pattern.test(obj.value))) ? false : true;
    //return ((obj.value == '')) ? false : true;
}

function checkEmail(emailObj) {
	return checkEmailValue(emailObj.value);
}

function checkEmailValue(email) {
	//var email = obj.elements['email'].value;
	var pattern = /^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/;
	return ((email == '') || (!pattern.test(email))) ? false : true;
	//return false;
}

function hideForm(){
	$('#emaildata').attr("style","display:none;");		
}
	
function showform(){

	window.location="/contact.html";
	/*$('#emaildata').attr("style","");
	$("#emailSubmitBtn").removeAttr("disabled"); 
	
	$('#sendfail').attr("style","display:none;");	
	$('#sendsuccess').attr("style","display:none;");	*/
}

