// JavaScript Document
function checkemail(em)   //Email validation 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(em))
	return true
	else
	return false
}
function validateDatas() 
{
	//alert("enter");
	var missinginfo;
	missinginfo = "";
	
	if(document.getElementById("cnt_name").value=="")
	{
		missinginfo += "\n     - Name ";
		document.getElementById("cnt_name").focus;
	}
	if(document.getElementById("cnt_address").value=="")
	{
		missinginfo += "\n     - Address ";
		document.getElementById("cnt_address").focus;
	}
	if(document.getElementById("cnt_phone").value=="")
	{
		missinginfo += "\n     - Phone ";
		document.getElementById("cnt_phone").focus;
	}

	if(document.getElementById("cnt_email").value == "") 
	{
		missinginfo += "\n     - Email Id";
		document.getElementById("cnt_email").focus();
	}
	if(document.getElementById("cnt_email").value!="")
	{
		var emailcheck = checkemail(document.getElementById("cnt_email").value);
		if(emailcheck==false)
			missinginfo += "\n -Enter a Valid Email ID!";
			document.getElementById("cnt_email").focus();
	}	
	if(document.getElementById("cnt_comments").value=="")
	{
		missinginfo += "\n     - Comments/Quiestions";
		document.getElementById("cnt_comments").focus;
	}
	
	if (missinginfo != "") 
	{
		missinginfo ="_____________________________\n" + "You failed to correctly fill in your:\n" + missinginfo + "\n_____________________________" + "\nPlease re-enter and submit again!";
		alert(missinginfo);
		return false;
	}
	else 
	{
		//alert("sucess");
		sendContactUs('actions/send_contactus.php');
	}
}

function sendContactUs(datasourse)
{ 		
	
	var XMLHttpreqobj2500 = false;
	if(window.XMLHttpRequest)
 	{
		XMLHttpreqobj2500 = new XMLHttpRequest();
		if(XMLHttpreqobj2500.overrideMimeType)
		{
			XMLHttpreqobj2500.overrideMimeType("text/xml");
		}
    }
    else if (window.ActiveXObject)
    {
        XMLHttpreqobj2500 = new ActiveXObject("Microsoft.XMLHTTP");
    }
				
							
		var contactusContent='cnt_name='+document.getElementById("cnt_name").value
		    +'&cnt_org='		 		+document.getElementById("cnt_org").value
			+'&cnt_address='			+document.getElementById("cnt_address").value
			+'&cnt_postcode='			+document.getElementById("cnt_postcode").value
			+'&cnt_phone='				+document.getElementById("cnt_phone").value					
			+'&cnt_email='		 		+document.getElementById("cnt_email").value
			+'&cnt_comments='			+document.getElementById("cnt_comments").value;
					  			
		 if (XMLHttpreqobj2500)
            {
               
                XMLHttpreqobj2500.open("POST",datasourse);
				XMLHttpreqobj2500.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                XMLHttpreqobj2500.onreadystatechange = function()
                {
					
				   if (XMLHttpreqobj2500.readyState == 4 && XMLHttpreqobj2500.status == 200)
                    {			
						//alert(XMLHttpreqobj2500.responseText);
						document.getElementById("sucMsg").innerHTML='<div class="loadingtextforeditpost1">Thank you for your comments/Questions.We will be contacting you as soon as possible...</div>';
						clearcontactus();
						location.href="#adTop";
						
					}				    			
					else
					{						
						document.getElementById("sucMsg").innerHTML ='<div><table width="50%"  border="0" cellspacing="0" cellpadding="0"><tr><td width="4%"><img src="images/ajax-loader.gif" alt="Loading"></td><td width="96%" class="loadingtext" valign="middle">Processing,&nbsp;Please&nbsp;Wait..</td></tr></table></div>';
						location.href="#adTop";
						
					}
                }
                XMLHttpreqobj2500.send(contactusContent);//send datas
				
            }
			
}


function clearcontactus()
{
	document.getElementById("cnt_name").value		="";
	document.getElementById("cnt_org").value		="";
	document.getElementById("cnt_address").value	="";
	document.getElementById("cnt_postcode").value	="";
	document.getElementById("cnt_phone").value		="";					
	document.getElementById("cnt_email").value		="";
	document.getElementById("cnt_comments").value	="";	
}
