var curPopupWindow;
var formToSubmit;
function salesforce(objForm) {
    formToSubmit=objForm;
    var first_name = document.getElementById('first_name1').value;
    var last_name = document.getElementById('last_name1').value;
    var email = document.getElementById('email1').value;
    if(!validateEmail(email)){
       alert("Email address not valid");
       return false;
     }
    
    var phone = document.getElementById('phone1').value;
    var country = document.getElementById('country1').value;
    var company = document.getElementById('company1').value;
    var source = document.getElementById('00N80000003Z7Cg1').value;
    //var target = document.getElementById('00N80000003Z7DF1').value;
    var target = "";
    var targetctrl = document.getElementById('00N80000003Z7DF1');
    for (var i = 0; i < targetctrl.options.length; i++) {
        if (targetctrl.options[i].selected) {
            target = target + '&00N80000003Z7DF=' + targetctrl.options[i].value;
        }
    }
    var currency = document.getElementById('00N80000003Z79K1').value;
    var message = document.getElementById('00N80000003Z7DP1').value;
    var aboutus = document.getElementById('00N80000003Z7Qb1').value;
    if (first_name != "" && last_name != "" && email != "" && phone != "" && currency != "---" && aboutus != "") {
        var url = "https://www.salesforce.com/servlet/servlet.WebToLead";
        var params = "encoding=UTF-8&oid=00D80000000M28u&first_name=" + first_name + "&last_name=" + last_name + "&email=" + email + "&phone=" + phone + "&country=" + country + "&company=" + company + "&00N80000003Z7Cg=" + source + target + "&00N80000003Z79K=" + currency + "&00N80000003Z7DP=" + message + "&00N80000003Z7Qb=" + aboutus + "";
       openWind(url + "?" + params);
    }    
    else {
        alert("Enter the required fields");
		
    }
	return false;
}
function validateEmail(elementValue){  
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
   return emailPattern.test(elementValue);  
 }  
function openWind(URL)
            {
//alert(URL);
                curPopupWindow = window.open(URL, "_blank","width=0, height=0,dependent=no,resizable=yes,toolbar=no,status=no,directories=no,menubar=no,scrollbars=0,location=no", false);            
                window.setTimeout(closeWindow,4000);
                curPopupWindow.blur();
                window.focus();
                
            }
            function closeWindow()
            {
                curPopupWindow.close();
		    formToSubmit.submit();
            }

