// 1. HIER GAR NICHTS MACHEN
//===============================================================
// XML REQUEST
//==============================================================
function initXMLHttpRequest() {
                                                                          // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
     }
     else if (window.ActiveXObject) {      // branch for IE/Windows ActiveX version
        req = new ActiveXObject("Microsoft.XMLHTTP");
     }
  return(req);
}
function makeCustomHandlerForObject(reqString, targetObjectString, returnProperty) {
        out = "var xmlOutput = processReadyStateChange(window[\"" + reqString + "\"],\"" + returnProperty +  "\");";
        out = out + "if ( ! (typeof(xmlOutput) == \"string\" && xmlOutput == \"\") ) {" + targetObjectString +  "= xmlOutput; window[\"" + reqString +"\"] = null;}";
        return out;
}
function makeCustomHandlerForFunction(reqString, targetObjectString, returnProperty) {
        out = "var xmlOutput = processReadyStateChange(window[\"" + reqString + "\"],\"" + returnProperty +  "\");";
        out = out +  "if ( ! (typeof(xmlOutput) == \"string\" && xmlOutput == \"\") ) {" + targetObjectString.substr(0,targetObjectString.length - 1)  +  ",xmlOutput); window[\"" + reqString +"\"] = null;}";
        return out;
}
function loadXMLDoc(url, reqIndex, target,property) {
        req = window[reqIndex];
        if (target.substr(target.length-1,1) == ")") {
             req.onreadystatechange = new Function( makeCustomHandlerForFunction(reqIndex,target,property) );
        }
        else {
                         req.onreadystatechange = new Function( makeCustomHandlerForObject(reqIndex,target,property) );
        }
        req.open("GET", url, true);
        if (window.XMLHttpRequest) {
                    req.send(null);
        }
        else {
                req.send();
        }
}
function processReadyStateChange(req, property) {
    // only if req shows "complete"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
                 return req[property];
        } else {
                    alert("There was a problem retrieving the RSS feed\n" + req.statusText)
        }
    }
    return "";
}
var reqNum = 0;
function getXMLText(source, target) {

        var reqIndex = "req" + (++reqNum);
        window[reqIndex] = initXMLHttpRequest();
        loadXMLDoc(source,  reqIndex, target, "responseText");
}
function getXMLDoc(source, target) {
        var reqIndex = "req" + (++reqNum);
        window[reqIndex] = initXMLHttpRequest();
        loadXMLDoc(source,  reqIndex, target, "responseXML");
}
function getFirstElement(node,elementName) {

        child =  node.firstChild;
        while (  child != null ) {
                if (child.nodeType == 1) {
                        if ( child.nodeName == elementName) {
                                return child;
                        }
                }
                child = child.nextSibling;
        }
        return null;
}
function getLastElement(node,elementName) {

        child =  node.lastChild;
        while (  child != null ) {
                if (child.nodeType == 1) {
                        if ( child.nodeName == elementName) {
                                return child;
                        }
                }
                child = child.previousSibling;
        }
        return null;
}
function getNthElement(node, elementName, n) {

        foundCount = 0;
        child =  node.firstChild;
        while (child != null)  {
                if (child.nodeType == 1) {
                        if (child.nodeName == elementName) {
                                foundCount = foundCount + 1;
                                if (foundCount == n) {
                                        return child;
                                }
                        }
                }
                child = child.nextSibling;
        }

        return null;
}
function getElementText(node) {

        if (node == null) {
                return("");
        }

        child =  node.firstChild;
        foundCDATA = false;
        foundPlainText = false;

        while (child != null) {
                if (child.nodeType == 4) {                        // CDATA node
                        result = child.nodeValue;
                        foundCDATA = true;
                }
                else {
                        if (child.nodeType == 3) {                // Text node
                                result = child.nodeValue;
                                foundPlainText = true;
                        }
                }
                if (foundCDATA == true) {
                        return result
                }
                child = child.nextSibling
        }
        if (foundPlainText == false) {
                return("")
        }
        return result;
}
//#####################################################################################################
// 2. HIER WERDEN DIE SPALTENINFOS GELESEN
//===============================================================
function parseXML(issue, xmlDoc)
{

        if (typeof(xmlDoc) != "object") {
                return;
        }
        //##########################################################################
        //###   WRITE DATA   ##########################################################
        entries = xmlDoc.documentElement;
        entry = getFirstElement(entries,"viewentry");
        entryCount = 1;
        while ( entry != null )
        {
                // user
                userEntry = getFirstElement(entry,"entrydata", 1);
                userEl = getFirstElement(userEntry,"text");
                userText = getElementText(userEl);

                // from - till information
                fromTillEntry = getNthElement(entry,"entrydata",2);
                fromTillEl = getFirstElement(fromTillEntry,"text");
                fromTillText = getElementText(fromTillEl);

                // subject
                subjectEntry = getNthElement(entry,"entrydata", 3);
                subjectEl = getFirstElement(subjectEntry,"text");
                subjectText = getElementText(subjectEl);

                // resource
                resEntry = getNthElement(entry,"entrydata",4);
                resEl = getFirstElement(resEntry,"text");
                resName = getElementText(resEl);

                //=======================================================
                //        ........................
                //=======================================================
                entryCount += 1;
                entry = getNthElement(entries,"viewentry",entryCount);
        }
}

// 3. FUNKTION WIRD MIT PARAMETERN AUFGERUFEN
// Ausgabe als Text ======================================================
function getAJAXData(iFunction, iURL, issue, iTarget)
{
        if( (issue == '-1') || (issue == '') )
        {
                var xTargetItem = document.getElementById( iTarget);
                var xTargetItem2 = document.getElementById( 'ILC' );
                var xTargetItem3 = document.getElementById( 'GRP1' );
                var xNewOption=null;
                var xNewOption2=null;
                var xNewOption3=null;
                if( xTargetItem )                // write station fields with - - - - -
                {
                        // remove all entries from list
                        var xLen = xTargetItem.length;
                        for( j=0; j< xLen; j++)
                        {
                                xTargetItem[0]= null;
                                xTargetItem2[0]= null;
                        }
                        xNewOption = new Option('- - - - - - - - - - - - - - - -', '-1',  true, false);
                        xNewOption2 = new Option('- - - - - - - - - - - - - - - -', '-1',  true, false);
                        xTargetItem[0]= xNewOption;
                        xTargetItem2[0]= xNewOption2;
                        xTargetItem.disabled=true;
                        xTargetItem2.disabled=true;
                }
                // hide search links only if country is - - - - -
                if( (iFunction == 'toggleLocations') || (iFunction == 'toggleCarGroups') )
                {
                        if( document.getElementById( 'SearchSTA' ))
                                document.getElementById( 'SearchSTA' ).style.display = 'none';
                        if( document.getElementById( 'SearchILC' ) )
                                document.getElementById( 'SearchILC' ).style.display = 'none';
                        if( document.getElementById( 'SearchGRP' ) )
                                document.getElementById( 'SearchGRP' ).style.display = 'none';
                        if( xTargetItem3 )        // write car group field with - - - - -
                        {
                                // remove all entries from list
                                var xLen = xTargetItem3 .length;
                                for( j=0; j< xLen; j++)
                                {
                                        xTargetItem3[0]= null;
                                }
                                xNewOption3 = new Option('- - - - - - - - - - - - - - - -', '-1',  true, false);
                                xTargetItem3[0]= xNewOption3;
                                xTargetItem3.disabled=true;
                        }
                }
        }
        else
        {
//alert( iURL + "\n" + issue + "\n" + iFunction + "\n" +  "(" + issue + ", " + iTarget + ")" );
                getXMLText( iURL + issue, iFunction + "(\"" + issue + "\",\"" + iTarget + "\")");
                // display search links only
                if( document.getElementById( 'SearchSTA' ))
                        document.getElementById( 'SearchSTA' ).style.display = 'block';
                if( document.getElementById( 'SearchILC' ) )
                        document.getElementById( 'SearchILC' ).style.display = 'block';
                if( document.getElementById( 'SearchGRP' ) )
                        document.getElementById( 'SearchGRP' ).style.display = 'block';
        }
}
function outputAJAX( iReturnString , iXMLOutput)
{
        alert( "AJAX call result:" + iXMLOutput);
}
// Rückgabe von Plain Text zur weiteren Verarbeitung =====================
// ----------------------------------------------------------------------
function readRemoteData(xURL, issue, xTarget)
{
        getXMLText( xURL + issue, "getRemoteData(\"" + issue + "\",\"" + xTarget + "\")");
}
function getRemoteData( iReturnString ,iTarget,  iXMLOutput)
{
        xElement = document.getElementById(iTarget);
        if( xElement )
        {
                xElement.innerHTML = xElement.innerHTML + iXMLOutput;
        }
}
var ReturnLocationFixed = false;
// Funktionen zum Laden der Location Daten =================================
//--------------------------------------------------------------------------
function toggleLocations(iReturnString , iTarget, iXMLOutput)
{
        //alert('START TOOGLE LOCATION');
        ReturnLocationFixed = false;
        var xTargetItemSTA = document.getElementById( 'STA' );
        var xTargetItemILC = document.getElementById( 'ILC');
        var xTargetItemSTAList = document.getElementById( 'STAList' );
        var xTargetItemILCList = document.getElementById( 'ILCList');
        if( xTargetItemSTA ) xTargetItemSTA.innerHTML = '';        // set visible value to nothing
        if( xTargetItemILC ) xTargetItemILC.innerHTML = '';        // set visible value to nothing
        if( xTargetItemSTAList ) xTargetItemSTAList.value = '';        // set textarea with stations to empty
        if( xTargetItemILCList ) xTargetItemILCList.value = '';        // set textarea with stations to empty
                if( iXMLOutput.search(/^ERROR/) == -1)
                {
                        var xSelected = false;
                        var yAir = 0;
                        var yFav = 0;
                        var yDow = 0;
                        var xTextArray;
                        var xAllLocationsList = new Array();
                        var xAllLocationsListEntry = new Array();
                        var xFavList = new Array();
                        var xFavListComplete = new Array();
                        var xAirportListComplete = new Array();
                        var xDowntownListComplete = new Array();
                        var xFav = document.getElementById( "CookieStations" );
                        xFavList = xFav.value.split('~');
                        var xAllLocationsList = unescape(decodeURI(iXMLOutput.replace( /\n/, "") )).split('~');
                        // go through the list and write airport staions and downtown stations into different lists
                        //=========================================================================
                        for( var xCounter = 1; xCounter < xAllLocationsList.length; xCounter++)        // the 1st entry is always '- - - - - - | -1' . 1st value is written by AjaxWebServices agent
                        {
                                xAllLocationsListEntry = xAllLocationsList[xCounter].split('$A$');        // left from $A$ = label and value, right from $A$ = 1 if airport stat
                                var xLocList = xAllLocationsListEntry[0];
                                if( xLocList != '' )
                                {
                                        var xAirportFlag = 0;
                                        if( xAllLocationsListEntry[1] && (xAllLocationsListEntry[1] == '1') )
                                                xAirportFlag = 1;

                                        if( xAirportFlag )        // >>> write airport stations into a list ============
                                        {
                                                xAirportListComplete[yAir] = xLocList ;                //array with airport stations
                                                yAir++;
                                        }
                                        else                        // >>> write downtown stations into a list ============
                                        {
                                                xDowntownListComplete[yDow] = xLocList ;        //array with favorit stations
                                                yDow++;
                                        }
                                        // >>> write favorits into a list ============
                                        xTextArray = xLocList.split('|');
                                        for( var c=0; c<xFavList.length; c++)
                                        {
                                                if( xTextArray[1] == xFavList[c] )
                                                {
                                                        xFavListComplete[yFav]= xLocList;        //array with favorit stations
                                                        yFav++;
                                                }
                                        }
                                }
                        }

                        var setEmptyLine = false;
                        // go through all lists and write stations into the fields
                        //=========================================================================
                        // >>> write FAVORITS into stations fields ============
                        if( xFavListComplete.length > 0 )
                        {
                                xLbl = document.getElementById( "FavoriteLocations" ).value;        // headline Favorits
                                writeStations( xLbl, xFavListComplete, xTargetItemSTA, setEmptyLine, 'dropdownHeadline' );
                                writeStations( xLbl, xFavListComplete, xTargetItemILC, setEmptyLine, 'dropdownHeadline' );
                        }
                        setEmptyLine = false;
                        // >>> write Airports into stations fields ============
                        if( xAirportListComplete.length > 0 )
                        {
                                xLbl = document.getElementById( "AirportLocations" ).value;        // headline Airports
                                if( xFavListComplete.length > 0 )
                                        setEmptyLine = true;
                                writeStations( xLbl, xAirportListComplete, xTargetItemSTA, setEmptyLine, 'dropdownHeadline' );
                                writeStations( xLbl, xAirportListComplete, xTargetItemILC, setEmptyLine, 'dropdownHeadline' );
                        }
                        setEmptyLine = false;
                        // >>> write Downtowns into stations fields ============
                        if( xDowntownListComplete.length > 0 )
                        {
                                xLbl = document.getElementById( "DowntownLocations" ).value;        // headline Airports
                                if( (xAirportListComplete.length > 0 && xFavListComplete.length > 0) || (xAirportListComplete.length > 0 && xFavListComplete.length < 1) || (xAirportListComplete.length < 1 && xFavListComplete.length > 0) )
                                        setEmptyLine = true;
                                writeStations( xLbl, xDowntownListComplete, xTargetItemSTA, setEmptyLine, 'dropdownHeadline' );
                                writeStations( xLbl, xDowntownListComplete, xTargetItemILC, setEmptyLine, 'dropdownHeadline' );
                        }
                        setEmptyLine = false;

                        // >>> "Select location" headline ============
                        if( (xAirportListComplete.length > 0) || (xDowntownListComplete.length > 0) )
                        {
                                xLbl = document.getElementById( "PleaseSelectSTA" ).value;        // headline Locations
                                xTargetItemSTA.innerHTML = xLbl;
                                xTargetItemSTA.setAttribute('valueSelected', '');
                                xTargetItemILC.innerHTML = xLbl;
                                xTargetItemILC.setAttribute('valueSelected', '');
                        }
                        setEmptyLine = false;

                        var xDstation = document.getElementById('Defaultstation')
                        if(xDstation.value != '')
                        {
                                xTargetItemSTA.setAttribute('valueSelected', xDstation.value);
                                xTargetItemSTA.innerHTML = 'Keflavik; International Airport';
                                xTargetItemILC.setAttribute('valueSelected', xDstation.value);
                                xTargetItemILC.innerHTML = 'Keflavik; International Airport';
                                xDstation.value = '';
                         }
                }
}


function writeStations( _Lbl, _StationList, _Target, _flag, _class )
{
        xLbl = _Lbl;
        var xSelected = false;
        var html = '';
        var xTargetList = document.getElementById( _Target.id + 'List' );
        html = xTargetList.value;
        if( _flag == true )        // 1.st entry is field headline - no stations
        {
                // insert empty lines
                html += '<tr><td value="-1" class="dropdownEmpty">&nbsp;</td></tr>' ;
        }
        // insert headlines
        html += '<tr><td value="-1" class="' + _class + '">' + xLbl + '</td></tr>' ;
        if( _StationList != '' )
        {
                for( var i=0; i<_StationList.length; i++)
                {
                        xTextArray = _StationList[i].split('|');
                        html += '<tr><td id="' + xTextArray[1] + '" class="dropdownEntry" onClick="setSelectedIntoDiv(this, \'' + _Target.id + '\');" onMouseOver="this.className=\'dropdownEntryHover\';" onMouseOut="this.className=\'dropdownEntry\';">' + xTextArray[0] + '</td></tr>' ;
                }
        }
        xTargetList.value = html;
}
// Funktionen zum Laden der Car Group Daten =================================
//--------------------------------------------------------------------------
function toggleCarGroups(iReturnString , iTarget, iXMLOutput)
{
        ReturnLocationFixed = false;
        var xTargetItem = document.getElementById( iTarget);
        var xNewOption=null;

        var xTargetList = document.getElementById( xTargetItem.id + 'List' );
        html = '';
        if( xTargetList )
        {
                xTargetList.value = '';

                if( iXMLOutput.search(/^ERROR/) == -1)
                {
                        var xSelected = false;
                        var xTextArray;
                        var xLocList = unescape(decodeURI(iXMLOutput.replace( /\n/, ""))).split('~');
                        for( var i=1; i<xLocList.length; i++)
                        {
                                xTextArray = xLocList[i].split('|');

                                html += '<tr><td id="' + xTextArray[1] + '" class="dropdownEntry" onClick="setSelectedIntoDiv(this, \'' + xTargetItem.id + '\');" onMouseOver="this.className=\'dropdownEntryHover\';" onMouseOut="this.className=\'dropdownEntry\';">' + xTextArray[0] + '</td></tr>' ;
                        }
                }
                else
                {
//                        xTargetItem.disabled=true;
                }
                xTargetItem.innerHTML = document.getElementById( "PleaseSelectGRP" ).value;
                xTargetList.value = html;

                var xDcar = document.getElementById('Defaultcar')
                        if(xDcar.value != '')
                        {
                                xTargetItem.setAttribute('valueSelected', xDcar.value);
                                xTargetItem.innerHTML = 'Grupp A (t ex. Toyota Yaris 1.0)';
                                xDcar.value = '';
                        }

        }
}

function toggleCarGroupProperties( iReturnString , iTarget, iXMLOutput )
{
        var xElement = document.getElementById(iTarget);
        var xText = iXMLOutput;
        xText = xText.replace(/%00/ig,'');
        xText = unescape(decodeURI( xText ));
        var xHTML ="";
        var xHTMLList = xText.split('~');

        if( xElement )
        {
                xHTML  ='<table border=\"0\" cellpadding=\"0\" cellpsacing=\"0\"><tr>';
                for( i=0; i< xHTMLList .length;i++)
                {
                        xHTML = xHTML + xHTMLList [i];
                        //alert(xHTMLList[i]);
                }
                xHTML  = xHTML + ' <td width="15"></td> ' + '</tr></table>';
                xElement.innerHTML = xHTML ;
        }

}


function selectReturnLocation( item, agentUrl )
{
        var xTargetItem = document.getElementById( 'ILC');

        if( ReturnLocationFixed == false)
        {
                xTargetItem.innerHTML = item.innerHTML;
                xTargetItem.setAttribute('valueSelected', item.getAttribute('valueSelected'));
                // set opening hours for the return station
                getAJAXData('toggleOpeningHours', agentUrl , item.getAttribute('valueSelected'), 'openingHoursReturn');
        }
}
function toggleOpeningHours( iReturnString , iTarget, iXMLOutput )
{
//alert(iReturnString + "\n" +  iTarget + "\n" + iXMLOutput);
        var xElement = document.getElementById(iTarget);
        var xText = unescape(decodeURI(iXMLOutput));
        var xGlobalList = xText.split('$');
        var xOpeningHourList = xGlobalList[0].split('#');
        var xPhoneNumber = xGlobalList[1];
        var xAddress = xGlobalList[2];
        var xWeekdayList = xGlobalList[5].split('~');
        var xTextHOUR = xGlobalList[6];
        var xTextTEL = xGlobalList[7];
        var xTextCLOSED = xGlobalList[8];
        var xTextHEADLINE = xGlobalList[9];
        var xHTML ="";
        var xOpenList;
        var xCloseList;
        var xHourList;

        var openHours = new Array();
//        xHTML='<table border="0">';
//        xHTML=xHTML + '<tr><td colspan="2">' + xAddress + '</td>';
//        xHTML=xHTML + '<tr><td>' + xTextTEL + '</td><td>' + xPhoneNumber + '</td></tr>';
//        xHTML=xHTML + '<tr><td colspan="2">' + xTextHEADLINE + '</td></tr>';

        xHTML = xTextHEADLINE;
        for(var i=0; i<xWeekdayList.length; i++)
        {
                xHTML=xHTML + '<tr><td>' + xWeekdayList[i] + '</td>';
                xOpenList = xOpeningHourList[i].split('*')[0].split(';');
                xCloseList = xOpeningHourList[i].split('*')[1].split(';');
                if(xCloseList == '00:00')
                {
                        openHours[i] = xTextCLOSED;
                        xHTML=xHTML + '<td>' + xTextCLOSED + '</td>';
                }
                else
                {
                        xHTML=xHTML + '<td>';
                        xHourList='';
                        for(var j=0; j< xOpenList.length; j++)
                        {
                                if( xHourList.length == 0)
                                        xHourList =  xOpenList[j] + '-' + xCloseList[j];
                                else
                                        xHourList = xHourList + ', ' + xOpenList[j] + '-' + xCloseList[j];

                        }
                        openHours[i] = xHourList + ' ' + xTextHOUR;
                        xHTML=xHTML + xHourList + ' ' + xTextHOUR + '</td>';
                }
                xHTML=xHTML + '</tr>';
        }
        xHTML=xHTML + '</table>';


//        if( xElement )
//                xElement.innerHTML = xHTML;
        // get pick-up date
        var PickupORReturn = '';
        if(xElement.id == 'openingHoursPickup')
                PickupORReturn = 'ETA';
        else
                PickupORReturn = 'ETT';
        var oField = document.getElementById(PickupORReturn + 'Day');
        var sPickupORReturnDAY = oField[oField.selectedIndex].value;
        oField = document.getElementById(PickupORReturn + 'Month');
        var sPickupORReturnMONTHYEAR = oField[oField.selectedIndex].value;
        var sPickupORReturnMONTH = sPickupORReturnMONTHYEAR.substr(0, 2);
        var sPickupORReturnYEAR = sPickupORReturnMONTHYEAR.substr(2, 4);
        var sWeekDayIndex = '';
        sWeekDayIndex = getWeekDay(sPickupORReturnDAY ,sPickupORReturnMONTH ,sPickupORReturnYEAR , xWeekdayList );
        var aTemp = new Array();
        aTemp = sWeekDayIndex.split('|');
        // display weekday in the front of the day
        var oField = document.getElementById(xElement.id + 'Weekday');
        if(oField)
                oField.innerHTML = aTemp[0] + '&nbsp;';
        // display opening hours above day
         xElement.innerHTML = xTextHEADLINE + ' ' + openHours[aTemp[1]];
      xElement.style.visibility = 'visible';
}
function toggleCarGroupImage( item, iURL, iTarget, iCountryItem)
{
        var xGRP = item[ item.selectedIndex].value;
        var xElement = document.getElementById(iTarget);
        var xCountryElement = document.getElementById(iCountryItem);

        if( xElement && xCountryElement)
        {
                var xCountry = xCountryElement[xCountryElement.selectedIndex].value;
                var xImageLink =  '<img src="' + iURL + xCountry + '-' + xGRP + '/$FILE/small.gif" alt="">';
                xElement.innerHTML = xImageLink;
        }
}
function setCssClass(obj)
{
        xVal = obj.options[obj.options.selectedIndex].value;
        if( xVal == '-1')
                obj.options.selectedIndex = 0;
/*
        if( obj.options[obj.options.selectedIndex] )
        {
                if( obj.options[obj.options.selectedIndex].value == '-1' )
                        obj.className = 'formField1 dropdownHeadline';
                else
                {
                        obj.className = 'formField1';
                }
        }
*/
}
function getWeekDay(dd,mm,yyyy, aWeekdayList) {
// aWeekDayList can contain short day translations, like (Mo, Tu,...) or a list with complete names
// coming from the staion's doc, like (Monday, Tuesday,...)
// return only the abbreviated day name depending on how much letters are entered in the translation
var strLength = dp_dayArrayShort[0].length;
if( isNaN(strLength) || (strLength == ''))
        strLength = 3;
var oDate = new Date(parseInt( yyyy, 10), parseInt( mm, 10) - 1, parseInt( dd, 10));
var aWeekday = new Array(6);
aWeekday[0] = aWeekdayList[0].substr(0, strLength) + "|0";                // SUNDAY
aWeekday[1] = aWeekdayList[1].substr(0, strLength) + "|1";                // MONDAY
aWeekday[2] = aWeekdayList[2].substr(0, strLength) + "|2";                // TUESDAY
aWeekday[3] = aWeekdayList[3].substr(0, strLength) + "|3";                // WEDNESDAY
aWeekday[4] = aWeekdayList[4].substr(0, strLength) + "|4";                // THURSDAY
aWeekday[5] = aWeekdayList[5].substr(0, strLength) + "|5";                // FRIDAY
aWeekday[6] = aWeekdayList[6].substr(0, strLength) + "|6";                // SATURDAY
var daySelected = aWeekday[oDate.getDay()];
return daySelected;
}
function removeStationInformation(station)
{
        if( station == 'ETA' )
        {
                document.getElementById('openingHoursPickup').style.visibility = 'hidden';
                document.getElementById('openingHoursPickup').innerHTML = '&nbsp;';
        }
        else
        {
                document.getElementById('openingHoursReturn').style.visibility = 'hidden';
                document.getElementById('openingHoursReturn').innerHTML = '&nbsp;';
        }
}
function setOpeningHours(where)
{
        var xAgentParam = '&RAN=' + Math.random() + '&LANG=' + gLng + '&COUNTRY=';
        var xFieldValue = '';
        var xTarget = '';
        var oPickup = document.getElementById('STA');
        var oReturn = document.getElementById('ILC');
        if(where == 'ETA')
        {
                xFieldValue = oPickup.getAttribute('valueSelected');
                xTarget = 'openingHoursPickup';
                // display week day in front of the day
                displayWeekDay('openingHoursPickupWeekday');
        }
        else
        {
                xFieldValue = oReturn.getAttribute('valueSelected');
                xTarget = 'openingHoursReturn';
                displayWeekDay('openingHoursReturnWeekday')
        }
        if( !xFieldValue || xFieldValue == '' || xFieldValue == '-1' || xFieldValue == 'xx')
                removeStationInformation(where);
        else
                getAJAXData('toggleOpeningHours', gStationsURL + '/AjaxWebService?OpenAgent' + xAgentParam + '&F=getOpeningHoursPerLocation&STA=', xFieldValue, xTarget);
}
function displayWeekDay(_FieldId)
{
        // swap places in Weekdays array, Sunday must be first
        var arrayWeekDays = new Array(dp_dayArrayLong[6], dp_dayArrayLong[0], dp_dayArrayLong[1], dp_dayArrayLong[2], dp_dayArrayLong[3], dp_dayArrayLong[4], dp_dayArrayLong[5]);
        var aTemp = new Array();
        var PickupORReturn = '';
        var Field = document.getElementById( _FieldId );

        if( Field )
        {
                if( _FieldId== 'openingHoursPickupWeekday' )
                        PickupORReturn = 'ETA';
                else
                        PickupORReturn = 'ETT';
                var oField = document.getElementById(PickupORReturn + 'Day');
                var sPickupORReturnDAY = oField[oField.selectedIndex].value;
                oField = document.getElementById(PickupORReturn + 'Month');
                var sPickupORReturnMONTHYEAR = oField[oField.selectedIndex].value;
                var sPickupORReturnMONTH = sPickupORReturnMONTHYEAR.substr(0, 2);
                var sPickupORReturnYEAR = sPickupORReturnMONTHYEAR.substr(2, 4);
                var sWeekDayIndex = getWeekDay(sPickupORReturnDAY ,sPickupORReturnMONTH ,sPickupORReturnYEAR , arrayWeekDays );
                aTemp = sWeekDayIndex.split('|');
                Field.innerHTML = aTemp[0] + '&nbsp;';
        }
}
