//'*****************************************************************************
//' FacilityOffice.com. All rights reserved.
//' Copyright(C) 2000.FusionX, Eutech Cybernetics Pvt. Ltd., India.
//' ----------------------------------------------------------------------------
//' Name			Type			Description
//' ----------------------------------------------------------------------------
//' Called by		:  
//' Description	:  
//' Modification History :  
//' ----------------------------------------------------------------------------
//' Date				By				Reason
//25-Jun-2004		Kishore			Incorporated time validation script
//									Find for text "Start code for time validation"
//29-Jun-2004		Kishore			Incorporated script for cal_view_customize_window
//									Find for text "start code for customize window"
//31-Aug-2004		Kishore			Incorporated script to select & clear time text box contents
//									Find for text "Start code for DE Phase II - Time control select & clear"
//01-Sep-2004		Kishore			Incorporated script to accept only numeric in time control text box
//									Find for text "Start code for DE Phase II - To accept only numeric"
//07-Sep-2004		Kishore			Incorporated script to check hrs (or) min is empty
//									Find for text "Start code for DE Phase II - To check hrs (or) min empty"
//18-Oct-2004		Tamilselvi		ML Implementation
//02-Dec-2004		Kishore			Added round() function
//									Find for text "FO22 - New development"
//01-Jun-2005		Shankar			Released on temp. ownership to FBS(Kalaivani)
//02-Jun-2005		Kalaivani		Find For "Start Code for FBS"
//02-Jun-2005		Kalaivani		Released ownership back to Product(Shankar)
//20-Jun-2005		Shankar			Released on temp. ownership to GIC(Rex)
//21-Jun-2005		Rex			Returned after GIC modifications
//'------------------------------------------------------------------------------------------------------------
//'************************************************************************************************************


var gsWinLcn;
//Start code for DE Phase II - Time control select & clear
	var gnCounter=0;
//End code for DE Phase II - Time control select & clear

function GetWindowLocation(nWidth, nHeight)
{

	var nLeft;
	var nTop;

	nLeft = parseInt((screen.width - nWidth) / 2);
	nTop = parseInt((screen.height - nHeight) / 2);
	gsWinLcn = "width=" + nWidth + ",height=" + nHeight + ",left=" + nLeft + ",top=" + nTop
}

function round(number,decimal)
{
	 number *= Math.pow(10,decimal);
	number= Math.round(Math.abs(number))	
	number /= Math.pow(10,decimal);
	return number
}
function vcheckNumeric(oSrc)
		{
			if (isNaN(oSrc.value))
			{
				alert ("Numbers Should be entered") ;
				oSrc.focus();
			}
		}
		

function RoundDecimal(Scnt,decimal) 
{

	Scnt.value *= Math.pow(10,decimal);
	Scnt.value = Math.round(Math.abs(Scnt.value))	
	Scnt.value /= Math.pow(10,decimal);
	
	return Scnt.value
}
 
function dGetCurrValue(sValue)
	{
		var rExp = new RegExp(",", "gi");
		sValue=sValue.replace(rExp,""); 
		sValue = parseFloat(sValue);
		return sValue;
	}

function lkpImage(sImgPath, sImgStatus)
{
var oImage;
var nInt;
oImage = event.srcElement; 

nInt = (sImgPath.length) -1

if (sImgPath.substr(nInt,1) != "/")
	sImgPath = sImgPath + "/";
if (sImgStatus == "OF")
{
	sImgPath = sImgPath + "foFolderOpen.gif";
}
else
{
	if(sImgStatus == "UF")
	{
		sImgPath = sImgPath + "fofolderclosed.gif";
	}
	else
	{
		if(sImgStatus == "O")
		{
			sImgPath = sImgPath + "eye_open.gif";
		}
		else
		{
			sImgPath = sImgPath + "eye_close.gif";
		}
	}
}

/*if (sImgStatus == "O")
	sImgPath = sImgPath + "eye_open.gif";
else
	sImgPath = sImgPath + "eye_close.gif";
*/
oImage.src = sImgPath;
}

function trim(sStr) 
{
     return sStr.replace(/^\s+|\s+$/g, "") ;
}

function vSwapImage(sImagePath)
{
	var oImage;

	oImage = event.srcElement;
	oImage.src = sImagePath;
}

function vNumericKeypress(sDecAllowed)
{
	
	if (window.event.keyCode < 48 || window.event.keyCode > 57)  
	{
		//To avoid flashing alert for non impression keys
		if (window.event.keyCode < 32)
		{
			window.event.keyCode = 0 ;
			return ;
		}

		if (window.event.keyCode == 46)
		{
			if (sDecAllowed == "Y")
			{
				
				var sValue = event.srcElement.value ;
				if (sValue.indexOf(".") > -1 )
				{
					alert(JS_FO_CLIE_DECI_DUPL)
					window.event.keyCode = 0 ;
					return ;
				}
				else
				{
					return ;
				}
			}
			else
			{
				alert(JS_FO_CLIE_DECI_INVL)
				window.event.keyCode = 0 ;
				return ;
			}
		}

		alert(JS_FO_CLIE_NUM_VAL);
		window.event.keyCode = 0  ; 
		return ;
		
	}	
}

function vNumericOnBlur()
{
	if (isNaN(event.srcElement.value))
	{
		alert (JS_FO_CLIE_NUM_VAL) ;
		event.srcElement.focus();
		return;
	}
}

function TextAreaPaste(maxlimit)
{
// Add the text value from the clipboard to the text in the source element
// Take the required number of characters from the list and store it to the source element
// Set the return value to false so that the actual paste operation will be cancelled.
	var sText = event.srcElement.value + window.clipboardData.getData("Text")
	event.srcElement.value = sText.substring(0, maxlimit);
	event.returnValue = false ;
}

function TextAreaKeyPress(maxlimit)
{
	if (event.srcElement.value.length >= maxlimit)
	{
		event.keyCode = 0;
	}
}

function FormatDateTime(datetime, FormatType)
/*
	 FomatType takes the following values
		1 - General Date = Friday, October 30, 1998
		2 - Typical Date = 10/30/98
		3 - Standard Time = 6:31 PM
		4 - Military Time = 18:31
*/
{
	var strDate = new String(datetime);

	if (strDate.toUpperCase() == "NOW") {
		var myDate = new Date();
		strDate = String(myDate);
	} else {
		var myDate = new Date(datetime);
		strDate = String(myDate);
	}


	// Get the date variable parts
	var Day = new String(strDate.substring(0,3));
	if (Day == "Sun") Day = "Sunday";
	if (Day == "Mon") Day = "Monday";
	if (Day == "Tue") Day = "Tuesday";
	if (Day == "Wed") Day = "Wednesday";
	if (Day == "Thu") Day = "Thursday";
	if (Day == "Fri") Day = "Friday";
	if (Day == "Sat") Day = "Saturday";	
	
	var Month = new String(strDate.substring(4,7)), MonthNumber = 0;
	if (Month == "Jan") { Month = "January"; MonthNumber = 1; }
	if (Month == "Feb") { Month = "February"; MonthNumber = 1; }
	if (Month == "Mar") { Month = "March"; MonthNumber = 1; }
	if (Month == "Apr") { Month = "April"; MonthNumber = 1; }
	if (Month == "May") { Month = "May"; MonthNumber = 1; }
	if (Month == "Jun") { Month = "June"; MonthNumber = 1; }
	if (Month == "Jul") { Month = "July"; MonthNumber = 1; }
	if (Month == "Aug") { Month = "August"; MonthNumber = 1; }
	if (Month == "Sep") { Month = "September"; MonthNumber = 1; }
	if (Month == "Oct") { Month = "October"; MonthNumber = 1; }
	if (Month == "Nov") { Month = "November"; MonthNumber = 1; }
	if (Month == "Dec") { Month = "December"; MonthNumber = 1; }
	
	var curPos = 11;
	var MonthDay = new String(strDate.substring(8,10));
	if (MonthDay.charAt(1) == " ") {
		MonthDay = "0" + MonthDay.charAt(0);
		curPos--;
	}	
	
	var MilitaryTime = new String(strDate.substring(curPos,curPos + 5));
	
	var Year = new String(strDate.substring(strDate.length - 4, strDate.length));	
	
	document.write(strDate + "");	

	// Format Type decision time!
	if (FormatType == 1)
		strDate = Day + ", " + Month + " " + MonthDay + ", " + Year;
	else if (FormatType == 2)
		strDate = MonthNumber + "/" + MonthDay + "/" + Year.substring(2,4);
	else if (FormatType == 3) {
		var AMPM = MilitaryTime.substring(0,2) >= 12 && MilitaryTime.substring(0,2) != "24" ? " PM" : " AM";
		if (MilitaryTime.substring(0,2) > 12)
			strDate = (MilitaryTime.substring(0,2) - 12) + ":" + MilitaryTime.substring(3,MilitaryTime.length) + AMPM;
		else {
			if (MilitaryTime.substring(0,2) < 10)
				strDate = MilitaryTime.substring(1,MilitaryTime.length) + AMPM;
			else
				strDate = MilitaryTime + AMPM;
		}
	}	
	else if (FormatType == 4)
		strDate = MilitaryTime;


	return strDate;
}


function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.										
 
	RETVAL:
		The formatted number!		
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))	
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart > 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}


function FormatCurrency(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.										
 
	RETVAL:
		The formatted number!		
 **********************************************************************/
{
	var tmpStr = new String(FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas));

	if (tmpStr.indexOf("(") != -1 || tmpStr.indexOf("-") != -1) {
		// We know we have a negative number, so place '$' inside of '(' / after '-'
		if (tmpStr.charAt(0) == "(")
			tmpStr = "($"  + tmpStr.substring(1,tmpStr.length);
		else if (tmpStr.charAt(0) == "-")
			tmpStr = "-$" + tmpStr.substring(1,tmpStr.length);
			
		return tmpStr;
	}
	else
		return "$" + tmpStr;		// Return formatted string!
}


function Left(str, n)
/***
        IN: str - the string we are LEFTing
            n - the number of characters we want to return

        RETVAL: n characters from the left side of the string
***/
{
        if (n <= 0)     // Invalid bound, return blank string
                return "";
        else if (n > String(str).length)   // Invalid bound, return
                return str;                // entire string
        else // Valid bound, return appropriate substring
                return String(str).substring(0,n);
}

function Right(str, n)
/***
        IN: str - the string we are RIGHTing
            n - the number of characters we want to return

        RETVAL: n characters from the right side of the string
***/
{
        if (n <= 0)     // Invalid bound, return blank string
           return "";
        else if (n > String(str).length)   // Invalid bound, return
           return str;                     // entire string
        else { // Valid bound, return appropriate substring
           var iLen = String(str).length;
           return String(str).substring(iLen, iLen - n);
        }
}

function hidestatus()
{
	window.status = "FacilityOffice.com";
	return true ;
}

function currencyFormat(fld, milSep, decSep, e) 
{
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
len = fld.value.length;

if (len > fld.maxLength ) 
{
window.event.keycode = 0;
return;
}


if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key


for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '0' + aux;
if (len == 2) fld.value = '0'+ decSep + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}







/**********************************************************************************
					---- Begning of Format Currency 
**********************************************************************************/
function ConvertCurrencyFormat(sNumber,groupSeparator,currencySymbol,fractionMark,precision)

/*
 1. Set default groupSeparator to a comma (,)
 2. Set default currencySymbol to dollars ($)
 3. Set default fractionMark to a period (.)
 4. Set the default precision to 2 decimal places 
	(extra test allows for 0 to override - exactly what you you would expect)
*/
	
	//Set Default Values. 
    {
         groupSeparator      = groupSeparator || '';                                        
         currencySymbol     = currencySymbol || '';                                        
         fractionMark     = fractionMark || '.';                                               
         precision != 0 ? precision = (precision || 2): null;          
         
         number = formatNumber(sNumber,groupSeparator,currencySymbol,fractionMark,precision)                  
         return number;
    }
    
     function formatNumber(sNumber,groupSeparator,currencySymbol,fractionMark,precision)
    {
         groupSeparator      = groupSeparator || '';                                        
         currencySymbol     = currencySymbol || '';                                          
         fractionMark     = fractionMark || '.';                                             
         precision != 0 ? precision = (precision || 2): null;          
         sUnformattedNumber = unformatNumber(sNumber);
                                                                   
         // round the number AND cast it to a string            
         sRoundedNumber = Math.round(sUnformattedNumber*Math.pow(10,precision))/Math.pow(10,precision)+'';      
         
         var whole = getWholeNumber(sRoundedNumber);
         var decimal = getDecimalNumber(sRoundedNumber);
         
         whole = addCommas(Math.abs(whole),groupSeparator);
         decimal = addZeros(decimal,precision);     
         
          sFormattedNumber = precision > 0 ?  (currencySymbol + whole + fractionMark + decimal) : (currencySymbol + whole + decimal);     
          if (isNegative(sNumber))
			{
              sFormattedNumber = '-' + sFormattedNumber;
			}
         return sFormattedNumber;
    
		    /***************************************************************************
			Adding Commas to the Input Number, This is a Private function defined.
		    ****************************************************************************/     
              function addCommas(number,groupSeparator)
              {
                   var groupSeparator = (groupSeparator || '');
                   if (number && number !=0)
                   {
                        number +='';
                        if (number.length > 3) 
                         {
							var mod = number.length % 3;
							var output = (mod > 0 ? (number.substring(0,mod)) : '');
							for (nCnt=0 ; nCnt < Math.floor(number.length/3) ; nCnt++) 
							{
									if ((mod ==0) && (nCnt ==0))
									{
										output+= number.substring(mod+3*nCnt,mod+3*nCnt+3);
									}     
									else
										{
											output+= groupSeparator + number.substring(mod+3*nCnt,mod+3*nCnt+3);
										}
							 }
							return (output);
						}
							return number+='';
                   }
                   
                   if (number == 0)
                        return number+='';
                   return '';
              }
              
              /***************************End of Adding Commas to the Nunbers. *********************/
              
              
			/***************************************************************************
			Adding Zeros to the Input Number based on the precision. This is defined as a Private function.
		    ****************************************************************************/     

               function addZeros(decimal,precision)
               {
                   if (precision)
                   {
                        if (decimal.toString().length == 0)
                             decimal = 0;
                        var zeros='';
                        numberOfZeros = (precision - decimal.toString().length);
                        for (z=0 ; numberOfZeros > z ; z++)
                             zeros+='0';
                        return decimal + zeros;
                   }
                   return '';
              }
			
			/*************************End of Adding Zeroes to the Inputed Number. *******************/
			
				
			/***************************************************************************
			Returning the Inputed Number in the Decimal Format. This function is defined as a Private Function.
		    ****************************************************************************/     
		    
              function getDecimalNumber(sNumber)
              {
                   sNumber = sNumber.toString();
                   if (sNumber.toString().indexOf('.')!= -1)
                   {
                        sWholeNumber = sNumber.substring(sNumber.indexOf('.')+1,sNumber.length);
                   }
                   else
                        sWholeNumber = '';
                   return sWholeNumber;
              }
              /***********************End of Getting the Decimal Number format ********************************/
             
             
              
			/***************************************************************************
			Fetch the Whole Number from the Inputed Number, This function is defined as a private number.
		    ****************************************************************************/     
               function getWholeNumber(sNumber)
               {
                   if (sNumber)
                   {
                        sNumber = sNumber.toString();
                        if (sNumber.toString().indexOf('.')!= -1)
                             sWholeNumber = sNumber.substring(0,sNumber.indexOf('.'));
                        else
                             sWholeNumber = sNumber;
                        return sWholeNumber;
                   }
                   return '0';
              }
             /*********************End of Fetching the Whole Number ****************************/ 
              
    }
    
    /***************************************************************************
	Verify whether the Input Number is a Negative. 
	****************************************************************************/     
     function isNegative(sNumber)
     {
         return sNumber.toString().indexOf("-") == 0;
     }
    
    /***************************************************************************
	Unformat the Number function, get the desired Output based on the input parameters.
	****************************************************************************/     
     function unformatNumber(sNumber,sFractionMark)
     {
         sFractionMark = (sFractionMark || '.');
         sNumber = sNumber.toString();
         if(sNumber || sNumber == 0)
         {
              var aNumber = sNumber.split(sFractionMark);
              
               if (aNumber[1])
              {
                   var sWholeNumber = removeNonDigits(aNumber[0]);               
                    var sDecimalNumber = removeNonDigits(aNumber[1]);
                   if (sDecimalNumber == '')
                   {
                        iUnformattedNumber = sWholeNumber - 0;
                        if (sWholeNumber == '') return '';
                   }
                   iUnformattedNumber = sWholeNumber + '.' + sDecimalNumber - 0;
              }
              else
              {
                   var sUnformattedNumber = removeNonDigits(sNumber);
                   if (sUnformattedNumber == '')
                   {
                        return sUnformattedNumber;
                   }
                   var iUnformattedNumber = sUnformattedNumber - 0;
              }
              if (isNegative(sNumber))
                   iUnformattedNumber = '-' + iUnformattedNumber - 0;
              return iUnformattedNumber;
         }
         return sNumber;

        function removeNonDigits(sMixedString)
        {
			var sNumbersOnly = sMixedString.replace(/[^0-9]/g,'');
			return sNumbersOnly;
       }

    }
    
/****************************End of FormatCurrency****************************/


/*  
functions added for Time checking - 18-Jun-2004 by Jayalakshmi  
*/


function vMergeTime(sHourCtrl,sMinCtrl,sMeridianCtrl,sCtrlTimeName,sFromctrl)
{
/*

This function written for getting MergedTime in passed text box.
--------------------------------------------------------------------------
Arguments			Purpose
--------------------------------------------------------------------------
sHourCtrl		Hours Control name  (it will be 'HH' or hours in digit)
sMinCtrl		Minutes Control name (it will be 'HH' or hours in digit) 
sMeridianCtrl	Meridian(combo for AM/PM selection) Control name 
sCtrlTimeName	Name of the control in which the merged time value to be stored. 
sFromctrl		This function called form which  control. 'H' for HoursTextBox 
				 'M' for MinutesTextBox.   ''(empty) for MeridianTextBox (AM/PM)
*/
var sHour
var sMin 
var sMeridian
var sValid
var sInTime
	
	sHour = document.all(sHourCtrl).value ;
	sMin = document.all(sMinCtrl).value; 
	sInTime = document.all(sCtrlTimeName).value
	sFromctrl = sFromctrl.toUpperCase()
	
	
	//alert ("merge " + sInTime )
	sMeridian = document.all(sMeridianCtrl).value ;

	if (trim(sHour) == "" ||  (sHour.toUpperCase() == "HH" ) )
	{
		sHour = "00";
	}

	if (trim(sMin) == "" ||  (sMin.toUpperCase() == "MM" ) )
	{
		sMin = "00";
	}

   sValid = IsValidTime(sHour,sMin,sFromctrl);
    if ( sValid != 0 )
	{
		alert("err:  Pre val " + document.all(sCtrlTimeName).value)
		document.all(sCtrlTimeName).value = sInTime;
		  if( sValid == 1 )
		  {
		  document.all(sHourCtrl).focus();
		  document.all(sHourCtrl).select();
		  return;
		  }
	
		  if( sValid == 2 ) 
		   	{
		   	document.all(sMinCtrl).focus();
		   	document.all(sMinCtrl).select();
		   	return;
		   	}
		return; 
	}
	else
   {	 	
		if ( sHour > 0  &&   sHour < 10 )
		{
		 sHour = "0" + eval( sHour)
		 document.all(sHourCtrl).value = sHour
		}

	
		if ( sMin < 10)
		{
		sMin = "0" + eval(sMin )
		document.all(sMinCtrl).value = sMin
		}	
		alert(JS_FO_CLIE_ASGN)
		document.all(sCtrlTimeName).value = sHour + ":" + sMin + ":" + "00" + " " + sMeridian;
		/* on success of hours set focus to minute */
			if(sFromctrl == "H")
			{
			  document.all(sMinCtrl).focus();
			  document.all(sMinCtrl).select();
			}
	}
	
}


function vSplitTime(sCtrlTimeName,sHourCtrl,sMinCtrl,sMeridianCtrl)
{
/* 
To split the time values (from 'HH:MM:SS AM/PM' format to  'HH'  'MM'  'AM/PM' )
Splits and strores in corresponding text boxes.
--------------------------------------------------------------------------
Arguments			Purpose
--------------------------------------------------------------------------
sCtrlTimeName       name of the control will have the value in 'HH:MM:SS AM/PM' format 

*/

var sTime
var sTimeArray  = new Array();


sTime = document.all(sCtrlTimeName).value ;
sTimeArray = sTime.split(":")
	
	document.all(sHourCtrl).value = sTimeArray[0]; 
	document.all(sMinCtrl).value = sTimeArray[1]; 
	 
	if (Right(sTime,2) == "AM")
		document.all(sMeridianCtrl).options.selectedIndex = 0
	else
		document.all(sMeridianCtrl).options.selectedIndex = 1
}




function IsValidTime(sHour,sMin,sFrom) 
{
/* 
this function called by  vMergeTime() 

*/

  if (sFrom == "H"  ) 
	if ((sHour < 1  || sHour > 12) || trim(sHour) == "" ) 
	{
		alert(JS_FO_CLIE_MSG_2630);
		return 1;
	}

  if (sFrom == "M"  ) 
	if( (sMin < 0 || sMin > 59) || trim(sMin) == "" )
	{
		alert (JS_FO_CLIE_MSG_2475);
		return 2;
	}
	
	return 0;
}

// ---------------------------------------------------------------------

function  vLimitHitKeys(sHourCtrl,sMinCtrl,sMeridianCtrl,sCtrlTimeName,sFromctrl)
{



var sHour
var sMin 
var sMeridian
var sValid
var sInTime
	
	sHour = document.all(sHourCtrl).value ;
	sMin = document.all(sMinCtrl).value; 
	sInTime = document.all(sCtrlTimeName).value
	sFromctrl = sFromctrl.toUpperCase()
	sMeridian = document.all(sMeridianCtrl).value ;

var sSrcText  =  event.srcElement.value;
var nSrcLen = trim(sSrcText).length;

	//alert("vLimitHitKeys from  " + sFromctrl)
	//To avoid flashing alert for non impression keys
	
	
					
	      var sEventType = window.event.type;
			if(trim(sEventType) != "BLUR")
			 {	
				if(window.event.keyCode < 32 ) 
				return;
			 }
			
				
	if (trim(sHour) == "" ||  (sHour.toUpperCase() == "HH" ) )
	{
		sHour = "00";
	}

	if (trim(sMin) == "" ||  (sMin.toUpperCase() == "MM" ) )
	{
		sMin = "00";
	}


if ( (nSrcLen >= 2 )) 
{ 
  		if ( sHour > 0  &&   sHour < 10 )
		{
		 sHour = "0" + eval( sHour)
		 document.all(sHourCtrl).value = sHour
		}

	
		if ( sMin < 10)
		{
		sMin = "0" + eval(sMin )
		document.all(sMinCtrl).value = sMin
		}	
		
		/* on hitkeys of hours, then set focus to minute */
			if (sFromctrl == "H")
			{
				document.all(sMinCtrl).focus() ;
				document.all(sMinCtrl).select();
			}
			if (sFromctrl == "M" )
			{
				document.all(sMeridianCtrl).focus() ;
			}
		return true ;

 }// if outer strlen>=2
}//fun




function  vMergeTimeValues(sHourCtrl,sMinCtrl,sMeridianCtrl,sCtrlTimeName,sFromctrl,sEvent)
{

var sHour
var sMin 
var sMeridian
var sValid
var sInTime
	
	sHour = document.all(sHourCtrl).value ;
	sMin = document.all(sMinCtrl).value; 
	sInTime = document.all(sCtrlTimeName).value
	sFromctrl = sFromctrl.toUpperCase()
	sMeridian = document.all(sMeridianCtrl).value ;
	
	
var sSrcText  =  event.srcElement.value;
var nSrcLen = trim(sSrcText).length;

	//To avoid flashing alert for non impression keys
	//if(window.event.keyCode == 9)

	if (trim(sHour) == "" ||  (sHour.toUpperCase() == "HH" ) )
	{
		sHour = "00";
	}

	if (trim(sMin) == "" ||  (sMin.toUpperCase() == "MM" ) )
	{
		sMin = "00";
	}

 

  sValid = IsValidTime(sHour,sMin,sFromctrl);
   if ( sValid != 0 )
	{

		document.all(sCtrlTimeName).value = sInTime;
		
		  if( sValid == 1 )
		 {
		  document.all(sHourCtrl).focus();
		  document.all(sHourCtrl).select();
		  return false;
		  }
	
		  if( sValid == 2 ) 
		   	{
		   	document.all(sMinCtrl).focus();
		   	document.all(sMinCtrl).select();
		   	return false;
		   	}
		return false; 
	}
    else
    {
		
		if ( sHour > 0  &&   sHour < 10 )
		{
		 sHour = "0" + eval( sHour)
		 document.all(sHourCtrl).value = sHour
		}

	
		if ( sMin < 10)
		{
		sMin = "0" + eval(sMin )
		document.all(sMinCtrl).value = sMin
		}	
		
		
		document.all(sCtrlTimeName).value = sHour + ":" + sMin + ":" + "00" + " " + sMeridian;
		/* on success of hours set focus to minute */
			if (sFromctrl == "H")
			{
				document.all(sMinCtrl).focus() ;
				document.all(sMinCtrl).select();
			}
			if (sFromctrl == "M" )
			{
				document.all(sMeridianCtrl).focus() ;
			}
		return true ;
    }//else

}//fun




function emailCheck (emailStr) {

var checkTLD=1;
var tmp;
//alert("email check")
/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|in|sg|aus|can)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "daya nand"@ecyber.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. daya@[10.0.0.112] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in daya.nand@somewhere.com, daya and nand are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

//alert("Email address seems incorrect (check @ and .'s)");
alert(JS_FO_CLIE_MSG_2631+".\n"+JS_FO_CLIE_MSG_2632)

return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert(JS_FO_CLIE_MSG_2633);
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert(JS_FO_CLIE_MSG_2634);
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert(JS_FO_CLIE_MSG_2635);
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert(JS_FO_CLIE_MSG_2636+"!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert(JS_FO_CLIE_MSG_2637+".");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */
tmp = domArr[domArr.length-1].toLowerCase()
//alert(tmp)
if (checkTLD && domArr[domArr.length-1].length!=2 && 
tmp.search(knownDomsPat)==-1) {
alert(JS_FO_CLIE_MSG_2638 + JS_FO_CLIE_CTRY+".");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert(JS_FO_CLIE_MSG_2639+"!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}




var InputMaskStep

function InputMaskStrip (InputMaskTemp, InputMask)
{
    InputMask = replace(InputMask,'#','');
    for (InputMaskStep = 0; InputMaskStep < InputMask.length++; InputMaskStep++)
		{
		    InputMaskTemp = replace(InputMaskTemp,InputMask.substring(InputMaskStep,InputMaskStep+1),'');
		}
		return InputMaskTemp;
}

function InputMaskMax (InputMask)
{
 		InputMaskTemp = InputMask;
    for (InputMaskStep = 0; InputMaskStep < (InputMask.length+1); InputMaskStep++)
		{
		 		if (InputMask.charAt(InputMaskStep)!='#')
				{
		        InputMaskTemp = replace(InputMaskTemp,InputMask.charAt(InputMaskStep),'');
				}
		}
		return InputMaskTemp.length;
}
function InputMask (key, textbox, InputMask)
{
//Start code for DE Phase II - Time control select & clear
	if (gnCounter==0)
	{
		textbox.value="";
	}
	gnCounter++;
//End code for DE Phase II - Time control select & clear

		InputMaskNum = InputMaskStrip(textbox.value, InputMask);
		
		if (key==9)
		{
		    return true;
		}
		else if (key==8&&InputMaskNum.length!=0)
		{
		 	InputMaskNum = InputMaskNum.substring(0,InputMaskNum.length-1);
		}
 	    else if ( ((key>47&&key<58)||(key>95&&key<106)) && InputMaskNum.length<InputMaskMax(InputMask) )
 	  	{
 	  	//Start code for DE Phase II - To accept only numeric
 	  		if ((key>=97&& key<=122) || (key>=65 && key<=90))
 	  		{
 	  			//************If the key is between a-z or A-Z, then do nothing***********
 	  		}
 	  		else
 	  		{
				InputMaskNum=InputMaskNum+String.fromCharCode(key);
			}	
		//End code for DE Phase II - To accept only numeric
		}

		var InputMaskFinal='';
    for (InputMaskStep = 0; InputMaskStep < InputMask.length; InputMaskStep++)
		{
        if (InputMask.charAt(InputMaskStep)=='#')
				{
					  if (InputMaskNum.length!=0)
					  {
				        InputMaskFinal = InputMaskFinal + InputMaskNum.charAt(0);
					      InputMaskNum = InputMaskNum.substring(1,InputMaskNum.length);
					  }
				    else
				    {
				        InputMaskFinal = InputMaskFinal + "";
				    }
				}
		 		else if (InputMask.charAt(InputMaskStep)!='#')
				{
				    InputMaskFinal = InputMaskFinal + InputMask.charAt(InputMaskStep); 			
				}

		}


		textbox.value = InputMaskFinal;
    return false;
}

function replace(fullString,text,by) {
// Replaces text with by in string
    var strLength = fullString.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return fullString;

    var i = fullString.indexOf(text);
    if ((!i) && (text != fullString.substring(0,txtLength))) return fullString;
    if (i == -1) return fullString;

    var newstr = fullString.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(fullString.substring(i+txtLength,strLength),text,by);

    return newstr;
}


//Start code for time validation
function vValidateTime(sTimeStr)
{
	var sHour;
	var sMin;
	var sMilTime;
	var asTime;
	var sDelim;
	sDelim = ":";
	
	if (sTimeStr == "")
	{
		alert (JS_FO_CLIE_STRT_TIM_EMTY+".")
		return false;
	}
	
	asTime = sTimeStr.split(sDelim)

	sHour = asTime[0];

	sMin = asTime[1];

	sMilTime = Left(sTimeStr,2)

	if (sHour == "")
	{
		alert (JS_FO_CLIE_ST_TIMH_EMTY)
		document.frmWOAssign.txtSchtime.focus();
		return false;
	}
	
	if (sMin == "")
	{
		alert (JS_FO_CLIE_ST_TIMM_EMTY+".")
		document.frmWOAssign.txtSchtime.focus();
		return false;
	}
		
	/*if (trim(sHour) == "" ||  (sHour.toUpperCase() == "HH" ) )
	{
		sHour = "00";
	}
	if (trim(sMin) == "" ||  (sMin.toUpperCase() == "MM" ) )
	{
		sMin = "00";
	}*/
	//by menaka
	sMin=sMin.replace("AM","")
	sMin=sMin.replace("PM","")
	//by menaka
	if ((eval(sHour) <= "0") || (eval(sHour) > "12"))
	{
		alert (JS_FO_CLIE_MSG_2640+".")
		return false;
	}
	
	if ((eval(sMin) < "0") || (eval(sMin) > "59"))
	{
		alert (JS_FO_CLIE_MSG_2641+".")
		return false;
	}	
return true;	
}
//Start code for time validation

//Start code for customize window
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//End code for customize window

function GetCurrFormat(fldvalue) 
{
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var decSep ='.';
var milSep = ',';
var nNoOfDecimals = 0;
var iStart = fldvalue.indexOf(".");

if (fldvalue == "0" || fldvalue == "0.00" || fldvalue == "" )
{
  
  return "0.00"
  
  }
if (iStart == fldvalue.length-2 && iStart > 0 )
    fldvalue = fldvalue.substr(0,fldvalue.length-2)+"."+fldvalue.charAt(fldvalue.length-1)+"0"

  
if (iStart > 0)
{
	if ((fldvalue.length - iStart) == 1)
	{
		fldvalue = fldvalue + "0";
	}
}
else 
	fldvalue = fldvalue + ".00";

len = fldvalue.length;

for(i = 0; i < len; i++)
	if ((fldvalue.charAt(i) != '0') && (fldvalue.charAt(i) != decSep)) break;
	aux = '';
	for(; i < len; i++)
		if (strCheck.indexOf(fldvalue.charAt(i))!=-1) aux += fldvalue.charAt(i);
		aux += key;
		len = aux.length;
		if (len == 0) fldvalue = '';
		if (len == 1) fldvalue = '0'+ decSep + '0' + aux;
		if (len == 2) fldvalue = '0'+ decSep + aux;
		if (len > 2) 
		{
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) 
		{
			if (j == 3) 
			{
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
	fldvalue = '';
	len2 = aux2.length;
	for (i = len2 - 1; i >= 0; i--)
		fldvalue += aux2.charAt(i);
		fldvalue += decSep + aux.substr(len - 2, len);
}
return fldvalue;
}

 
function dGetCurrValue(sValue)
	{	
		var rExp = new RegExp(",", "gi");
		sValue=sValue.replace(rExp,""); 
		sValue = parseFloat(sValue);
		return sValue;
	}
	
/*Start code for Time Validation. This function 
Controls hours and minutes at onBlur event. */

function sValidateTime()
{
  //Start code for DE Phase II - Time control select & clear
	gnCounter=0;
  //Start code for DE Phase II - Time control select & clear
var oTxt;
var sText;
var sSplitTime;
var nHrs;
var nMins;
oTxt = event.srcElement; 
sText = oTxt.value;
sSplitTime = sText.split(":");

nHrs = eval(sSplitTime[0]);
nMins = eval(sSplitTime[1]);

/* if time text box is empty string, skips checking */
if (sText == "" ) 
	return;

//Start code for DE Phase II - To check hrs (or) min empty
/* If hrs or min part is empty, skips checking */
	var sHour;	
	var sMin;
	var asTime;
	asTime = sText.split(":")
	sHour = asTime[0];
	sMin = asTime[1];
	
if (sHour=="")
{
	alert(JS_FO_CLIE_MSG_2630+".")
	oTxt.focus();
	oTxt.select();
	return false;
}
if (sMin=="")
{
	alert("Minutes must be between 0 and 59")
	oTxt.focus();
	oTxt.select();
	return false;
}
//End code for DE Phase II - To check hrs (or) min empty

/* if time text box is not empty string, checking continues*/
if( (nHrs <=0 || nHrs > 12) && (nMins <0 || nMins > 59 ) )
{
	alert("1."+JS_FO_CLIE_MSG_2630+".\n2."+JS_FO_CLIE_MSG_2475%+". ")
	oTxt.focus();
	oTxt.select();
	return false;
}

if( nHrs <= 0 || nHrs > 12)
 {alert("Hours must be between 1 and 12.")
  oTxt.focus();
  oTxt.select();
  return false;
  }

if( nMins < 0 || nMins > 59)
	
 {alert(JS_FO_CLIE_MSG_2475)
  oTxt.focus();
  oTxt.select();
  return false;
  }
 return;
}

//Start code for DE Phase II - Time control select & clear
function vSelectThis(sThisValue)
{
	sThisValue.select();
}
//End code for DE Phase II - Time control select & clear


function DecimalFormat(fld, milSep, decSep, e) 
{
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
len = fld.value.length;

if (len > fld.maxLength ) 
{
window.event.keycode = 0;
return;
}


if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key


for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '0' + aux;
if (len == 2) fld.value = '0'+ decSep + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
//aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}


//FO22 - New development - Start
function round(number,decimal)
{
	 number *= Math.pow(10,decimal);
	number= Math.round(Math.abs(number))	
	number /= Math.pow(10,decimal);
	return number
}
//FO22 - New development - End

//"Start Code for FBS"
function vCheckUser(sFaciID)
{

//GetWindowLocation(700,550)
//window.open("chkuserrights.asp?"+sFaciID);
//return

		var sUrl;
		sUrl="chkuserrights.asp?FacId="+sFaciID;
		
		GetWindowLocation(700,600);
	hwnd=window.open(sUrl,"fbsnew",gsWinLcn+",scrollbars=no");
	return
	
}
//End Code for FBS"