/* 
'=========================================================================
' Revision History
'=========================================================================
' Page Name	: ePZBCommon.js
' Page Author	: Unknown
' Date Written	:	04/03/2003
' Revision #		: 0
' Reason			: 
' Description	: Common file to be used by all of ePZB
'==========================================================================
' Revision #		: 1
' Date				: 12/21/2004
' Programmer	: Rich Ingves
' Reason			: cares # 74604
' Description	: changed error message
'=================================================================================
'==========================================================================
' Revision #		: 11
' Date				: 08/30/2011
' Programmer	: Sanjeev Gandhi
' Reason			: WO# 56130
' Description	: Functions added: Sleep and checkSpecialChars
'=================================================================================
*/
	/*************************************************
	*	List of Functions Included in this JS.
	*   Please update this list whenever a new
	*   function is added
	**************************************************
	*	1.isEmpty
	*	2.isPosInteger
	*	3.isInteger
	*	4.isNumber
	*	5.isAlphaNumeric
	*	6.formatDecimal
	*	7.isAlPha
	*	9.Replace
	*	10.checkScreenResolution
	*	11.formatDecimal
	*   12.isDecimal(expression,maxIntegerLen,maxDecimalLen)
	*	13.setFocusFirstField
	*	14.ltrim,	rtrim,	trim
	*   15.isEmail
	*	16.MandatoryCheck
	*	17.IsDate(objName)
	*	18.isAlphabetic (s) 'internally used by IsDate
	*	19.isLetter (c) 'internally used by IsDate
	*	20.chkdate(objName) 'internally used by IsDate
	*   22.Padding()    'For padding specified substring to right or left of specified string
	*	23.isPhoneNoValid()
	*   24.isAlphaWithSpecial(Fieldvalue,specialcharacter)
    *   25.MandatoryCheckWithFrame
    *   26.ShowWaitMessage
    *	27.HideWaitMessage
    *   28.formatCurrency
    *   29.toNumber
    *	30.urlencode
    *	31. sleep 'Javscript function to make delay on client side
    *   32 checkSpecialChars(objControl,blnReplaceYN,blnSilent) 
	*************************************************/

	/*************************************************
	*	Function:	isEmpty
	*	Purpose:	It checks whether the value passed
	*				is blank or null. If yes,it returns
	*				true else it returns false.
	*************************************************/
	function isEmpty(strInput){
		if(strInput == null || strInput == ""){
			return true;
		}
			return false;
	}
	/*************************************************
	*	Function:	isPosInteger
	*	Purpose:	It checks whether the value passed
	*				is a positive integer. If yes,it returns
	*				true else it returns false.
	*************************************************/
	function isPosInteger(intInput){
		var strInput;
		var counter;
		strInput = intInput.toString();
		for(counter = 0; counter < strInput.length; counter++){
			var oneChar = strInput.charAt(counter);
			if(oneChar < "0" || oneChar > "9"){
				return false;
			}
		}
		return true;
	}
	/*************************************************
	*	Function:	isInteger
	*	Purpose:	It checks whether the value passed
	*				is a positive or negative integer.
	*				If yes,it returns true else it returns false.
	*************************************************/
	function isInteger(intInput){
		var strInput;
		var counter;
		strInput = intInput.toString();
		for(counter = 0; counter < strInput.length; counter++){
			var oneChar = strInput.charAt(counter);
			if(counter == 0 && oneChar == "-"){
				continue;
			}
			if(oneChar < "0" || oneChar > "9"){
				return false;
			}
		}
		return true;
	}
	/*************************************************
	*	Function:	isNumber
	*	Purpose:	It checks whether the value passed
	*				is a positive or negative number.
	*				If yes,it returns true else it returns false.
	*************************************************/
	function isNumber(intInput){
		var strInput;
		var blnOneDecimal;
		var counter;
		
		strInput = intInput.toString();
		blnOneDecimal = false;
		for(counter = 0; counter < strInput.length; counter++){
			var oneChar = strInput.charAt(counter);
			if(counter == 0 && oneChar == "-"){
				continue;
			}
			if(oneChar == "." && !blnOneDecimal){
				blnOneDecimal = true;
				continue;
			}
			if(oneChar < "0" || oneChar > "9"){
				return false;
			}
		}
		return true;		
	}
	/*************************************************
	*	Function:	isAlphaNumeric
	*	Purpose:	It checks whether the value passed
	*				is alphanumeric.
	*				If yes,it returns true else it returns false.
	*************************************************/
	function isAlphaNumeric(strInput){
		var counter;
		for(counter = 0; counter < strInput.length; counter++){
			var oneChar = strInput.charAt(counter);
			if	(!(	
					((oneChar <= '9') && (oneChar >= '0'))	||
					((oneChar <= 'z') && (oneChar >= 'a'))	||
					(oneChar == ' ') || (oneChar == '-')	||
					((oneChar <= 'Z') && (oneChar >= 'A')) 
				)){
					return false;
			}
		}
		return true;
	}
	/*************************************************
	*	Function:	isAlpha
	*	Purpose:	It checks whether the value passed
	*				is alphabetic.
	*				If yes,it returns true else it returns false.
	*************************************************/
	function isAlpha(strInput){
		var counter;
		for(counter = 0; counter < strInput.length; counter++){
			var oneChar = strInput.charAt(counter);
			if	(!(
					((oneChar <= 'z') && (oneChar >= 'a')) ||
					(oneChar == ' ') || (oneChar == '-') ||
					((oneChar <= 'Z') && (oneChar >= 'A')) 
				)){
					return(false);
			}
		}
		return true;
	}
	/*************************************************
	*	Function:	trim
	*	Purpose:	It trims leading and trailin spaces from
	*				the supplied string.
	*				If returns trimmed string.
	*************************************************/
	/*function trim(strInput){
		//trim leading spaces
		while(true){
			if(strInput.charAt(0) == ' ')
				strInput = strInput.substr(1);
			else
				break;
		}
		//trim trailing spaces
		while(true){
			if(strInput.charAt(strInput.length-1) == ' ')
				strInput = strInput.substr(0,strInput.length-1);
			else
				break;
		}
		return strInput;
	}*/
	/*************************************************
	*	Function:	Replace
	*	Purpose:	It replaces a substring with new
	*				substring in the specified string.
	*				If returns new string.
	*************************************************/
/*
	function Replace(expression,find,replace){

		var temp = "";
		var counter;
	
		expression = '' + expression;
		splitstring = expression.split(find);
		for(counter = 0; counter < splitstring.length; counter++){
			if(counter < (splitstring.length -1))
				temp += splitstring[counter] + replace;
			else
				temp += splitstring[counter];
		}
		return temp;
	}
*/
    //function Replace(strInput,strFrom,strTo,blnCaseSensitive){
    function Replace(strInput,strFrom,strTo){
        if(strFrom == ""){
            return strInput; 
        }
        var re;
        var strTemp;
    /*
        if(blnCaseSensitive){
            //g stands for globa and i stands for case-sensitive
            re = new RegExp(strFrom,'gi')
        }else{
            re = new RegExp(strFrom,'g')
        }
    */
        re = new RegExp(strFrom,'g')
    
        strTemp = strInput.replace(re,strTo);
        return strTemp;
    }
	
	
	/*************************************************
	*	Function:	checkScreenResolution
	*	Purpose:	This function checks screen resolution.
	*************************************************/
	function checkScreenResolution(){
		var BroW = navigator.appVersion;
		var x;
		var y;
		//check visitor screen resolution
		if(BroW >= 4){
			x = screen.width ;
			y = screen.height;
			if(document.layers){
				if((x >= 800) && (x <= 1028)) {
					x = 1028;
				}
				if((y >= 600) && (y <= 780)){
					y = 780;
				}
				if((x >= 640) && (x <= 800)){
					x = 800;
				}
				if((y >= 480) && (y <= 600)){
					y = 600;
				}
				if(x <= 640){
					x = 640;
				}
				if(y <= 480){
					y = 480;
				}
			}
			Res = x + "x" + y;
		}else{
			Res = 'unknown'
		}
	}

	/*************************************************
	*	Function:	formatDecimal
	*	Purpose:	It formats a float number.
	*	Input:		expression - the floating point number which
	*							will be formatted
	*				addzero - a boolean which will be used to
	*							decide whether add '0' at the
	*							end of the floating point number.
	*				deimaln - a number indicating how many decimal point
	*						one want. (Default is 2)
	*************************************************/
	function formatDecimal(expression, addzero, decimaln) {
		var numOfDecimal = (decimaln == null) ? 2 : decimaln;
		var number = 1;

		number = Math.pow(10, numOfDecimal);

		expression = Math.round(parseFloat(expression) * number) / number;
		// If you're using IE3.x, you will get error with the following line.
		// expression = expression.toString();
		// It works fine in IE4.
		expression = "" + expression;

		if(expression.indexOf(".") == 0){
			expression = "0" + expression;
		}

		if (addzero == true){
			if(expression.indexOf(".") == -1){
			  expression = expression + ".";
			}

			while ((expression.indexOf(".") + 1) > (expression.length - numOfDecimal)){
				expression = expression + "0";
			}
		}
		return expression;
	}


	/**************************************************************************
	*	Function:	isDecimal
	*	Purpose:	It checks whether the passed value
	*               is a valid number having integer part
	*               as well as decimal part within allowed
	*               limits.
	*               This function returns false if number is
	*               negative.
	*	Input:		expression - the floating point number which
	*							will be formatted
	*				maxIntegerLen - an integer value indicating
	*							max no of digits allowed for integer part
	*				maxDecimalLen - a number indicating 
	*						        max no of digits allowed for integer part
	**************************************************************************/
    function isDecimal(expression,maxIntegerLen,maxDecimalLen){
        if(! (isNumber(expression)) ){
            //alert("not a valid number");
            return false;
        }
        //Negative Number Is Not Allowed
        if(!(expression.indexOf("-") == -1)){
            //alert("Negative Sign Not Allowed");
            return false;
        }
        var DecimalPosn = expression.indexOf(".")
        //If Decimal Point Present, Check For Decimal Data Length
        if(!(DecimalPosn == -1) ){
            var DecimalData = expression.substring(DecimalPosn+1);
            if(DecimalData.length > maxDecimalLen){
                //alert("Decimal Data Exceeding Allowed Limit Of " + maxDecimalLen + " digits");
                return false;
            }
        }
        //Check For Integer Data Length
        //alert("DecimalPosn=" + DecimalPosn);
        if(! (DecimalPosn == 0) ){
            var IntegerData = (DecimalPosn == -1) ? expression : expression.substr(0,DecimalPosn);
            //alert(IntegerData);
            if(IntegerData.length > maxIntegerLen){
                //alert("Integer Data Exceeding Allowed Limit Of " + maxIntegerLen + " digits");
                return false;
            }
        }
        //alert("Integer Data validated too");
        //txtAmount.value = formatDecimal(expression,true,maxDecimalLen);
        return true;
    }



	/************************************************* 12. ******
	*	Function:	setFocusFirstField
	*	Purpose:	It sets the focus on first available Field.
	*	Input:		-
	*
	*************************************************/
	function setFocusFirstField()
	{
		var frm = document.forms[0];
		var ele = frm.elements;
	
		for ( i=0; i < ele.length; i++ ) 
		{ 
	 		if ( ele[i].type.length > 0 ) 
			switch ( ele[i].type )
			{	case "text" :
					ele[i].focus();
					return;
					break;
				case "textarea" :
					ele[i].focus();
					return;
					break;
				case "select-one" :
					ele[i].focus();
					return;
					break;
				default:
					break;
			}
		}
		return;
	}
	/************************************************* 13. ******
	*	Function:	trim,ltrim, rtrim
	*	Purpose:	It trims leading and trailin spaces from
	*				the supplied string.
	*				It returns trimmed string.
	*
	*************************************************/
	function trim ( s )
	{
		return rtrim(ltrim(s));
	}
	function ltrim ( s )
	{
		return s.replace( /^\s*/, "" );
	}
	function rtrim ( s )
	{
		return s.replace( /\s*$/, "" );
	}
	/************************************************* 14. ******
	*	Function:	isEmail
	*	Purpose:	It validates Email Address.
	*	Input:		-
	*
	*************************************************/

	//VALID isEMAIL
	function isEmail(mail){
	  if ((mail != "") && (mail.indexOf('.',0) == -1 || mail.indexOf('.',0) == -1 || mail.indexOf('@',0) == -1 || mail == "")){    
			return false
	  }
	  else{
			return(true)
	  }
	}
	// end of isEmail
	
	/************************************************* 15. ***********************
	*	Function:	MandatoryCheck
	*	Purpose:	This function checks whether all the mandatory fields
	*		        have values entered.
	*		
	*	Input:		This Function uses REQUIRED and LABEL Property of Elements 
	*				to identify required field and field label which will be 
	*				used to show message. 
	*				For a field, an element name and element id should be same.
	*				Ex.
	*				<input id=txtFirstname name=txtFirstname Value="" required label="First Name">
	*				Note:  Use lower case for property name 
	*				like   "required label=<<User friendly label>>"
	*
	*	Output:		None
	*****************************************************************************/
	//Mandatory Field Validation
	function MandatoryCheck(){
		var arrMandatoryField,arrLength,strMissingFields,intTotalMissing,strFirstField;
		var obj2,objreqd;
		arrMandatoryField = document.forms[0].elements
		arrLength = arrMandatoryField.length;
		strMissingFields	= "";
		intTotalMissing		= 0;
		//Loop thru all fields
		for(i=0;i<arrLength;i++){
			objreqd = arrMandatoryField[i].required;
			if (!(objreqd == null)){ // if Required Field
				var strFirstField,obj1,objtype
				obj1 = arrMandatoryField[i]
				objType = obj1.type
				//Check individual Required field for blank
				//Get Data Type
				switch (objType){
				 case 'radio':
				 case 'checkbox':
					obj3 = eval("document.all." + arrMandatoryField[i].name) 
				 	if (obj3.length == null){
						if(obj3.checked == false){
							intTotalMissing  += 1
							strMissingFields += "                        " + arrMandatoryField[i].label + "\n"
							if (intTotalMissing == 1){
								strFirstField = arrMandatoryField[i].name 
							}
						}
					}
					else{
						var blnFlag; //temp flag to indicate that radio/checkbox button is checked
						blnFlag = false
						for (j=0; j<obj3.length;j++){ 
							if(obj3[j].checked)
							blnFlag = true; 
							
						}
						if (!blnFlag){
							intTotalMissing  += 1
							strMissingFields += "                        " + arrMandatoryField[i].label + "\n"
							if (intTotalMissing == 1){
								strFirstField = arrMandatoryField[i].name
							}
						}
					}
	
					break;
					
				 default:
					if (trim(obj1.value) == ""){
						intTotalMissing  += 1
						strMissingFields += "                        " + arrMandatoryField[i].label + "\n"
						if (intTotalMissing == 1){
							strFirstField = arrMandatoryField[i].name
						}
					}
			
				} //End switch
			} // End if required
		}//End for
		
		//If mandatory fields are empty alert message
		if(strMissingFields != ""){
			var strMessage;
			//   start  REV #1
			//strMessage = "Sorry, you must fill in the following " +
			//			(intTotalMissing == 1 ? "field:" : "fields:") +
			//			 "\n_______________________________________\n"
			//strMessage +=  strMissingFields 
			//strMessage += "________________________________________\n\n" +
			//				"Please fill in these fields and then resubmit the form."
			//
			strMessage = "The following fields are required:" +
						(intTotalMissing == 1 ? "" : "fields:") +
						      "\n_______________________________________\n"
			strMessage +=  strMissingFields 
			strMessage += "_______________________________________\n\n" 
			//   end  REV #1
			alert(strMessage)
			//Position the cursor to the first empty mandatory field.
			obj2 = eval("document.all." + strFirstField);
			
			if (obj2.length == null || obj2.type == 'select-one' ){
					obj2.focus();
			}
			else{
				obj2[0].focus();
			}
			return (false);
		}
		return (true);
	}


//---------------------------------------------------------------------------------
	/************************************************* 16. ******
	*	Function:	IsDate(objName)
	*	Purpose:	It check the if the data entered in this field is 
	*				 valid Date. (or field is empty): Returns true
	*				 Format of date is mm/dd/yyyy
	*	Input:		the Object
	*	Usage:		in the Date input field , onblur="IsDate(this)"
	*
	*************************************************/
function IsDate(objName) {
	var datefield = objName;
	if (isAlphabetic(objName.value) == false || chkdate(objName) == false) {
		datefield.select();
		alert("That date is invalid.  Please try again.");
		datefield.focus();
		return false;
	}
	else 
		return true;
		
}

	/************************************************* 17. ******
	*	Function:	chkdate(objName)
	*	Purpose:	It check the if the data entered in this field is 
	*				 valid Date. 
	*	Input:		the Object
	*	Usage:		'internally being used by IsDate(obj)
	*
	*************************************************/
function chkdate(objName) {
	var strDate;
	var datefield = objName;
	strDate = datefield.value;
	if (strDate.length < 1) 
		return true;
	var strDateArray, strDay, strMonth, strYear;
	var intday, intMonth, intYear, intElementNr;
	var booFound = false;
	strYear=""
	var strSeparatorArray = new Array("-"," ","/",".");
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
				return false;
			else {
				strMonth = strDateArray[0];
				strDay = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
	   }
	}
	if (booFound == false) 
	{
		if(strDate.length == 8)
		{
				strMonth = strDate.substr(0, 2);
				strDay = strDate.substr(2, 2);
				if (strDate.length == 6) strYear = strDate.substr(2);
									else strYear = strDate.substr(4);
		}
		else
			return false;
    }
    if(strYear.length > 4) return false;
	intYear = parseInt(strYear, 10);
	if(intYear > 3000) return false;
	if (strYear!="") {							
    
					if (strYear.length == 2) {
						if (intYear > 50)
							strYear = '19' + strYear;
						else 
							strYear = '20' + strYear;
					}
					if (strYear.length == 1)
						strYear = '200' + intYear;	
						if (strYear.length == 3)
						return false;	
		}
	intday = parseInt(strDay, 10);
	//
	
	//
	if (isNaN(intday))
		return false;
	if (intday < 1) 
		return false;
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) 
		return false;
	if (intMonth>12 || intMonth<1)
		return false;
	if (isNaN(intYear))
		return false;
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31))
		return false;
	
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30))
			return false;
	if (intMonth == 2){
		if ((intYear % 4) == 0) {
			if (intday > 29) 
				return false;
		}
		else {
			if (intday > 28) 
				return false;
		}
	}	
	//Format Day and month to 2 digit
	if(strMonth.length < 2){
		strMonth = '0' + strMonth
	}
	if(strDay.length < 2){
		strDay = '0' + strDay
	}
    if(strYear.length > 4) return false;
	datefield.value = strMonth + "/" + strDay + "/" + strYear;
}

	/************************************************* 18. ******
	*	Function:	isAlphabetic(s)
	*	Purpose:	It check the if the data entered in this field is 
	*				 not having any alphabetics i.e. not in (a.z, A.Z)
	*	Input:		the Object
	*	Usage:		'internally being used by IsDate(obj)
	*
	*************************************************/
function isAlphabetic (s)

{   var i;

   
    // Search through string's characters one by one
    // until we find a non-alphabetic character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);
		if (isLetter(c))
        
        return false;
    }

    // All characters are letters.
    return true;
}

	/************************************************* 19. ******
	*	Function:	isLetter (c)
	*	Purpose:	It check that c is alphabetic or not i.e. belongs to
	*				 (a.z, A.Z)
	*	Input:		the Object
	*	Usage:		'internally being used by IsDate(obj) and isAlphabetic (s)
	*
	*************************************************/
function isLetter (c)
{   
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

        /*
		'------------------------------------------------------------------
		'	Name	:	Padding
		'	Purpose	:	This function pads a text to right or left to make
		'				it specified length longer.
		'	Inputs	:	Source text, direction (to pad on right or left),
		'				text to be padded, total length of new text
		'	Outputs	:	padded text
		'------------------------------------------------------------------
        */
		function Padding(text,direction,padtext,totalLength){
			direction = direction.toLowerCase();
			if(text != ""){
				if (direction != "right" && direction != "left"){
					alert("wrong direction parameter in Padding.");
					return text;
				}
				padtext = "" + padtext;
				text = "" + text;
				var textlen = text.length;
				var totalCharLen = parseInt(totalLength,10);
				var extraCharLen = totalCharLen - textlen;
				
				for (var i=0;i<extraCharLen;i++){
					if (direction == "right"){
						text = text + padtext;
					}else if(direction == "left"){
						text = padtext + text;
					}
				}
			}
			return text;
		}
		
		 /*
		'------------------------------------------------------------------
		'	Name	:	Phone No validation
		'	Purpose	:	This function validate Phone number fields to see if 
	    '			:   all the fields are not emty then each of them should 
		'			:   have some value
		'	Inputs	:	Phone Area code, Phone Excange No, phone No
		'	Outputs	:	True or false
		'------------------------------------------------------------------
        */
		//Phone no validation
		function isPhoneNoValid(strAreaCode,strExchange,strNumber){
		var obj1, obj2,obj3;
			obj1 = eval('document.all.' + strAreaCode);
			obj2 = eval('document.all.' + strExchange);
			obj3 = eval('document.all.' + strNumber);
			if (obj1.value != '' || obj2.value != '' || obj3.value != ''){
				if(isEmpty(obj1.value) || obj1.value.length < 3){
					obj1.focus();
					alert('Please Enter complete Phone number1!!!');
					return false;
				}
				if(isEmpty(obj2.value) || obj2.value.length < 3 ){
					obj2.focus();
					alert('Please Enter complete Phone number!!!');
					return false;
				}
				if(isEmpty(obj3.value) || obj3.value.length < 4){
					obj3.focus();
					alert('Please Enter Complete Phone Number!!!');
					return false;
				}
			}
			return true;
		}

		 /*
		'------------------------------------------------------------------
		'	Name	:	Alpha Characters + Special Characters
		'	Purpose	:	This function checks the specified input string against 
	    '			:   valid Alpha characters and the special characters that
	    '			:   are specified passed to this function Eg:isAlphaSpecial(this.value,'/*')
		'			:   have some value
		'	Inputs	:	Text Value, Special Characters
		'	Outputs	:	True or false
		'------------------------------------------------------------------
        */		
		function isAlphaWithSpecial(strInput,strspecial){
			var counter;
			for(counter = 0; counter < strInput.length; counter++){
				var oneChar = strInput.charAt(counter);
				if	(!(
						((oneChar <= 'z') && (oneChar >= 'a')) ||
						(oneChar == ' ') || (oneChar == '-') ||
						((oneChar <= 'Z') && (oneChar >= 'A')) ||
						(strspecial.indexOf(oneChar)==0) 
					)){
						return(false);
				}
			}	
			return true;	
		}


	 /*
		'------------------------------------------------------------------
		'	Name	:	Alpha Characters + Numeric + Few Special Characters ( e.g. -,/)
		'	Purpose	:	This function checks the specified input string against 
	    '			:   valid Alpha characters , Numeric digits and the special characters that
	    '			:   are specified passed to this function Eg:isAlphaSpecial(this.value,'/*')
		'			:   have some value
		'	Inputs	:	Text Value, Special Characters
		'	Outputs	:	True or false
		'------------------------------------------------------------------
        */


		function isAlphaNumWithSpecial(strInput)
		{
			var counter;
			for(counter = 0; counter < strInput.length; counter++)
			{	
				var oneChar = strInput.charAt(counter);
				if	(!(
						((oneChar <= 'z') && (oneChar >= 'a')) ||
						(oneChar == '/') || (oneChar == '-') ||
						((oneChar <= 'Z') && (oneChar >= 'A')) ||
						((oneChar <= '9') && (oneChar >= '0'))
					))
					{ return(false); }
			}	
			return true;	
		}        
        
        
        /*
		'------------------------------------------------------------------
		'	Name	:	MandatoryCheckWithFrame()
		'	Purpose	:	This function checks whether all the mandatory fields
		'               have values entered.
		'	Inputs	:	This function uses hdnMandatoryFields hidden field
		'               to identify all the mandatory fields, field type,
		'               and field label which will be used to show message.
		'               For a field, an element name/ element id should be send.
		'               For textbox,password,select - Element id
		'               For checkbox,radio          - Element Name / Element Id
		'               Format for a field data should be
		'               Label : Element Name : Element Type
		'               OR
		'               Label : Element Id : Element Type
		'               Valid Element Types are
		'                   text , password, textarea, radio, checkbox and select.
		'               Multiple values should be comma separated.
		'	Outputs	:	None
		'------------------------------------------------------------------
        */
        function MandatoryCheckWithFrame(frameName){
            var path;
            if(frameName == ""){
                path = "document.all";
            }else{
                path = "top.frames('" + frameName + "').document.all";
            }
            var temp = eval(path);
            //with(document.all){
            with(temp){
                var MandatoryFields = hdnMandatoryFields.value;
                var ElementArray = MandatoryFields.split(",");
                var ElementAttributesArray;
                var strMissingFields = "";
                //var strFirstMissingField;
                var blnFirstMissingFieldFound = false;
                //var strFirstMissingFieldType;
                var ElementVal;
                var intTotalMissing = 0;   //indicates Total number of missing fields                
                //Main loop for the number of elements
                var ElementLabel;
                for(var i=0; i< ElementArray.length; i++){
                    ElementAttributesArray = ElementArray[i].split(":");
                    ElementLabel = ElementAttributesArray[0];
                        switch(ElementAttributesArray[2]){
                            case 'text':
                            case 'password':
                            case 'textarea':
                                ElementVal = trim(item(ElementAttributesArray[1]).value);
                                if(ElementVal == ""){
                                    strMissingFields = strMissingFields + ElementLabel + "\n";
                                    intTotalMissing = parseInt(intTotalMissing,10) + 1;
                                    if(! (blnFirstMissingFieldFound) ){
                                        blnFirstMissingFieldFound = true;
                                        item(ElementAttributesArray[1]).select();
                                        item(ElementAttributesArray[1]).focus();
                                    }
                                }
                                //alert(ElementVal);
                                break;
                            case 'radio':
                                /*
                                var blnChecked = false;
                                for(var r=0; r<item(ElementAttributesArray[1]).length; r++){
                                    if(item(ElementAttributesArray[1])[r].checked){
                                        blnChecked = true;
                                        break;
                                    }
                                }
                                if(! (blnChecked) ){
                                    strMissingFields = strMissingFields + ElementLabel + "\n";
                                    intTotalMissing = parseInt(intTotalMissing,10) + 1;
                                    if(! (blnFirstMissingFieldFound) ){
                                        blnFirstMissingFieldFound = true;
                                        item(ElementAttributesArray[1])[0].focus();
                                    }
                                 }

                                break;
                                */
                            case 'checkbox':
                                //only for one checkbox
                                if(! ( item(ElementAttributesArray[1]).length ) ){
                                    if( !(item(ElementAttributesArray[1]).checked) ){
                                        //blnCheckBoxChecked = true;
                                        strMissingFields = strMissingFields + ElementLabel + "\n";
                                        intTotalMissing = parseInt(intTotalMissing,10) + 1;
                                        if(! (blnFirstMissingFieldFound) ){
                                            blnFirstMissingFieldFound = true;
                                            item(ElementAttributesArray[1]).focus();
                                        }
                                    }
                                }else{ //for multiple checkbox with same name
                                    var blnChecked = false;
                                    for(c=0; c<item(ElementAttributesArray[1]).length; c++){
                                        if(item(ElementAttributesArray[1])[c].checked){
                                            blnChecked = true;
                                        }
                                    }
                                    if (!(blnChecked)){
                                        strMissingFields = strMissingFields + ElementLabel + "\n";
                                        intTotalMissing = parseInt(intTotalMissing,10) + 1;
                                        if(! (blnFirstMissingFieldFound) ){
                                            blnFirstMissingFieldFound = true;
                                            item(ElementAttributesArray[1])[0].focus();
                                        }
                                    }
                                
                                }
                                break;
                            case 'select':
                                  if(item(ElementAttributesArray[1]).length > 0){
                                        //var selIndex = item(ElementAttributesArray[1]).selectedIndex;
                                        //var ElementVal = item(ElementAttributesArray[1]).options[selIndex].value;
                                        var ElementVal = item(ElementAttributesArray[1]).value;
                                   }else{
                                        ElementVal = "";
                                   }
                                  if(ElementVal == ""){
                                        strMissingFields = strMissingFields + ElementLabel + "\n";
                                        intTotalMissing = parseInt(intTotalMissing,10) + 1;
                                        if(! (blnFirstMissingFieldFound) ){
                                            blnFirstMissingFieldFound = true;
                                            item(ElementAttributesArray[1]).focus();
                                        }
                                  }
                                break;
                            default:
                                alert("Invalid element type.");
                        }
                    //}
                }
            }
            if(strMissingFields != ""){
                //strMissingFields = "Following fields does not have value.\n" + strMissingFields;
                //alert(strMissingFields);
			    var strMessage;
			    strMessage = "Sorry, you must fill in the following " +
			    			(intTotalMissing == 1 ? " field:" : " fields:") +
			    			 "\n_______________________________________\n";
			    strMessage +=  strMissingFields 
			    strMessage += "________________________________________\n\n" +
			    				"Please fill in these fields and then resubmit the form.";
			    alert(strMessage);
			    return false;
                
            }else{
                //alert("All mandatory fields have value entered.");
                return true;
            }
        }


/************************************************* 19. ******
*	Function:	isLetter (c)
*	Purpose:	It check that c is alphabetic or not i.e. belongs to
*				 (a.z, A.Z)
*	Input:		the Object
*	Usage:		'internally being used by IsDate(obj) and isAlphabetic (s)
*
*************************************************/
function isLetter (c)
{   
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

/**************************************************************
*	Function:	ShowWaitMessage
*	Purpose:	Display the wait message 
*	Input:		
*	Usage:		
*
**************************************************************/
var winhandle = null; 

function ShowWaitMessage ()
{   
	//Wait PopUP
	winhandle = window.open('waitmessage.htm',"condition","height=10,width=250,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,top=170,left=360");
	return winhandle
	//--	
}

/**************************************************************
*	Function:	HideWaitMessage
*	Purpose:	Close the wait message window
*	Input:		
*	Usage:		
*
**************************************************************/
function HideWaitMessage()
{
	if (winhandle != null){
		wh = winhandle;
		wh.close();}
}
/**************************************************************
*	Function:	formatCurrency
*	Purpose:	Formats a number in Currency format.
*	Input:		number
*	Usage:		
*************************************************
    Original:  Cyanide_7 (leo7278@hotmail.com)
    Web Site:  http://www7.ewebcity.com/cyanide7 
*************************************************
**************************************************************/
function formatCurrency(num){
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num)){
        num = "0";
    }
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10){
        cents = "0" + cents;
    }
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++){
        num = num.substring(0,num.length-(4*i+3)) + ',' +
              num.substring(num.length-(4*i+3));
    }
    //return (((sign)?'':'-') + '$' + num + '.' + cents);
    return (((sign)?'':'-') + num + '.' + cents);
}
/**************************************************************
*	Function:	toNumber
*	Purpose:	This routine removes a comma from a numeric data
*               and returns it as a numeric field. 
*               e.g.for 1,000.00 it returns 1000
*                   for 2,000.15 it returns 2000.15
*	Input:		pInput - input numeric data of string data type
*                        to be returned as numeric data type
*	Usage:		
***************************************************************/
function toNumeric(pInput){
    //remove comma
    var temp = new String(pInput);
    var newData = "";
    var foundoffset = temp.indexOf(",");
    if(foundoffset == -1){
        newData = temp;
    }else{
        newData = Replace(temp,",","");
    }
    return parseFloat(newData);
}

/**************************************************************
*	Function:	urlencode
*	Purpose:	This routine replaces special characters used in URL
*	Input:		text - input text
*	Usage:		
***************************************************************/
function urlencode(text) {
	 
     text = Replace(text,"/","%2F");
     text = Replace(text,"=","%3D");
     text = Replace(text,"&","%26");
     return text;
}

/**************************************************************
*	Function:	setFocusOnFirstElement()
*	Purpose:	Set the focus to the first element on the page
*	Input:		
*	Usage:		
***************************************************************/
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isUndefined(a) {
    return typeof a == 'undefined';
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
	return index;
}
	
function setFocusOnFirstElement_DotNet(strFirstElement) {
	if (strFirstElement == "") {
		setFocusOnFirstElement();
	} else {
            if(document.all.item(strFirstElement)==null)
               {return;}

	    if (!document.all.item(strFirstElement).disabled ){
		document.all.item(strFirstElement).focus();
		}
	}
}
function setFocusOnFirstElement()
{	
	var frm = document.forms[0];		
	var ele = frm.elements;    
	var strID = ele.id;
	
	for ( i=0; i < ele.length - 1; i++ ) 
		//{if (((ele[i].readOnly == false) || (ele[i].readOnly == undefined) ) && (ele[i].disabled == false))
		{if ((!ele[i].readOnly) && (!ele[i].disabled) && (ele[i].style.display != "none") && (ele[i].style.visible != "hidden") && (isObject(ele[i]))) // && !isUndefined(ele[i]))
			{
				switch ( ele[i].type )
				{	case "text" :
							ele[i].focus();
							return;
							break;
					case "textarea" :
							ele[i].focus();
							return;
							break;						

					case "select-one" :
							ele[i].focus();
							return;
							break;
					case "select-multiple" :
							ele[i].focus();
							return;
							break;		
					case "radio" :
							ele[i].focus();
							return;
							break;
					case "checkbox" :
							ele[i].focus();
							return;
							break;
					case "button" : 
								try {
								ele[i].focus();
								} catch (e) {
								
								}
							return;
							break;
					case "reset" : 
								try {
								ele[i].focus();
								} catch (e) {
								
								}
							return;
							break;		
					case "submit" : 
								try {
								ele[i].focus();
								} catch (e) {
								
								}
			
							return;
							break;										
					default:
							break;
				}
			}
		}		
		return;			
}
/*
'------------------------------------------------------------------
'	Name	:	fnFormatYear
'	Purpose	:	This function Format Year field per EPZB standard.
'	Inputs	:	Source Digit,to be formatted as an year.
'	Outputs	:	padded text
'------------------------------------------------------------------
*/

function fnFormatYear(strYear){
	var yr = strYear;

	if(yr.length == 1) yr = '200' + yr;
	if(yr.length == 2) 
	{ 
		var currDate = new Date();
		
		var currYear = currDate.getFullYear();
		currYear = currYear.toString()
		
		var currYearFist2Digit = currYear.substr(0,2);
		var currYearLast2Digit = currYear.substr(2,2);
		
		
		if (parseInt(yr,10) <= parseInt(currYearLast2Digit,10)+1){
		     yr = 	currYearFist2Digit  + yr;
		}
		else {
		     yr = 	(parseInt(currYearFist2Digit,10) - 1) + yr;
		}
	}
	if(yr.length == 3) {
		return '2' + yr;
	}
	yr = parseInt(yr,10);
	if (yr == 0) yr = '';
	return yr;
}

/*
'------------------------------------------------------------------
'	Name	:	setYear
'	Purpose	:	Format Year using above function and insert the year in the passed textbox
*/

function setYear(objthis, opt) {
    if (opt == null || opt == '') opt = true;
    objthis.value = trim(objthis.value);
    var yr = objthis.value;
    if (yr.length == 0) return true;
    if (isNaN(yr)) {
        if (opt == true) { alert("Please enter numbers only"); objthis.select(); }
        return false;
    }
    yr = fnFormatYear(yr);
    objthis.value = yr;
    return true;
}

/*
'------------------------------------------------------------------
'	Name	:	fnGetNextBusinessDay
'	Purpose	:	This function returns the next businessday after adding the days provided.
'			:   Currently County holidays are counted as business days
'	Inputs	:	Current Date (mm/dd/yyyy), Days to be Added.
'	Outputs	:	Next Business day
'	Author  :   Yunus Kazi 
'------------------------------------------------------------------
*/
function fnGetNextBusinessDay(CurrentDate, businessDays){
	//var businessDays = 1
	var now = new Date(CurrentDate) ;
	
	var dayOfTheWeek = now.getDay();
	var calendarDays = businessDays;
	var NextBusinessDay = dayOfTheWeek + businessDays;
	
	if (NextBusinessDay >= 6) {
		businessDays -= 6 - dayOfTheWeek;  //deduct this-week days
		calendarDays += 2;  //count this coming weekend
		NextBusinessWeeks = Math.floor(businessDays / 5); //how many whole weeks?
		calendarDays += NextBusinessWeeks * 2;  //two days per weekend per week
	}
	now.setTime(now.getTime() + calendarDays * 24 * 60 * 60 * 1000);
	
	return (now.getMonth() + "/" + now.getDate() + "/" + now.getFullYear());
}

/*
		Name   : Sanjeev Gandhi
		Purpose: Sometimes, client side script need wait for few seconds; this function keep client waiting
				 for milli-seconds specified
		Date   : 04/06/2010 
*/
	function sleep(strMessage,WaitMillisecond)
	{
		window.showModalDialog("/epzb/include_files/WaitMessage.asp?WaitMessage="+ strMessage + "&Timeout="+ WaitMillisecond,"","dialogLeft:200px;dialogTop:150px;dialogWidth:10px;dialogHeight:10px;minimize=yes;status=no;menubar=no;toolbar=no;maximize=yes;")
	}
/*
		Name   : fnLookup
		Purpose: Common function to show the LookUp page for controls
		Date   : 05/07/2010 
*/
/*
		Name : Monika Nanda-Arora
		Change : fixed the error on clicking the "X" to close the Window
		Date : 01/27/2012
*/

	function fnLookUp(ControlName,FirstField,SecondField)
	{	var returnValue='';
		var controlName;
		var separator = "-";			
		returnValue = window.showModalDialog("/epzbcommon/asp_html/ControlLookUp.aspx?ControlName=" + ControlName,"","dialogLeft:200px;dialogTop:150px;dialogWidth:400px;dialogHeight:300px;minimize=yes;status=no;menubar=no;toolbar=no;");
		if (returnValue!='' && returnValue != undefined)
			{var arrValue= returnValue.split(separator);
			 if (arrValue.length==2){
				var firstField =	eval("document.all." + FirstField); 
				var secondField =  eval("document.all." + SecondField); 		
				firstField.value = arrValue[0];
				secondField.value = arrValue[1];
				}
			}			
	}
/*
	Sanjeev Gandhi -- 08/30/2011 -- WO# 56130
	Name: checkSpecialChars
	Pupose: Check for special characters which gives problem in merging letters.
	Some of them can be replaced with alternatives for example: Em Dash to Regular hyphen
	Some of them needs to be remoived, so they can be replaced with *
	if blnSilent param id false, then this function will give error message alongwith returning false 
*/
	function checkSpecialChars(objControl,blnReplaceYN,blnSilent)
	{
		var counter;
		var strText = objControl.value;
		var charToBeRemoved = ''; 
		var charToBeReplaced = '';
		var ascValuetoBeRemoved = '';
		for(counter = 0; counter < strText.length; counter++)
		{	var strspecial = ',9,13,10,137,153,160,161,162,163,165,167,169,174,176,';
			var strSpecialCanBeReplaced = ',130,132,133,145,146,147,148,149,150,151,152,160,215,247,'
			
			var oneChar = strText.charAt(counter);
			var ascValue =  strText.charCodeAt(counter);
			

			if	(!((ascValue >= 32 && ascValue <= 126) || strspecial.indexOf(',' + ascValue + ',') > 0 || ascValue > 900))
			{	
				if (strSpecialCanBeReplaced.indexOf(',' + ascValue + ',') > 0) 
					charToBeReplaced = charToBeReplaced + oneChar;
				else
					{
						charToBeRemoved =  charToBeRemoved + oneChar;
						ascValuetoBeRemoved = ascValuetoBeRemoved + ',' + ascValue;
					}
			}
		}	
		//alert('These will be replaced:' + charToBeReplaced);
		//alert('These will be ignored:' + charToBeRemoved + '\nTheir ascii values are:' + ascValuetoBeRemoved);
		if(charToBeReplaced == '' && charToBeRemoved == '') return true;
		else
		if(charToBeReplaced != '' && charToBeRemoved != '')
		{	if(!blnSilent) alert('There are some special characters in the text.\nSome of them will be replaced with alternatives before saving into the database \nAnd some of them will be replaced with * to avoid problem in merging letters.');
			return false;
		}
		else
		if(charToBeReplaced != '')
		{
			if(!blnSilent) alert('There are some special characters in the text which will be replaced before saving into the database.');
			return false;
		}
		else //if(charToBeRemoved != '')
		{
			if(!blnSilent) alert('There are special characters in the text which will be replaced with * before saving into the database.');
			return false;
		}
		return true;
}
//*********************************
