// JavaScript Document
function ContactUs()
{
		if(ValidateData())
		{				
			SendMailToAdmin();
		}			
}
function ValidateData()
{
		var name = document.form1.name.value;
		var title = document.form1.title.value;
		var tel = document.form1.tel.value;
		var fax = document.form1.fax.value;
		var email = document.form1.email.value;
		var address = document.form1.address.value;
		var country = document.form1.country.value;
		var interest = document.form1.interest.value;
		var yourMessage = document.form1.msg.value;		
		if((name == "") || (tel == "") || (email == "") ||  (yourMessage == ""))
		{
			var message='';
			if(name == "")
			{
				message = message + " Name \n" ;
			}	
			if(tel == "")
			{
				message = message + " Telephone \n" ;
			}			
			if(email == "")
			{
				message = message + " Email \n" ;
			}    			
			 if(yourMessage == "")
			{
				message = message + " Your Message \n" ;
			}       
			alert('Please Enter the Following fields \n\n' + message);
			return false;
		}
		else
		{
			if(format())
				return true;
			else
			{
				alert('Please Enter Valid Email Id ');
				return false;
			}
		}
}
function format()
{
		var str = document.form1.email.value;
		if( (str.indexOf('@') < 1) && (str.indexOf('.')-str.indexOf('@')) < 2 )
		{
			return false;
		}
		else 
			return true;
}
//Sending Email using Ajax
function SendMailToAdmin()
{ 
	var queryString="?name="+document.form1.name.value+"&title="+document.form1.title.value+"&tel="+document.form1.tel.value+"&fax="+document.form1.fax.value+"&email="+document.form1.email.value+"&address="+document.form1.address.value+"&country="+document.form1.country.value+"&interest="+document.form1.interest.value+"&yourMessage="+document.form1.msg.value;			
	var url="include/mail/sendmail.php" + queryString;		
	xmlHttp = GetXmlHttpObject(MailSentToAdmin);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);		
	document.getElementById("contactDIV").innerHTML="<img src='image/sendingmail.gif' alt='Sending Email' height='150'  width='140'  />";
	document.getElementById("contactDIV").innerHTML +="<br />";
	document.getElementById("contactDIV").innerHTML +="<img src='image/sending.gif' alt='Sending Email' height='25'  width='140'  />";
}
//Event handler to fire on completing the mail
function MailSentToAdmin() 
{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			var response = xmlHttp.responseText;		
			if(response.split('|||')[0]='Y')
			{ 
				Success();
				//alert('Thank you for you interest in Comma Group'); 
				//window.location="home.html";  
			}
			else if(response.split('|||')[0]='N')
			{
				alert('Please try again.'); 
				window.location="contactus.html";  
			} 
		}
}
//General function for creating the HttpObject
function GetXmlHttpObject(handler)
{ 
		var objXmlHttp=null
		if (navigator.userAgent.indexOf("Opera")>=0)
		{
			alert("This example doesn't work in Opera") 
			return 
		}
		if (navigator.userAgent.indexOf("MSIE")>=0)
		{ 
			var strName="Msxml2.XMLHTTP"
			if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
			{
				strName="Microsoft.XMLHTTP"
			} 
			try
			{ 
				objXmlHttp=new ActiveXObject(strName)
				objXmlHttp.onreadystatechange=handler 
				return objXmlHttp
			} 
			catch(e)
			{ 
				alert("Error. Scripting for ActiveX might be disabled") 
				return 
			} 
		} 
		if (navigator.userAgent.indexOf("Mozilla")>=0)
		{
			objXmlHttp=new XMLHttpRequest()
			objXmlHttp.onload=handler
			objXmlHttp.onerror=handler 
			return objXmlHttp
		}
} 
function Sending()
{
	document.getElementById("contactDIV").innerHTML="<img src='image/sendingmail.gif' alt='Sending Email' height='150'  width='140'  />";
	document.getElementById("contactDIV").innerHTML +="<br />";
	document.getElementById("contactDIV").innerHTML +="<img src='image/sending.gif' alt='Sending Email' height='25'  width='140'  />";
}
function Success()
{
	document.getElementById("contactDIV").innerHTML="Mail to support@commagtp.com delivered successfully. You will receive an acknowledgement on your mail. <br />";
	document.getElementById("contactDIV").innerHTML +="<a href='index.html' >Go To Home page</a>";
}
	
/*For character count*/
function check_length(txtMessage)
{	
	maxLen = 150; // max number of characters allowed		
	if (txtMessage.value.length >= maxLen) 
	{
		// Alert message if maximum limit is reached. 
		// If required Alert can be removed. 
		var msg = "You have reached your maximum limit of characters allowed";
		alert(msg);
		// Reached the Maximum length so trim the textarea
		txtMessage.value = txtMessage.value.substring(0, maxLen);
		document.getElementById("text_num").value = 0;
	}
	else
	{
		// Maximum length not reached so update the value of my_text counter
		document.getElementById("text_num").value = (maxLen - txtMessage.value.length)-1;		
	}
}
function ShowTextSize(txtMessage)
{
	maxLen = 150;
	if((maxLen - txtMessage.value.length) >= 0)
	{
		document.getElementById("text_num").value = maxLen - txtMessage.value.length;	
	}
}