﻿// JScript File

var flag;
function valid() 
	{
        
		if(document.form1.txtname.value=='')
		{
			alert("Fill Proper Name !!!");
			document.form1.txtname.focus();
			return false;
		}		
		if(document.form1.txtemail.value=='')
		{
			alert("Fill Proper Email-ID !!!");
			document.form1.txtemail.focus();
			return false;
		}
		
		
		if(document.form1.txtproduct.value=='')
		{
			alert("Fill Proper Product Name !!!");
			document.form1.txtproduct.focus();
			return false;
		}
		
		
		if(ValidMail()==false) 
		{
			
			return false;
		}
		
		
		
		
		
		return true;
		
	// ====================== end of validation of Blank Values for the compulsorry Value =============
		
	}
	
	
	
	function validateEmail(str) 
	{
		str=xtremeAllTrim(str);
		if (str=='')
		{
			return true;
		}
//========================== working ==========================
//		if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
//			return(true);
//		else
//			return(false);
//=============================================================
//================== working===================================
//		return(str.indexOf(".") > 2) && (str.indexOf("@") > 0) && (str.length > str.indexOf(".")+1) && (str.indexOf(" ") <= 0);
//=============================================================
		str=str.toLowerCase();
		var checkTLD=0; 
		var knownDomsPat=/ ^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; 
		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=str.match(emailPat); 
		if (matchArray==null) 
		{ 
			alert("The Email Address Is Invalid !!!"); 
			return(false); 
		} 
		var user=matchArray[1]; 
		var domain=matchArray[2]; 
		for (i=0; i<user.length; i++) 
		{ 
			if (user.charCodeAt(i)>127) 
			{ 

				alert("The Email Username Contains Invalid Characters."); ////=========by Bhavik as on 25 08 2008 added Email
				return false; 
			} 
		} 
	
		for (i=0; i<domain.length; i++) 
		{ 
			if (domain.charCodeAt(i)>127) 
			{ 
				alert("Ths Email Domain Name Contains Invalid Characters."); 
				return false; 
			} 
		} 
	
		if (user.match(userPat)==null) 
		{ 
//			alert("The Username Is Invalid."); '=========by Bhavik as on 25 08 2008
			alert("Email Username Is Invalid."); 
			return false; 
		} 
	
		var IPArray=domain.match(ipDomainPat); 
		if (IPArray!=null) 
		{ 
			for (var i=1;i<=4;i++) 
			{ 
				if (IPArray>255) 
				{ 
					alert("The Destination IP Address Is Invalid."); 
					return false; 
				} 
			} 
			return true; 
		} 

		var atomPat=new RegExp("^" + atom + "$"); 
		var domArr=domain.split("."); 
		var len=domArr.length; 
		for (i=0;i<len;i++) 
		{ 
			if (domArr[i].search(atomPat)==-1) 
			{ 
				alert("The Email Domain Name Is Invalid."); 
				return false; 
			} 
		} 
		if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1)
		{ 
			alert("The Email Domain Name Extension Is Invalid"); 
			return false; 
		} 
		if (len<2) 
		{ 
			alert("The Email Address Is Missing A Hostname."); 
			return false; 
		}
		return true;
	}
	
function ValidMail() 
{
				
	if (document.form1.txtemail.value!='')
	{
	
		ArrEmail_CC=(document.form1.txtemail.value).split(";")
		for (CntEmailCC=0;CntEmailCC<ArrEmail_CC.length;CntEmailCC++)
		{
			if (ArrEmail_CC[CntEmailCC]!="")
				{
					if(validateEmail(ArrEmail_CC[CntEmailCC])==false)
					{
						
						alert("Please Enter Valid  Email address in the form of test@test.com!!!");
						document.form1.txtemail.focus();
						return(false);				
					}
				}
		}
	}
}	

function xtremeAllTrim(str) 
{
	while (str.substring(0,1) == ' ')
	{
		str = str.substring(1, str.length);
	}
	while (str.substring(str.length-1, str.length) == ' ')
	{
		str = str.substring(0,str.length-1);
	}
	return(str);

}


	
	function next_click()
	{
	

	if ((valid() == true))
	    {
	    
    	    document.form1.hidGLBMode.value="UI"
    	     
            form1.action=""		
		    form1.submit();
		    //window.location="reg_statistic.aspx?id="+objid
		   return true; 
	    }
	    return false;
	
	}
	function window_onload()
	{
	document.form1.txtname.focus();

	}
	
	
	
	
	
	