function trim(pstrString)
{
	var intLoop=0;
   
	for(intLoop=0;intLoop<pstrString.length;)
	{
		if(pstrString.charAt(intLoop)==" ")
			pstrString=pstrString.substring(intLoop+1, pstrString.length);
		else
			break;
	}

	for(intLoop=pstrString.length-1; intLoop>=0; intLoop=pstrString.length-1)
	{
		if(pstrString.charAt(intLoop)==" ")
			pstrString=pstrString.substring(0,intLoop);
		else
			break;
	}
	return pstrString;
}

// FUNCTION TO REFRESH THE CAPTCHA IMAGE
//ADDED BY : Sachin.pawar@ecotechservices.com ON : 26 Aug 2009
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

function IsEmail(InString)
{
   var left,right;
   
   if(InString.length==0) return(false);
   for(Count=0;Count<InString.length;Count++)
   {
       TempChar = InString.substring(Count,Count + 1);
       if("'1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.@_-".indexOf(TempChar,0)==-1) return(false); 
   }

   if(InString.indexOf('@')< 1) return(false);//if it has no @ or @ at the beginning
   
   if(InString.lastIndexOf('@')!= InString.indexOf('@')) return(false);// if it has more than one @
   
   left = InString.substring(0,InString.indexOf('@'));
   right = InString.substring(InString.indexOf('@') + 1,InString.length);
   
   if((!isDotExpression(left,0))||(!isDotExpression(right,1))) return(false);
   return(true);

}//end of function

function isDotExpression(InString,NeedsDot)
{
   var dots,index,tmpNeedDot;
   dots=0;
   
   for(index=0;index<InString.length;index++)
   {
      if(InString.substring(index,index+1)==".")
      {
         if((index==0)||(index==InString.length-1)) return(false);
         dots ++;
         
         if(dots>1)tmpNeedDot=1;
         else tmpNeedDot=0;

         if(!isDotExpression(InString.substring(0,index),tmpNeedDot)) return(false);
      }      
   }
   if((NeedsDot==1)&&(dots<1)) return (false);
   if(InString.length < dots * 2+1) return (false);
   return (true);
}


function isSelected(str)
{
	if(str == 0)
	{
		return false;
	}
	else
	{
	return true;
	}
}
function fnsend() 
	{	
			/*if(trim(document.theForm.txtName.value) == "")
			{
					alert("Name is mandatory.");
					document.theForm.txtName.focus();
					return false;
			} */
			if(trim(document.theForm.txtmailid.value) == "")
			{
					alert("Your Email Address is mandatory.");
					document.theForm.txtmailid.focus();
					return false;
			}

				
					 
				 
				 if(!IsEmail(trim(document.theForm.txtmailid.value)) ){
				//		alert("in")
						alert("Your Email Address is invalid.");
						document.theForm.txtmailid.focus();
						return false;	
					}
					
/*
	if(isSelected(trim(document.theForm.selContact.value))=="0") {			
				//alert(trim(obj_name.value));
				alert("Contact us for is mandatory.");
					document.theForm.selContact.focus();
					return false;
				}
			

					if(trim(document.theForm.Description.value) == "")	{
					alert("Description is mandatory.");
					document.theForm.Description.focus();
					return false;
				}
					
					// CHECK FOR CAPTCHA
					if(document.getElementById("captchacode")!=null && trim(document.getElementById("captchacode").value)=="")	{
					alert("Please enter the Anti spam code.");
					document.getElementById("captchacode").focus();
					return false;
				}
*/
	document.theForm.action = "smail.asp";
	document.theForm.submit();	
	/*Commented By : Sachin.pawar@ecotechservices.com
	 On            : 24 auguast 2009
	 Purpose       : No need for the new changes*/
	//alert("Thank you, E-mail sent successfully.");	
 }
 
 function fnalert()
 {	
	if (location.href.indexOf("?n") != -1){
		alert("E-mail sent successfully.");
		document.location.href="Index.html";
	}
 } 

