
//pass the textbox value for checking sqlinjection
//It will check for any special character that match with the values we specified. 
//If invalid character is found it will gice alert and return 0.

function chktxt(txtvalue)
{

		var tval =txtvalue;
		myArray = new Array("<",">","'","!","$","%","-","(",")",";","=","#","^","||","&");
		var len =myArray.length;
		var tlen = tval.length;
		if (tlen ==0)
		{
		return 0;
		}
		for (var x = 0; x <= len - 1 ; x++)
			{
				for (var y = 0; y <= tlen; y++)
					{
					if (myArray[x] == tval.charAt(y))
					{
					alert("Invalid Characters found in entries..Please Check!!");
					return 0;					
					}
				//	else
					//return true;}
				}
			}
		}
//*************************************************************************************		

function chktxt1(txtvalue)
{

		var tval =txtvalue;
		myArray = new Array("<",">","'","!","$","%","(",")",";","=","#","^","||","&");
		var len =myArray.length;
		var tlen = tval.length;
		if (tlen ==0)
		{
		return 0;
		}
		for (var x = 0; x <= len - 1 ; x++)
			{
				for (var y = 0; y <= tlen; y++)
					{
					if (myArray[x] == tval.charAt(y))
					{
					alert("Invalid Characters found in entries..Please Check!!");
					return 0;					
					}
				//	else
					//return true;}
				}
			}
		}
//*************************************************************************************		

function gotot()
{
   var sTargetURL = "k_home.aspx";
  location.href = sTargetURL;
    
}

//*************************************************************************************

function indexchange(element,message)
{
  var mess = message;
  var ddl = document.getElementById(element);
  var dd = ddl.selectedIndex;
  if (dd == 0)
  {
  alert("Select a " + message);
  }
}

//*************************************************************************************


function gotoadmin()
{
   var sTargetURL ="k_training_adminhome.aspx";
  location.href = sTargetURL;
    
}

//*************************************************************************************

//check whether the value entered is numeric and check the range of acceptable integers
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = 1;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         alert("Should be Numeric");
         blnResult = 0;
         }
      }
   return blnResult;
   }

 //*************************************************************************************
 
 function md5auth(element,element2,element3,seed)
		{
				var btn =document.getElementById(element);
				
				var password = document.getElementById(element2).value;
				//password =decryption2(element2);
				if (password.length = 0 || password.length >10)
					{
						alert("Password field cannot be blank");
						return false;
					}
				var rno = decryption(seed);
				seed = rno;
				var pwdhash = hex_md5(password);
				
				var hash= hex_md5(seed + pwdhash);
				document.getElementById(element3).value = hash;
				document.getElementById(element2).value = hash;
				btn.focus();
				return false;
}
 
 
 
 var pas;

function md5auth1(element,element2,element3,seed)
		{
				var btn =document.getElementById(element);
				var password = document.getElementById(element2).value;
				//var pas=document.getElementById(element).value;
			
				//password =decryption2(element2);
				if (password.length = 0 || password.length >10)
					{
						alert("Password field cannot be blank");
						return false;
					}
					
				var rno = decryption(seed);
				seed = rno;
				var pwdhash = hex_md5(password);
				pas=pwdhash;
				var hash= hex_md5(seed + pwdhash);
				document.getElementById(element3).value = hash;
				document.getElementById(element2).value = hash;
				btn.focus();	
				return false;
}

 /*//*************************************************************************************
function md5pwd(element,element2)
		{
				
				var password = document.getElementById(element).value;
				alert(password);
				var pwdhash = hex_md5(password);
				alert(pwdhash);
				document.getElementById(element2).value = pwdhash;
				return false;
}*/
 //*************************************************************************************

function clearpwd(element)
		{
				
				var password = document.getElementById(element).value;
				if (password.length = 0)
					{
						return true;
					}
					else
					{
					document.getElementById(element).value ='';
					}
		}


// *******Decryption*********************// ****************************// ****

function decryption(element)
		{
			var str = element;
			var asci = '';
			
				for (var y =0; y < str.length; y++)
					{
						var charc=128 - ascii_value((str.charAt(y)));
						var asci = asci.concat(String.fromCharCode(charc));
					}					
					return asci;
		}
		
	
// *******Encryption*********************// ****************************// ****
		function encryption(element)
		{
			var str = document.getElementById(element).value;
		var tlen = str.length;
		if (tlen ==0)
		{
		return 0;
		}
			chktxt1(str);
					
			var asci = '';
			if (str.length < 4 || str.length >10)
					{
					alert("Password should contain characters between 4 and 10");
					return 0;
					}
				for (var y =0; y < str.length; y++)
					{
						var charc= ascii_value((str.charAt(y))) + 8;
						var asci = asci.concat(String.fromCharCode(charc));
					}
			document.getElementById(element).value = asci;
			
			return asci;
		}
	//	*******Encryption2*********************// ****************************// ****	
	function encryption2(element,element2)
		{
		
		var str = document.getElementById(element).value;
		var tlen = str.length;
		if (tlen ==0)
		{
		return 0;
		}
		chktxt1(str);
		md5pwd(element,element2);
		
		var asci = '';
		if (str.length < 4 || str.length >10)
					{
					alert("Password should contain characters between 4 and 10");
					return 0;
					}
				for (var y =0; y < str.length; y++)
					{
						var charc= ascii_value((str.charAt(y))) + 8;
						var asci = asci.concat(String.fromCharCode(charc));
					}
			document.getElementById(element).value = asci;
			return asci;
		}
		
//	*******Decryption2*********************// ****************************// ****	
			function decryption2(element)
		{
			var str = document.getElementById(element).value;
			
			var asci = '';
			for (var y =0; y < str.length; y++)
					{
						var charc= ascii_value((str.charAt(y)))-128;
						var asci = asci.concat(String.fromCharCode(charc));
					}
			return asci;
		}
		
// *******Ascii Value*********************// ****************************// ********

function ascii_value (c)
	{
	// restrict input to a single character
		c = c.charAt(0);
	// loop through all possible ASCII values
	var i;
	for (i = 0; i < 256; ++ i)
	{
		// convert i into a 2-digit hex string
		var h = i.toString (16);
		if (h.length == 1)
			h = "0" + h;

		// insert a % character into the string
		h = "%" + h;

		// determine the character represented by the escape code
		h = unescape(h);

		// if the characters match, we've found the ASCII value
		if (h == c)
			break;
	}
	return i;
}

// ****************************// ****************************// ****************************
var oLastBtn=0;
	bIsMenu = false;
	//No RIGHT CLICK************************
	
	if (window.Event) 
	document.captureEvents(Event.MOUSEUP); 
	function nocontextmenu()
	{ 
	event.cancelBubble = true 
	event.returnValue = false; 
	return false; 
	} 
	function norightclick(e) 
	{ 
	if (window.Event) 
	{ 
	if (e.which !=1) 
	return false; 
	} 
	else 
	if (event.button !=1) 
	{ 
	event.cancelBubble = true 
	event.returnValue = false; 
	return false; 
	} 
	} 
	document.oncontextmenu = nocontextmenu; 
	document.onmousedown = norightclick; 
	//**************************************
	// ****************************
	// Block backspace onKeyDown************
	// ***************************


    	 function onKeyDown() {
    	 	if ( (event.altKey) || ((event.keyCode == 8) && 
    	 			(event.srcElement.type != "text" &&
    	 			event.srcElement.type != "textarea" &&
    	 			event.srcElement.type != "password")) || 
    	 			((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82)) ) ||
    	 	
        	 			(event.keyCode == 116) ) {
        	 		event.keyCode = 0;
        	 		event.returnValue = false;
        	 	}
        	 }


			
//********************check email********************************
function emailcheck(tmail) {
				var str =tmail.value;
				if (str == null){
				//alert("Enter valid email id");
				return false;
				}
				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){
						tmail.value="";
						alert("Invalid E-mail ID");
						return false;
					}
					if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
						tmail.value="";
						alert("Invalid E-mail ID");
						return false;
					}
					if (str.indexOf(at,(lat+1))!=-1){
						tmail.value="";
						alert("Invalid E-mail ID");
						return false;	
					}
					if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
						tmail.value="";
						alert("Invalid E-mail ID");
						return false;
					}
					if (str.indexOf(dot,(lat+2))==-1){
						tmail.value="";
						alert("Invalid E-mail ID");
						return false;
					}
				 if (str.indexOf(" ")!=-1){
					    tmail.value="";
					    alert("Invalid E-mail ID");
						return false;
					}
		 		 return true;					
		}
		
		////*******************md5 without salting and without encryption***********

function md5pwd(element)
		{
				
				//var password = document.getElementById(element).value;
				var password = element;
				
				//chktxt(password);
				if (password.length = 0 )
					{
						alert("Please enter a valid password");
						return 0;
					}
					
				var pwdhash = hex_md5(password);
				
				//document.getElementById(element).value =pwdhash;
				element=pwdhash;
				//alert(element);
				return element;
}
//*****************************md5 without salting*********************
function md5pwd1(element,element2)
		{
				
				//var password = document.getElementById(element).value;
				
				var password = element;
				
				
				//chktxt(password);
				encryption3(element,element2);
				if (password.length = 0)
					{
						alert("Please enter a valid password");
						return 0;
					}
					
				var pwdhash = hex_md5(password);
				if (pwdhash==pas)
				{
				alert('New password and Old password are same!!!');	
				pwdhash='';
				document.getElementById('txtnewpwd').value = '';
				}
				else
				//document.getElementById(element).value =pwdhash;
				{
				element=pwdhash;
				//alert(element);
				return element;
				}
}

//**********************************************************************
//	*******Encryption3*********************// ****************************// ****	
			function encryption3(element,element2)
		{
		
			var str = element;
			
				
			var asci = '';
			if (str.length < 4 || str.length >10)
					{
					alert("Password should contain characters between 4 and 10");
					return 0;
					}
				for (var y =0; y < str.length; y++)
					{
						var charc= 128 + ascii_value((str.charAt(y)));
						var asci = asci.concat(String.fromCharCode(charc));
					}
					
			document.getElementById(element2).value = asci;
			
			return asci;
		}
		
//********************check email*************************************************

//function cleardropdown(element)
//{
//var str = document.getElementById(element);
//str.selectedIndex =0;
//alert(str);
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//pass the textbox value of address for checking sqlinjection
//It will check for any special character that match with the values we specified. 
//If invalid character is found it will gice alert and return 0.
		
function chkadd(txtvalue)
{
        var tval =txtvalue;
		myArray = new Array("<",">");
		var len =myArray.length;
		var tlen = tval.length;
		if (tlen ==0)
		{
		return 0;
		}
		for (var x = 0; x <= len - 1 ; x++)
			{
				for (var y = 0; y <= tlen; y++)
					{
					if (myArray[x] == tval.charAt(y))
					{
					alert("Invalid Characters found in entries..Please Check!!");
					return 0;					
					}
				//	else
					//return true;}
				}
			}
		}







function passwordChanged(txtvalue,element) 
{
var result;
var lowercase="abcdefghijklmnopqrstuvwxyz";
var uppercase="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var num="0123456789";
var special="!@#$%^&*()_+|\=-{}[]:,./?";
var password=txtvalue;
var length=password.length;
var containslowercase=contains(password,lowercase);
var containsuppercase=contains(password,uppercase);
var containsnum=contains(password,num);
var containsspecial=contains(password,special);
if (length>=8)
{
if (containslowercase)
{

   if (containsuppercase)
    { 
     //alert("uppercase");
        if(containsnum)
        {
             if(containsspecial)
             {
            // result="Password is Strong.";
             document.getElementById('txtnewpwd').value = md5pwd(password);
			 }
			 else
			 {
		    alert("Password is not Strong.Password must have minimum 8 character having at least 1 numeric,1 upper case,1 lower case and 1 special character.");
     		 document.getElementById('txtnewpwd').value="";
     		 }
        }
        else
        {
         alert("Password is not Strong.Password must have minimum 8 character having at least 1 numeric,1 upper case,1 lower case and 1 special character.");
         document.getElementById('txtnewpwd').value="";
        }
     } 
     else
     {
     alert("Password is not Strong.Password must have minimum 8 character having at least 1 numeric,1 upper case,1 lower case and 1 special character.");
     document.getElementById('txtnewpwd').value="";
     }
}
else
{
 alert("Password is not Strong.Password must have minimum 8 character having at least 1 numeric,1 upper case,1 lower case and 1 special character.");
 document.getElementById('txtnewpwd').value="";
}
}
else
{
alert("Password is not Strong.Password must have minimum 8 character having at least 1 numeric,1 upper case,1 lower case and 1 special character.");
document.getElementById('txtnewpwd').value="";
}
//alert(result);
md5pwd1(password,'mdp')
}

function contains(password,validChars)
{
  for (i=0;i<password.length;i++)
   {
      var chr=password.charAt(i);
      if(validChars.indexOf(chr)>-1)
      {
       return true;
      }
   }
return false;
}

function passwordChanged1(txtvalue,element) 
{
var result;
var lowercase="abcdefghijklmnopqrstuvwxyz";
var uppercase="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var num="0123456789";
var special="!@#$%^&*()_+|\=-{}[]:,./?";
var password=txtvalue;
var length=password.length;
var containslowercase=contains(password,lowercase);
var containsuppercase=contains(password,uppercase);
var containsnum=contains(password,num);
var containsspecial=contains(password,special);
if (length>=8)
{
if (containslowercase)
{

   if (containsuppercase)
    { 
     //alert("uppercase");
        if(containsnum)
        {
             if(containsspecial)
             {
            // result="Password is Strong.";
             document.getElementById('txtpwd').value = md5pwd(password);
			 }
			 else
			 {
		    alert("Password is not Strong.Password must have minimum 8 character having at least 1 numeric,1 upper case,1 lower case and 1 special character.");
     		 document.getElementById('txtpwd').value="";
     		 }
        }
        else
        {
         alert("Password is not Strong.Password must have minimum 8 character having at least 1 numeric,1 upper case,1 lower case and 1 special character.");
         document.getElementById('txtpwd').value="";
        }
     } 
     else
     {
     alert("Password is not Strong.Password must have minimum 8 character having at least 1 numeric,1 upper case,1 lower case and 1 special character.");
     document.getElementById('txtpwd').value="";
     }
}
else
{
 alert("Password is not Strong.Password must have minimum 8 character having at least 1 numeric,1 upper case,1 lower case and 1 special character.");
 document.getElementById('txtpwd').value="";
}
}
else
{
alert("Password is not Strong.Password must have minimum 8 character having at least 1 numeric,1 upper case,1 lower case and 1 special character.");
document.getElementById('txtpwd').value="";
}
//alert(result);

}





