function resetValues(form, values){
for(var i = 0; i < values.length; i++){
		eval("document.forms."+form+"."+values[i]+".value = ''");
	}
}

/*
* If user select the room numbers we start to display the rooms row with adults and children combo
*/
function showRoom(roomNr){
  for(var i = 4; i > parseInt(roomNr); i--){
		document.getElementById('room'+i).style.display = 'none';
		document.getElementById('room'+i).style.display = 'none';
		document.getElementById('adult'+i+'_f').selectedIndex = 1;
		document.getElementById('children'+i+'_f').selectedIndex = 0;
		resetAges(i, 0);
	}
	for(var i = 1; i <= roomNr; i++){
		document.getElementById('room'+i).style.display = 'block';
	}
}//end function showRoom

/*
* If user select the room numbers we start to display the rooms row with adults and children combo
*/
function showAge(rowNr, chidrenNr){
 	if(chidrenNr == '')
 	chidrenNr = 0;
	resetAges(rowNr, chidrenNr);
	for(var i = 1; i <= chidrenNr; i++){
		document.getElementById('age'+rowNr+'_'+i).style.display = 'block';
	}
}//end function showRoom

function resetAges(rowNr, chidrenNr){
	for(var i = 4; i > parseInt(chidrenNr); i--){
		document.getElementById('age'+rowNr+'_'+i).style.display = 'none';
		document.getElementById('age'+rowNr+'_'+i+'_f').selectedIndex = 0;
	}	
}//end function resetAges

function lnk_showLoadingPage(){
	document.getElementById('mainTpl').style.display = 'none';
	document.getElementById('iframeLoadCont').style.display = 'block';
	return true;
}

function showLoadingPage(){
	document.getElementById('mainTpl').style.display = 'none';
	document.getElementById('iframeLoadCont').style.display = 'block';
	setTimeout("submitSearchPage()",500);
	return false;
}
function submitSearchPage(){
	document.forms['searchForm'].submit();
}
function showLoadingPage2(){
	document.getElementById('mainTpl').style.display = 'none';
	document.getElementById('iframeLoadCont').style.display = 'block';
	setTimeout("submitSearchPage2()",500);
	return false;
}
function submitSearchPage2(){
	document.forms['sortBy'].submit();
}


/*
* Checking if the search form is properly filled
*/
function checkSearch(){
	var roomNr = 4;
	var errorMsg = '';
	var focusField = '';
	//destination field
	//if(document.forms['searchForm'].country_f.value == ''){
		//errorMsg += searchTranslate[0]+'\n';
		//focusField = document.forms['searchForm'].country_f;
	//}
	//children ages
	for(var i = 1; i <= roomNr; i++){
		var childrenRoom = eval("document.forms['searchForm'].children"+i+"_f.value");
		if(childrenRoom != ''){
			for(var j = 1; j <= childrenRoom; j++){			
				age = eval("document.forms['searchForm'].age"+i+'_'+j+"_f.value");
				if(age == ''){
					if(focusField == '')
						focusField = eval("document.forms['searchForm'].age"+i+'_'+j+"_f");
					errorMsg += searchTranslate[1]+' '+ j + ' ' + searchTranslate[2]+' '+ i + '.\n';
				}
			}
		}
	}
	//dates
	var startDate = document.forms['searchForm'].startDate_f.value;
	var dataSplit = startDate.split('-');	
	var start = new Date (parseInt(dataSplit[2], 10),  parseInt(dataSplit[1], 10),  parseInt(dataSplit[0], 10));
	var endDate = document.forms['searchForm'].endDate_f.value;
	var dataSplit = endDate.split('-');	
	var end = new Date (parseInt(dataSplit[2], 10),  parseInt(dataSplit[1], 10),  parseInt(dataSplit[0], 10));
	if (start >= end){
		errorMsg += searchTranslate[3]+'\n';
		if(focusField == '')
			focusField = document.forms['searchForm'].startDate_f;
	}
	else {
		var nightsNr = document.getElementById('nights_f').value;
		var ONE_DAY = 1000 * 60 * 60 * 24;
		// Calculate the difference in milliseconds
		var difference_ms = Math.abs(end - start);
		var days = Math.round(difference_ms/ONE_DAY);
		if(days < nightsNr){
			errorMsg += searchTranslate[5]+'\n';
			if(focusField == '')
				focusField = document.forms['searchForm'].startDate_f;
		}
	}
	if(errorMsg != ''){
		focusField.focus();
		alert(errorMsg);
		return false;
	}
	return true;
}//end function checkSearch

/*
* Checking if the search form is properly filled
*/
function checkSearch2(){
	var errorMsg = '';
	var focusField = '';
	//destination field
	//if(document.forms['searchForm'].country_f.value == ''){
		//errorMsg += searchTranslate[0]+'\n';
		//focusField = document.forms['searchForm'].country_f;
	//}
	//dates
	var startDate = document.forms['searchForm'].startDate_f.value;
	var dataSplit = startDate.split('-');	
	var start = new Date (parseInt(dataSplit[2], 10),  parseInt(dataSplit[1], 10),  parseInt(dataSplit[0], 10));
	var endDate = document.forms['searchForm'].endDate_f.value;
	var dataSplit = endDate.split('-');	
	var end = new Date (parseInt(dataSplit[2], 10),  parseInt(dataSplit[1], 10),  parseInt(dataSplit[0], 10));
	if (start >= end){
		errorMsg += searchTranslate[3]+'\n';
		if(focusField == '')
			focusField = document.forms['searchForm'].startDate_f;
	}
	if(errorMsg != ''){
		focusField.focus();
		alert(errorMsg);
		return false;
	}
	return true;
}//end function checkSearch


/*
* Adding to the session a room for a future booking
*/
function pushRoom(id, sec, lang){
	AjaxRequest.get(
    {
      'url':'/index.php?componentCall=1&sec='+sec+'&cmd=pushRoom&lang='+lang+'&id='+id
	  ,'onLoading':function(req){ }
      ,'onSuccess':function(req){}
    }
  );
}//end fucntion pushRoom

/*
* Removing from the session a room for a future booking
*/
function popRoom(id, sec, lang){
	AjaxRequest.get(
    {
      'url':'/index.php?componentCall=1&sec='+sec+'&cmd=popRoom&lang='+lang+'&id='+id
	  ,'onLoading':function(req){ }
      ,'onSuccess':function(req){}
    }
  );
}//end fucntion popRoom


/*
* Adding units and offers into two different list for some details comparation
*/
function addToCompaireList(compareType, id, sec){
	AjaxRequest.get(
    {
      'url':'/index.php?componentCall=1&sec='+sec+'&cmd=addToList&id='+id+'&compareType='+compareType
	  ,'onLoading':function(req){ }
      ,'onSuccess':function(req){ showInactiveIcon();}
    }
  );
}//end fucntion addToCompaireList

function showInactiveIcon(){
	document.getElementById('compaireList').style.display = "none";
}

var country = 0;	
var zone = 0;
var loc = 0;
var params = 0;
function loadCountry(country, zone, loc, params){
	this.country = country;	
	this.zone = zone;	
	this.loc = loc;	
	this.params = params;
	var url = '/index.php?componentCall=1&type=2&cmd=loadDestination&country='+country+params;
	AjaxRequest.get(
			{
				'url': url
				,'onLoading':function(req){ }
				,'onSuccess':function(req){loadCountryData(req.responseText);}
			}
		);
}//end function loadCountry(...)

function loadCountryData(data){
	var country_f = document.getElementById('country_f');
	country_f.options.length = 0;
	var t = data.split('#!#');
	var optn = '';
	var info = Array();
	optn = document.createElement("option");optn.text = this.searchTranslate[4];optn.value = '';country_f.options.add(optn);
	for(var i = 0; i < (t.length-1); i++){
		info = t[i].split(':');
		optn = document.createElement("option");optn.text = info[0];optn.value = info[1];country_f.options.add(optn);
		if(info[1] == this.country && this.country != ''){
			optn.selected = true;
			this.country = info[1];
		}
	}//end for
	if(this.country != 0){
		loadZone(this.country, '');
	}
}//end loadCountryData(...)

function loadZone(country, resetVar){
	/*if(document.getElementById('country_f').options[document.getElementById('country_f').selectedIndex].text.toLowerCase() == 'romania'){
		document.getElementById('currency_f').value = 'RON';
		document.getElementById('currency_').innerHTML = 'RON';
	}
	else {
		document.getElementById('currency_f').value = 'EUR';
		document.getElementById('currency_').innerHTML = 'EUR';
	}
	*/
	if(country != ''){	
		if(resetVar == 1){
			resetZoneLoc();	
		}
		this.country = country;	
		var url = '/index.php?componentCall=1&type=4&cmd=loadDestination&country='+this.country+this.params;
		AjaxRequest.get(
			{
				'url': url
				,'onLoading':function(req){ }
				,'onSuccess':function(req){loadZoneData(req.responseText);}
			}
		);
	}
	else {
		resetZoneLoc();
	}

}//end function loadZone(...)

function resetZoneLoc(){
	var zone_f = document.getElementById('zone_f');
	zone_f.options.length = 0;
	optn = document.createElement("option");optn.text = this.searchTranslate[4];optn.value = '';zone_f.options.add(optn);
	var loc_f = document.getElementById('loc_f');
	loc_f.options.length = 0;
	optn = document.createElement("option");optn.text = this.searchTranslate[4];optn.value = '';loc_f.options.add(optn);
	this.zone = 0;
	this.loc = 0;
}

function loadZoneData(data){
	var zone_f = document.getElementById('zone_f');
	zone_f.options.length = 0;
	var t = data.split('#!#');
	var optn = '';
	var info = Array();
	optn = document.createElement("option");optn.text = this.searchTranslate[4];optn.value = '';zone_f.options.add(optn);
	for(var i = 0; i < (t.length-1); i++){
		info = t[i].split(':');
		optn = document.createElement("option");optn.text = info[0];optn.value = info[1];zone_f.options.add(optn);
		if(info[1] == this.zone && this.zone != ''){
			optn.selected = true;
			this.zone = info[1];
		}
	}//end for
	if(this.zone != 0){
		loadLoc(this.zone);
	}
}//end loadZoneData

function loadLoc(zone){
	if(zone != ''){
		this.zone = zone;	
		var url = '/index.php?componentCall=1&type=9&cmd=loadDestination&zone='+this.zone+this.params;
		AjaxRequest.get(
			{
				'url': url
				,'onLoading':function(req){ }
				,'onSuccess':function(req){loadLocData(req.responseText);}
			}
		);		
	}//end if
	else {
		var loc_f = document.getElementById('loc_f');
		loc_f.options.length = 0;
		optn = document.createElement("option");optn.text = this.searchTranslate[4];optn.value = '';loc_f.options.add(optn);
	}
}//end function loadLoc(...)

function loadLocData(data){
	var loc_f = document.getElementById('loc_f');
	loc_f.options.length = 0;
	var t = data.split('#!#');
	var optn = '';
	var info = Array();
	optn = document.createElement("option");optn.text = this.searchTranslate[4];optn.value = '';loc_f.options.add(optn);
	for(var i = 0; i < (t.length-1); i++){
		info = t[i].split(':');
		optn = document.createElement("option");optn.text = info[0];optn.value = info[1];loc_f.options.add(optn);
		if(info[1] == this.loc && this.loc != ''){
			optn.selected = true;
		}
	}//end for
	//loadLocation(this.loc)
}//end loadZoneData

function loadCountry2(country, zone, params){
	this.country = country;	
	this.zone = zone;	
	this.loc = 0;	
	this.params = params;
	var url = '/index.php?componentCall=1&type=2&cmd=loadDestination&country='+country+params;
	AjaxRequest.get(
			{
				'url': url
				,'onLoading':function(req){ }
				,'onSuccess':function(req){loadCountryData2(req.responseText);}
			}
		);
}//end function loadCountry(...)

function loadCountryData2(data){
	var country_f = document.getElementById('country_f');
	country_f.options.length = 0;
	var t = data.split('#!#');
	var optn = '';
	var info = Array();
	optn = document.createElement("option");optn.text = this.searchTranslate[4];optn.value = '';country_f.options.add(optn);
	for(var i = 0; i < (t.length-1); i++){
		info = t[i].split(':');
		optn = document.createElement("option");optn.text = info[0];optn.value = info[1];country_f.options.add(optn);
		if(info[1] == this.country && this.country != ''){
			optn.selected = true;
			this.country = info[1];
		}
	}//end for
	if(this.country != 0){
		loadZone2(this.country, '');
	}
}//end loadCountryData(...)


function loadZone2(country, resetVar){
	if(country != ''){	
		if(resetVar == 1){
			resetZone();	
		}
		this.country = country;	
		var url = '/index.php?componentCall=1&type=4&cmd=loadDestination&country='+this.country+this.params;
		AjaxRequest.get(
			{
				'url': url
				,'onLoading':function(req){ }
				,'onSuccess':function(req){loadZoneData2(req.responseText);}
			}
		);
	}
	else {
		resetZone();
	}

}//end function loadZone2(...)

function resetZone(){
	var zone_f = document.getElementById('zone_f');
	zone_f.options.length = 0;
	optn = document.createElement("option");optn.text = this.searchTranslate[4];optn.value = '';zone_f.options.add(optn);
	this.zone = 0;
}

function loadZoneData2(data){
	var zone_f = document.getElementById('zone_f');
	zone_f.options.length = 0;
	var t = data.split('#!#');
	var optn = '';
	var info = Array();
	optn = document.createElement("option");optn.text = this.searchTranslate[4];optn.value = '';zone_f.options.add(optn);
	for(var i = 0; i < (t.length-1); i++){
		info = t[i].split(':');
		optn = document.createElement("option");optn.text = info[0];optn.value = info[1];zone_f.options.add(optn);
		if(info[1] == this.zone && this.zone != ''){
			optn.selected = true;
			this.zone = info[1];
		}
	}//end for
}//end loadZoneData2


/*function loadOfferDates(url){
	AjaxRequest.get(
    {
      'url': '/index.php?'+url
	  ,'onLoading':function(req){}
      ,'onSuccess':function(req){addValidDate(req.responseText);}
    }
	);
}//end function loadOfferDates(...)
*/
/*--selection tab for details on units--*/
function selectTab(listName, area){
	var obj = document.getElementById('tabLink_'+area);
	for(var i = 0; i < document.getElementById(listName).getElementsByTagName('a').length; i++){
			document.getElementById(listName).getElementsByTagName('a')[i].className = '';
			document.getElementById('tab_'+parseInt((i+1), 10)).style.display='none';
	}
	obj.className = 'selected';
	document.getElementById('tab_'+parseInt(area, 10)).style.display='block';
	return true;
}

/*var DISABLED_DATES = new Array();
function addValidDate(data){
	this.DISABLED_DATES = new Array();
	var t = data.split('#!#');
	if(t != -1){
		for(var i=0;i<=t.length;i++){
			if(t[i] != '')this.DISABLED_DATES[t[i]] = true;
		}//end for
	}//end if
	cal.redraw();
}//end function addRoomRow(...)
*/
