function refreshimg()
{
	//alert("test");
	//Get a reference to CAPTCHA image
	img = document.getElementById('captcha_img'); 
	//Change the image
	img.src = 'http://www.dotcominfoway.com/components/com_chronocontact/create_image.php?' + Math.random();
}
function showUser(str)
{ 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
//alert(xmlhttp);
xmlhttp.onreadystatechange=function()
  {
  	//  alert(xmlhttp);
//alert(xmlhttp.responseText);
  if (xmlhttp.readyState==4 )
    {
    	//alert(xmlhttp.responseText);
  
    if(xmlhttp.responseText == "Correct")
    {
    		document.ChronoContact_quick_form_portfolio.submit();
    	var c="correct";
    	return c;
	}
	else
	{ 
		alert("You have entered wrong security code. Please enter correct code. Click OK to re-enter.");
			document.ChronoContact_quick_form_portfolio.chrono_verification.focus();
			document.ChronoContact_quick_form_portfolio.chrono_verification.select();
		// document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
		   var c="incorrect";
    	return c;
}
    }
  }

xmlhttp.open("GET","http://www.dotcominfoway.com/components/com_chronocontact/get.php?q="+str,true);
xmlhttp.send();
 
}


function resetValues(what) {
 document.ChronoContact_quick_form_portfolio.name.value="Name";
 document.ChronoContact_quick_form_portfolio.email.value="E-Mail";
 document.ChronoContact_quick_form_portfolio.requirement.value="Requirement";
 document.ChronoContact_quick_form_portfolio.chrono_verification.value="";
  return false;
 }
  function hasNumbers(t)
{
return /\d/.test(t);
}

function ltrim(s)
{
	var l=0;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	return s.substring(l, s.length);
}

function verif_mail() 
{
	var id = document.ChronoContact_quick_form_portfolio.email.value;
	if(id == "")  
	{
	alert("Please enter valid email id (example@example.com). Click OK to re-enter");
	document.ChronoContact_quick_form_portfolio.email.select();
	return false;
	}
	  
	var apos=id.indexOf("@");
	var lpos=id.lastIndexOf("@");
	var dotpos=id.lastIndexOf(".");
	var id_len=id.length;
	//alert(dotpos);
	var dif=id_len-dotpos;
	//alert(dif);
	
	
	if(dif<3 || dif>5)
	{
	alert("Please enter valid email id (example@example.com). Click OK to re-enter");
	document.ChronoContact_quick_form_portfolio.email.select();
	return false;
	}
	
	if(apos!=lpos)
	{
	alert("Please enter valid email id (example@example.com). Click OK to re-enter");
	document.ChronoContact_quick_form_portfolio.email.select();
	return false;
	}
	
	if (apos<1||dotpos-apos<2) 
	  {
		alert("Please enter valid email id (example@example.com). Click OK to re-enter");
		document.ChronoContact_quick_form_portfolio.email.select();
		return false;
	  }
	  
	for(i=0;i<=dotpos;i++)
	{
		var str=id;
		var ch=str.substring(i,i+1);
		
		if(ch==' ' || ch==';' || ch==',' || ch=='!' || ch=='#' || ch=='$' || ch=='%' || ch=='^' || ch=='&' || ch=='*' )
		{
			alert("Please enter valid email id (example@example.com). Click OK to re-enter");
			document.ChronoContact_quick_form_portfolio.email.select();
			return false;
		}
	}
	var str=id.substring(dotpos+1,id_len);
	//alert(str);
	
		for (var i = 0; i < str.length; i++) 
		{
			var ch = str.substring(i, i + 1);
		//alert(ch)
			//if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch == '.')) 
			if(ch==1 || ch==2 || ch==3 || ch==4 || ch==5 || ch==6 || ch==7 || ch==8 || ch==9 || ch==0 || ch==';' || ch=='$' || ch=='@' || ch=='*' || ch=='^' || ch=='&' || ch=='%' ||ch=='#')
			//if((ch < "0" || "9" < ch))
			{
				alert("Please enter valid email id (example@example.com). Click OK to re-enter");
				document.ChronoContact_quick_form_portfolio.email.select();
				return false;
			}
		}
	return true;
	}
function checkfirstemptyspace(Field)
	{
		//var ivalue =" ";
		var ivalue ="*|,\":~&-=<>''![]{}`\';^_?()@$#+/.%\\";
		
			if (ivalue.indexOf(Field.substring(0,1)) != -1)
			{
				alert ("Special character not allowed in the begining of the Name. Click OK to re-enter.");
			return false;
			}
			
		return true;
	}
	
function checkfirstspecials(Field)
	{
		var isplvalue = "*|,\":~&-=<>''![]{}`\';^_?()@$#+/.%\\";
		if (isplvalue.indexOf(Field.substring(0,1)) != -1)
			{
			alert ("Special character not allowed in the begining of the Requirement. Click OK to re-enter.");
			return false;
			}
		return true;
	}

function checkform()
{
	var checknum=/^([0-9]+)$/;
		var checkchar=/^([a-zA-Z ]+)$/;
		var checksp=/^([a-zA-Z0-9.+():,-\/ ]+)$/;
		var emailadd = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		var invalid = " ";
		var name=ltrim(document.ChronoContact_quick_form_portfolio.name.value);
		
		if (name == 0 || name == "Name")
			{
			alert("Please enter your name. Click OK to re-enter");
			document.ChronoContact_quick_form_portfolio.name.focus();
			document.ChronoContact_quick_form_portfolio.name.select();
			return false;
			}
		if (!checkfirstemptyspace(name))
			{
			document.ChronoContact_quick_form_portfolio.name.focus();
			document.ChronoContact_quick_form_portfolio.name.select();
			return false;
			}	
			if(hasNumbers(name))
{
        alert('Please enter a valid name. Click OK to re-enter');
        	document.ChronoContact_quick_form_portfolio.name.focus();
			document.ChronoContact_quick_form_portfolio.name.select();
			return false;
}
		
		if (document.ChronoContact_quick_form_portfolio.email.value=="")
{
		alert("Please enter your email id. Click OK to re-enter.");

		document.ChronoContact_quick_form_portfolio.email.focus();

		return false;
	}
if(!verif_mail())
			{
				return false;
			}
		if (document.ChronoContact_quick_form_portfolio.requirement.value == 0 || document.ChronoContact_quick_form_portfolio.requirement.value == "Requirement") 
			{
			alert("Please enter your requirements. Click OK to re-enter.");
			document.ChronoContact_quick_form_portfolio.requirement.focus();
			document.ChronoContact_quick_form_portfolio.requirement.select();
			return false;
			}
	/* if (!checkfirstemptyspace(document.ChronoContact_quick_form_portfolio.requirement.value))
			{
			document.ChronoContact_quick_form_portfolio.requirement.focus();
			document.ChronoContact_quick_form_portfolio.requirement.select();
			return false;
			}	 */
	if (!checkfirstspecials(document.ChronoContact_quick_form_portfolio.requirement.value))
			{
			document.ChronoContact_quick_form_portfolio.requirement.focus();
			document.ChronoContact_quick_form_portfolio.requirement.select();
			return false;
			}
			if (document.ChronoContact_quick_form_portfolio.chrono_verification.value == 0)
			{
			alert("Please enter Security Code. Click OK to re-enter.");
			document.ChronoContact_quick_form_portfolio.chrono_verification.focus();
			document.ChronoContact_quick_form_portfolio.chrono_verification.select();
			return false;
			} 
			if(!showUser(document.getElementById("chrono_verification").value))
     {
     	
     //	alert("if");
     	return false;
	}
	else
	{
	//	alert("else");
			return false;
	}
//alert("We value the interest you have taken in our services. We will attend to your query at the earliest and get back to you within 2 business day");	
document.ChronoContact_quick_form_portfolio.submit();

}
	
