

function fillSelect(selectName, textArray, valueArray, selectedValue, firstOption){
	sel='document.forms.rental.'+selectName;
	eval(sel+".options.length = 0");		//eloszor kiuritjuk
	if(firstOption!='')selectNewOption(sel, '', firstOption);
	for(a=0;a<eval(textArray+'.length');a++){
		selectNewOption(sel, eval(valueArray+'['+a+']'), eval(textArray+'['+a+']'));
	}
}

function selectNewOption(selName, optVal, optText){
	NewOpt = new Option;        //same as the HTML option; tag
    NewOpt.value = optVal;    //same as option value=[id]
    NewOpt.text = optText;  //now we have optionvalue=[id]>[name]
    eval(selName+".options["+sel+".length] =  NewOpt;"); //put the new option in the select box
}

function setSelectByValue(sname, svalue){
	l=eval(sname+'.length');
	for(h=0;h<l;h++){
		if(eval(sname+'['+h+'].value')==svalue)eval(sname+'.selectedIndex='+h+';');
	}
	return true;
}
function getKalendar(mode){
	window.open('/hu/rental/rental_kalendar.htm?mode='+mode, 'kal', 'width=200,height=200,top=400,left=400,srollbars=0');
}

function openTerms(){
	w=550;
	h=500;
	t=(screen.height-h)/2;
	l=(screen.width-w)/2;
	window.open('/hu/rental/terms.htm', 'terms', 'width='+w+',height='+h+',top='+t+',left='+l+',scrollbars=yes');
}









//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Data Loading Functions
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////






function xmlFeldolgozo(xmlcont){
	if(is_ie==true){
		for(z=0;z<xmlcont.childNodes.length;z++){
			tmp=xmlcont.childNodes(z).text;
			if(tmp=='true' || tmp=='false')eval("parent."+xmlcont.childNodes(z).tagName+"="+xmlcont.childNodes(z).text+";");
			else eval("parent."+xmlcont.childNodes(z).tagName+"='"+xmlcont.childNodes(z).text+"';");
		}
	} else {
		test=xmlcont.split('\r\n\t');
		for(z=1;z<test.length;z++){
			sor=test[z];
			xtmp1=sor.split('>');
			name=xtmp1[0].substr(1,xtmp1[0].length);
			xtmp2=xtmp1[1].split('<');
			value=xtmp2[0];
			tmp=value;
			if(tmp=='true' || tmp=='false')eval("parent."+name+"="+value+";");
			else eval("parent."+name+"='"+value+"';");
		}
	}
}
/*
function readXML(xmlFilePath){
	if(is_ie==true){
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.onreadystatechange=xmlVerifyOnLoad;
		xmlDoc.load(xmlFilePath);
		xmlObj=xmlDoc.documentElement;
		return xmlObj;
	} else {
		return readXml2(xmlFilePath);
	}
}
*/
function readXML(url, fv) {
        var httpRequest;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!httpRequest) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        httpRequest.onreadystatechange = function() { alertContents(httpRequest, fv); };
        httpRequest.open('GET', url, true);
        httpRequest.send(null);
    }
	XMLcont='';
    function alertContents(httpRequest, fv) {

        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
				XMLcont=httpRequest.responseXML;
				//if(is_ie!=true)alert(httpRequest.responseText);
				eval(""+fv+"();");
            } else {
                alert('There was a problem with the request.');
            }
        }

    }
alerts=0;

function readXml2(xmlFilePath){
	xmlDoc = document.implementation.createDocument("", "", null);
  	teszt='';
	xmlDoc.onload=function(){teszt='g';};
	xmlDoc.load(xmlFilePath);
	/*
	while(teszt==''){
		if(alerts<20){
			alert("toltom...");
			alerts++;
		}
	}*/
	xmlObj=xmlDoc.getElementsByTagName('OfferListQuery');
	tmp=xmlObj[0];
	return tmp;
}




function xmlVerifyOnLoad(){
	if (xmlDoc.readyState != 4) return false;
}

function getMaxUtEsRegDij(days){
	var utdij=4.8;
	var regdij=2.4;
	
	var utdijMax=48;
	var regdijMax=36;
	
	tmp=(utdij+regdij)*days;
	if(tmp>(utdijMax+regdijMax))tmp=(utdijMax+regdijMax);
	return tmp;
	
}

function fillOfferList(offerData, days, oneWayFee){
	offD=offerData.getElementsByTagName('OfferList')[0];
	for(x=0;x<offD.childNodes.length;x++){
		offerObj=offD.getElementsByTagName('Offer')[x];
		if(offerObj!=null && offerObj!=undefined){
			///////////////////////////
			//groupId
			//
			tmp_1=offerObj.getAttribute('GroupID');
	
	
			///////////////////////////
			//on request - ezeket mi tesszuk bele
			//
			if(offerObj.getElementsByTagName("onRequest")[0].firstChild.nodeValue!='true')tmp_req='false';
			else tmp_req='true';
		
			///////////////////////////
			//a kategória autói
			//
			examples_tmp=new Array();
			tmp=offerObj.getElementsByTagName('ExampleCars')[0];
			exes=tmp.getElementsByTagName('ExampleCar');
			for(z=0;z<exes.length;z++){
				examples_tmp[z]=exes[z].firstChild.nodeValue;
			}	
			
			///////////////////////////
			//ár
			//
			var owf=0;
			if(tmp_req!='true'){
				if(oneWayFee==true)owf=32.64;
				tmp_2=(parseFloat(offerObj.getElementsByTagName('Price')[0].firstChild.nodeValue)-getMaxUtEsRegDij(days)-owf)/1.25;
			} else {
				tmp_2=parseFloat(offerObj.getElementsByTagName('Price')[0].firstChild.nodeValue);
			}
			//ha repulo ES nem request, kivonjuk az arbol a 12%-ot (kesobb hozzaadjuk)
			rextranode=offerObj.getElementsByTagName('Extra');
			if(rextranode[0]!=null && rextranode[0]!=undefined && tmp_req=='false'){
				pricenode2=rextranode[0].getElementsByTagName('Price');
				if(pricenode2[0]!=null){
					repteri=pricenode2[0].firstChild.nodeValue;
					tmp_2=tmp_2/repteriSzorzo;
				}
			}
			//vegul kerekitjuk
			tmp_2=Math.round(tmp_2*100)/100;

			///////////////////////////
			//serial (a rendelés sorozatszáma)
			//
			tmp_4=offerObj.getElementsByTagName('Serial')[0].firstChild.nodeValue;
	
			///////////////////////////
			//TarifID
			//
			tmp_5=offerObj.getAttribute('TarifID');
		
	
			//végül ebben a sorrendben bepakoljuk az adatokat az objektumba		
			//groupId, Price, exampleCars, Serial, Class, Type, Doors, Persons, tarifId
			offers[x]=new addOffer(tmp_1, tmp_2, examples_tmp, tmp_4, getCategoryFromGroupId(tmp_1), 'Személygépkocsi', '5', '5', tmp_5, tmp_req);
		
		
		}
	}
	
}


function getCategoryFromGroupId(id){
	id=id.substr(0,1);
	if(id=='E')return 'Economy';
	if(id=='C')return 'Compact';
	if(id=='I')return 'Intermediate';
	if(id=='S')return 'Standard';
	if(id=='F')return 'Full size';
	if(id=='P')return 'Premium';
	if(id=='L')return 'Luxury';
	return '';
}

function addOffer(groupId, Price, exampleCars, Serial, Class, Type, Doors, Persons, tarifId, onRequest){
	this.groupId=groupId;
	this.Price=Price;
	this.exampleCars=exampleCars;
	this.Serial=Serial;
	this.Class=Class;
	this.Type=Type;
	this.Doors=Doors;
	this.Persons=Persons;
	this.tarifId=tarifId;
	this.onRequest=onRequest;
}



function replaceAccents(text){
	text=replaceAll(text, 'á', 'a');
	text=replaceAll(text, 'Á', 'A');
	text=replaceAll(text, 'í', 'i');
	text=replaceAll(text, 'Í', 'I');
	text=replaceAll(text, 'é', 'e');
	text=replaceAll(text, 'É', 'E');
	text=replaceAll(text, 'ó', 'o');
	text=replaceAll(text, 'Ó', 'O');
	text=replaceAll(text, 'ö', 'o');
	text=replaceAll(text, 'Ö', 'O');
	text=replaceAll(text, 'ő', 'o');
	text=replaceAll(text, 'Ő', 'O');
	text=replaceAll(text, 'ú', 'u');
	text=replaceAll(text, 'Ú', 'U');
	text=replaceAll(text, 'ü', 'u');
	text=replaceAll(text, 'Ü', 'U');
	text=replaceAll(text, 'ű', 'u');
	text=replaceAll(text, 'Ű', 'U');
	return text
}


function days_between(date1, time1, date2, time2) {
	
	t1tmp=time1.split(":");
	t2tmp=time2.split(":");
	
	d1tmp=date1.split("-");
	d1=new Date(d1tmp[0],d1tmp[1]-1,d1tmp[2],t1tmp[0],t1tmp[1]);
	
	d2tmp=date2.split('-');
	d2=new Date(d2tmp[0],d2tmp[1]-1,d2tmp[2],t2tmp[0],t2tmp[1]);
	
    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24;

    // Convert both dates to milliseconds
    var date1_ms = d1.getTime();
    var date2_ms = d2.getTime();

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms);
    
    // Convert back to days and return
    output=difference_ms/ONE_DAY;
	
	if((output%1)>0) return parseInt(output)+1;
	else return output;

}


function oneWayFeeNeeded(id1, id2){
	id1=parseInt(id1);
	id2=parseInt(id2);
	//true-t ad vissza, ha kell szamolni leadasi dijat, a ket helyszin idjet visszuk be
	//ha id1 pesti es id2 nem az
	if((id1==3523 || id1==6693 || id1==234 || id1==239) && (id2!=3523 && id2!=6693 && id2!=234 && id2!=239))return true;
	//ha id2 pest es id1 nem az
	if((id2==3523 || id2==6693 || id2==234 || id2==239) && (id1!=3523 && id1!=6693 && id1!=234 && id1!=239))return true;
	return false;
}
