// JavaScript Document
function KeyPress(OPT) {
//alert("in");
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (OPT == 1)
{
	//alert("numeric and character");
	if ( ((keycode >= 48) && (keycode <= 57)) || ((keycode >= 97) && (keycode <= 122)) || ((keycode >= 65) && (keycode <= 90)) )
	{
		return true;
	}
	else
	{ return false;
	}
}
//Only numeric
if (OPT == 2)
{
	//alert("numeric");
	if ( ((keycode >= 48) && (keycode <= 57)) )
	{
		return true;
	}
	else
	{ return false;
	}
}

//Only characters
if (OPT == 3)
{
	//alert("character");
	if ( ((keycode >= 97) && (keycode <= 122)) || ((keycode >= 65) && (keycode <= 90)) )
	{
		return true
	}
	else
	{ return false;
	}
}

//characters , Numeric , Space and comma
if (OPT == 4)
{
	//alert("Numeric,Character,Comma and Space");
	if ( ((keycode >= 48) && (keycode <= 57)) || ((keycode >= 97) && (keycode <= 122)) || ((keycode >= 65) && (keycode <= 90)) || (keycode == 32) || (keycode == 44))
	{
		return true;
	}
	else
	{ return false;
	}
}

if (OPT == 5)
{
	//alert("Numeric and dash(-) and +");
	if ( ((keycode >= 48) && (keycode <= 57)) || keycode == 45 || keycode == 43)
	{
		return true;
	}
	else
	{ return false;
	}
}

if (OPT == 6)
{
	//alert("characters , Numeric , Space, dash(-) and +");
	if ( ((keycode >= 97) && (keycode <= 122)) || ((keycode >= 65) && (keycode <= 90)) || ((keycode >= 48) && (keycode <= 57)) || keycode == 45 || keycode == 43|| keycode == 32 || keycode == 46)
	{
		return true;
	}
	else
	{ return false;
	}
}

//CHECK FOR NIC ID
if (OPT == 7)
{
	//Characters between a-f,A-F,0-9
		if ( ((keycode >= 97) && (keycode <= 102)) || ((keycode >= 65) && (keycode <= 70)) || ((keycode >= 48) && (keycode <= 57)) || (keycode == 46) || (keycode == 8) || (keycode == 37) || (keycode == 39) )
	{
		return true;
	}
	else
	{ return false;
	}
}

//For Decimal
if (OPT == 8)
{
	//alert("numeric");
	if ( ((keycode >= 48) && (keycode <= 57)) ||(keycode == 46))
	{
		return true;
	}
	else
	{ return false;
	}
}

if (OPT == 9)
{
	//alert("Numeric and dash(-) and +");
	if ( ((keycode >= 48) && (keycode <= 57)) || keycode == 45)
	{
		return true;
	}
	else
	{ return false;
	}
}
/*return true */
}

//onclick make username=blank
function make_blank(me)
{
	//var val = <?php echo ltrim(me.value); ?>
//	alert(me.value)
	if(me.value=="Email ID")
	{ me.value="";
	}
}

//email address validation
function emailCheck (emailStr) {
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 + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
/* Finally, let's start trying to figure out if the supplied address is
   valid. */
/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]
// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.")
    return false
}
/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
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) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
//  End -->

function checkpass(npassword,cpassword){

if (npassword.value != cpassword.value)
{
	alert("New password and confirm password are not same, please verify.");
	npassword.value="";
	cpassword.value="";
	nform.npword.focus();
	return false;
}
else
{
	var value = confirm("Do you really want to change the password?")
	if (value == true) {
		return true;
	} else {
		return false;
	}
}
}


function validate1(uname,pword)
{
if (uname.value=="" || uname.value=="Email ID")
	{
	alert ("Please Provide Your Email ID as Username..");
	uname.value='';
	uname.focus();
	return false;
	}
else if (pword.value=="")
	{
	alert ("Please Provide Your password ..");
	pword.focus();
	return false;
	}
else
	return true;
}

function subm(aname,apword)
{ 
if (aname.value=='')
	{
	alert("Provide your Admin User Name..");
	aname.focus();
	return false;	
	}
else if (apword.value=='')
	{
	alert("Provide your Admin Password..");
	apword.focus();
	return false;	
	}
else
	{
		return true;
	}
}
// encryption and decryption
//Message Encrypter- By Naresh Hotchandani (nhotchandani@rediffmail.com)
//Script featured on Dynamic Drive
//Visit http://www.dynamicdrive.com for this script and more 

  len=0;
	
  function CalcKey()
	{
		len=0;
		//var temp=document.Encrypt.Key.value;
		var temp="slscorp";
		
		for(i=0;i<temp.length;i++)
		{
			len=len+temp.charCodeAt(i);
		}
		if(len==0)
		{
			alert('Please Enter the appropriate Key');
			//document.Encrypt.Key.focus();
		}
		return len;
	}

 function Encryption(text)
 {

	CalcKey();
	//document.Encrypt.Encrypted.value="";
	//var txt=document.Encrypt.normal.value;
	var txt = text.value;
	//alert(txt);
	var net="";
	var fin=0;
	
	if(len>0)
	{
	
		if(txt.length>0)
		{
			for(i=0;i<txt.length;i++)
			{
				fin=txt.charCodeAt(i)+len;
			
				if(fin>99)
				{
					net=net+fin;
				}
				else
				{
					net=net+'0'+fin;
				}
				}
			
			//document.Encrypt.Encrypted.value=net;
			//document.Encrypt.normal.value="";
			}
		else
		{
			//alert('Please Enter the Text to be Encrypted');
			//document.Encrypt.normal.focus();
		}
	
	}
	return net;
}

function Decryption(text)
{
	//var txt=document.Encrypt.Encrypted.value;
	var txt= text.toString();
	var j=3;
	var temp1;
	var res="";

	CalcKey();

	if(len>0)
	{
		if(txt.length>0)
		{
			for(i=0;i<txt.length;i+=3)
			{
				var temp=txt.substring(i,j);
				temp1=(parseInt(temp)-len);
				var t=unescape('%'+temp1.toString(16));
				if(t=='%d' || t=='%a')
				{
					res=res+' ';
				}
				else
				{
					res=res+t
				} 
				j+=3;
		   }
			//document.Encrypt.normal.value=res;
			//document.Encrypt.Encrypted.value="";
		}
		else
		{
			alert('Please Enter the Encrypted Text');
			//document.Encrypt.Encrypted.focus();
		}
	}
	return res;
}



/*
function check_date()
{		//alert(main_form.orderdate.value);		
		if (main_form.fname.value == "")
		{
			alert("Please Specify First Name");
			main_form.fname.focus();
			return false;
		}
	 	if(main_form.mname.value == "" )
	 	{
			alert("Please Specify Middle Name");
			main_form.mname.focus();
			return false;
		}
		 if(main_form.lname.value == "")
			{
				alert("Please Specify Last Name");
				main_form.lname.focus();
				return false;
			}
		if (main_form.orderdate.value == '31-DEC-2005')
		{
			alert("please Specify Birth Date");
			return false;
		}
		if (main_form.email.value == "")
			{
				alert("Specify Your Email Address");
				main_form.email.focus();
				return false;
			}
		else
			{
				if (!(echeck(main_form.email.value)))
				{
					return false;
				}
			}
		if (main_form.add.value == "")
		{
			alert("Specify Your address");
			main_form.add.focus();
			return false;
		}

		if (main_form.city.value == "")
		{
			alert("Specify  city name");
			main_form.city.focus();
			return false;
		}
		
		
		if (main_form.state.value == "")
		{
			alert("Specify  state name");
			main_form.state.focus();
			return false;
		}
		
		
		
	if(!validateZIP())
	{
	 return false;
	}
		
		
		if(main_form.ssc_year.value== "year")
		{
		
			alert("Please Specify SSC Year");
			main_form.ssc_year.focus();
			return false;
		
		}
		if(main_form.ssc_board.value== "")
		{
			alert("Please Enter SSC Board University");
			main_form.ssc_board.focus();
			return false;
		}
		if(main_form.ssc_per.value== "")
		{
		
			alert("Please Enter SSC Percent(%)");
			main_form.ssc_per.focus();
			return false;
		
		}
	/*	if(main_form.ssc_sub.value== "")
		{
		}
		*/
		
		
	/*	if(main_form.hsc_year.value== "year")
		{
			
			alert("Please Specify HSC Year");
			main_form.hsc_year.focus();
			return false;	
		
		}
		if(main_form.hsc_board.value== "")
		{
			
			alert("Please Enter HSC Board University");
			main_form.hsc_board.focus();
			return false;
		
		}
		if(main_form.hsc_per.value== "")
		{
			alert("Please Enter HSC Percent(%)");
			main_form.hsc_board.focus();
			return false;
		}
		if(main_form.hsc_sub.value== "")
		{
		
		}
		
		if(main_form.g_year.value== "year")
		{
			alert("Please Specify  Graduation Year");
			main_form.g_year.focus();
			return false;	
		}
		if(main_form.g_board.value== "")
		{
			alert("Please Enter Graduation University");
			main_form.g_board.focus();
			return false;				
		}
		if(main_form.g_per.value== "")
		{
		alert("Please Enter Graduation Percent");
			main_form.g_per.focus();
			return false;
		}

		if(main_form.g_sub.value== "")
		{
		
		}
		
		if(main_form.hi_degree.value=="")
		{
			alert("Please Select Degree");
			main_form.hi_degree.focus();
			return false;
		}	 
	 
	 	if(main_form.hi_degree2.value!="")
		{
			if(main_form.pg_year.value == "")
			{
			alert("Please Select The Year For " + main_form.hi_degree2.value);
			main_form.pg_year.focus();
			return false;
			}
		}
	return true;
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false;
		 }

 		 return true;					
	}

function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false;
	}
	return true;
 }
 
 
function validateZIP()
	 {
		var valid = "0123456789";
		if(main_form.pin.value=="")
		{
		 alert("please enter the pincode");
		 main_form.pin.focus();
		 return false;
		}
			
		if(isNaN(main_form.pin.value))
		{
		  alert('please entre the number digit');		
		  main_form.pin.focus();
		  return false;
		}
		
		
		
		if (main_form.pin.length<7) 
			{
				alert(parseInt(main_form.pin.value));
				alert("Please enter your 6 digit  zip code.");
				main_form.pin.focus();
				return false;
			}
			
			
			for(temp=0;temp<main_form.pin.length;temp++)
			{
				if (valid.indexOf(temp) == "-1") 
			{
				alert("Invalid characters in your zip code.  Please try again.");
				main_form.pin.focus();
				return false;
			}
		}
					
	return true;
	}
	
	function page_onunload()
	{
		main_form.action='window_unload.php';
  		//frm_user.submit();
		return true;
	}
*/