String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g,'');
}
function getXMLHTTP()
{ //function to return the xml http object
	var xmlhttp=false;	
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)	{		
		try{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1){
				xmlhttp=false;
			}
		}
	}
		
	return xmlhttp;
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function isEmail(emailStr1)
{
		var emailPat=/^(.+)@(.+)$/
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
		var validChars="\[^\\s" + specialChars + "\]"
		var quotedUser="(\"[^\"]*\")"
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

		var matchArray=emailStr1.match(emailPat)
		if (matchArray==null) {
			
			document.getElementById('error').innerHTML="Email address seems incorrect (check @ and .'s).";
			//alert("Email address seems incorrect (check @ and .'s).")		
			return false;
		}
		
		var user=matchArray[1]
		var domain=matchArray[2]
		if (user.match(userPat)==null) {
			document.getElementById('error').innerHTML="The user name doesn't seem to be valid.";
			//alert("The user name doesn't seem to be valid.")
			return false;
		}

		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
			  for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					document.getElementById('error').innerHTML="Destination IP address is invalid.";
					//alert("Destination IP address is invalid.")
					return false;
				}
			}	    
			return true
		}

		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
			document.getElementById('error').innerHTML="The domain name doesn't seem to be valid.";
			//alert("The domain name doesn't seem to be valid.")
			return false;
		}

		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || 
			domArr[domArr.length-1].length>3) {
		   document.getElementById('error').innerHTML="The address must end in a three-letter domain, or two letter country.";
		   //alert("The address must end in a three-letter domain, or two letter country.")
		   return false;
		}

		if (len<2) {
		   var errStr="This address is missing a hostname.";
		   document.getElementById('error').innerHTML=errStr;
		   //alert(errStr)
		   return false;
		}	
		return true;
 }

function validateForm()
{
	if(jQuery("#join-form-wrapper-outer-thanks").hasClass('hide')==false)
	{
		jQuery("#join-form-wrapper-outer-thanks").addClass('hide');
	}
	if(document.getElementById("u_name").value.trim()=='')
	{
		//document.getElementById('error').style.display="block";
		jQuery("#error").fadeOut('fast');
		jQuery("#error").fadeIn('slow');
		document.getElementById('error').innerHTML="Please enter your name.";
		document.getElementById('u_name').focus();
		return false;
	}
	else if(document.getElementById("email").value.trim()=='')
	{
		jQuery("#error").fadeOut('fast');
		jQuery("#error").fadeIn('slow');
		document.getElementById('error').innerHTML="Please enter email.";
		document.getElementById('email').focus();
		return false;
	}
	else if(isEmail(document.getElementById("email").value.trim()) == false)
	{
		jQuery("#error").fadeOut('fast');
		jQuery("#error").fadeIn('slow');
		document.getElementById('email').focus();
		return false;
	}
	else if(isEmail(document.getElementById("email").value.trim()) == false)
	{
		jQuery("#error").fadeOut('fast');
		jQuery("#error").fadeIn('slow');
		document.getElementById('email').focus();
		return false;
	}
	else if(document.getElementById("phone").value.trim()!='' && IsNumeric(document.getElementById("phone").value.trim())==false)
	{
		jQuery("#error").fadeOut('fast');
		jQuery("#error").fadeIn('slow');
		document.getElementById('error').innerHTML="Please enter valid phone no.";
		document.getElementById('phone').focus();
		return false;
	}
	else if(document.getElementById("text_describe").value.trim()=='')
	{
		jQuery("#error").fadeOut('fast');
		jQuery("#error").fadeIn('slow');
		document.getElementById('error').innerHTML="Please describe your brand / business and what you seek.";
		document.getElementById('text_describe').focus();
		return false;
	}
	else
	{
		document.getElementById('error').style.display="none";
		ajaxSubmit(document.getElementById("u_name").value.trim(),document.getElementById("email").value.trim(),document.getElementById("phone").value.trim(),document.getElementById("sub").value.trim(),document.getElementById("text_describe").value.trim());
		document.emailform.reset();
		jQuery("#join-form-wrapper-outer-thanks").removeClass('hide');		//return false;
	}
	function SentMailOutLook()
	{
		var theApp = new ActiveXObject("Outlook.Application");
		var theMailItem = theApp.CreateItem(0);
		var txtAttachements = theMailItem.Attachments	

		try
		{
			strString = 'tester1';
			strReportName = 'tester2';
			strPartyEmail = 'harish.cmantra@gmail.com';
			
			theMailItem.To = strPartyEmail;
			theMailItem.Subject = (strReportName);
			theMailItem.HTMLBody = strString

			//theMailItem.Importance = strReportPriority;
			
			//var strEmailAttachFlNm = new String(fileItem)			
			//strEmailAttachFlNm = replaceAll(strEmailAttachFlNm,'\\',"\\\\") 	

			//arrAttachMents = strAttachMents.split('|')
			
			//for(iloop=0;iloop<arrAttachMents.length;iloop++)
			///{
			//	if (arrAttachMents[iloop] != '')
			//	{
			//		txtAttachements.Add(arrAttachMents[iloop]);
			//	}
			//}

			theMailItem.Send;
			delete theMailItem
			//window.location.replace("msg.asp");
		}
		catch(e)
		{
			alert('Error cannot proceed. ' + e.desciption  )
		}
	}

function sendMail() {
   
}

}
function ajaxSubmit(name,email,phone,subject,describe) 
{		
	var strURL="http://anomaly.in/ajaxsubmit.php?send=email&name="+name+"&email="+email+"&phone="+phone+"&subject="+subject+"&describe="+describe;
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				//alert(req.responseText);
				if (req.status == 200) {
					//alert(req.responseText);
					if(req.responseText==1)
					{
						
						document.emailform.reset();
						jQuery("#join-form-wrapper-outer-thanks").removeClass('hide');
					}
				}
				/*else 
				{
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}*/
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);

	}
			
}

