//document.onkeypress=
//	function checkKeyPress(e) {
//		key=document.layers?e.which:document.all?event.keyCode:e.keyCode;
//		if (key == 13)
//			document.forms[0].submit();
//			return;
//	}
function CheckFieldLenght( iFieldName , iLen)
{
	var text;
	var xField;
	xField = document.forms[0].elements[ iFieldName ]
	text=xField.value;
	if (text.length >= iLen)
	{
		xField.value=text.substring(0,iLen);
		xField.blur();
	}
}
function getListValue( option_object  )
{
    var xReturn = "";
    for( i=0; i < option_object .length; i++)
    {
         if( option_object[i].selected == true)
         {
              xReturn = xReturn + "~" + option_object[i].value;
         }
    }
    return xReturn;
}
function getListValueOLD( option_object  )
{
 return option_object[ option_object.selectedIndex ].value;
}
function getYear( iYear )
{
var xF = document.forms[0];
var TargetElement = xF.ETAMonth;
      for( i=0; i < TargetElement.length; i++)
        {
            if( TargetElement[i].value.substr(2, 4) == iYear)
            {
                var YearIndex= i;
             }     
         }
  return YearIndex;
}

function changeCarGroup( _This )
{
		if( _This )
		{
			var xAgentUrl = '';
			var xGRP = getValue( 'STA' );
		xAgentUrl += gFleetURL + "/AjaxWebService?OpenAgent&MST=" + gMst + "&MSTPATH=" + gMstPath + "&MSTICONS=" + gMSTIcons;
		xAgentUrl +=   "&COUNTRY=" + gCountry + "&CTR=" + gCtr + "&LNG=" + gLng + "&F=getCarIconsPerFleetOwner&GRP=" + _This[_This.selectedIndex].value + "&STA=" + xGRP;
		getAJAXData('toggleCarGroup', xAgentUrl, '&RAN=' +  Math.random()  , 'carGroupIcons'); 	
	}	
}
function changeReturnStation(_This)
{
	if(_This[_This.selectedIndex].value == '' || _This[_This.selectedIndex].value == '-1'  || _This[_This.selectedIndex].value == 'xx')
		removeStationInformation('ETT');
	else
	{
		var xAgentUrl = '';
		xAgentUrl += gStationsURL + "/AjaxWebService?OpenAgent";
		xAgentUrl += gRandom + gAgentParam + "&F=getOpeningHoursPerLocation&STA=";
	
		setCssClass(_This); 
		setILCChanged();
		getAJAXData('toggleOpeningHours', xAgentUrl, _This[_This.selectedIndex].value, 'openingHoursReturn'); 	
	}
}
function resendEmail( iURL )
{
	xObj = document.getElementById( 'RESENDMAILSTART' );
	xObj2 = document.getElementById( 'RESENDMAILEND' );
	if( xObj && xObj2){
		xObj.style.display='block';
		xObj2.style.display='none';
	}
	getAJAXData('processConfirmationEmail', iURL,  '&RAN=' +  Math.random()  , 'RESENDMAILEND');
}
function changePickupStation(_This)
{
	var xSTA = '';
	var xFlag = getValue( 'NoFleetOwner');
	if(_This[_This.selectedIndex].value == '' || _This[_This.selectedIndex].value == '-1'  || _This[_This.selectedIndex].value == 'xx')
	{
		removeStationInformation('ETA');
	}
	else
	{
		var xAgentUrl = '';
		xAgentUrl += gStationsURL + "/AjaxWebService?OpenAgent";
		xAgentUrl += gRandom + gAgentParam + "&F=getOpeningHoursPerLocation";
		
		setCssClass(_This); 
		copySTA2ILC(); 
		setCssClass(document.getElementById('ILC')); 	
		// set Pickup hours
		getAJAXData('toggleOpeningHours', xAgentUrl +  "&DATE=" + gETADay +  gETAMonth + "&STA=", _This[_This.selectedIndex].value, 'openingHoursPickup'); 
		// set Return hours
		getAJAXData('toggleOpeningHours', xAgentUrl + "&DATE=" + gETTDay +  gETTMonth + "&STA=", _This[_This.selectedIndex].value, 'openingHoursReturn'); 
		xSTA= _This[_This.selectedIndex].value;
	}
	// relaod default car group list based on fleet owner
	if( xFlag != '1')
	{
		xAgentUrl = gFleetURL + "/AjaxWebService?OpenAgent&MST=" + gMst + "&MSTPATH=" + gMstPath + "&MSTICONS=" + gMSTIcons ;
		xAgentUrl +=   "&COUNTRY=" + gCountry + "&CTR=" + gCtr + "&LNG=" + gLng + "&F=getCarGroupsPerFleetOwner&STA=" + xSTA;
		getAJAXData('toggleCarList', xAgentUrl, '&RAN=' +  Math.random()  , 'GRP'); 	
	}
}
//********** runs in onLoad event and sets different CSS classes into the options. headlines are bold ************
function setCSSinDropdowns()
{
	var aDropdowns = new Array('Country', 'STA', 'Country2', 'ILC'); 	// define hier fields where to set headlines to bold
	var xHeadlineValue1 = 'xx';	// headlines
	var xHeadlineValue2 = '';	// 1st headline
	var xHeadlineValue3 = '-1';	// empty lines
	
	for( var i=0; i<aDropdowns.length; i++)
	{
		if( document.getElementsByName(aDropdowns[i]).item(0) )
		{
			var xField = document.getElementsByName(aDropdowns[i]).item(0);
			if( xField.options)
			{
				for( var j=0; j<xField.options.length; j++ )
				{
					if( (xField.options[j].value == xHeadlineValue1) || (xField.options[j].value == xHeadlineValue2) || (xField.options[j].value == xHeadlineValue3) )
					{
						switch(xField.options[j].value) 
						{
							case xHeadlineValue3:	
								xField.options[j].className = 'dropdownEmpty';	// set font color for labels of empty lines to white 
								break;
							case xHeadlineValue2:
								xField.options[j].className = 'dropdownFirstRow';	// set style for the 'Select...' entry
								break;
							case xHeadlineValue1:
								xField.options[j].className = 'dropdownHeadline';	// set style for the dropdown headlines
								break;
							default:
								 break;
						}
					}
					else
						xField.options[j].className = 'dropdownEntry';
				}
			}
		}
//		setCssClass(xField);
	}					
}
//******** set css for select fields to bold if a headline was selected ****************
function setCssClass(obj)
{
	if( obj.options[obj.options.selectedIndex] )
	{	
		xVal = obj.options[obj.options.selectedIndex].value;
		if( xVal == '-1') 
			obj.options.selectedIndex = 0;	// set to the 'select ...' label if an empty line was selected
		
/*		xVal = obj.options[obj.options.selectedIndex].value;
		if( (xVal == '' ) || (xVal == 'xx') )
			obj.style.fontWeight = 'bold';	// not possible to set to bold using an existing CSS class like this -> obj.className = 'defaultText dropdownHeadline';
		else
			obj.style.fontWeight = 'normal';	//obj.className = 'defaultText';		
*/
	}
}
function getNextDate(pEndDate, pAddDays)
{
  var aDate = new Array();
  aDate = pEndDate.split(".");
 
  var oDate = new Date( parseInt(aDate[2], 10), (parseInt(aDate[1], 10)-1), parseInt(aDate[0], 10), 0, 0, 0);
  oDate.setDate(oDate.getDate()+pAddDays)  
 
  return strright("00" + oDate.getDate(), 2) + "." + strright("00" + (oDate.getMonth()+1), 2) + "." + oDate.getFullYear();
}
function strright( xVal, xNr)
{
  return xVal.substr(xVal.length - xNr, xNr);
}
function DiffDays(S1, S2) {
  var aDate = new Array();
  aDate = S1.split(".")
  var D1 = new Date(parseInt(aDate[2], 10), parseInt(aDate[1], 10)-1, parseInt(aDate[0], 10), 0,0,0);
 
  aDate = S2.split(".")
  var D2 = new Date(parseInt(aDate[2], 10), parseInt(aDate[1], 10)-1, parseInt(aDate[0], 10), 0,0,0);
 
  return Math.round((D1 - D2) / 86400000);
}
function setETTDay()
{
  var xF = document.forms[0];
  var startMonthYear = xF.ETAMonth[xF.ETAMonth.selectedIndex].value;
  var endMonthYear = xF.ETTMonth[xF.ETTMonth.selectedIndex].value;
  var DayLoaded = document.getElementsByName('ETADayLoaded').item(0).value;
// ETA DAY, MONTH, YEAR
  var sDay = Number( xF.ETADay[xF.ETADay.selectedIndex].value );
  var sMonth = Number( startMonthYear.substr(0,2) );
  var sYear = Number( startMonthYear.substr(2,4) );
// ETT DAY, MONTH, YEAR
  var eDay = Number( xF.ETTDay[xF.ETTDay.selectedIndex].value );
  var eMonth = Number( endMonthYear.substr(0,2) );
  var eYear = Number( endMonthYear.substr(2,4) );
  // Get the difference between day end - day start. Day start is set in field ETADayLoaded
  var xOffset = DiffDays( eDay+ "."+eMonth+"."+eYear, DayLoaded);
// update ETADayLoaded value
  document.getElementsByName('ETADayLoaded')[0].value = sDay+"."+sMonth+"."+sYear;
// Max number of days in selected start Month
  var MaxDays = 31;
  if(sMonth==4 ||sMonth==6 || sMonth==9 || sMonth==11 )
  {
      MaxDays = 30;
  }
  if(sMonth==2)
  {
    MaxDays = 28;
    if(sYear%4==0)  MaxDays = 29;
    if(sYear%100==0) MaxDays = 28;
    if(sYear%400==0) MaxDays = 29;
  }
// Set start day to the last day of the start month, if selected day > max days
  if( sDay > MaxDays )
  {
    sDay = MaxDays;
    xF.ETADay.selectedIndex = MaxDays - 1;
  }
// calculate Offset 
if( xOffset < 0) 
  Diff =  xOffset +  MaxDays ;
else
  Diff = xOffset;
// Add Offset to the Start date
  var startDateNew = sDay + "." + sMonth + "." + sYear
  var newEndDate = getNextDate( startDateNew, Diff )
  var oNewEndDate = new Array();
  oNewEndDate = newEndDate.split(".");
 
  var newEndDay = oNewEndDate[0];
  var newEndMonth = oNewEndDate[1];
  var newEndYear = oNewEndDate[2];
  gETTDay = newEndDay;
  gETTMonth = newEndMonth + '' + newEndYear;
  xF.ETTDay.selectedIndex = newEndDay - 1;
  xF.ETTMonth[newEndMonth - 1].selected = true;
  var xNotInList = false;
  for(var i=0; i<xF.ETTMonth.length; i++)
  {
    if(xF.ETTMonth[i].value == newEndMonth + '' + newEndYear )
    {
      xF.ETTMonth[i].selected = true;
      xNotInList = false;
      break;
    }
    else
      xNotInList = true;
  }
  if( xNotInList )
  {
    xF.ETTMonth.selectedIndex = 0;
  }
// set opening hours for ETA and ETT
  setOpeningHours('ETA');
  setOpeningHours('ETT');
}
var xILCChanged = false;
function copySTA2ILC() 
{
    var xF = document.forms[0];
    var xSTA = xF.STA[ xF.STA.selectedIndex].value;
    if (xILCChanged == false)
    {
      for( var i=0; i<xF.ILC.length; i++)
      {
        if( xF.ILC[ i ].value == xSTA)
          xF.ILC.selectedIndex = i;
      }
    }
}
function setILCTickbox(){
	if( xILCChanged == false){
		x = $('input[name="restrictstationsSTA"]:checked').val();
		$('#restrictstationsILC' + x.toLowerCase() ).attr('checked','checked');
	}
}
function enableGRPChioce( iSTA )
{
  var xGRP = document.getElementById('GRP');
  var xFleetLink = document.getElementById('OpenFleetLink');
  if( xGRP )
  {
    if( iSTA.length > 0)
      xGRP.disabled = false;
    else
      xGRP.disabled = true;
  }
 if( xFleetLink )
  {
    if( iSTA.length > 0)
      xFleetLink.style.display = 'inline';
    else
      xFleetLink.style.display = 'none';
  }
}
function setILCChanged() 
{
    xILCChanged = true;
}
// Calender Picker
var opener_feld = "";
function getDate() 
{
    var datum = new Date();
    var h_jahr = datum.getFullYear();
    var h_monat = datum.getMonth()+1;
    var h_tag = datum.getDate();
}
// MIt Hilfe dieser Funktion wird das Datum an den Opener übermittlelt
function setOpenerDatum(tag, monat, jahr) 
{
     var xF = document.forms[0];
    xF.elements[opener_feld + "Day"].selectedIndex = (tag -1);
    xF.elements[opener_feld + "Month"].selectedIndex = (monat -1);
    xF.elements[opener_feld + "Year"].value = jahr
if (opener_feld == "ETA")
{ setETTDay(); }
}
function openKalender(of, iCalendarPickerURL) 
{
    opener_feld = of;
    window.open(iCalendarPickerURL,'newCal', 'width=230,height=230,left=30,screenX=30,top=30,screenY=30,resizable=no');	
}
function openPocketThis( iURL) 
{
    window.open(iURL,'newCal', 'width=264,height=370,left=600,screenX=30,top=30,screenY=30,resizable=yes');	
}
function checkRate() 
{
   var xF = document.forms[0];
    if( xF.elements["RAT1"] )
    {
        if( xF.elements["InputMemory"].value == "")
        {
            if( xF.elements["IsDomestic"].value == "0" && xF.elements["RATDefault"].value == "") 
                xF.elements["RAT1"].value ="";		
            else
                 xF.elements["RAT1"].value = xF.elements["RATMemory"].value;
        }
        else
        {
            if( xF.elements["InputMemory"].value == "XXXX")
                xF.elements["RAT1"].value = "";
            else
                xF.elements["RAT1"].value = xF.elements["InputMemory"].value
        }
    }
	
    var xSTAMemory  = xF.elements[ 'SelectedSTAStation'];
    var xILCMemory = xF.elements[ 'SelectedILCStation'];
    var xElement = null;
    
     xElement = xF.elements[ "_DEL"];
     if( xElement != null && xElement.checked == true)
     {
          setStation( 'STA' );
          if( xSTAMemory && xSTAMemory.value != "")
          {
                 insertDelColStation( xSTAMemory.value , 'STA');
           }
      }
     xElement = xF.elements[ "_COL"];
     if( xElement != null && xElement.checked == true)
     {
         setStation( 'ILC' );
         if( xILCMemory && xILCMemory.value != "")
         {
              insertDelColStation( xILCMemory.value , 'ILC');
         }
     }
         
    var now = new Date();
    var dateString = "";
    dateString= now.getYear() + ";" + (now.getMonth()+1) + ";" + now.getDate() + ";" + now.getHours() + ";" + now.getMinutes() +";" + now.getSeconds() ;
    xF.elements["_UserTime"].value = dateString;
    xType = "3";
    var xCountry = "";
    var xCountry2 = "";
    var xURL = xF.elements["DefaultSearch"].value;
    var win = null;
    var target = "STA";
   
      if( xF.elements["Country"] )
        xCountry = getValue("Country");
    if( xF.elements["Country2"] )
        xCountry2 = getValue("Country2");
    if( xCountry == "US" || xCountry == "CA" )
    {
        xURL = xURL.replace( /%TARGET%/, target).replace( /%TYPE%/, xType).replace( /%COUNTRY%/, xCountry);
        win = window.open( xURL, 'Stationfinder', "width=700,height=600 resizable=yes scrollbars=yes status=yes");
        win.focus(); 
    }
    else if( xCountry2 == "US" || xCountry2 == "CA" )
    {
        xURL = xURL.replace( /%TARGET%/, "ILC").replace( /%TYPE%/, xType).replace( /%COUNTRY%/, xCountry2);
        win = window.open( xURL, 'Stationfinder', "width=700,height=600 resizable=yes scrollbars=yes status=yes");
        win.focus(); 
    }
}
function inputMemory()
{
    var xF = document.forms[0];
    xInput = xF.elements["RAT1"].value;
    if( xInput=="")
        xF.elements["InputMemory"].value = "XXXX";
    else
        xF.elements["InputMemory"].value = xF.elements["RAT1"].value;
}
function insertDelColStation( station, target)
{
    var i=0;
    var TargetElement;
    var xSelectedStation;
    var xElements;
    var xValueArray = new Array();
    var xTextArray = new Array();
    var xNewEntry= null;
    var xNewEntry2= null;
    var xF = document.forms[0];
    
    xValueArray = xF.elements[ target + "StationValueList"].value.split("#");
    xTextArray = xF.elements[ target + "StationTextList"].value.split("#");
    TargetElement = xF.elements[ target ];
    xElements = TargetElement.length;
    xSelectedStation = station;
    //alert("xx " +  station+ " len:" + xValueArray.length + " target:" + target);
      
    for( i=0; i < xValueArray.length; i++)
    {       
        sString = xValueArray[i];
        yString = station.replace (/^\s+/, '').replace (/\s+$/, '');
        
        if( yString == sString && sString != "")
        {
            xNewEntry = new Option( xTextArray[i], xValueArray[i], true, true);
            TargetElement[0] = xNewEntry;
            xF.elements["Selected" + target + "Station"].value = xValueArray[i] + "#" + xTextArray[i];
            if( target == "STA"){
              changePickupStation( TargetElement ); 
              enableGRPChioce( TargetElement[ TargetElement.selectedIndex].value);
            }
            if( target == "STA"  && xF.elements['_COL'].checked == true)
           {
                TargetElement = xF.elements[ 'ILC' ]; 
	xNewEntry2 = new Option( xTextArray[i], xValueArray[i], true, true);
                TargetElement[0] = xNewEntry2;
           }
             self.window.name = i;
         }      
    }  
}    
function selectStationSTA( station, target)
{
    var TargetElement;
    var i =0;
    var xF = document.forms[0];
  
    TargetElement = xF.elements[ target ];
    
        for( i=0; i < TargetElement.length; i++)
        {
            if( TargetElement[i].value == station)
            {
                TargetElement.selectedIndex = i;
             }     
         }
     
         if( target == "STA")
        {
            changePickupStation( TargetElement ); 
            enableGRPChioce( TargetElement[ TargetElement.selectedIndex].value);
            TargetElement = xF.elements[ "ILC" ];
            for( i=0; i < TargetElement.length; i++)
            {
                 if( TargetElement[i].value == station)
                 {
                     TargetElement.selectedIndex = i;
                 }     
            }
        }
}
function setStation( target )
{
    var xNewEntry= null;
    var xF = document.forms[0];
    var xValueArray = new Array();
    var xTextArray = new Array();
    var xElement = null;
    var xCountry =  getValue("Country").slice(0,2);
    var xListbox = xF.elements[ target];
    var xEmptyString = "";
    var xTextList = "";
    var xValueList = "";
    xValueArray = xF.elements[ target + "StationValueList"].value.split("#");
    xTextArray = xF.elements[ target + "StationTextList"].value.split("#");
      
    if( xCountry == "GB")
    {
        if( target == "STA")
        {
             xElement = xF.elements[ "_DEL"];
             xEmptyString = xF.elements[ "UKDelString"].value;
         }
        else
        {
             xElement = xF.elements[ "_COL"];
             xEmptyString = xF.elements[ "UKColString"].value;
         }
               
        if( xElement != null && xElement.checked == true)
        {
            for( i=0; i < xListbox.length; i++)
            {
                if( i==0)
                {
                  xValueList = xListbox[i].value;
                  xTextList = xListbox[i].text;
                }
                else
                {
                    xValueList = xValueList + "#" + xListbox[i].value;
                    xTextList = xTextList + "#" + xListbox[i].text;
                }
            }
            xF.elements[ target + "StationValueList"].value = xValueList;
            xF.elements[ target + "StationTextList"].value = xTextList;
                
            xListbox.length = 1;
            xNewEntry = new Option( xEmptyString, "", true, true);
            xListbox[0] = xNewEntry;     
         }
         else
        {
            for( i=0; i < xValueArray.length; i++)
            {       
                xNewEntry = new Option( xTextArray[i], xValueArray[i], true, true);
                 xListbox[i] = xNewEntry;      
            }  
            xListbox.selectedIndex = 0;
        } 
    }
    setCSSinDropdowns();
}
function openSearchform( target , country)
{
    var xF = document.forms[0];
    xType = "";
    var xElement = null;
    var xCountry = "";
    var xCTR = "";
    var URL = "";
    var win = null;
    var xBox = "";
    
    xCountry = getValue("Country").slice(0,2);
    xCTR = xF.elements["_Ctr"].value;
    
    if( target=="STA")
       xBox = "_DEL";
   else
       xBox = "_COL";
    
    xElement = xF.elements[ xBox ];
    if( xElement != null && xElement.checked == true  && xCountry == "GB")
    {
        xURL = xF.elements["UKDelColSearch"].value;
        xType = "1";        
    }
   else
    {
        xType = "3";
        xURL = xF.elements["DefaultSearch"].value;
    }
    
   xURL = xURL.replace( /%TARGET%/, target).replace( /%TYPE%/, xType).replace( /%COUNTRY%/, country);
   win = window.open( xURL, 'Stationfinder', "width=700,height=600, resizable=yes, scrollbars=yes, status=yes");
   win.focus(); 
}
function openFleetSearch( target )
{
    var URL = "";
    var win = null;
    
    xURL = this.document.forms[0].elements["FleetSearch"].value;
    xSTA = getValue("STA");
    win = window.open( xURL + '&STA=' + xSTA, 'Fleetfinder', "width=650,height=400, resizable=yes, scrollbars=yes, status=yes");
    win.focus(); 
}
function openUPSFleet( target )
{
    var win = null;    
    win = window.open( target, 'CarDetails', "width=610,height=320, resizable=yes, scrollbars=yes, status=yes");
    win.focus(); 
}
function setGroup( xGroup)
{
    var xGRPItem = document.forms[0].elements['GRP1'];    
    var xGRP ="";
    for( var i=0; i < xGRPItem.length; i++)
    {
        xGRP =  xGRPItem.options[i].value;
       if( xGRP.substr(0,1) == "/")
           xGRP = xGRP.substr(0,2);
       else
           xGRP=xGRP.substr(0,1);
        if( xGRP == xGroup)
            xGRPItem.options[i].selected = true;
    }
    changeCarGroup( xGRPItem  );
}
function openTarget( iURL , iTarget)
{
    if( iTarget == "_self")
    {
        location.href = iURL;
    }
    else if( iTarget == "_top")
    {
        top.location.href = iURL;
    }
    else if ( iTarget == "_new")
    {
        FNew = window.open( iURL,"NewWindow","toolbar=yes, scrollbars=yes, status=yes, resizable=yes, menubar=yes, location=yes, left=0,top=0");
    }
}
function openEmailMeWindow( xURL)
{
  var  win = window.open( xURL, 'EmailMeThisQuote', "width=620,height=345 resizable=yes scrollbars=yes status=yes");
}
function openHelpWindow( xURL )
{
    var win = null
    win = window.open( xURL , 'HELP', "width=550,height=500,resizable=yes,scrollbars=yes,status=yes");
    win.focus();
}
//-->
function getValue( iFieldname)
{
    var xF = document.forms[0];
    if( iFieldname == 'ETA' || iFieldname == 'ETT')
    {
        if( xF.elements[ iFieldname + 'Day'] )
        {
	var xMonthYear = '';
	xMonthYear = document.getElementById(iFieldname + 'Month');
            var day1 = (xF.elements[ iFieldname + 'Day'].options[ xF.elements[ iFieldname+ 'Day'].selectedIndex].value); 
            var month1 = xMonthYear[xMonthYear.selectedIndex].value.substr(0, 2); 
            var year1 = xMonthYear[xMonthYear.selectedIndex].value.substr(2, 4); 
            var hour1 = (xF.elements[ iFieldname + 'Hour'].options[ xF.elements[ iFieldname+ 'Hour'].selectedIndex].value); 
            var min1 = (xF.elements[ iFieldname + 'Minute'].options[ xF.elements[ iFieldname+ 'Minute'].selectedIndex].value); 
            return( day1 + "-" + month1 +  "-" + year1 +  "-" + hour1 +  "-" + min1);
        }
    }
    else if(  iFieldname =='restrictstationsSTA')
    {
      xField1 = document.getElementById( 'restrictstationsSTAa');
      xField2 = document.getElementById( 'restrictstationsSTAc');
      if( xField1.checked) 
        return( xField1.value);
     else
        return( xField2.value);
     }
    else if( iFieldname =='restrictstationsILC')
    {
      xField1 = document.getElementById( 'restrictstationsILCa');
      xField2 = document.getElementById( 'restrictstationsILCc');
      if( xField1.checked >0) 
        return( xField1.value);
     else
        return( xField2.value);
     }
    else
    {
        if( xF.elements[ iFieldname] )
        {
            if( iFieldname =='restrictstationsSTA'){
                xField = xF.elements[ iFieldname];
           	alert( iFieldname + "  " +   xField.name + "  " + xF.elements[ iFieldname].type);
                alert( xField);
           }
           if( xF.elements[ iFieldname].type=='select-one')
           {
                return(xF.elements[ iFieldname].options[ xF.elements[ iFieldname].selectedIndex].value); 
            }
            else if( xF.elements[ iFieldname].type=='checkbox')
            {
                  if( xF.elements[ iFieldname].checked)
                        return( xF.elements[ iFieldname].value);
                 else
                        return("");
             }
             else
             {
                return( xF.elements[ iFieldname].value);
             }
         }
    }
}
function callReloadfromPopup( iParam)
{
    this.reloadDocument( iParam );
}
 
function reloadDocument( iFieldname )
{
    var xF = this.document.forms[0];
    var xPathList =  window.location.href.split( "&");
    var xPath = xPathList[0];
    var xPrefix ="";
    var xPos = 0;
    var xRefreshList = xF.elements[ 'ReloadFields'].value.split("&");
    var xRefreshParams = "";
    var xSetCountry ="";
    var xSetCountry2 = "";
 
    for( var i=1; i < xPathList.length; i++)
    {
        if( xPathList[i] )
        {
            xPrefix = xPathList[i].substring( 0, 3);
            if( xPrefix != 'RL_'  && xPrefix != 'Err')
            {
                if( iFieldname == 'NLCarType' && xPrefix == 'MST')
                  {}
	else  if( iFieldname == 'CPMST' && xPrefix == 'MST')
                  {}
	else
                  xPath = xPath + "&" + xPathList[i];
            
            }
        }
    }
    
     if( iFieldname.substring(0,4) == "STA=" )
          xSetCountry = iFieldname.slice(8) ;
     if( iFieldname.substring(0,4) == "ILC=" )
          xSetCountry2 = iFieldname.slice(8) ;
  
    for( var j=1; j < xRefreshList.length; j++)
    {
        if( iFieldname.substring(0,4) == "STA=" && xRefreshList[j] == "STA")
        {
             xRefreshParams =  xRefreshParams + "&RL_" + xRefreshList[j] + "=" + iFieldname.substring(4,7);    
        }
        else if( iFieldname.substring(0,4) == "ILC=" && xRefreshList[j] == "ILC")
        {
             xRefreshParams =  xRefreshParams + "&RL_" + xRefreshList[j] + "=" + iFieldname.substring(4,7);    
        }
        else if(  xRefreshList[j] == "TFE")
        {
             xRefreshParams =  xRefreshParams + "&RL_" + xRefreshList[j] + "=" + getValue( xRefreshList[j]);    
        }
        else if( ( xRefreshList[j] == "NLCarType"  ) && ( typeof( getValue( xRefreshList[j] )) != 'undefined'))
        {
             xRefreshParams =  xRefreshParams + "&MST=" + getValue( xRefreshList[j]);    
        }
        else if(  ( xRefreshList[j] == "CPMST"  ) && ( typeof( getValue( xRefreshList[j] )) != 'undefined'))
        {
             xRefreshParams =  xRefreshParams + "&MST=" + getValue( xRefreshList[j]);    
        }
        else
        {
            if( xF.elements[ xRefreshList[j]] && xF.elements[ xRefreshList[j]].type != 'hidden')
            {
                if( xRefreshList[j] == "Country" && xSetCountry.length > 0)
                    xRefreshParams =  xRefreshParams + "&RL_" + xRefreshList[j] + "=" + xSetCountry;
                else if( xRefreshList[j] == "Country2" && xSetCountry2.length > 0)
                    xRefreshParams =  xRefreshParams + "&RL_" + xRefreshList[j] + "=" + xSetCountry2;
                else
                    xRefreshParams =  xRefreshParams + "&RL_" + xRefreshList[j] + "=" + getValue( xRefreshList[j]);
            }
            if( xRefreshList[j] == 'ETA' || xRefreshList[j] == 'ETT' )
           {
                xRefreshParams =  xRefreshParams + "&RL_" + xRefreshList[j] + "=" + getValue( xRefreshList[j]);
           }
        }
    }
      if( iFieldname == "Country2")
          xPath = xPath + xRefreshParams + "&C2C=1";
       else
          xPath = xPath + xRefreshParams
     
     xPath = xPath +"&RL_Source=" + iFieldname;  
    location.href  =    xPath;
}
function reloadCorporateMST( iMSTFieldname)
{
    var xF = this.document.forms[0];
    var xPathList =  window.location.href.split( "&");
    var xPath = xPathList[0];
    var xPrefix ="";
    var xPos = 0;
    var xMSTfound = 0;
 
    for( var i=1; i < xPathList.length; i++)
    {
        if( xPathList[i] )
        {
            xPrefix = xPathList[i].substring( 0, 3);
            if( xPrefix != 'RL_'  && xPrefix != 'Err')
            {
                if( xPrefix == 'MST'){
                  xPath = xPath + "&MST=" + getValue( iMSTFieldname ) ;
                  xMSTfound = 1;
                }  
	else {
                  xPath = xPath + "&" + xPathList[i];
              }
            }
        }
    }
    if( xMSTfound == 0 ) 
       location.href  =    xPath + "&MST=" + getValue( iMSTFieldname ) ;
    else
       location.href  =    xPath;
}
cookiedomain = ".budget.is";
var CookieLIVEDAYSDefault=30;
var CookieLIVEDAYS=0;
var CookieExpireDate=new Date();
function setCookieDomain( iDomain ) 
{
  cookiedomain = iDomain;
}
function adjustCookieExpireDate( iDays, iHours, iMinutes)
{
     var date=new Date();
     var xTTL=0;
     if( !isNaN( iDays ))
    { 
       xTTL= iDays;
    }
    date.setDate(date.getDate() + xTTL);
    xTTL=0;
    if( !isNaN( iHours ))
    { 
       xTTL= iHours;
    }
     date.setTime(date.getTime() + (xTTL*1000*60*60));
     xTTL=0;
    if( !isNaN( iMinutes ))
    { 
       xTTL= iMinutes;
    }
     date.setTime(date.getTime() + (xTTL*1000*60));
    CookieExpireDate = date;
}
function getCookieExpireDate()
{
    var date=CookieExpireDate;
    var gmt=date.toGMTString();
    var k1=gmt.indexOf(" ");
    var k2=gmt.indexOf(" ", k1+1);
    var k3=gmt.indexOf(" ", k2+1);
    var str=gmt.substring(0,k2)+"-"+gmt.substring(k2+1,k3)+"-"+gmt.substring(k3+3,gmt.length);
    return str;
}
function clearCookie()
{
	var expires = new Date();
	var expiryDate = 'Wednesday, 07-Jan-04 23:59:59 GMT';
	document.cookie= 'expires=' + expiryDate;
}
function deleteCookieValue( iParam ) 
{
	var expires = new Date();
	var expiryDate = 'Wednesday, 07-Jan-04 23:59:59 GMT';
 	var xParamString =  iParam + ';expires='+ expiryDate + ';domain=' + cookiedomain + ';path=/';
 	document.cookie= xParamString;
}
function getCookieValue( xParam )
{
	var xRet = "";
	if(document.cookie)
	{
		values = document.cookie.split( xParam + '=');
		if( values[1] )
		{
			tid = values[1].split(';');
			xRet = tid[0];
		}
	}
	return xRet;
}
function setCookieValue( xParam )
{
  var xParamString =  xParam + ';expires='+ getCookieExpireDate() + ';domain=' + cookiedomain + ';path=/';
  document.cookie= xParamString;
}
function setSessionCookieValue( xParam )
{
  var xParamString =  xParam + ';domain=' + cookiedomain + ';path=/';
  document.cookie= xParamString;
}
function setCookieValuewithTTL( iParam, iTTLDays, iTTLHours , iMinutes)
{
  adjustCookieExpireDate( iTTLDays, iTTLHours, iMinutes);
  var xParamString =  iParam + ';expires='+ getCookieExpireDate() + ';domain=' + cookiedomain + ';path=/';
  document.cookie= xParamString;
}
function toggleMail2()
{
	var xField2 = document.getElementById("MAIL2ENABLED");
	var xLink = document.getElementById("MAIL2ON");
	
	$('tr.MAILROW2').show();
	if( xLink )
		xLink.style.display='none';
	if( xField2 ) 
		xField2.value = "1";
}
function recalculateSEPrice( xObject, xValue)
{
	var xF = document.forms[0];
	var xSEList = xF.elements['SEItems'].value.split(";");
	var xSEItem=null;
	var xFieldvalue="";
	var xValueArray = null;
	var xCount=0;
	var xPrice=0;
	var xPriceAll=0;
	var xMaxCost=0;
	xCur = null;
	var xTarget = $('#SEPrice')
	for(i=0; i< xSEList.length; i++)
	{
		xSEItem = xF.elements[xSEList[i]];
		if( xSEItem)
		{
			if( xSEItem.type=="checkbox")
			{
				if( xSEItem.checked)
					xFieldvalue = xSEItem.value;
				else
					xFieldvalue="";
			}
			else
			{
				xFieldvalue = xSEItem.options[ xSEItem.selectedIndex].value;		
			}
			
			xValueArray = xFieldvalue.split('~');	
			if( xValueArray.length == 5)
			{			
				xCount = parseInt( xValueArray[1], 10);
				xPrice = parseInt( xValueArray[2], 10);
				xCur = xValueArray[3];						
				xMaxCost = parseInt( xValueArray[4], 10);
				if( xMaxCost >0 && xMaxCost < xPrice )
					xPriceAll = xPriceAll + (xMaxCost * xCount);
				else					
					xPriceAll = xPriceAll + (xPrice * xCount);			
			}
		}		
	}	
	
	var xPriceString = new String(xPriceAll);
	var xPriceFull = xPriceString.substring(0, xPriceString.length -2);
	var xPriceFullDispaly = '';
	if( xPriceFull.length >3)
	{
		xPriceFullDispaly = xPriceFull.substring(0, xPriceFull.length -3) + gSEThousandSeparator  + xPriceFull.substring( xPriceFull.length -3, xPriceFull.length);
	}
	else
		xPriceFullDispaly = xPriceFull;
	var xPriceDec = xPriceString.substring(xPriceString.length -2, xPriceString.length );
	var xPriceDecInit = xPriceDec;
	if( xPriceString.length==1){
		xPriceFull = '0';
		xPriceFullDispaly  = '0';
		xPriceDec = '00';
	}
	if( xPriceDec =='00')
		xPriceDec = gSEZeroValue ;
	
	xTarget.html( xPriceFullDispaly + gSEDecimalSeparator + xPriceDec + '&nbsp;' + gSECurrency );
	//_ update prices in new step2
	
	cargrp = $('input[name="upspayment"]:checked').parents('div.cargroup').attr('id');
	var cargrp_poacur = poaPrices[ cargrp ].cur;
	var cargrp_poaprice = poaPrices[ cargrp ].price;
		
	if( cargrp_poacur == gSECurrency)
	{
		var price = cargrp_poaprice + (parseFloat(xPriceFull + '.' + xPriceDecInit));
		price = price.toFixed(2);
		xPriceFull = price.substring(0, price.length -3);
		if( xPriceFull.length >3)
		{
			var xPriceFullDispaly = xPriceFull.substring(0, xPriceFull.length -3) + gSEThousandSeparator  + xPriceFull.substring( xPriceFull.length -3, xPriceFull.length);
		}
		else
			var xPriceFullDispaly = xPriceFull;
		xPriceDec = price.substring(price.length -2, price.length );
	
		if($(cargrp).parents('div.cargroup').find('.pp.active').length)
		{
			$('#' + cargrp + ' .par .price' ).html( $('#' + cargrp + '.pp.active .price' ).text() )
		}else{
			$('#' + cargrp + ' .par2 .price' ).html(xPriceFullDispaly + gSEDecimalSeparator + xPriceDec + '&nbsp;' + gSECurrency) 
		}		
	}
}
function toggleCarGroupList( xAction )
{
	var xDiv = document.getElementById('MORECARLIST');
	var xDivOFF = document.getElementById('MORECARSOFF');
	var xOpenDiv = document.getElementById('MORECARS');
	var xCloseDiv = document.getElementById('CLOSEMORECARS');
		
	if( xDiv)
	{
		var xCompare =  xAction == 'ON';
		if( xCompare && xDiv.style && xDivOFF.style)
		{
			xDiv.style.display = 'block';
			if( xOpenDiv && xCloseDiv)
			{
				xOpenDiv.style.display='none';
				xDivOFF.style.display='block';
				xCloseDiv.style.display='block';
			}
		}
		else 
		{
			xDiv.style.display = 'none';	
			if( xOpenDiv && xCloseDiv)
			{
				xOpenDiv.style.display='block';
				xDivOFF.style.display='none';
				xCloseDiv.style.display='none';
			}
		}
	}
}
function openWaitScreen( iOpenerURL )
{
               //setup vars
	var xNewDoc = "";
	var xString = "";
	var xDocTitle = "Budget - Rent a Car";
	var xName = 'WaitScreen';
	var xWidth = "120";
	var xHeight = "120";
	var xPos = (screen.availWidth - xWidth)/2 ;
	var yPos = (screen.availHeight - xHeight)/2;
		
	// initialize new window
	xWindowOptions = 'width=' + xWidth + ',height=' + xHeight + ',status=no,toolbar=no,menubar=no,resizable=no,location=no,scrollbars=no';
	xPopUp = window.open('', xName, xWindowOptions);
	// place window
	xPopUp.moveTo(xPos,yPos);
	xNewDoc = xPopUp.document;
	
	// write document
	xNewDoc.write( '<html><head><title>' + xDocTitle + '</title>');
	xNewDoc.write('<SCRIPT LANGUAGE="JavaScript">');
	xNewDoc.write(' function closeWaitScreen(){');
	xNewDoc.write(' if(opener.location.href != "' + iOpenerURL + '") { this.close();} ');
	xNewDoc.write( '}' );
	xNewDoc.write( 'var hTimer01 =  window.setInterval( \'closeWaitScreen()\', 300); <\/SCRIPT>');
	xNewDoc.write( '<body marginwidth=0 marginheight=0 topmargin=0 leftmargin=0>');	
	
	xNewDoc.write('<FONT FACE="arial" SIZE="2" COLOR="#000000"><CENTER><BR></CENTER></FONT></body></html>');
	
	xPopUp.focus();
}
