﻿function doPopup(theURL, theWinName, theLeft, theTop, theWidth, theHeight, theresize, thescrollbars, thestatusbar, themenu, thetools, thelocationbar, thedirs){
	// EXAMPLE doPopup('popup.asp', 'popwin', 10, 10, 500, 300, 'no', 'no', 'yes', 'no', 'no', 'no', 'no')
	// USE theLeft AND theTop = -1 FOR AUTO-CENTER

	if (theLeft == -1 && theTop == -1){
		theLeft = (screen.width - theWidth) / 2;
		theTop = (screen.height - theHeight) / 2;
	}
	var paramstr;
	paramstr = "width=" + theWidth + "px,height=" + theHeight + "px,left=" + theLeft + "px,top=" + theTop + "px,resizable=" + theresize + ",scrollbars=" + thescrollbars + ",status=" + thestatusbar + ",menubar=" + themenu + ",toolbar=" + thetools + ",location=" + thelocationbar + ",directories=" + thedirs;
	window.open(theURL, theWinName, paramstr);
}



function EnlargeImage(theImg, theAlt){
	theURL = "../Assets/EnlargeImage.asp?theImg=" + theImg + "&theAlt=" + theAlt
	theWidth = 400;
	theHeight = 400;
	theLeft = (screen.width - theWidth) / 2;
	theTop = (screen.height - theHeight) / 2;
	window.open(theURL, 'enlarge', "width=" + theWidth + "px,height=" + theHeight + "px,left=" + theLeft + "px,top=" + theTop + "px,resizable=yes,scrollbars=no,statusbar=no,menubar=no,personalbar=no,toolbar=no,locationbar=no,directories=no");
}

function alertModal(theMessage,isError, wdt, hgt, pageRequested){
	var myObject = new Object();
	var lft, tp;
	lft = (screen.width - wdt) / 2;
	tp = (screen.height - hgt) / 2;
	myObject.bodys = theMessage;

	if (isError=="ERROR"){
		win = window.showModalDialog("assets/modalError.asp", myObject, "dialogWidth:" + wdt + "px; dialogHeight:"+ hgt +"px; dialogLeft:" + lft + "px; dialogTop:" + tp + "px; help:0;status:0;scroll:0;resizable:0");
	}
	else if (isError=="TERMS"){
		win = window.showModalDialog("assets/modalTerms.asp", myObject, "dialogWidth:" + wdt + "px; dialogHeight:"+ hgt +"px; dialogLeft:" + lft + "px; dialogTop:" + tp + "px; help:0; status:0 ");
	}
	else{
		win = window.showModalDialog("assets/modalInfo.asp", myObject, "dialogWidth:" + wdt + "px; dialogHeight:" + hgt + "px; dialogLeft:" + lft + "px; dialogTop:" + tp + "px; help:0; status:0 ");
	}
}


var nsstyle='display:""'
if (document.layers)
var scrolldoc=document.scroll1.document.scroll2

function up(){
	if (!document.layers) return
	if (scrolldoc.top<0)
	scrolldoc.top+=10
	temp2=setTimeout("up()",50)
}

function down(){
	if (!document.layers) return
	if (scrolldoc.top-150>=scrolldoc.document.height*-1)
	scrolldoc.top-=10
	temp=setTimeout("down()",50)
}

function clearup(){
	if (window.temp2)
	clearInterval(temp2)
}

function cleardown(){
	if (window.temp)
	clearInterval(temp)
}

function goToPage(thePage, showPageFrom, showPageTo, listPage){
	if (eval(thePage) > eval(showPageTo)){
		document.forms.mainForm.iBlockCurrent.value = eval(document.forms.mainForm.iBlockCurrent.value) + 1
	}
	if (eval(thePage) < eval(showPageFrom)){
		document.forms.mainForm.iBlockCurrent.value = eval(document.forms.mainForm.iBlockCurrent.value) - 1
	}
	document.forms.mainForm.action = listPage;
	document.forms.mainForm.iPageCurrent.value = thePage;
	document.forms.mainForm.submit();
}

function goToBlock(theBlock, thePage, listPage){
	document.forms.mainForm.action = listPage;
	document.forms.mainForm.iPageCurrent.value = thePage;
	document.forms.mainForm.iBlockCurrent.value = theBlock;
	document.forms.mainForm.submit();
}

function goToView(theArea, theRecord){
	document.forms.mainForm.action = theArea + "&a=" + theRecord;
	document.forms.mainForm.submit();
}


function goToBack(theArea){
	document.forms.mainForm.action = theArea;
	document.forms.mainForm.submit();
}

function changeSorting(newSorting, theArea){
	document.forms.mainForm.sorting.value = newSorting;
	document.forms.mainForm.action = theArea;
	document.forms.mainForm.submit();
}

function isDate(strDate,DateFormat){
	 DateFormat=DateFormat.toLowerCase()

	 if (DateFormat=='dd/mm/yyyy'){var DatePattern = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;}
	 else if (DateFormat=='mm/dd/yyyy'){var DatePattern = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;}
	 else if (DateFormat=='yyyy/mm/dd'){var DatePattern = /^(\d{2}|\d{4})(\/|-)(\d{1,2})\2(\d{1,2})$/;}

	 var matchArray = strDate.match(DatePattern);
	 if (matchArray == null) return false;

	 if (DateFormat=='dd/mm/yyyy'){var day = matchArray[1];var month = matchArray[3];var year = matchArray[4];}
	 else if (DateFormat=='mm/dd/yyyy'){var day = matchArray[3];var month = matchArray[1];var year = matchArray[4];}
	 else if (DateFormat=='yyyy/mm/dd'){var day = matchArray[4];var month = matchArray[3];var year = matchArray[1];}
	 else{return false;}

	 if (month < 1 || month > 12) return false;
	 if (day < 1 || day > 31) return false;
	 if (year < 1900) return false;
	 if ((month == 4 || month == 6 || month==9 || month == 11) && day == 31) return false;
	 if (day>=29 && month == 2 && parseInt(year) % 4 !== 0) {return false;}
	 if (day>=30 && month == 2 && parseInt(year) % 4 == 0) {return false;}
	 return true;
}

function isInteger(theData){ return (theData.search(/^\d+$/) != -1); }

function isEmpty(s){ return ((s == null) || (s.length == 0) || s=="");}

function isMail(sString){
	var emailEXP = /^[a-z_0-9\.]+@[a-z_0-9\-\_\.]+\.[a-z]{2,3}$/i
	if (!sString.match(emailEXP)){
		return false;
	}
	else{
		return true;
	}
}

function isDecimal(theData){ return (theData.search(/\d*\.\d+/) != -1); }

function isChecked(theData){
	var len, found
	len = theData.length;
	found = true
	for(var i=0;i<len;i++){
		if (theData[i].checked) found=false;
	}
	return found;
}

function hasMaxLength(theString, theLen){
	if (theString.length > theLen) {
		return false
	}
	else {
		return true
	}
}

function RepositionLayer(ReferenceObject, ObjectToMove, OffsetX, OffsetY){
	var RefObj, MoveObj
	var RefObjLeftPos, RefObjTopPos
	RefObj = document.getElementById(ReferenceObject);
	MoveObj = document.getElementById(ObjectToMove);
	
	RefObjLeftPos = findPosX(RefObj);
	RefObjTopPos = findPosY(RefObj);

	MoveObj.style.left = (RefObjLeftPos + OffsetX);
	MoveObj.style.top = (RefObjTopPos + OffsetY);
	MoveObj.style.visibility = "visible";
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function SwapImage(ImageId,NewSrc){
	document.getElementById(ImageId).src = NewSrc;
}

function ChangeOpacity(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

function getFlashMovieObject(movieName){
	if (window.document[movieName]){
		return window.document[movieName];
	}
	
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName])
		return document.embeds[movieName]; 
	}
	else{
		return document.getElementById(movieName);
	}
}

function DisplayInfo(id, img) {
	//var H = parseInt(document.getElementById(id).offsetHeight);
	if(document.getElementById(id).style.display=='block'){
	    document.getElementById(id).style.display = 'none';

	    SwapImage(img, "Assets/Images/ArrowDown.gif");

	    //movediv(id,'bottom',H,10);
	}
	else {
		document.getElementById(id).style.display='block';
		SwapImage(img,"Assets/Images/ArrowUp.gif");
		//opacity(id,0,100,500);
		//movediv(id,'top',10,H);
    }
}
/*
function movediv(id,dir,amt,togo) {  
  var elem = document.getElementById(id)
  elem.style.top = togo+"px";
  var currentPos, ready, newPos;
  if (elem) { 
    the_interval = window.setInterval(function () { 
      currentPos = parseInt(elem.style.top); 
	  
      ready = (dir == 'top' && currentPos > amt) ? true : (dir == 'bottom' && currentPos < amt) ? true : false; 
	  
      if (ready) { 
        newPos = (dir == 'top') ? currentPos - 2 : currentPos + 2; 
        if (document.layers) { 
          elem.style.top = newPos; 
        } else { 
          elem.style.top = newPos + "px"; 
        } 
      } else { 
        window.clearInterval(the_interval);
      } 
    },1); 
  }   
}
*/
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 300);
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    changeOpac(opacStart,id);
	if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function Transparency(id){
	var object = document.getElementById(id).style;
	object.opacity = 0;
    object.MozOpacity = 0;
    object.KhtmlOpacity = 0;
    object.filter = "alpha(opacity=" + 0 + ")";
}

function SwapBgImage(Id){	
	var theObj = Id.parentNode.parentNode;
	if(! theObj.className){
		var theObj = Id.parentNode.parentNode.parentNode;
	}
	var theClass = theObj.className;
	
	if(theClass == "TopMenuText"){
		theObj.className = "TopMenuTextActive";
	} else {
		theObj.className = "TopMenuText";
	}	
}

function topMenuChangeImage(imgId, hover) {
    if (!hover) {
        img = "Assets/Images/" + String(imgId) + ".gif";
    } else {
        img = "Assets/Images/" + String(imgId) + String(hover) + ".gif";
    }
    SwapImage(imgId, img);
}

function findParentNode(parentName, childObj) {
    var testObj = childObj.parentNode;
    var count = 1;
    while(testObj.getAttribute('name') != parentName) {
        alert('My name is ' + testObj.getAttribute('name') + '. Let\'s try moving up one level to see what we get.');
        testObj = testObj.parentNode;
        count++;
    }
    // now you have the object you are looking for - do something with it
    alert('Finally found ' + testObj.getAttribute('name') + ' after going up ' + count + ' level(s) through the DOM tree');
}

function DisplayObject(id,imgId,imgOrig,imgRepl,allTabsArray){
	imgPath = "Assets/Images/";
	if(allTabsArray){
		for(i=0;i<allTabsArray.length;i+=2){
			document.getElementById(allTabsArray[i]).style.display='none';
			var theimgId = String(allTabsArray[i+1]);
			document.getElementById(theimgId).src = imgPath+imgOrig;
		}
	}
	if(document.getElementById(id).style.display=='block'){
		document.getElementById(id).style.display='none';
		if(imgId){
			SwapImage(imgId,imgPath+imgOrig);
		}		
	}else{
		document.getElementById(id).style.display='block';
		if(imgId){
			SwapImage(imgId,imgPath+imgRepl);
		}
	}
}

function ShowHideArrayElements(TabData, elementToShow) {
    var i;
    for (i = 0; i < TabData.length; i += 2) {
        if (TabData[i] == elementToShow) {
            document.getElementById(TabData[i]).style.display = "block";
            document.getElementById(TabData[i + 1]).style.display = "block";
        }
        else {
            document.getElementById(TabData[i]).style.display = "none";
            document.getElementById(TabData[i + 1]).style.display = "none";
        }
    }
}

/* --------------: MediaBox Custom: Start :-------------- */
function MediaBox(objShow, objRef, extraOffset) {
    MediaBoxPrepare(objShow, objRef, extraOffset);     
    document.getElementById(objShow).style.display = 'block';
    hideSelects("hidden");
}

function MediaBoxPrepare(objShow, objRef, extraOffset) {
    var scroll = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
    var theOffset = 0;
    setObjHeighteqHTML(objShow);
    setObjWidtheqHTML(objShow);
    if (extraOffset) {
        theOffset += parseInt(extraOffset);
    }
    if (document.getElementById(objRef)) {
        theOffset += parseInt(findPosY(document.getElementById(objRef)));
    }
    document.getElementById(objShow).getElementsByTagName("table")[0].style.marginTop = theOffset + "px";
    document.getElementById(objShow).style.zIndex = 1000;
}

function MediaboxClose(objShow) {
	document.getElementById(objShow).style.display='none';	
	hideSelects("visible");
}

function setObjHeighteqHTML(changeObj) {
	document.getElementById(changeObj).style.height = getDocHeight()+"px"
}

function setObjWidtheqHTML(changeObj) {
    document.getElementById(changeObj).style.width = getDocWidth() + "px";
}


function getDocHeight() {
    var D = document;
    return Math.max(
		Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
		Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
		Math.max(D.body.clientHeight, D.documentElement.clientHeight)
	);
}
function getDocWidth() {
    var D = document;
    return Math.max(
		Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
		Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
		Math.max(D.body.clientWidth, D.documentElement.clientWidth)
	);
}

function hideSelects(action) {
    //documentation for this script at http://www.shawnolson.net/a/1198/hide-select-menus-javascript.html
    //possible values for action are 'hidden' and 'visible'
    if (action != 'visible') { action = 'hidden'; }
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
        var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
        if (ieversion >= 6 && ieversion < 7) {
            for (var S = 0; S < document.forms.length; S++) {
                for (var R = 0; R < document.forms[S].length; R++) {
                    if (document.forms[S].elements[R].options) {
                        document.forms[S].elements[R].style.visibility = action;
                    }
                }
            }
        }
    }
}

/* --------------: MediaBox Custom: End :-------------- */

/* --------------: Custom Validation functions: Start :--------------- */
function DateInFuture(source, arguments) {
    var currentTime = new Date();
    var boolResult=false;
    var theDate=document.getElementById(theOutDate).value;
    var theHour = parseInt(document.getElementById(theOutHour).value) / 100;
    var theMinute = document.getElementById(theOutMinute).value;
    var dateRegex=/^((((0?[1-9])|([12][0-9])|(3[01]))\/((0?[13578])|(1[02])))|(((0?[1-9])|([12][0-9])|(30))\/((0?[469])|11))|(((0?[1-9])|([12][0-9]))\/0?2))\/20[0-9]{2}$/;
    if (theDate.match(dateRegex)) {
        var dateArray=theDate.split("/");
        if (theHour>=0 && theHour<24){
            if (theMinute==0 ||theMinute==15||theMinute==30||theMinute==45){
                var finalDate = new Date();
                finalDate.setFullYear(dateArray[2], dateArray[1], dateArray[0]);
                finalDate.setHours(theHour,theMinute,0,0);
                if (finalDate>currentTime){
                    boolResult=true;
                }
            }
        }
    }
    arguments.IsValid = boolResult;
}

function DatesMatch(source, arguments) {
    var finalOutDate = null;
    var finalInDate = null;
    var currentTime = new Date();
    var boolResult = false;
    var getOutDate = document.getElementById(theOutDate).value;
    var getOutHour = parseInt(document.getElementById(theOutHour).value) / 100;
    var getOutMinute = document.getElementById(theOutMinute).value;
    var getInDate = document.getElementById(theInDate).value;
    var getInHour = parseInt(document.getElementById(theInHour).value) / 100;
    var getInMinute = document.getElementById(theInMinute).value;
    var dateRegex = /^((((0?[1-9])|([12][0-9])|(3[01]))\/((0?[13578])|(1[02])))|(((0?[1-9])|([12][0-9])|(30))\/((0?[469])|11))|(((0?[1-9])|([12][0-9]))\/0?2))\/20[0-9]{2}$/;
    //Parse the outDate and outTime to see if they have valid data, and create a datetime object from that
    if (getOutDate.match(dateRegex)) {
        var dateOutArray = getOutDate.split("/");
        if (getOutHour >= 0 && getOutHour < 24) {
            if (getOutMinute == 0 || getOutMinute == 15 || getOutMinute == 30 || getOutMinute == 45) {
                finalOutDate = new Date();
                finalOutDate.setFullYear(dateOutArray[2], dateOutArray[1], dateOutArray[0]);
                finalOutDate.setHours(getOutHour, getOutMinute, 0, 0);
            }
        }
    }
    //Parse the inDate and outTime to see if they have valid data, and create a datetime object from that
    if (getInDate.match(dateRegex)) {
        var dateInArray = getInDate.split("/");
        if (getInHour >= 0 && getInHour < 24) {
            if (getInMinute == 0 || getInMinute == 15 || getInMinute == 30 || getInMinute == 45) {
                finalInDate = new Date();
                finalInDate.setFullYear(dateInArray[2], dateInArray[1], dateInArray[0]);
                finalInDate.setHours(getInHour, getInMinute, 0, 0);
            }
        }
    }
    //If both datetime objects have been created, compare them. The outDateTime must be before the inDateTime
    if (finalOutDate && finalInDate) {
        if (finalOutDate < finalInDate) {
            boolResult = true;
        }
    }
    arguments.IsValid = boolResult;
}

function NoHtmlComments(source, arguments) {
    arguments.IsValid = !arguments.Value.match(/<\s*?[^>]+\s*?>/);
}      

/* --------------: Custom Validation functions: End :--------------- */

/* --------------: Custom Ajax Calls For pricing: Start :-------------- */

function justPrice(item, vehicleGroup, shopFrom, dayFrom, timeFrom, shopTo, dayTo, timeTo, countryCode, tariffType, tariffCode, domain) {
    var XMLObj;
    var Response = '';
    try { XMLObj = new ActiveXObject('Msxml2.XMLHTTP'); }
    catch (e) {
        try { XMLObj = new ActiveXObject('Microsoft.XMLHTTP'); }
        catch (e2) {
            try { XMLObj = new XMLHttpRequest(); }
            catch (e3) { XMLObj = false; }
        }
    }

    XMLObj.onreadystatechange = function() {
        if (XMLObj.readyState == 4) {
            if (XMLObj.status == 200) {
                var data = XMLObj.responseXML;
                Response = ParseRSS(XMLObj.responseXML);
            }
            else {
                Response = "-";
            }
            item.innerHTML = " (" + Response + ")";
        }
    };


    var url = "../XML.ashx?FromLocation=" + shopFrom + "&FromDate=" + dayFrom + "&FromTime=" + timeFrom + "&ReturnLocation=" + shopTo + "&ReturnDate=" + dayTo + "&ReturnTime=" + timeTo + "&VehicleGroup=" + vehicleGroup + "&CountryCode=" + countryCode + "&TariffType=" + tariffType + "&TariffCode=" + tariffCode + "&Command=Prices";
    try {
        XMLObj.open("GET", url, true);
        XMLObj.send(null);
    }
    catch (e) {
        Response = "--";
    }
}

function addPrices(tblId, options) {
    tds = document.getElementById(tblId).getElementsByTagName("td");
    labels = document.getElementById(tblId).getElementsByTagName("label");
    for (i = 0; i < tds.length; i++) {
        tds[i].appendChild(document.createElement("span"));
        if (i<labels.length)       
            justPrice(tds[i].getElementsByTagName("span")[tds[i].getElementsByTagName("span").length - 1], labels[i].innerHTML, options[0], options[1], options[2], options[3], options[4], options[5], options[6], options[7], options[8]);
    }
    
}

function getPrice(idToAssign, vehicleType, options, item) {
    AjaxPrice(idToAssign, options[0], options[1], options[2], options[3], options[4], options[5], vehicleType, options[6], options[7], options[8], item);
}

function getMultiPrice(stringofids, stringofvehicles, options) {
    var XMLObj;
    var Response = '';
    try { XMLObj = new ActiveXObject('Msxml2.XMLHTTP'); }
    catch (e) {
        try { XMLObj = new ActiveXObject('Microsoft.XMLHTTP'); }
        catch (e2) {
            try { XMLObj = new XMLHttpRequest(); }
            catch (e3) { XMLObj = false; }
        }
    }

    XMLObj.onreadystatechange = function() {
        var data;
        if (XMLObj.readyState == 4) {
            if (XMLObj.status == 200) {
                data = XMLObj.responseXML;
            }
            var idsArray = stringofids.split(",");
            if (data) {
                for (i = 0; i < idsArray.length; i++) {
                    document.getElementById(idsArray[i]).innerHTML = "&euro;" + data.getElementsByTagName("group")[i].firstChild.nodeValue;
                    carSelectionArray[i][2] = parseFloat(data.getElementsByTagName("group")[i].firstChild.nodeValue);
                }
                document.getElementById("sortOrdering").style.visibility = "visible";
            }
        }
    };
    var url = "XML.ashx?FromLocation=" + options[0] + "&FromDate=" + options[1] + "&FromTime=" + options[2] + "&ReturnLocation=" + options[3] + "&ReturnDate=" + options[4] + "&ReturnTime=" + options[5] + "&VehicleGroup=" + stringofvehicles + "&CountryCode=" + options[6] + "&TariffType=" + options[7] + "&TariffCode=" + options[8] + "&TariffList=" + options[9] + "&Command=MultiPrices";
    try {
        XMLObj.open("GET", url, true);
        XMLObj.send(null);
    }
    catch (e) {
        Response = "";
    }
}



function AjaxPrice(idToAssign, shopFrom, dayFrom, timeFrom, shopTo, dayTo, timeTo, vehicleType, countryCode, tariffType, tariffCode, item) {
    var XMLObj;
    var Response = '';
    try { XMLObj = new ActiveXObject('Msxml2.XMLHTTP'); }
    catch (e) {
        try { XMLObj = new ActiveXObject('Microsoft.XMLHTTP'); }
        catch (e2) {
            try { XMLObj = new XMLHttpRequest(); }
            catch (e3) { XMLObj = false; }
        }
    }

    XMLObj.onreadystatechange = function() {
        if (XMLObj.readyState == 4) {
            if (XMLObj.status == 200) {
                var data = XMLObj.responseXML;
                Response = ParseRSS(XMLObj.responseXML);
            }
            else {
                Response = "-";
            }
            document.getElementById(idToAssign).innerHTML = Response;
            Response = Response.replace("&euro;", "");
            if (parseFloat(Response, 10)) {
                if (item >= 0) {
                    carSelectionArray[item][2] = parseFloat(Response);
                    priceCounter++;
                    if (priceCounter == carSelectionArray.length) {
                        document.getElementById("sortOrdering").style.visibility = "visible";
                    }
                }
            }
        }
    };
    
    
    var url = "XML.ashx?FromLocation=" + shopFrom + "&FromDate=" + dayFrom + "&FromTime=" + timeFrom + "&ReturnLocation=" + shopTo + "&ReturnDate=" + dayTo + "&ReturnTime=" + timeTo + "&VehicleGroup=" + vehicleType + "&CountryCode=" + countryCode + "&TariffType=" + tariffType + "&TariffCode=" + tariffCode + "&Command=Prices";
    try {
        XMLObj.open("GET", url, true);
        XMLObj.send(null);
    }
    catch (e) {
        Response = "--";
    }
}


function ParseRSS(XMLDoc) {
    var Node = XMLDoc.getElementsByTagName("RentalCost");
    var Len = Node.length;
    var RentalCost;
    var FromDate;
    var ReturnDate;
    var Price;
    if (Len > 0) {
        if (XMLDoc.getElementsByTagName("RentalCost")[0].firstChild) {
            RentalCost = "&euro;" + XMLDoc.getElementsByTagName("RentalCost")[0].firstChild.nodeValue;
        } else {
            RentalCost = "--";
        }
    }
    else {
        if (XMLDoc.documentElement.getElementsByTagName("RentalCost")[0].firstChild) {
            RentalCost = "&euro;" + XMLDoc.documentElement.getElementsByTagName("RentalCost")[0].firstChild.nodeValue;
        } else {
            RentalCost = "--";
        }
    }

    Price = RentalCost
    return Price;
}

function getAllPrices(arrXMLData, arrCarData) {
    for (i = 0; i < arrCarData.length; i++) {
        if (arrCarData[i][4] != "") {
            getPrice(arrCarData[i][4], arrCarData[i][3], arrXMLData, i);
        }
        else {
            priceCounter++;
        }
    }
}
function getAllPricesMulti(arrXMLData, arrCarData) {
    var idString = "";
    var vehicleString = "";
    for (i = 0; i < arrCarData.length; i++) {
        if (arrCarData[i][4] != "") {
            idString += idString == "" ? arrCarData[i][4] : "," + arrCarData[i][4];
            vehicleString += vehicleString == "" ? arrCarData[i][3] : "," + arrCarData[i][3];
        }
        else {
            priceCounter++;
        }
    }
    if (vehicleString != "") {
        getMultiPrice(idString, vehicleString, arrXMLData);
    }
}

/* --------------: Custom Ajax Calls For pricing: End :-------------- */

/* --------------: Calls for paging/filtering in car selection: start:--------- */
var currPage=0;
var perpage=5;
var totalPages=0;
var totalCount = 0;
var showAll = false;
var carSelectionArray = new Array();
var priceCounter = 0;

function populateCarSelectionArray(divObj, groupOrder, price, groupName, priceTag, filter) {
    var newElement=carSelectionArray.length;
    carSelectionArray[newElement] = new Array();
    carSelectionArray[newElement][0] = divObj;
    carSelectionArray[newElement][1] = groupOrder;
    carSelectionArray[newElement][2] = price;
    carSelectionArray[newElement][3] = groupName;
    carSelectionArray[newElement][4] = priceTag;
    var shown = divObj.getElementsByTagName("div")[0].innerHTML;
    if (shown.indexOf("|" + filter + "|") >= 0 || filter==0) {
        carSelectionArray[newElement][5] = true;
        carSelectionArray[newElement][0].style.display = "block";
        totalCount++;
    }
    else {
        carSelectionArray[newElement][0].style.display = "none";
        carSelectionArray[newElement][5] = false;
    }
    setTotalPages(totalCount % perpage ? parseInt(totalCount / perpage) + 1 : parseInt(totalCount / perpage));
}

function displayCarResults(selectedCat) {
    totalCount = 0;
    for (i = 0; i < carSelectionArray.length; i++) {
        var shown = carSelectionArray[i][0].getElementsByTagName("div")[0].innerHTML;
        if (shown.indexOf("|" + selectedCat + "|") < 0 && selectedCat>0) {
            carSelectionArray[i][5] = false;
            carSelectionArray[i][0].style.display = "none";
        }
        else {
            carSelectionArray[i][5] = true;
            carSelectionArray[i][0].style.display = "block";
            totalCount++;
        }
    }
    setTotalPages(totalCount % perpage ? parseInt(totalCount / perpage) + 1 : parseInt(totalCount / perpage));
    showPage(0);
}


function debugArray() {
    var txt="";
    for (i = 0; i < totalCount; i++) {
        txt += carSelectionArray[i][0].id + "\n";
        txt += carSelectionArray[i][1] + "\n";
        txt += carSelectionArray[i][2] + "\n";
    }
    alert(txt);
}

function setCurrPage(num) {
    currPage = num;
}

function setPerPage(num){
    perpage = num;
}

function setTotalPages(num) {
    totalPages = num;
    document.getElementById('totalCount').innerHTML = totalCount;
    if (num <= 1) {
        document.getElementById('toggleButtons').style.visibility = "hidden";
    }
    else {
        document.getElementById('toggleButtons').style.visibility = "visible";
    }
}

 function toggleShowPages() {
    if (showAll) {
        perpage = 5;
        setTotalPages(totalCount % perpage ? parseInt(totalCount / perpage) + 1 : parseInt(totalCount / perpage));
        showPage(0);
        showAll = false;
        document.getElementById("divShowPages").style.display = "none";
        document.getElementById("divShowAll").style.display = "block";
    }
    else {
        perpage = totalCount;
        setTotalPages(1);
        showPage(0);
        showAll = true;
        document.getElementById("divShowAll").style.display = "none";
        document.getElementById("divShowPages").style.display = "block";
    }
    document.getElementById('toggleButtons').style.visibility = "visible";
}

function showPage(pageNum) {
    var parsed = 0;
    if ((parseInt(pageNum, 10) < totalPages) && (parseInt(pageNum, 10) >= 0)) {
        currPage = parseInt(pageNum, 10);
        for (i = 0; i < carSelectionArray.length; i++) {
            if (carSelectionArray[i][5]) {
                if (parsed >= currPage * perpage && parsed < (currPage + 1) * perpage) {
                    carSelectionArray[i][0].style.display = "block";
                }
                else {
                    carSelectionArray[i][0].style.display = "none";
                }
                parsed++;
            }
        }
        setPager();
    }
    else {
        showPage(0);
    }
}

function nextPage() {
    showPage(currPage + 1);
}

function previousPage() {
    showPage(currPage - 1);
}


function setPager() {
    var pagerText = currPage * perpage + 1 + " - " + Math.min((currPage + 1) * perpage, totalCount);
    document.getElementById("pagerText").innerHTML = pagerText;
    if (currPage == 0) {
        document.getElementById("imgPrevPage").style.display = "none";
    }
    else {
        document.getElementById("imgPrevPage").style.display = "inline";
    }
    if (currPage == totalPages-1) {
        document.getElementById("imgNextPage").style.display = "none";
    }
    else {
        document.getElementById("imgNextPage").style.display = "inline";
    }
}

/* --------------: Calls for paging/filtering in car selection: end:--------- */


/* --------------: Calls for sorting in car selection: start:--------- */
function Quicksort(vec, loBound, hiBound, point)
/**************************************************************
This function adapted from the algorithm given in:
Data Abstractions & Structures Using C++, by
Mark Headington and David Riley, pg. 586.

Quicksort is the fastest array sorting routine for
unordered arrays.  Its big O is n log n.
**************************************************************/
{

    var pivot, loSwap, hiSwap, temp;

    // Two items to sort
    if (hiBound - loBound == 1) {
        if (vec[loBound][point] > vec[hiBound][point]) {
            temp = vec[loBound];
            vec[loBound] = vec[hiBound];
            vec[hiBound] = temp;
        }
        return;
    }

    // Three or more items to sort
    pivot = vec[parseInt((loBound + hiBound) / 2)];
    vec[parseInt((loBound + hiBound) / 2)] = vec[loBound];
    vec[loBound] = pivot;
    loSwap = loBound + 1;
    hiSwap = hiBound;

    do {
        // Find the right loSwap
        while (loSwap <= hiSwap && vec[loSwap][point] <= pivot[point])
            loSwap++;

        // Find the right hiSwap
        while (vec[hiSwap][point] > pivot[point])
            hiSwap--;

        // Swap values if loSwap is less than hiSwap
        if (loSwap < hiSwap) {
            temp = vec[loSwap];
            vec[loSwap] = vec[hiSwap];
            vec[hiSwap] = temp;
        }
    } while (loSwap < hiSwap);

    vec[loBound] = vec[hiSwap];
    vec[hiSwap] = pivot;


    // Recursively call function...  the beauty of quicksort

    // 2 or more items in first section		
    if (loBound < hiSwap - 1)
        Quicksort(vec, loBound, hiSwap - 1, point);


    // 2 or more items in second section
    if (hiSwap + 1 < hiBound)
        Quicksort(vec, hiSwap + 1, hiBound, point);
}


function sortCarSelectionArray(type) {
    switch (type) {
        case "priceAsc":
            for (i = 0; i < carSelectionArray.length; i++) {
                if (carSelectionArray[i][2] < 0) {
                    carSelectionArray[i][2] = 1000000;
                }
            }
            Quicksort(carSelectionArray, 0, carSelectionArray.length - 1, 2);
            break;
        case "priceDesc":
            for (i = 0; i < carSelectionArray.length; i++) {
                if (carSelectionArray[i][2] == 1000000) {
                    carSelectionArray[i][2] = -1;
                }
            }
            Quicksort(carSelectionArray, 0, carSelectionArray.length - 1, 2);
            carSelectionArray.reverse();
            break;
        case "typeAsc":
            Quicksort(carSelectionArray, 0, carSelectionArray.length - 1, 1);
            break;
        case "typeDesc":
            Quicksort(carSelectionArray, 0, carSelectionArray.length - 1, 1);
            carSelectionArray.reverse();
            break;
        default:
            Quicksort(carSelectionArray, 0, carSelectionArray.length - 1, 1);
            break;
    }
    for (i = 0; i < document.getElementById("KratisisList").childNodes.length; i++) {
        document.getElementById("KratisisList").removeChild(document.getElementById("KratisisList").childNodes[i]);
    }
    for (i = 0; i < carSelectionArray.length; i++) {
        document.getElementById("KratisisList").appendChild(carSelectionArray[i][0]);
    }
    showPage(0);
}

/* --------------: Calls for sorting in car selection: end :--------- */


function deactivateButton(tableObj) {
    var newimg = document.createElement("img");
    newimg.src = "Assets/Images/pleasewait.gif";
    newimg.id = "pleasewait";
    newimg.style.width = "185px";
    newimg.style.height = "35px";
    tableObj.parentNode.appendChild(newimg);
    tableObj.style.display = "none";
}

function disableSelects() {
    var sels = document.getElementsByTagName("select");
    var i = 0;
    for (i = 0; i < sels.length; i++) {
        sels[i].disabled = "disabled";
    }
}


function ShowCarModelDetails(objRef, carData) {
    document.getElementById("carDetailsGroup").innerHTML = carData[8];
    document.getElementById("carDetailsAcrissCode").innerHTML = carData[6];
    document.getElementById("carDetailsPhoto").src = carData[9];
    document.getElementById("carDetailsEngine").innerHTML = carData[0];
    document.getElementById("carDetailsModel").innerHTML = carData[7];
    document.getElementById("carDetailsCategories").innerHTML = carData[11];
    document.getElementById("carDetailsAdults").src = "Assets/Images/CarDetailPopup/adults" + carData[1] + ".jpg";
    document.getElementById("carDetailsBigLuggage").src = "Assets/Images/CarDetailPopup/BLuggage" + carData[2] + ".jpg";
    document.getElementById("carDetailsSmallLuggage").src = "Assets/Images/CarDetailPopup/SLuggage" + carData[3] + ".jpg";
    if (carData[4]) {
        document.getElementById("carDetailsAC").style.display = "block";
    } else {
        document.getElementById("carDetailsAC").style.display = "none";
    }
    if (carData[5]) {
        document.getElementById("carDetailsExtras").style.display = "block";
        document.getElementById("carDetailsExtraData").innerHTML = carData[5];
    } else {
        document.getElementById("carDetailsExtras").style.display = "none";
    }
}

/*---------------------: Code for Gallery: Start : -------------------*/

function moveGallerySet(direction, buttonClicked, GalleryMove, OtherButton) {
    var thumbsArea = document.getElementById(GalleryMove);
    var leftMargin = thumbsArea.style.marginLeft;
    if (!leftMargin) {
        leftMargin = 0;
    }
    else {
        leftMargin = leftMargin.replace("px", "");
    }
    thumbsArea.style.marginLeft = leftMargin + "px";
    if (direction == 1) {
        //check if there is something to show. We need absolute values. Since leftMargin is either
        //negative or 0, its absolute value is its opposite number. So, what we are looking for, is
        //whether there is anything hidden to the right. If there is, then the thumbnail area width
        //must be greater than the sum of the width of the showable area and the amount we've already 
        //shifted the thumbnail area to the left.
        if (thumbsArea.parentNode.offsetWidth - leftMargin < thumbsArea.offsetWidth-10) {
            leftMargin = leftMargin - thumbsArea.parentNode.offsetWidth;
            slideLeft(thumbsArea.style.marginLeft.replace("px", ""), leftMargin, GalleryMove, 4);
            //thumbsArea.style.marginLeft = leftMargin + "px";
        }
        //Now that we've moved the area, blindly activate the "back" button.
        document.getElementById(OtherButton).style.display = "inline";
        //Also, check whether we need to de-activate the "forward" button. Same rationale as above.
        if (thumbsArea.parentNode.offsetWidth - leftMargin > thumbsArea.offsetWidth) {
            document.getElementById(buttonClicked).style.display = "none";
        }
    }
    else {
        //check if there is something to show. We need absolute values. Since leftMargin is either
        //negative or 0, its absolute value is its opposite number. So, what we are looking for, is
        //whether there is anything hidden to the left. If there is, then the margin is negative.
        if (leftMargin < 0) {
            leftMargin = parseInt(leftMargin) + parseInt(thumbsArea.parentNode.offsetWidth);
            //The leftmost position is with left margin equal to 0. If we go beyond that, it's an error
            if (leftMargin > 0) {
                leftMargin = 0;
            }
            slideRight(thumbsArea.style.marginLeft.replace("px", ""), leftMargin, GalleryMove, 4);
            //thumbsArea.style.marginLeft = leftMargin + "px";
        }
        //Now that we've moved the area, blindly activate the "forward" button.
        document.getElementById(OtherButton).style.display = "inline";
        //Also, check whether we need to de-activate the "back" button. Same rationale as above.
        if (leftMargin >= 0) {
            document.getElementById(buttonClicked).style.display = "none";
        }
    }
}

function slideLeft(start, stop, elementId, speed) {
    var i;
    var counter=0;
    for (i = start; i > stop; i--) {
        counter++;
        window.setTimeout("document.getElementById('" + elementId + "').style.marginLeft = '" + i + "px';", (10 / speed) * counter);
    }
 }

 function slideRight(start, stop, elementId, speed) {
    var i;
    var counter = 0;
    for (i = start; i < stop; i++) {
        counter++;
        window.setTimeout("document.getElementById('" + elementId + "').style.marginLeft = '" + i + "px';", (10/speed) * counter);
    }
}

/*---------------------: Code for Gallery: End : -------------------*/

/*---------------------: Code for quotation request: Start : -------------------*/
function removeCar(num) {
    var val = document.forms[0].CSCT.value;
    var valarray = new Array();
    valarray = val.split(",");
    if (valarray.length > 1) {
        val = "";
        for (var i = 0; i < valarray.length; i++) {
            if (valarray[i] != num) {
                val = val + valarray[i] + ",";
            }
        }
        if (val.charAt(val.length - 1) == ",") {
            val = val.substring(0, val.length - 1);
        }
        document.forms[0].CSCT.value = val;
    }
}

function addCar() {
    var val = document.forms[0].CSCT.value;
    var maxval = parseInt(document.forms[0].CSCTM.value);
    document.forms[0].CSCTM.value = maxval + 1;
    val = val + "," + document.forms[0].CSCTM.value;
    document.forms[0].CSCT.value = val;
}

/*---------------------: Code for quotation request: End : -------------------*/

/*---------------------: Code for Fleet: Start : ------------------------------*/
function createCarDataArray(a,b,c,d,e,f,g,h,i,j,k,l) {
    var CarData = new Array();
    CarData[0] = a;
    CarData[1] = b;
    CarData[2] = c;
    CarData[3] = d;
    CarData[4] = e;
    CarData[5] = f;
    CarData[6] = g;
    CarData[7] = h;
    CarData[8] = i;
    CarData[9] = j;
    CarData[10] = k;
    CarData[11] = l;
    return CarData;
}

function ShowFleetModelDetails(objRef, carData) {
    document.getElementById("carDetailsGroup").innerHTML = carData[8];
    document.getElementById("carDetailsAcrissCode").innerHTML = carData[6];
    document.getElementById("carDetailsPhoto").src = carData[9];
    document.getElementById("carDetailsEngine").innerHTML = carData[0];
    document.getElementById("carDetailsCategories").innerHTML = carData[11];
    document.getElementById("carDetailsModel").innerHTML = carData[7];
    document.getElementById("carDetailsAdults").src = "Assets/Images/CarDetailPopup/adults" + carData[1] + ".jpg";
    document.getElementById("carDetailsBigLuggage").src = "Assets/Images/CarDetailPopup/BLuggage" + carData[2] + ".jpg";
    document.getElementById("carDetailsSmallLuggage").src = "Assets/Images/CarDetailPopup/SLuggage" + carData[3] + ".jpg";
    if (carData[4]) {
        document.getElementById("carDetailsAC").style.display = "block";
    } 
    else {
        document.getElementById("carDetailsAC").style.display = "none";
    }
    if (carData[5]) {
        document.getElementById("carDetailsExtras").style.display = "block";
        document.getElementById("carDetailsExtraData").innerHTML = carData[5];
    } 
    else {
        document.getElementById("carDetailsExtras").style.display = "none";
    }
}

function SetActiveCarGroup(carGroup) {
    document.getElementById(hid).value = carGroup;
}

/*---------------------: Code for Fleet: End : ------------------------------*/
    
