/**********************************************************
/	Project : Travel Studio
/	Description: This file contains globaly define variable
/				and it must be included/define in .htm file
/				where any other java script is included and
/				may used the following variables.
/
/	File	: Common.js
/	Author  : Mazher Mian
/	Created : 04/Feb/2000
/
/   History:
/   Who        Date        Description
/   RS[01]     07 Nov 2000 Added function GetPageinNewWindow()
/	AI		   15 Oct 2004	Fixed TSWeb French version
/   GGOSAVI 03 09 SEP 06  ADDED TWO NEW FUNCTIONS PopulateGlobalBookedOptions and StoreBookedOptions
***********************************************************/

//HOME = "http://IRS_SERVER/tsmweb/";
//OBJECTSPATH = HOME+"Objects.asp";
//SESSIONOBJECTSPATH = HOME+"SessionObjects.asp";

var HelpWindow;
var bFamilyRoomMergeToHotel;
var separator = ","; // use comma as 000's separator
var decpoint = "."; // use period as decimal point
var percent = "%";
var currency = "$"; // use dollar sign for currency
bFamilyRoomMergeToHotel = 1;  // can 1 or 0; 1 for merge and 0 for old style
//BOC GGOSAVI(03)
var strBookedOptions="";
//EOC GGOSAVI(03)

function GetHome()
{
	var index, nextindex, lastindex, i;
	var Path, vLenOfPath, vDirectory, vHome;

	vPath = location.pathname;
	vLenOfPath = vPath.length;
	
	index = 0;
	nextindex = 0;
	lastindex = 0;
	for(i=0 ; i < vLenOfPath ;  i++)
	{
		index = vPath.indexOf("/",nextindex);
		if( index != -1)
		{
			nextindex = index+1;
			lastindex = index;
		}
	}
	
	vDirectory = vPath.substr( 0, lastindex+1 );
	vHome = location.protocol+"//"+location.hostname+vDirectory;
	return vHome;
}

function GetObjectPath()
{
	return GetHome()+"Objects.asp";
}

function GetSessionObjectPath()
{
	return GetHome()+"SessionObjects.asp";
}

function GetRulesPath()
{
	return GetHome()+"GetRulesXML.asp" ;
}

function GetPage( page )
{
	var addr;
	addr = GetHome()+page;
	document.location.href = addr;
//	document.location.reload();
}

function GetPageInParent( page )
{
	var addr;
	addr = GetHome()+page;
	parent.document.location.replace( addr );
	return true;
}

function GetPageInChild( page )
{
	var addr;
	addr = GetHome()+page;
	parent.document.ChildFrame.location.replace( addr );
	return true;
}


// Variant-Type Constants.
var VT_EMPTY	   =   0
var VT_NULL      =   1
var VT_I2        =   3
var VT_I4        =   3
var VT_R4        =   4
var VT_R8        =   5
var VT_CY        =   6
var VT_DATE      =   7
var VT_BSTR      =   8
var VT_DISPATCH  =   9
var VT_ERROR     =   10
var VT_BOOL      =   11
var VT_VARIANT   =   12
var VT_DECIMAL   =   13
var VT_RECORD    =   14
var VT_UNKNOWN   =   15
var VT_I1        =   16
var VT_UI1       =   17
var VT_UI2       =   18
var VT_UI4       =   19
var VT_INT       =   20
var VT_UINT      =   21


/*
	Developer	:	Mansoor Ahmed Siddiqui
	Function	:	This function takes you to the page whose address
					is passed as parameter.
*/
function GotoPage(page)
{
	window.location.href = page ;
//	window.location.reload() ;
}

/*
	Developer	:	Mansoor Ahmed Siddiqui
	Function	:	This function takes Click event handler name for an Anchor, and
					the text to be displayed in Anchor as parameters, and returns
					the html string.
*/
function AnchorHTML(r_ClickHandler, r_Text)
{
	var html ;
	html = "[" + "<A class=cNormLinks href = \"\" onclick = \"" + r_ClickHandler + "();\" >" + r_Text + "</A>" + "]" ;
	return html ;
}

/*
	Developer	:	Raahim Ali Syed
	Function	:	This function set VISIBLE property HIDDEN of any DIV 
					DIV name should be specified to perform action.
*/	

function hidemsg(n)
{		
	document.all["msg" +n].style.visibility="hidden";
}

/*
	Developer	:	Raahim Ali Syed
	Function	:	This function set VISIBLE property VISIBLE of any DIV 
					DIV name should be specified to perform action.
*/
function showmsg(n)
{
	//hidemsg();
    document.all["msg" +n].style.visibility= "visible";
}

/*  RS[01]
	Developer	:	Rehan Shamsi
	Function	:	This function loads the given html page in a new specified window.
*/
function GetPageinNewWindow(r_vPage,r_vTarget)
{
    try{
        var wnd;
        wnd = window.open (r_vPage, r_vTarget, "directories=no,status=yes,toolbar=no,menubar=no,location=no,resizable=yes")
        
        
        
        wnd.opener=window;
        wnd.focus();
        wnd.location.href=GetHome()+r_vPage;
        //return wnd;
    }
    catch(e)
    {
    }
}
//EOC RS[01]



function SendNonFinalizedInfo(vBookingID,FromPage,strMethodName){
	PrepareDocument(oRequestXML,"IRSClientGen.CWebBookingFactory","GetNonFinalizedBooking");
	AddObj(oRequestXML,strMethodName)   
	var paraIndex = 1; 
	AddObjPara(oRequestXML,gObjIndex,paraIndex++,vBookingID,VT_I2) ;
	AddObjPara(oRequestXML,gObjIndex,paraIndex++,'12/12/2000',VT_NULL) ;  //DUMMY DATE
   AddObjPara(oRequestXML,gObjIndex,paraIndex++,FromPage,VT_I2) ;
		
	try
	{
		SubmitRequest();
	
		if( IsErrorInResponseXML() )
		{
			alert( ErrorDescription ) ;
			return false ;
		}
		return true;
	}
	catch(e)
	{
		window.alert("Exception in Calling SendNonFinalizedInfo : " + e.description );
		return false;
	}
}



//added by JW 04 Jan 2001 to use for screen sensitive help

function OpenHelpFile(){

	var HelpFile = 	parent.HelpFile.value + "help.htm"
		if (HelpWindow && ! HelpWindow.closed){
			HelpWindow.location.href=HelpFile;
	}else{
		window.open(HelpFile,"HelpWindow","menubar=no,toolbar=no,resizable=yes,status=no,scrollbars=yes,top=50,left=50,height=500,width=500");
	}
}

function StoreServerDateTime(strValue,oData)
{
	try{
		var oDateTime = new Date(GetDateFromISODate(strValue));
//		alert(oDateTime.toString());
		var strServerDate = FormatDate(oDateTime.getDate(),oDateTime.getMonth()+1,oDateTime.getFullYear());
		//BOC() Mufaddal 
		var strServerTime=oDateTime.getHours()+":"+oDateTime.getMinutes()+":"+oDateTime.getSeconds()
		//EOC() Mufaddal
		var strServerDateTime=strServerDate+" "+strServerTime
		AddDataToTempStore( oData, "ServerDate", strServerDate );
		AddDataToTempStore( oData, "ServerTime", strServerTime );
		AddDataToTempStore( oData, "ServerDateTime", strServerDateTime );
		return true;
		}catch(e){
					alert('Error storing Server Date'+ ' '+e.description)
					return false;
				}
}

function opendestinations(){
	
	window.open("http://www.opendestinations.com","Open");

}

function IsValidNumber(iNumber)
{
  var checkOK = "0123456789";
  var checkStr = iNumber;
  var allValid = true;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch != ",")
      allNum += ch;
  }
  return allValid;
}

function IsValidEmail(sEmail)
{
  // test if valid email address, must have @ and .
  var checkEmail = "@.";
  var checkStr = sEmail;
  var EmailValid = false;
  var EmailAt = false;
  var EmailPeriod = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkEmail.length;  j++)
    {
      if (ch == checkEmail.charAt(j) && ch == "@")
        EmailAt = true;
      if (ch == checkEmail.charAt(j) && ch == ".")
        EmailPeriod = true;
	  if (EmailAt && EmailPeriod)
		break;
	  if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string
    if (EmailAt && EmailPeriod)
    {
		EmailValid = true
		break;
	}
  }
  return EmailValid;
}

function GetParamValue(sParam)
{
	sParam += "="
	//alert("location = " + window.location.href + " sParam = " + sParam)
	var iStartPos = window.location.href.indexOf(sParam)
	//alert(iStartPos)
	if (iStartPos < 0) 
		return ""
	var iEndPos = window.location.href.indexOf("&", iStartPos)
	//alert(iEndPos)
	return ( iEndPos >= iStartPos  ? 
			window.location.href.substring(iStartPos + sParam.length, iEndPos) :
			window.location.href.substring(iStartPos + sParam.length))
}


function trim( Value )
{
	return( ltrim( rtrim( Value ) ) );
}

function ltrim( Value )
{
	while( Value.charAt( 0 ) == " " )
	{
		Value = Value.substr(1, Value.length - 1);
	}

	while( Value.charCodeAt( 0 ) == 13 )
	{
		Value = Value.substr(2, Value.length - 2);
	}

	return(Value);
}

function rtrim( Value )
{
	while( Value.charAt(Value.length - 1) == " " )
	{
		Value = Value.substr(0, Value.length - 1);
	}

	while( Value.charCodeAt(Value.length - 2) == 13 )
	{
		Value = Value.substr(0, Value.length - 2);
	}

	return(Value);
}

function IsFirstCharacterAlpha(inStr)
{
	if ((inStr.charAt(0) < "A" || inStr.charAt(0) > "Z") &&
		(inStr.charAt(0) < "a" || inStr.charAt(0) > "z"))
	{
		return false
	}
	return true
}

function IsEmpty(inStr)
{
	if (inStr == null || trim(inStr) == "")
	{
		return true
	}
	return false
}

function IsInteger(inVal)
{
	inStr = inVal.toString()
	for (var i = 0; i < inStr.length; i++)
	{
		var oneChar = inStr.charAt(i)
		if (oneChar < "0" || oneChar > "9")
		{
			return false
		}
	}
	return true
}

function IsContainSpaces( Value )
{
	var i;
	for (i = 0; i <= Value.length - 1; i++)
	{
		if (Value.charAt(i) == " ")
			return (true)
	}
	return(false);
}

function IsValidMoney2(fNumber)
{
	if (IsEmpty(fNumber)) return true;

	var i = 0;

	for (i = 0; i < fNumber.length; i++)
		if ((fNumber.charAt(i) < '0' || fNumber.charAt(i) > '9') && (fNumber.charAt(i) != '.')) {
			return false;
		}

	return true;
}

function IsValidMoney(fNumber)
{
	var iState
	var iLength
	var iLoop
	iState = 1
	iLength = fNumber.length

	for (iLoop = 0; iLoop < iLength; iLoop++)
	{	
		switch (iState)
		{
		case 1 :
			if ((fNumber.charAt(iLoop) == '+') || (fNumber.charAt(iLoop) == '-'))
				iState = 5
			else
			if ((fNumber.charAt(iLoop) >= '0') && (fNumber.charAt(iLoop) <= '9'))
				iState = 2
			else
				return false;
			break;
		case 2 :
			if ((fNumber.charAt(iLoop) >= '0') && (fNumber.charAt(iLoop) <= '9'))
				iState = 2
			else
			if (fNumber.charAt(iLoop) == '.')
				iState = 3
			else
				return false;
			break;
		case 3 :
			if ((fNumber.charAt(iLoop) >= '0') && (fNumber.charAt(iLoop) <= '9'))
				iState = 3
			else	
				return false;			
			break;
		case 5 :
			if ((fNumber.charAt(iLoop) >= '0') && (fNumber.charAt(iLoop) <= '9'))
				iState = 2
			else
				return false;
			break;
		}
	}
	return true;
}

function RoundOff(fNumber, iDecimalPlaces)
{
	var factor = Math.pow(10, iDecimalPlaces)
	var magicNumber=0.01;
		
	if(fNumber < 0)
	    magicNumber = -0.01
	
	fNumber = Math.round(fNumber *  factor+ magicNumber)/factor

        return fNumber;


}

function CInt(sNumber)
{
	var iIndex;
	var iNumber = 0;
	for (iIndex = 0; iIndex < sNumber.length; iIndex++)
	{
		iNumber = (iNumber * 10) + sNumber.charCodeAt(iIndex) - 48;
	}
	return iNumber;
}

function IsInRange(iNumber, iMinRange, iMaxRange)
{
	if (iNumber >= iMinRange && iNumber <= iMaxRange)
		return true;
	else
		return false;
}

function IsFloat(rsInString)
{
	var bDotFound = false;
	var lsFloat = trim(new String(rsInString));
	
	if (lsFloat.charAt(0) == '+' || lsFloat.charAt(0) == '-')
		lsFloat = trim(lsFloat.substr(1, lsFloat.length - 1));
	
	for(i=0; i < lsFloat.length; i++)
	{
		if (lsFloat.charAt(i) < '0' || lsFloat.charAt(i) > '9')
		{
			if (lsFloat.charAt(i) == '.')
			{
				if (i == lsFloat.length -1)
					return false;
				else if (bDotFound)
					return false;
				else
					bDotFound = true;
			}
			else
				return false;
		}
	}
	
	return true;
}

function getSearchServerName()
{
		var strServerToUse="";
		// 
		try
		{	// try to read global variable "gvSearchServerName" defined in Cutomize.js
			// if its not defined SOMEHOW ! then use ""
			strServerToUse=gvSearchServerName
		}
		catch(e){;}
		return strServerToUse;

}

/*
	This function loads the booking record in oRequestXML and if successful
	it returns true otherwise it returns false.
*/
function LoadBooking(r_BookingID)
{
	try
	{
		// Load Booking.
		PrepareDocument(oRequestXML,"IRSClientGen.CWebBookingFactory","GetWebBooking");
		AddObj(oRequestXML,"G") ;  // Get objects by parameters.
		var paraIndex = 1 ;
		AddObjPara(oRequestXML,gObjIndex,paraIndex++,r_BookingID,VT_I2) ;
		SubmitRequest() ;
		if( IsErrorInResponseXML() )
			return false ;
		else
			return true ;
	}
	catch(e)
	{
		return false ;
	}
}

/*
	This function loads the booking details from the database.
*/
function LoadBookingDetails(r_BookingID)
{
	try
	{
		// Load Booking.
		PrepareDocument(oRequestXML,"IRSClientGen.CWebBookingFactory","GetWebBookingDetails");
		AddObj(oRequestXML,"G") ;  // Get objects by parameters.
		var paraIndex = 1 ;
		AddObjPara(oRequestXML,gObjIndex,paraIndex++,r_BookingID,VT_I2) ;
		SubmitRequest() ;
		if( IsErrorInResponseXML() )
			return false ;
		else
			return true ;
	}
	catch(e)
	{
		return false ;
	}
}
/*
	This function will be called whenever user selects a booking from the list.
	This function loads the Booking and details (booked options) and stores
	these xmls in parent.
*/
function SelectBooking(BookingID,bChild)
{
	if(isNaN(bChild))
		bChild = 0
	
	if (isNaN(BookingID))
	{
		BookingID = parseInt(window.event.srcElement.alt) ;
		if(isNaN(BookingID)) // if still Booking Id is NAN
		{
			if (document.SearchTemplateForm)
			{
				if ((isNaN(BookingID))||(SearchTemplateForm.txtNewBookingFlag.value == 1))// (BookingID == 0)
				{
					//window.history.go(-1);
					window.location.replace('default.asp')
					return ;
				}
				try
				{
					// Store BookingID in parent.
					//AddDataToTempStore(oData, "BookingId", BookingID) ;
					
					GetPage("EditCancelBooking_Parent.asp?BookingId="+BookingID) ;
					return false;
				}
				catch(e)
				{
					alert("Exception in loading \"Booking/Booking Details\" : " + e.description) ;
					return false ;
				}
				
			}
			else
			{
				if(parent)
					parent.window.location.replace('default.asp');
				else
					window.location.replace('default.asp');
				return false;
			}
			
		}
	}
	else
	{
		if (parent.NewBooking)  // Checks whether we are in Non Accomodation
		{
			if ((BookingID == 0) || (( parent.NewBooking.value * 1) == 1))
			{
				//window.history.go(-3);	
				parent.window.location.replace('default.asp')
				return
			}
		}
		else
		{
			if (SearchTemplateForm.txtNewBookingFlag)
			{
				if ((isNaN(BookingID))||(SearchTemplateForm.txtNewBookingFlag.value == 1))// (BookingID == 0)
				{
					//window.history.go(-1);
					window.location.replace('default.asp')
					return ;
				}
				try
				{
					// Store BookingID in parent.
					//AddDataToTempStore(oData, "BookingId", BookingID) ;
					
					GetPage("EditCancelBooking_Parent.asp?BookingId="+BookingID) ;
					return false;
				}
				catch(e)
				{
					alert("Exception in loading \"Booking/Booking Details\" : " + e.description) ;
					return false ;
				}
				
			}
			else
				return false;
		}
		
	}
//	alert("In SelectBooking()" + BookingID) ;
	
	// Get the booking and booked services and store in the parent.
	try
	{
		var oObjs ;
		var Count ;
		var CurID;
		
		// Store BookingID in parent.
		AddDataToTempStore(parent.oData, "BookingId", BookingID) ;
/*		
		CurID = FindNameByCodeEx( 0, 10, BookingID , oTempXML );
		AddDataToTempStore( parent.oData, "BookingCurrencyIDForCurrentSession", CurID );
		AddDataToTempStore( parent.oData, "TempBookingCurrencyID", CurID );
*/				
		// Loads the booking in oRequestXML object.
		if (LoadBooking(BookingID))
		{
			oObjs = oResponseXML.getElementsByTagName( "OBJ" ) ;
			Count = oObjs.length ;
			if (Count > 0)
			{
				CurID = FindNameByCodeEx(0, 8, BookingID, oResponseXML)
				AddDataToTempStore( parent.oData, "BookingCurrencyIDForCurrentSession", CurID);
				AddDataToTempStore( parent.oData, "TempBookingCurrencyID", CurID);

				AddDataToTempStore(parent.oData, "Booking", oResponseXML.xml) ;
				var BookingName = FindNameByCodeEx(0, 1, BookingID, oResponseXML) ;
				AddDataToTempStore(parent.oData, "BookingName", BookingName) ;
				//added by SHAHJAHAN to store Cancelled Booking
				var vCancelledBooking=FindNameByCodeEx(0, 12, BookingID, oResponseXML) ;
				AddDataToTempStore(parent.oData, "CancelledBooking", vCancelledBooking) ;
				var BookingRef = FindNameByCodeEx(0, 11, BookingID, oResponseXML) ;
				AddDataToTempStore(parent.oData, "BookingRef", BookingRef) ;
				
				var BookingDateWithTime = FindNameByCodeEx(0, 4, BookingID, oResponseXML) ;
				BookingDateWithTime = new Date(BookingDateWithTime) ;
				//var vTestDate = oResponseXML.selectSingleNode("IRSCALL/OBJECTS/OBJ/PARA3").text;
				//vTestDate = new Date(vTestDate);
				with (BookingDateWithTime)
				{
					var BookingTime = getHours() + ":" + getMinutes() + ":" + getSeconds() ;
					//var BookingTime = getTime() ;
					//var BookingDate = FormatDate(getDate(),getMonth()+1,getFullYear()) ;
					//var BookingDate = BookingDateWithTime ;
					var BookingDate = FindNameByCodeEx(0, 4, BookingID, oResponseXML) ;
					AddDataToTempStore(parent.oData, "BookingDate", BookingDate) ;
					AddDataToTempStore(parent.oData, "BookingTime", BookingTime) ;
				}
			}
		}
		else
		{
			alert("Booking could not be loaded.\n" + ErrorDescription) ;
			return false ;
		}		
		// Loads the booking details in oResponseXML object.
		if (LoadBookingDetails(BookingID))
		{
			oObjs = oResponseXML.getElementsByTagName("OBJ") ;
			// We are not checking for (Count > 0) because count might be equal
			// to 0 b/c a booking might not be assigned any options.
			AddDataToTempStore(parent.oData, "BookingDetails", oResponseXML.xml) ;
		}
		else
		{
			alert("Booking details could not be loaded\n" + ErrorDescription) ;
			return false ;
		}

		//GotoNextPage() ;
		var childframe
		childframe=parent.document.all["ChildFrame"]
		childframe.style.display = "none"
		if (bChild  == 0)
			GetPage("BookingAndBookedServices.htm") ;
		else
			GetPageInChild("BookingAndBookedServices.htm");
	}
	catch(e)
	{
		alert("Exception in loading \"Booking/Booking Details\" : " + e.description) ;
		return false ;
	}

}
function SubmitLoggingDetails(rstrMethodName,rarrValues)
{
	try
	{	
			PrepareDocument(oRequestXML,"Common",rstrMethodName);
			AddObj(oRequestXML,"A") ;  // append the record
			for (var lngIndex=0;lngIndex<rarrValues.length;lngIndex++)
				AddObjPara(oRequestXML,gObjIndex,lngIndex+1,rarrValues[lngIndex],0);	
			SubmitRequest("Logging Booking Details");

			if( IsErrorInResponseXML() )
			{
				alert("Error in Logging Details - " + ErrorDescription );
				return false;
			}
	}
	catch(e)
	{
		window.alert( "Exception in Logging Details: " + e.description );
		return false;
	}
	return true;
}


function RefreshDateTimeFromServer(){
try{
		PrepareDocument(oRequestXML,"SessionObjects","GetDateTime");
		SubmitSessionRequest("Getting Server Date Time");
		var strDateTime = GetSessionResponse();
//		alert("Getting Server DateTime");
		StoreServerDateTime(strDateTime,parent.oData)		
}
catch(e){
		alert("Error getting Server Time in ServiceBooking");
		return false;
		}
}

//BOC() Mufaddal
function SubmitErrorLog(rstrErrNumber,rstrErrDescription,rstrErrSource)
{
	arrLoggingValues = new Array();
	arrLoggingValues[0] = "" //LOGPARAMETER_SESSIONID
	arrLoggingValues[1] = "" //LOGPARAMETER_LOGGEDDATETIME
	arrLoggingValues[2] = rstrErrNumber //LOGPARAMETER_ERRORNUMBER
	arrLoggingValues[3] = rstrErrSource //LOGPARAMETER_ERRORSOURCE
	arrLoggingValues[4] = rstrErrDescription //LOGPARAMETER_ERRORDESCRIPTION
	arrLoggingValues[5] = "" //LOGPARAMETER_ERROREXTENDEDINFO
	
	SubmitLoggingDetails("LOGERRORDETAILS",arrLoggingValues);
}
//EOC() Mufaddal

function GetDateFromISODate(rstrDate)
{
	// YYYY-MM-ddTHH:MM:SS
	var strString = new String(rstrDate);
	var yyyy, MM, dd, hh, mm, ss, dtdate;
	strString = strString.replace("T", " ");
	yyyy = strString.substr(0, 4);
	MM = strString.substr(5, 2);
	dd = strString.substr(8, 2);
	hh = strString.substr(11, 2);
	mm = strString.substr(14, 2);
	ss = strString.substr(17, 2);
	
	dtdate = new Date(yyyy, MM-1, dd, hh, mm, ss);
	return dtdate;
}

/*
function GetIso8601DateFromDate(rstrDate)
{
	// YYYY-MM-ddTHH:MM:SS
	var oDateTime = new Date(rstrDate);
	var m = oDateTime.getMonth()+1;
	
	var strServerDate = oDateTime.getFullYear() + "-" + m + "-" + oDateTime.getDate();
	var strServerDate = strServerDate + " " + oDateTime.getHours() + ":" + oDateTime.getMinutes() + ":" + oDateTime.getSeconds();
	
	return strServerDate;
}

*/

function GetIso8601DateFromDate( ldate )
{
	var localDate = new Date(ldate)
	var ISO801Date   =  formatNumber(localDate.getYear(),"0000") + "-" + formatNumber(localDate.getMonth()+1,"00")  + "-" + formatNumber(localDate.getDate(),"00")+ " " + formatNumber(localDate.getHours(),"00")  +":"+ formatNumber(localDate.getMinutes(),"00")+":"+ formatNumber(localDate.getSeconds(),"00");
	return ISO801Date;
}


function formatNumber(theNumber, format) 
{ 
	if (theNumber - 0 != theNumber) return null; // if theNumber is NaN return null
	var useSeparator = format.indexOf(separator) != -1; // use separators in theNumber
	var usePercent = format.indexOf(percent) != -1; // convert output to percentage
	var useCurrency = format.indexOf(currency) != -1; // use currency format
	var isNegative = (theNumber < 0);
	theNumber = Math.abs (theNumber);
	if (usePercent) theNumber *= 100;
	format = strip(format, separator + percent + currency); // remove key characters
	theNumber = "" + theNumber; // convert theNumber input to string
	
	// split input value into LHS and RHS using decpoint as divider
	var dec = theNumber.indexOf(decpoint) != -1;
	var nleftEnd = (dec) ? theNumber.substring(0, theNumber.indexOf(".")) : theNumber;
	var nrightEnd = (dec) ? theNumber.substring(theNumber.indexOf(".") + 1) : "";
	
	// split format string into LHS and RHS using decpoint as divider
	dec = format.indexOf(decpoint) != -1;
	var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
	var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";
	
	// adjust decimal places by cropping or adding zeros to LHS of theNumber
	if (srightEnd.length < nrightEnd.length) 
	{
	var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
	nrightEnd = nrightEnd.substring(0, srightEnd.length);
	if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1); // round up
	
	// patch provided by Patti Marcoux 1999/08/06
	while (srightEnd.length > nrightEnd.length) 
	{
	nrightEnd = "0" + nrightEnd;
	}
	
	if (srightEnd.length < nrightEnd.length) 
	{
	nrightEnd = nrightEnd.substring(1);
	nleftEnd = (nleftEnd - 0) + 1;
	}
	} else {
	for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) 
	{
	if (srightEnd.charAt(i) == "0") nrightEnd += "0"; // append zero to RHS of theNumber
	else break;
	}
	}
	
	// adjust leading zeros
	sleftEnd = strip(sleftEnd, "#"); // remove hashes from LHS of format
	while (sleftEnd.length > nleftEnd.length) 
	{
	nleftEnd = "0" + nleftEnd; // prepend zero to LHS of theNumber
	}
	
	if (useSeparator) nleftEnd = separate(nleftEnd, separator); // add separator
	var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : ""); // combine parts
	output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
	if (isNegative) 
	{
	// patch suggested by Tom Denn 25/4/2001
	output = (useCurrency) ? "(" + output + ")" : "-" + output;
	}
	return output;
}

function strip(input, chars) 
{ 
	// strip all characters in 'chars' from input
	var output = ""; // initialise output string
	for (var i=0; i < input.length; i++)
	if (chars.indexOf(input.charAt(i)) == -1)
	output += input.charAt(i);
	return output;
}

function separate(input, separator) 
{ 
	// format input using 'separator' to mark 000's
	input = "" + input;
	var output = ""; // initialise output string
	for (var i=0; i < input.length; i++) 
	{
	if (i != 0 && (input.length - i) % 3 == 0) output += separator;
	output += input.charAt(i);
	}
	return output;
}

/* BOC GGOSAVI(03)*/

function PopulateGlobalBookedOptions(BookedOptionsId)
{
  /*Intially this will collected all the bookedoptionsid for the service*/
  strBookedOptions=BookedOptionsId +"-"+strBookedOptions;
  return "";
}

   function StoreBookedOptions()
{
  /*This will store the bookedoptionsid string from above to  the session variable 
    BookedOptionsId which will be used later*/
  var strCacheValue;
  var oElement;
  oElement=parent.document.all("BookedOptionsId");
  if(oElement!=null){
      
	 
      strCacheValue=(parent.BookedOptionsId.value);
	  strCacheValue=strCacheValue+strBookedOptions;
	  AddDataToTempStore(parent.oData, "BookedOptionsId", strCacheValue) ;
	  
	 
   }else
   {  
       AddDataToTempStore(parent.oData, "BookedOptionsId", strBookedOptions) ;
	   
   }
   return ""
}


/* EOC GGOSAVI(03)*/
