// JavaScript Document

// TRIM FUNCTION IN JAVASCRIPT
function jTrim(str)
{  while(str.charAt(0) == (" ") )
  {  
  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
  return str;
}


// FUNCTION FOR VALIDATION OF FORM

// USE THIC FINCTION onKeyPress EVENT OF INPUT BOX

function chkChars(type,SChars)
{

// type 
// 'A' ALPHABETS
// 'N' NUMERIC
// 'AN' APLPHA NUMERIC

// SChars :- All the Special Character that you don't wanna check Pass them like -!=+


if(SChars.indexOf(String.fromCharCode(window.event.keyCode))>=0)
{
return true;
}

if (window.event.keyCode==32)  // Check For Space Key
{
return true;
}
if (window.event.keyCode==13)  // Check For Enter Key
{
return true;
}


switch(type)
	{				
		case 'A':	// Parameter 'A' used for Alphabets Only
			{		
				if ((window.event.keyCode<65 || window.event.keyCode>122) && (window.event.keyCode<90 || window.event.keyCode>97) ) 
				{
				window.event.returnValue=false;
				alert("Please Enter Only Alphabets");
				}
				break;
			}		// Case A End

		case 'N':	// Parameter 'N' used for Numbers Only
			{
				if ((window.event.keyCode<48 || window.event.keyCode>57)) 
				{
				window.event.returnValue=false;
				alert("Please Enter Only Numeric Values");
				}
				break;
			}
		case 'AN':
			{
				if ((window.event.keyCode<48) ||(window.event.keyCode>57 && window.event.keyCode<65) || window.event.keyCode>122 || (window.event.keyCode>90 && window.event.keyCode<97)) 
				{
				window.event.returnValue=false;
				alert("Please Enter Only Alpha Numeric Values");
				}
				break;
			}	
	}			
}

//--------------------------------------Comparing Date Just Return True and false d1 is less then d2 return true else false--------------------------------------------
function compDate(d1,d2)
{
var dd1=new Date(convDate(d1))
var dd2=new Date(convDate(d2))
var a=dd1.getTime()
var b=dd2.getTime()
if (a<b)
{
return true
}
if (a>b)
{
return false
}

}

function convDate(dt)
{
d=dt.split("-")
mon=d[1]
switch (mon)
{
case "Jan" :
m="01"
break
case "Feb" :
m="02"
break
case "Mar" :
m="03"
break
case "Apr" :
m="04"
break
case "May" :
m="05"
break
case "Jun" :
m="06"
break
case "Jul" :
m="07"
break
case "Aug" :
m="08"
break
case "Sep" :
m="09"
break
case "Oct" :
m="10"
break
case "Nov" :
m="11"
break
case "Dec" :
m="12"
break
}
s=m+"/"+d[0]+"/"+d[2]
return s
}


//-----------------------------------------------Count of characters on typing------------------------------------
function countChars(maxLength,val)
{
//alert(window.event.keyCode)
if(val.value.indexOf(String.fromCharCode(window.event.keyCode))>=0)
{
return true;
}

if (window.event.keyCode==46)  // Check For Delete Key
{
return true;
}

if (window.event.keyCode==32)  // Check For Space Key
{
return true;
}
if (window.event.keyCode==13)  // Check For Enter Key
{
return true;
}

var c=val.value.length+1
//alert(c)
if(c>maxLength)
{
	window.event.returnValue=false;
}
}


//----------------------------------------Check for Email validation----------------------------------------------------------
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)
		{
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		    return false
		}
		 if (str.indexOf(at,(lat+1))!=-1)
		 {
		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		 {
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1)
		 {
		    return false
		 }
		 if (str.indexOf(" ")!=-1)
		 {
		    return false
		 }
		for(i=1; i<=lstr-1;i++)
		{
			if (str.charAt(i)==dot && str.charAt(i-1)==dot)
			{
				return false
			}
		}

 		 return true					
}

//Check for valid numaric value

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   var dotch=0	
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }

   var d=sText.split(".")
	if (d.length>2)
	{
		IsNumber=false;
	}
	if(d.length==2)
	{
		if(d[1]=="")
		{
		IsNumber=false;			
		}
	}
   }
   return IsNumber;
   
   }
  
  
  //Disabele functionkey
    function disablefunctionkey()
    {
		//alert('hi------');
		
		document.onkeydown =function(){

///alert("window.event--"+window.event);
//alert("window.event.keyCode--"+window.event.keyCode);
//F5
if(window.event && window.event.keyCode == 116){
window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 505){
alert("Sorry! This Functionality is Blocked..")
return false;
}

//F11
if(window.event && window.event.keyCode == 122){
window.event.keyCode = 505;
}

if(window.event && window.event.keyCode == 505){
alert("Sorry! This Functionality is Blocked..")
return false;
}

//F4
if(window.event && window.event.keyCode == 115){
window.event.keyCode = 505;
}

if(window.event && window.event.keyCode == 505){
alert("Sorry! This Functionality is Blocked..")
return false;
}



//Blocking ALT key
//if(window.event && window.event.keyCode == 18){
//window.event.keyCode = 505;
//}

if(window.event && window.event.keyCode == 505){
alert("Sorry! This Functionality is Blocked..")
return false;
}

/////////////disable Ctrls
if (window.event.ctrlKey)
		 {
		if (window.event.keyCode == 65) 
		alert('Function Not Allowed'); //A
     //   if (window.event.keyCode == 67) 
		//alert('Function Not Allowed'); //C
		if (window.event.keyCode == 78) 
		alert('Function Not Allowed'); //N
		//if (window.event.keyCode == 86) 
		//alert('Function Not Allowed'); //V
		}


/////////////

}
}








//Disabelling Right Clicks
function disablerightclick()
{
//alert('RIGHT CLICK');
document.oncontextmenu = function NoRightClick () {
      alert("This function is disabled!");
      return false;
};

}


//  Disable/Enable a Text Box
function EnableTextBox(txtname)
{
	txtname.disabled=false
	txtname.style.background="#00FFFF"
	txtname.select()
}

function DisableTextBox(txtname)
{
	
	txtname.disabled=true
	txtname.style.background="#f8f8f8"
	//txtname.focus()
}