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 showLoadingPage(){
	document.getElementById('mainTpl').style.display = 'none';
	document.getElementById('iframeLoadCont').style.display = 'block';
	setTimeout("submitSearchPage()",500);
	return false;
}
function submitSearchPage(){
	document.forms['searchForm'].submit();
}

/*
* Checking if the search form is properly filled
*/
function checkSearch(){
	var roomNr = 4;
	var errorMsg = '';
	var focusField = '';

	initFieldID();
	//destination field
	if(document.forms['searchForm'].location_f.value == '' || document.forms['searchForm'].location__f.value == ''){
		errorMsg += searchTranslate[0]+'\n';
		focusField = document.forms['searchForm'].location__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((startDate == '' && endDate != '') || (startDate != '' && endDate == '')){
		errorMsg += searchTranslate[3];
		if(startDate == '' && focusField == ''){
			focusField = document.forms['searchForm'].startDate_f;
		}
		if(endDate == '' && focusField == ''){
			focusField = document.forms['searchForm'].endDate_f;
		}
	}//end if
	else if (start >= end){
		errorMsg += searchTranslate[4]+'\n';
		if(focusField == '')
			focusField = document.forms['searchForm'].startDate_f;
	}
	if(errorMsg != ''){
		focusField.focus();
		alert(errorMsg);
		return false;
	}
	return true;
}//end function checkSearch
function initFieldID(){
	document.forms['searchForm'].location_f.value = document.forms['searchFlag'].locationFlag_f.value;
	document.forms['searchForm'].locationNamePathIDs_f.value = document.forms['searchFlag'].locationFlagNamePathIDs_f.value;
}
function checkKey(id, pathIDs){
	document.forms['searchFlag'].locationFlag_f.value = id;
	document.forms['searchFlag'].locationFlagNamePathIDs_f.value = pathIDs;
}


/*
* Checking if the last minute form is properly filled
*/
function checkSearchLM(){
	var errorMsg = '';
	var focusField = '';

	//destination field
	if(document.forms['addLMForm'].locationLM_f.value == '' || document.forms['addLMForm'].locationLM__f.value == ''){
		errorMsg += searchTranslateLM[0]+'\n';
		focusField = document.forms['addLMForm'].locationLM__f;
	}
	//dates
	var startDate = document.forms['addLMForm'].startDateLM_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['addLMForm'].endDateLM_f.value;
	var dataSplit = endDate.split('-');	
	var end = new Date (parseInt(dataSplit[2], 10),  parseInt(dataSplit[1], 10),  parseInt(dataSplit[0], 10));

	if(startDate == '' || endDate == ''){
		errorMsg += searchTranslateLM[1]+'\n';
		if(startDate == '' && focusField == ''){
			focusField = document.forms['addLMForm'].startDateLM_f;
		}
		if(endDate == '' && focusField == ''){
			focusField = document.forms['addLMForm'].endDateLM_f;
		}
	}//end if
	else if (start >= end){
		errorMsg += searchTranslateLM[2]+'\n';
		if(focusField == '')
			focusField = document.forms['addLMForm'].startDateLM_f;
	}
	if (document.forms['addLMForm'].titleLM_f.value == ''){
		errorMsg += searchTranslateLM[4]+'\n';
		if(focusField == '')
			focusField = document.forms['addLMForm'].titleLM_f;
	}
	//if (document.forms['addLMForm'].descLM_f.value == ''){
	//	errorMsg += searchTranslateLM[3]+'\n';
		//if(focusField == '')
			//focusField = document.forms['addLMForm'].descLM_f;
	//}
	if(errorMsg != ''){
		focusField.focus();
		alert(errorMsg);
		return false;
	}
	return true;
}//end function checkSearchLM


/*
* Displaying a rooms legend in the right position
*/
function showRoomsLegend(objName){
	var obj = document.getElementById(objName);
	var y = findPosY(obj)-100;
	var x = findPosX(obj)+50;
	var legend = document.getElementById('legendRooms');
	legend.style.top = y+'px';
	legend.style.left = x+'px';
	legend.style.display = 'block';
}//end function showRoomsLgend

function hideRoomsLegend(){
	var legend = document.getElementById('legendRooms');
	legend.style.display = 'none';
}//end function showRoomsLgend

function showHideUnitAgency(actionType) {
	var unitLayer = 'addUnitAgency';
	var offerLayer = 'addOfferAgency';
	//if no action specified, this function will toggle the current state	
	if (document.getElementById(unitLayer) == null)
		return false;
	if (actionType == 2)
	{
		 if(document.getElementById(unitLayer).style.display != "none"){
			new_style = "none";
		}
		 else{
			new_style = "block";
   		}//end else
		if(new_style == 'block'){
			document.getElementById(offerLayer).style.display = 'none';
		}
		else if(new_style == 'none'){
			document.getElementById(offerLayer).style.display = 'block';
		}
  }
   else
   	new_style = (actionType == 1) ? "block" : "none";
	document.getElementById('infoDoc').style.display = 'none';
	document.getElementById('infoAddUnit1').style.display = 'none';
	document.getElementById('infoAddUnit2').style.display = 'none';
	document.getElementById(unitLayer).style.display = new_style;
}

/*
* Loading the weather for the right location
*/
function loadWeather(location){
	document.getElementById('weatherFrame').src = '/modcomp/weather/index.php?weather_f='+location;
}//end function loadWeather(location) 

/*
* 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";
}