$(document).ready(function(){
	  
	  function FormValidate(rtn){
		  
		  var FName_length
		  FName_length = '0'
		  
		  if ($("#Header1_GetAQuote1_GetAQuoteForm1_txtFName").val() == 'First Name'){
			  $("#Header1_GetAQuote1_GetAQuoteForm1_txtFName").parent("div").css('background-image', 'url(/Images/HomeNovUpdate/txtfielderrorbg.png)') 
			  $("#Header1_GetAQuote1_GetAQuoteForm1_txtFName").css('background-color', '#fdffd5') 
			  $("#GAQtxtFieldValid1").css('display', 'block') 
			  $("#GAQtxtFieldValidBaloon1").css('display', 'block')
		  }
		  else {
			  FName_length = '1'
			  $("#Header1_GetAQuote1_GetAQuoteForm1_txtFName").parent("div").css('background-image', 'url(/Images/HomeNovUpdate/txtfieldbg.png)')
			  $("#GAQtxtFieldValid1").css('display', 'none') 
			  $("#GAQtxtFieldValidBaloon1").css('display', 'none')
			  $("#Header1_GetAQuote1_GetAQuoteForm1_txtFName").css('background-color', '#ffffff') 
		  }
		  
		  var LName_length
		  LName_length = '0'
		  
		  if ($("#Header1_GetAQuote1_GetAQuoteForm1_txtLName").val() == 'Last Name'){
			  $("#Header1_GetAQuote1_GetAQuoteForm1_txtLName").parent("div").css('background-image', 'url(/Images/HomeNovUpdate/txtfielderrorbg.png)') 
			  $("#Header1_GetAQuote1_GetAQuoteForm1_txtLName").css('background-color', '#fdffd5') 
			  $("#GAQtxtFieldValid2").css('display', 'block') 
			  $("#GAQtxtFieldValidBaloon2").css('display', 'block')
		  }
		  else {
			  LName_length = '1'
			  $("#Header1_GetAQuote1_GetAQuoteForm1_txtLName").parent("div").css('background-image', 'url(/Images/HomeNovUpdate/txtfieldbg.png)')
			  $("#GAQtxtFieldValid2").css('display', 'none') 
			  $("#GAQtxtFieldValidBaloon2").css('display', 'none')
			  $("#Header1_GetAQuote1_GetAQuoteForm1_txtLName").css('background-color', '#ffffff') 
		  }
		  
		  var Phone_length
		  Phone_length = '0'
		  
		  if ($("#Header1_GetAQuote1_GetAQuoteForm1_txtPhone").val() != 'Phone'){
			  Phone_length = '1'
		  }
		  
		  var Email_length
		  var hasEmailError = false
		  Email_length = '0'
		  
		  if ($("#Header1_GetAQuote1_GetAQuoteForm1_txtEmail").val() != 'Email'){
		  	Email_length = '1'
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
			var emailaddressVal = $("#Header1_GetAQuote1_GetAQuoteForm1_txtEmail").val();
			 
		  	if(!emailReg.test(emailaddressVal)) {
				hasEmailError = true
			}
			else{
				hasEmailError = false
			}
			
		  }

		  if (Email_length != '0' || Phone_length != '0'){
			  
			  $("#Header1_GetAQuote1_GetAQuoteForm1_txtEmail").parent("div").css('background-image', 'url(/Images/HomeNovUpdate/txtfieldbg.png)')
			  $("#GAQtxtFieldValid3").css('display', 'none') 
			  $("#GAQtxtFieldValid4").css('display', 'none') 
			  $("#GAQtxtFieldValidBaloon3").css('display', 'none')
			  $("#Header1_GetAQuote1_GetAQuoteForm1_txtEmail").css('background-color', '#ffffff')
			  
			  $("#Header1_GetAQuote1_GetAQuoteForm1_txtPhone").parent("div").css('background-image', 'url(/Images/HomeNovUpdate/txtfieldbg.png)')
			  $("#GAQtxtFieldValid5").css('display', 'none') 
			  $("#GAQtxtFieldValidBaloon4").css('display', 'none')
			  $("#Header1_GetAQuote1_GetAQuoteForm1_txtPhone").css('background-color', '#ffffff')
			  
			  if (hasEmailError == true){
					 
					  $("#Header1_GetAQuote1_GetAQuoteForm1_txtEmail").css('background-color', '#fdffd5') 
					  $("#Header1_GetAQuote1_GetAQuoteForm1_txtEmail").parent("div").css('background-image', 'url(/Images/HomeNovUpdate/txtfielderrorbg.png)') 
					  $("#GAQtxtFieldValid4").css('display', 'block') 
					  $("#GAQtxtFieldValid3").css('display', 'none') 
					  $("#GAQtxtFieldValidBaloon3").css('display', 'block')
				  }
		  }
		  else {
			  if (Email_length == '0'){
				  
				   $("#Header1_GetAQuote1_GetAQuoteForm1_txtEmail").parent("div").css('background-image', 'url(/Images/HomeNovUpdate/txtfielderrorbg.png)') 
					  $("#Header1_GetAQuote1_GetAQuoteForm1_txtEmail").css('background-color', '#fdffd5') 
					  $("#GAQtxtFieldValid3").css('display', 'block') 
					  $("#GAQtxtFieldValidBaloon3").css('display', 'block')
				 				  
			  }
			  else {
				  if (hasEmailError == true){
					  
					  $("#Header1_GetAQuote1_GetAQuoteForm1_txtEmail").css('background-color', '#fdffd5') 
					  $("#GAQtxtFieldValid4").css('display', 'block') 
					  $("#GAQtxtFieldValid3").css('display', 'none') 
					  $("#GAQtxtFieldValidBaloon3").css('display', 'block')
				  }
				  else {
					  
					  $("#Header1_GetAQuote1_GetAQuoteForm1_txtEmail").parent("div").css('background-image', 'url(/Images/HomeNovUpdate/txtfielderrorbg.png)') 
					  $("#Header1_GetAQuote1_GetAQuoteForm1_txtEmail").css('background-color', '#fdffd5') 
					  $("#GAQtxtFieldValid3").css('display', 'block') 
					  $("#GAQtxtFieldValidBaloon3").css('display', 'block')
				  }
		     	}
			  
			  if (Phone_length == '0'){
				  $("#Header1_GetAQuote1_GetAQuoteForm1_txtPhone").parent("div").css('background-image', 'url(/Images/HomeNovUpdate/txtfielderrorbg.png)') 
				  $("#Header1_GetAQuote1_GetAQuoteForm1_txtPhone").css('background-color', '#fdffd5') 
				  $("#GAQtxtFieldValid5").css('display', 'block') 
				  $("#GAQtxtFieldValidBaloon4").css('display', 'block') 
			  }
		  }
		  		 
				 //alert(hasEmailError) 
//				 alert(Email_length)
//				 alert(Phone_length)
		  if (FName_length == '0' ||  LName_length == '0' || hasEmailError == true || (Email_length == '0' && Phone_length == '0')){
			  rtn = false;
		  }
		  else {
			  rtn = true;
		  }
		  
		  return rtn
	  }
	   
	  $(".SubmitCss").click(function() {
		 //return FormValidate();
                 var result = FormValidate();
                 if(result == true)
                     {
                         sendMailQuote();
                     }
	  });
	  
	  $(".txtFieldClass").blur(function() {
		  
		  return FormValidate();
		  
	  });
  });

function GetXmlHttpObject()
{
    var xmlhttp = false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try
	{
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		alert(e + "...");
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E)
		{
			alert(E);
			xmlhttp = false;
		}
	}
	@end @*/
    if (!xmlhttp && typeof XMLHttpRequest!='undefined')
    {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function sendMailPartner()
{
    
    var name= document.getElementById("NameoftheOrganisation").value;
    var area= document.getElementById("AreaofBusiness").value;
    var person= document.getElementById("ConcernedPerson").value;
    var email = document.getElementById("Email").value;
    var PhoneNo = document.getElementById("PhoneNo").value;

    var emailRegExp = /^([a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$/;
    
    if(name == "" || area == "" || person == "" || email == "" || PhoneNo == "")
    {
        alert("Please Fill Required Fields");
       // document.getElementById("errormsg").innerHTML = "Please Fill All Parameters";
       // document.getElementById("errormsg").style.display = "";
    }
    else if(emailRegExp.test(email) == false)
    {
        alert("Please enter valid email id");
        //document.getElementById("errormsg").innerHTML = "Please enter valid email id";
       // document.getElementById("errormsg").style.display = "";
    }
    else
    {
        var xmlhttp = false;
        xmlhttp = GetXmlHttpObject();
        if (xmlhttp)
        {
            var  url ="Action=sendMailPartnership&name="+name + "&area=" +area + "&person="+ person+"&email="+email+"&Phone="+PhoneNo;
           // alert(url);
            xmlhttp.open("POST", "action.php");
            xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
            xmlhttp.send(url);
            xmlhttp.onreadystatechange = function()
            {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                {
                    var response = xmlhttp.responseText;
                   // alert(response);
                    alert("Message Sent Successfully");

                  // document.getElementById("errormsg").innerHTML = "Message Sent Successfully";
                  // document.getElementById("errormsg").style.color = "green";
                  // document.getElementById("errormsg").style.display = "";
                   setTimeout("location.reload(true);",1000);
                }
                delete xmlhttp;
            }
        }
    }
}


function sendMailQuote()
{
       
        var firstName = document.getElementById("Header1_GetAQuote1_GetAQuoteForm1_txtFName").value;
        var lastName = document.getElementById("Header1_GetAQuote1_GetAQuoteForm1_txtLName").value;
        var email = document.getElementById("Header1_GetAQuote1_GetAQuoteForm1_txtEmail").value;
        var phone = document.getElementById("Header1_GetAQuote1_GetAQuoteForm1_txtPhone").value;
        
        var fullName = firstName + " " + lastName;
        
        var contact = "";
        if(email!="")
            {
                contact += email;
                
            }
            if(phone!="Phone")
            {
                contact += ","+phone;
            }
        
        var xmlhttp = false;
        xmlhttp = GetXmlHttpObject();
        if (xmlhttp)
        {
            var  url ="Action=sendMailQuote&name="+fullName + "&contact="+contact;
            //alert(url);
            xmlhttp.open("POST", "http://www.avissol.com/avissol/avislive/action.php");
            xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
            xmlhttp.send(url);
            xmlhttp.onreadystatechange = function()
            {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                {
                    var response = xmlhttp.responseText;
                  // alert(response);
                    alert("Message Sent Successfully");
                    setTimeout("location.reload(true);",1000);
                }
                delete xmlhttp;
            }
        }
    
}

