/*
* Name of Project		: College E Cube
* Name of Module		: Common Functions
* Functionality 		: Javascript Functions
* Author			: Nitin Dubey
* Date				: 20/10/2003
* Review			: 
* Date				:
* Modified by			:
* Date and Remark		:
*/

//-------------------------------------------------------------------
// isNull(value)
//   Returns true if value is null
//-------------------------------------------------------------------
function isNull(val)	{
	return(val==null);
}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val)	{
	if(val==null)	{
		return true;
	}
	for(var i=0;i<val.length;i++)	{
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))	{
			return false;
		}
	}
	return true;
}


function isSpecialAddressChar(val)	{
	var counter		= 0;
	var	singleChar	= "";
	var	invalidChars	=  "`~@#$%^*+=|\;:>?!";

	for(counter = -1;counter < val.length-1; counter++)	{
		singleChar	= val.substr(counter + 1, 1);
		if(invalidChars.indexOf(singleChar) != -1 ){
			return true;
		}
	}
	return false;
}





//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val)	{
	var counter		= 0;
	var	singleChar	= "";
	var	validChars	= "0123456789";
	
	if(isBlank(val))
		return false;
		
	for(;counter < val.length; counter++)	{
		singleChar	= val.substr(counter + 1, 1);
		if(validChars.indexOf(singleChar) == -1)
			return false;
	}
	return true;		
}

//-------------------------------------------------------------------
// isNumeric(value)
//   Returns true if value contains a positive float value
//-------------------------------------------------------------------
function isNumeric(val)	{
	return(parseFloat(val,10)==(val*1));
}

//------------------------------------------------------------------
// isComboSelected(formName, comboName)
//		Returns true if a value is selected else false;
//------------------------------------------------------------------
function isComboSelected(formName, comboName)	{
	var	str	= "window.document." + formName + "." + comboName + ".value";
	if(eval(str) != 0)
		return true;
	else
		return false;
}

//------------------------------------------------------------------
// getSelectedCheckboxCount(formNameString, comboNameString)
//		Returns the number of checked checkboxes in the form that start with comboNameString;
//------------------------------------------------------------------
function getSelectedCheckboxCount(formNameString, checkboxNameString)	{
	
	var	tempString		= "";
	var	noOfFields		= eval("window.document." + formNameString + ".elements.length");
	var	checkBoxCount	= 0;
	var	counter			= 0;

	
	for(;counter < noOfFields; counter++)	{
		tempString	= "document." + formNameString + ".elements[" + counter + "]";
		if(	eval(tempString + ".type") == 'checkbox'
			 && eval(tempString + ".name.substring(0, " + checkboxNameString.length + ")") == checkboxNameString	)	{

				if(eval(tempString + ".checked") == true)	{
					checkBoxCount++;
				}
		}
	}

	return checkBoxCount;
}


//------------------------------------------------------------------
// checkEmail(value)
//		Returns true if email is valid.
//------------------------------------------------------------------

/*function isEMail(str2)
{
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str2))
{
	return true;
}
	return false;
}*/

function isEMail(fld)
{
// simple email check
/*  var phony= /@(\w+\.)*example\.(com|net|org)$/i;
  if(phony.test(fld))
  { return false; }
  var emailfmt= /^\w+([.-]\w+)*@\w+([.-]\w+)*\.\w{2,8}$/;
  if(!emailfmt.test(fld))
  {  return false; }
  return true; 
  */
  if(fld.search(/^[A-Za-z](([A-Za-z0-9])|(\.[A-Za-z0-9])|(\_[A-Za-z0-9]))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!= -1)
		return true;
	else
		return false;
		
}


//------------------------------------------------------------------
// isPhoneNumber(value)
//		This function is used to validate the phone number and returns the message.
//------------------------------------------------------------------

function isPhoneNumber(phoneNo)	{
	var validChars	= "0123456789-+";
	var	counter		= 0;
	var singleChar	= "";
	var phoneLength;
	var cnt = 0;   //Is used to check for two consecutive '-'
	var cnt1 = 0;  //Is used to check for more than two '-'
	var message;
	
	if(isBlank(phoneNo))
	 return message;
	 
	phoneLength=phoneNo.length;

	//Checks for more than two consecutive '0' in the starting position of the number.
	if((phoneNo.substring(0,3)=='000')||((phoneNo.substring(0,1)=='+')&&(phoneNo.substring(1,3)=='00')))
		message="Invalid zeros; valid number like +91-08345-123456";

	//This loop checks for all the digits and '-' and '+' characters.

	for(;counter <= validChars.length; counter++)	{

		singleChar	= phoneNo.substr(counter, 1);

		//Checks for '+' character in the number.
		if(counter>0 && singleChar=='+')
			message="'+' not allowed from second position; valid number like +91-08345-123456";
		//Checks for numbers after '+'
		if((phoneNo.substring(0,1) == '+') && (phoneNo.substring(1,2) == '-'))
			message = "After '+' only numbers are allowed; valid number like +91-08345-123456";
		//Checks for '-' in first and last positions in the number.
		if((phoneNo.substring(0,1)=='-')||(phoneNo.substring(phoneLength-1,phoneLength)=='-'))
			message="'-' should not be the first or last character; valid number like +91-08345-123456";
		//Checks for consecutive '-' in the number.
		else
		{
			if(cnt == 0 && singleChar == '-')
			{
				cnt++;
				cnt1++;
			}
			else if(cnt == 1 && singleChar == '-')
			{
					message="Two '-' are not allowed consecutively; valid number like +91-08345-123456";
					cnt1++;
			}
			else
				cnt = 0;
		}

		//Checks for all other than the numbers, '+', '-' in the number.
		if(validChars.indexOf(singleChar) == -1)	{
			message="Not a valid phone number; valid number like +91-08345-123456";
			break;
		}

		//Checks for the minimum length of the number to be 10.
	else if(phoneLength<10)
			message = "Minimum length is 10; valid number like +91-08345-123456";
	}
	if(cnt1 > 2)
		message = "More than two '-' are not allowed; valid number like +91-08345-123456";

	return message;
}


//------------------------------------------------------------------
//Created By   Shinu/Suresh
// isMobileNumber(value)
//		This function is used to validate the O/R phone number and returns the message.
//------------------------------------------------------------------
function isMobileNumber(phoneNo)	{
	var validChars	= "0123456789";
	var singleChar	= "";
	var phoneLength=0;
	var message = "";
	if(isBlank(phoneNo))
	 return message;
	 
	phoneLength=phoneNo.length;

	//Checks for more than one consecutive '0' in the starting position of the number.
	if(phoneNo.substring(0,2)=="00")
		message="Invalid zeros; valid number like 9194480710 or 09894480710 or 9894480710";

	

	if(phoneLength<10 || phoneLength>12)
		message="The Mobile Number should have 10 to 12 digits like 9194480710 or 09894480710 or 9894480710";
	
	for(counter=0;counter <= phoneLength; counter++)	{

		singleChar	= phoneNo.substr(counter,1);
	if(validChars.indexOf(singleChar) == -1)	{
			message="Not a valid phone number; valid number like 9194480710 or 09894480710 or 9894480710";
			break;
		}
		}
	return message;
}

function checkDecimalNumber(obj) {
	// Code added by Sumit Prakash on 22/11/05 for focusing on next control by pressing ENTER key
	if (window.event.keyCode==13) {
		var lenOfElements  = document.forms[0].elements.length;
		for(var i =0;i<lenOfElements;i++) {
			if(document.forms[0].elements[i]==obj) {
				if(document.forms[0].elements[i+1]!=null) {
					//document.forms[0].elements[i+1].focus();
					document.forms[0].elements[i+1].select();
					return;
				}
			}
		}
	}
	// end of Code of 22/11/05
	var x = obj.value;
	var len = x.length;
	var cnt = 0;
	for(var i = 0; i<len;i++) {
		if(x.substring(i,i+1)=='.') {
			cnt++;
			if(cnt>=1 && window.event.keyCode ==46) {
				window.event.keyCode = 0;

			} // end of inner if statement
		} // end of upper if statement
	} // end of for statement

	if((window.event.keyCode < 48  || window.event.keyCode > 57 ) && !(window.event.keyCode==46))
		window.event.keyCode = 0

	// Updated by Sumit Prakash on 25/11/05
	//This code does not allow to enter any values after two digit of decimal 
	/*if(cnt>=1) {
		var str = x.substring(x.indexOf(".")+1);
		if(str!=null && str.length >= 2) {
			window.event.keyCode = 0;
		}
	}*/
}
function isLandlineNumber(phoneNo)	{
	var validChars	= "0123456789-+";
	var	counter		= 0;
	var singleChar	= "";
	var phoneLength;
	var cnt = 0;   //Is used to check for two consecutive '-'
	var cnt1 = 0;  //Is used to check for more than two '-'
	var message;
	
	if(isBlank(phoneNo))
	 return message;
	 
	phoneLength=phoneNo.length;

	//Checks for more than two consecutive '0' in the starting position of the number.
	if((phoneNo.substring(0,3)=='000')||((phoneNo.substring(0,1)=='+')&&(phoneNo.substring(1,3)=='00')))
		message="Invalid zeros; valid number like +91-08345-123456";

	//This loop checks for all the digits and '-' and '+' characters.

	for(;counter <= validChars.length; counter++)	{

		singleChar	= phoneNo.substr(counter, 1);

		//Checks for '+' character in the number.
		if(counter>0 && singleChar=='+')
			message="'+' not allowed from second position; valid number like +91-08345-123456";
		//Checks for numbers after '+'
		if((phoneNo.substring(0,1) == '+') && (phoneNo.substring(1,2) == '-'))
			message = "After '+' only numbers are allowed; valid number like +91-08345-123456";
		//Checks for '-' in first and last positions in the number.
		if((phoneNo.substring(0,1)=='-')||(phoneNo.substring(phoneLength-1,phoneLength)=='-'))
			message="'-' should not be the first or last character; valid number like +91-08345-123456";
		//Checks for consecutive '-' in the number.
		else
		{
			if(cnt == 0 && singleChar == '-')
			{
				cnt++;
				cnt1++;
			}
			else if(cnt == 1 && singleChar == '-')
			{
					message="Two '-' are not allowed consecutively; valid number like +91-08345-123456";
					cnt1++;
			}
			else
				cnt = 0;
		}

		//Checks for all other than the numbers, '+', '-' in the number.
		if(validChars.indexOf(singleChar) == -1)	{
			message="Not a valid phone number; valid number like +91-08345-123456";
			break;
		}

		//Checks for the minimum length of the number to be 10.
		//else if(phoneLength<10)
			//message = "Minimum length is 10; valid number like +91-08345-123456";
	}
	if(cnt1 > 2)
		message = "More than two '-' are not allowed; valid number like +91-08345-123456";

	return message;
}







//------------------------------------------------------------------
//Checks for the valid characters in the string.
//It uses the "isBlank" function for the white space validations.
//------------------------------------------------------------------

function isCharacter(name)
{
	var nameCount = 0;
	var singleChar;
	var message;

	//Checks for each character in the loop.
	for(;nameCount<name.length;nameCount++)
	{
		singleChar = name.substr(nameCount,1);

		//Enters into this only if it is a character or space.
		if((singleChar >= 'a' && singleChar <= 'z')||(singleChar <= 'Z' && singleChar >= 'A')||(isBlank(singleChar)))
		{

			//Enters into this if the first or last character is space.
			if((name.substring(0,1)==' ') || (name.substring(name.length-1,name.length)==' '))
			{
				message="Space is not allowed in the starting or ending position";
				break;
			}
		}

		//Enters if it is not a valid character.
		else
		{
			message="Not a valid string";
		}
	}
	return message;
}


//------------------------------------------------------------------
//This function is used to validate the salary
//------------------------------------------------------------------

function chkSalary(salary)
{
	var validChars	= "0123456789.";
	var counter = 0;
	var cnt=0;
	var singleChar;
	var str="0";
	var message;

	for(;counter <= validChars.length; counter++)	{
		singleChar	= salary.substr(counter, 1);

		//Checks whether the first and last positions are '.'
		if((salary.substring(0,1)=='.')||(salary.substring(salary.length-1,salary.length)=='.'))
		{
			message="'.' is not allowed at first or last position";
			break;
		}

		if(singleChar == '.')
		{
			cnt++;
			str = salary.substring(counter+1,validChars.length);
		}
		//Checks for more than two '.' in the number.
		if(cnt>=2)
		{
			message="Only one '.' allowed";
			return message;
		}
		//Character validation is checked here.
		if(validChars.indexOf(singleChar) == -1)	{
				message="Invalid Characters are not allowed";
				break;
		}

	}
	//Checks if more than two numbers are present after '.'
	if(str.length>2)
		message="Only two numbers are allowed after '.'";

	return message;
}


//------------------------------------------------------------------
//To use this function "chkSalary" function should be called compulsorily.
//------------------------------------------------------------------

function chkPercentage(percentage)
{
	var msg;
	var flg=0;
	var len;
	var message;

	//This chkSalary function is used to check for the '.' validations and number validations.
	msg=chkSalary(percentage);

	//If the message returned from chkSalary is some error it enters into 'if' else it goes to 'else'
	if(msg)
	{
		message="Invalid Percentage";
		return message;
	}
	else
	{
		if(percentage.indexOf('.',1) > 0)
		flg=1;
	}

	//If no '.' is present in the percentage then it enters 'if' else into 'else'
	if(flg==0)
	{
		len=percentage.length;
		//If percentage length is greater than 2, it will give error
		if(len>2)
		{
			message="If '.' is not there, maximum length should be 2";
			return message;
		}
		else if(percentage == "00")
		{
			message="00 is not a valid percentage";
			return message;
		}
	}
	else
	{
		//Checks for the '.' position if it is greater than two.
		if(percentage.indexOf('.',1) > 2)
		{
			message="Not a valid percentage. The maximum value is 99.99";
			return message;
		}
		else if(percentage == "00.0"||percentage == "0.0"||percentage == "0.00"||percentage == "00.00")
		{
			message="Not a valid percentage";
			return message;
		}
	}
	return message;
}


//------------------------------------------------------------------
// getSelectedItemsInListBox(formName, listBoxName)
//		Returns the no of items selected in listbox
//------------------------------------------------------------------

function getSelectedItemsInListBox(formName, listBoxName)	{
	var	items	= eval("window.document." + formName + "." + listBoxName + ".options");
	var	nCount	= 0;
	var	counter	= 0;

	for(;counter < items.length; counter++)	{
		if(items[counter].selected)
			nCount++;
	}
	
	return nCount;
}


//------------------------------------------------------------------
//This function checks whether radio button with the same name is selcted or not.
//------------------------------------------------------------------

function getSelectedRadioCount(formNameString,radioNameString)
{

	var	tempString		= "";
	var	noOfFields		= eval("window.document." + formNameString + ".elements.length");
	var	select	= false;
	var	counter			= 0;

	for(;counter < noOfFields; counter++)	{
		tempString	= "document." + formNameString + ".elements[" + counter + "]";

		//Checks whether the type of the element for the given name is radio button or not
		if(	eval(tempString + ".type") == 'radio'
			 && eval(tempString + ".name.substring(0, " + radioNameString.length + ")") == radioNameString	)	{
				if(eval(tempString + ".checked") == true)	{
					select = true;
					break;
				}
		}
	}

	return select;
}


//------------------------------------------------------------------
// elementCount(formName, fieldName)
//		Returns the no of times field appears in the form
//------------------------------------------------------------------
function elementCount(formNameString, elementName)	{
	var	tempString		= "";
	var	noOfFields		= eval("window.document." + formNameString + ".elements.length");
	var	nCount			= 0;
	var	counter			= 0;

	for(;counter < noOfFields; counter++)	{
		tempString	= "document." + formNameString + ".elements[" + counter + "]";
		if(eval(tempString + ".name") == elementName)
			nCount++;
	}

	return nCount;
}

//------------------------------------------------------------------
// chkName(val, flag)
//	does not allow the user to enter invalid name, flag:1 represents 
//  for name in capital letters and flag:2 representa name in capital
//  and small letters.
//------------------------------------------------------------------

function chkName(val,flag)
{

	var name1,i,chr,incr=0,temp,chr1;
	name1=val.value;
	if(flag=="1")
	{
		if(!((event.keyCode>=65 && event.keyCode<=90) || event.keyCode==32))
			event.keyCode=0;
	}
	else
	{
		if(!((event.keyCode>=65 && event.keyCode<=90) ||
		     (event.keyCode>=97 && event.keyCode<=122)  || event.keyCode==32))
			event.keyCode=0;
	
	}
}


//------------------------------------------------------------------
// checkList(this) -->added by trupti 1-5-2005
//  call this function on keyup.
//  allows the user to search the option in the combo box
//  by typing searchkey
//------------------------------------------------------------------
	var seconds = 1000;	//DELAY
	var timerID = 0;	//TIMER ID
	var keySearch =""; 	//SEARCH KEY

	function UpdateTimer() {
		if(timerID){
		   clearTimeout(timerID);//CLEAR TIMER
		   keySearch = "";//CLEAR THE SEARCH
		   lastIndex = 0;
		}
	}

	function Start() {
		clearTimeout(timerID);
	    timerID  = setTimeout("UpdateTimer()", seconds);//START THE TIMER
	}

	function checkList(selectBoxObj){
		var keyCodePressed = window.event.keyCode;//OBTAIN THE KEY PRESSED
		if(keyCodePressed >= 64 && keyCodePressed <=122){

			if(keySearch.length != 0){
				keySearch+= String.fromCharCode(keyCodePressed).toUpperCase();
			} else {
				keySearch = String.fromCharCode(keyCodePressed).toUpperCase();
			}
			setSelectBox(selectBoxObj);
			Start();
		}
	}

	function setSelectBox(selectBoxObj){
		var isMatched = 0;
		//var selectBoxObj = document.getElementById(SelectBoxName);

		for(var i = 0; i < selectBoxObj.options.length; i++){
			var opt = selectBoxObj.options[i].text;
			if(selectBoxObj.options[i].text.toUpperCase().indexOf(keySearch) == 0){
				isMatched = 1;
				selectBoxObj.options[i].selected = true;
				break;
			}
		}
	}

//-------------------------------------------------------------------



// --------------------- VIchu --------------------------------------------

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

//----------------------Subham ---------------------------------------
function validateCustname()	{ 
	{

	//alert(event.keyCode);
var name1,i,chr,incr=0,temp,chr1;
	//name1=val.value;
	if(!((event.keyCode>=65 && event.keyCode<=90) ||  event.keyCode==42 ||  event.keyCode==92 || window.event.keyCode == 32 || window.event.keyCode == 34 || window.event.keyCode == 39 ||
		     (event.keyCode>=97 && event.keyCode<=122) ||(window.event.keyCode >= 48  && window.event.keyCode <= 57 )||(window.event.keyCode>=43 && window.event.keyCode <=47) || window.event.keyCode==95 || window.event.keyCode==38 || window.event.keyCode ==40 || window.event.keyCode==41))
	     		event.keyCode=0;	
}

}
function validatePhoneNumber(){

if(!((window.event.keyCode >= 48  && window.event.keyCode <= 57 ) || window.event.keyCode ==45 ))
	event.keyCode=0;	

}

function validateEmail(){

if(!((event.keyCode>=65 && event.keyCode<=90) || (event.keyCode>=97 && event.keyCode<=122) ||(window.event.keyCode >= 48  && window.event.keyCode <= 57 ) || window.event.keyCode ==64 || window.event.keyCode==46 || window.event.keyCode==95))
	event.keyCode=0;	

}

function validateName(){
if(!((event.keyCode>=65 && event.keyCode<=90) || (event.keyCode>=97 && event.keyCode<=122)  || window.event.keyCode ==32  || window.event.keyCode ==46))
	event.keyCode=0;	

}
function validatemachine(){
        if(!((event.keyCode>=65 && event.keyCode<=90) || window.event.keyCode==47 || window.event.keyCode==95 || window.event.keyCode==92 ||
		     (event.keyCode>=97 && event.keyCode<=122) ||
		       (window.event.keyCode >= 48  && window.event.keyCode <= 57 )|| 
		       window.event.keyCode==45))
	     		event.keyCode=0;	
      
      }
      
      function	validateIAC(){
        if(!((event.keyCode>=65 && event.keyCode<=90) ||
		     (event.keyCode>=97 && event.keyCode<=122) 
		      || event.keyCode==32 || (window.event.keyCode >= 48  && window.event.keyCode <= 57 ) 
		      || window.event.keyCode==47 || window.event.keyCode==45))
	     		event.keyCode=0;	
      
      }	
      
       function validatefloat(){
 	      if(!((window.event.keyCode >= 48  && window.event.keyCode <= 57 )|| 
		       window.event.keyCode==46))
	     		event.keyCode=0;	
 	    
 	    }
     
function validateLotNo(){
if(!((event.keyCode>=65 && event.keyCode<=90) || window.event.keyCode == 32 || 
		     (event.keyCode>=97 && event.keyCode<=122) ||(window.event.keyCode >= 48  && window.event.keyCode <= 57 )|| window.event.keyCode==44 || window.event.keyCode ==45 || window.event.keyCode ==47 || window.event.keyCode==95  || window.event.keyCode ==40 || window.event.keyCode ==92  || window.event.keyCode==41))
	     		event.keyCode=0;	


}


//-------------------------------------------------------------------------
//         Function check for positive integer. It can take 0 as well. 
//          If entered -0. It won't flash an error but will finally make it to 0.
  
function checkPositiveInteger(val)
{
       
     if  (isNaN(val)  || (val < 0.0 ) )
     {
 		return false;
     }
     if (val == -0) 
     {
	    val = 0;
        return true;
     }
      return true;
}

//-------------------------------------------------------------------------------
//		Function dose not allow values less than or equal to 0

function checkZero(val)
{
   if (val <= 0 )   
	   return true;
}

//--------------------------------------------------------------------------------
//  	Function for checking dot(.) in numeric value. Dot should not be allowed.

function checkDot(val)
{
     if ((val.indexOf("." )) != -1  )
     //return true;
     return false;
}

//----------------------------------------------------------------------------------
//  Function does not allow to enter the spevial characters.

function isSpecialChar(val)	{

	var counter		= 0;
	var	singleChar	= "";
	var	invalidChars	= "`_.~@#$%^&*+=|\';:<{}>?,/()!";

	for(counter = -1;counter < val.length-1; counter++)	{
		singleChar	= val.substr(counter + 1, 1);
		if(invalidChars.indexOf(singleChar) != -1 ){
			return true;
		}
	}
	return false;
}

//  Function does not allow to enter the Number characters.

function isNumber(val)	{

	var counter		= 0;
	var	singleChar	= "";
	var	invalidChars	= "0123456789";

	for(counter = -1;counter < val.length-1; counter++)	{
		singleChar	= val.substr(counter + 1, 1);
		if(invalidChars.indexOf(singleChar) != -1 ){
			return true;
		}
	}
	return false;
}

function isAlphabate(val)	{

	//Checks for each character in the loop.
	var counter		= 0;
	var	singleChar	= "";
	var	invalidChars	= "[A-Za-z]";

	for(counter = -1;counter < val.length-1; counter++)	{
		singleChar	= val.substr(counter + 1, 1);
	  if(singleChar.search(/^[A-Za-z]/)!= -1)
		 	 return true;
		
	}
	return false;
}

function  stopSpecialChar()
	{
	if((window.event.keyCode >= 33  && window.event.keyCode <= 44) || (window.event.keyCode >= 46  && window.event.keyCode < 48) || (window.event.keyCode > 57  && window.event.keyCode <= 64) || window.event.keyCode == 96 || (window.event.keyCode >= 91  && window.event.keyCode <= 94) || (window.event.keyCode >= 123  && window.event.keyCode <= 126))
	{
	window.event.keyCode = 0;
	}
	}



//------------------------------------------------------------------------------
//function restrictNumberOfChars(txtobj,max)  added by ashok m
//function to restrict the number of characters for a textarea
//first param-textarea being validated, second param-maximum number of allowed chars.
//to be called for onkeypress event
//--------------------------------------------------------------------------------
function restrictNumberOfChars(txtobj,max){
			var str=txtobj.value;
			var len=str.length;
			if(len>=max){	
			 window.event.keyCode=0;
			 
			}	
		}//end of function
		
//----------------------------------------------------------------------------------
//function restrictPastedNumberOfChars(txtobj,max)  added by ashok m
//function to restrict the number of characters for a textarea when text is pasted into the textarea
//first param-textarea being validated, second param-maximum number of allowed chars., third param is name of field to be shown in alert
//to be called for onblur event of textarea 
//-----------------------------------------------------------------------------------

		
		function restrictPastedNumberOfChars(txtobj,max,displayname){

			var str=txtobj.value;
			var len=str.length;
			if(len>max){
				alert("Length of "+displayname+" exceeded.");
				txtobj.value="";
				txtobj.focus();
				}//end of if

			}//end of function
		
		
//---------------------- DATE VALIDATION -----------------------------------------------------------------------------------
function hasInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function DaysArray(n)
{
	for (var i = 1; i <= n; i++)
	{
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}
function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function stripCharsInBag(s, bag)
{
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function isDate(dtStr,dtCh){
	// Declaring valid date character, minimum year and maximum year
	//var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	// ending of declaration
	var returnval = false // returning value to calling function
	var daysInMonth = DaysArray(12)
	var pos1 = dtStr.indexOf(dtCh)
	var pos2 = dtStr.indexOf(dtCh,pos1+1)
	var strDay = dtStr.substring(0,pos1)
	var strMonth = dtStr.substring(pos1+1,pos2)
	var strYear = dtStr.substring(pos2+1)
	strYr = strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month = parseInt(strMonth)
	day = parseInt(strDay)
	year = parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd"+dtCh+"mm"+dtCh+"yyyy")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || hasInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}

return true
}


//=============================================== END OF DATE VALIDATION ===================================================			
//----------------------------------------------------------------------------------------------------------------------------------
//checkPastedSpecialChars(obj,msg)     added by ashok m
//function to check for special characters which may be copy-pasted into the text box
//first parameter-textbox being validated. second parameter-message to be displayed if special chars are found
//------------------------------------------------------------------------------------------------------------------------------


function checkPastedSpecialChars(obj,msg){

var str = obj.value;

var len = str.length;
var singlecharcode;
for(var i=0;i<len;i++)
 {
	singlecharcode = str.charCodeAt(i);

	if((singlecharcode >= 33  && singlecharcode <= 44) || (singlecharcode == 47) || (singlecharcode >= 58  && singlecharcode <= 64) || singlecharcode == 96 || (singlecharcode >= 91  && singlecharcode <= 94) || (singlecharcode >= 123  && singlecharcode <= 126))
		{
			alert(msg);
			obj.value="";
			obj.focus();
			return;
		}

  }

}			
			
			
			
	function trim(s) {
		// Remove leading spaces and carriage returns
		while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')) { 
			s = s.substring(1,s.length); 
		}
		// Remove trailing spaces and carriage returns
		while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')) {
			s = s.substring(0,s.length-1);
		}
		return s;
	}	
	
function Isnum(){	
	if (window.event.keyCode < 48  || window.event.keyCode > 57)
		window.event.keyCode = 0;
}//

function IsFloat(){	
	if (window.event.keyCode == 47 || window.event.keyCode < 46 || window.event.keyCode > 57)
		window.event.keyCode = 0;
}	


function colorrow(CONTROL1)
	{
		var i=CONTROL1.childNodes.length;

		for (var j=0;j<i;j++)
		{
	     	CONTROL1.childNodes[j].className="MTTD3";
	   		
		}
	
 

	}

function uncolorrow(CONTROL)
{
	var i=CONTROL.childNodes.length;

	
	for (var j=0;j<i;j++)
	{
	   
 		CONTROL.childNodes[j].className="MTTD2";
	}
}
       
  
  // function for the checking the decimal number
// it allows user to enter the numeric value and one decimal. After decimal user can enter only two digits
function checkDecimalNumber(obj) {
	// Code added by Sumit Prakash on 22/11/05 for focusing on next control by pressing ENTER key
	if (window.event.keyCode==13) {
		var lenOfElements  = document.forms[0].elements.length;
		for(var i =0;i<lenOfElements;i++) {
			if(document.forms[0].elements[i]==obj) {
				if(document.forms[0].elements[i+1]!=null) {
					//document.forms[0].elements[i+1].focus();
					document.forms[0].elements[i+1].select();
					return;
				}
			}
		}
	}
	// end of Code of 22/11/05
	var x = obj.value;
	var len = x.length;
	var cnt = 0;
	for(var i = 0; i<len;i++) {
		if(x.substring(i,i+1)=='.') {
			cnt++;
			if(cnt>=1 && window.event.keyCode ==46) {
				window.event.keyCode = 0;

			} // end of inner if statement
		} // end of upper if statement
	} // end of for statement

	
	
	if((window.event.keyCode < 48  || window.event.keyCode > 57 ) && !(window.event.keyCode==46))
		window.event.keyCode = 0
		
	else if(x.substring(0,2)=='00' || x.substring(0,3)=='0.0' || x.substring(0,2)=='.0') {           
			cnt++;  
			if(cnt>=1  && !(window.event.keyCode < 48  || window.event.keyCode > 57) && !(window.event.keyCode==46)) {      
				window.event.keyCode = 0; 
       
			} // end of inner if statement  
		}



	// Updated by Sumit Prakash on 25/11/05
	//This code does not allow to enter any values after two digit of decimal 
	/*if(cnt>=1) {
		var str = x.substring(x.indexOf(".")+1);
		if(str!=null && str.length >= 2) {
			window.event.keyCode = 0;
		}
	}*/
	
	function chkAllCheckBox(formNameString, checkboxNameString , chkbox)	
{


	var	tempString		= "";
	var	noOfFields		= eval("window.document." + formNameString + ".elements.length");
	

	var	counter			= 0;

	for(;counter < noOfFields; counter++)	
	{
		tempString	= "document." + formNameString + ".elements[" + counter + "]";
		if(	eval(tempString + ".type") == 'checkbox'
			 && eval(tempString + ".name.substring(0, " + checkboxNameString.length + ")") == checkboxNameString	)	
			{

				if(eval(tempString + ".checked") == true)	
				{
						var	noOfchk		= eval("window.document."+formNameString+"."+chkbox);
						var noOfchkbox = noOfchk.length;
						
						if(noOfchkbox){
							for(var count = 0;count < noOfchkbox; count++)
							{


								noOfchk[count].checked = true;
							}
						}else{
							noOfchk.checked = true;
						}
				}
				else
				{
						var	noOfchk		= eval("window.document." + formNameString + "."+chkbox);
						var noOfchkbox = noOfchk.length;
						
						if(noOfchkbox){
							for(var count = 0;count < noOfchkbox; count++)
							{


								noOfchk[count].checked = false;
							}
						}else{
							noOfchk.checked = false;
						}
				}
				
					
						
				
			}
	}

	return true;
}


function chkAllBox(formNameString, checkboxNameString , chkbox)
{

	var	tempString		= "";
	var	noOfFields		= eval("window.document." + formNameString + ".elements.length");


	var	counter			= 0;

	for(;counter < noOfFields; counter++)
	{
		tempString	= "document." + formNameString + ".elements[" + counter + "]";
		if(	eval(tempString + ".type") == 'checkbox'
			 && eval(tempString + ".name.substring(0, " + checkboxNameString.length + ")") == checkboxNameString	)
			{



						var	noOfchk		= eval("window.document."+formNameString+"."+chkbox);
						var noOfchkbox = noOfchk.length;
						var flag = true;

						for(var count = 0;count < noOfchkbox; count++)
						{

							if(noOfchk[count].checked != true){
								flag = false;
								break;
							}
						}
						
					if(!noOfchkbox && noOfchk.checked == false){
						flag = false;
					}

				        var temp  = eval(tempString);
				        if(flag == true)
				        {
				        	temp.checked = true;
				        	return;
				        }else if(flag == false){
							temp.checked = false;
							return;
				        }			}
	}

	return true;
}
	

}

