function resetValues(form, values){
for(var i = 0; i < values.length; i++){
		eval("document.forms."+form+"."+values[i]+".value = ''");
	}
}

function showLoadingPage(){
	document.getElementById('bgCols').style.display = 'none';
	if(document.getElementById('sponsorLinks') != null)document.getElementById('sponsorLinks').style.display = 'none';
	document.getElementById('iframeLoadCont').style.display = 'block';
	setTimeout("submitSearchPage()",500);
	return false;
}
function showLoadingPage2(){
	document.getElementById('bgCols').style.display = 'none';
	if(document.getElementById('sponsorLinks') != null)document.getElementById('sponsorLinks').style.display = 'none';
	document.getElementById('iframeLoadCont').style.display = 'block';
	setTimeout("submitSearchPage2()",500);
	return false;
}
function submitSearchPage(){
	document.forms['unitDetSearch'].submit();
}
function submitSearchPage2(){
	document.forms['fastSearch'].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;
	}
	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

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;
}

/*
* Adding units and offers into two different list for some details comparation
*/
function addToCompaireList(compareType, id, sec, sectionID){
	AjaxRequest.get(
    {
      'url':'/index.php?componentCall=1&sec='+sec+'&cmd=addToList&id='+id+'&compareType='+compareType+'&sectionID='+sectionID
	  ,'onLoading':function(req){ }
      ,'onSuccess':function(req){ showInactiveIcon(req.responseText);}
    }
  );
}//end fucntion addToCompaireList

function showInactiveIcon(data){
	document.getElementById('compaireList').style.display = "none";
}

/*
* Setting up the right intervals of prices depending by currency
*/
function setPriceCost(currency, el, selected){
	var price_f = document.getElementById(el);
	price_f.options.length = 0;
	var optn = document.createElement("option");optn.text = 'toate';optn.value = '';price_f.options.add(optn);
	if(currency == 'eur'){
		var optn = document.createElement("option");optn.text = '< 150';optn.value = '150';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 200';optn.value = '200'; price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 250';optn.value = '250';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 300';optn.value = '300';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 350';optn.value = '350';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 450';optn.value = '450';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 500';optn.value = '500';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 600';optn.value = '600';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 700';optn.value = '700';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 800';optn.value = '800';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 900';optn.value = '900';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 1200';optn.value = '1200';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '> 1500';optn.value = '1500';price_f.options.add(optn);
	}
	else if(currency == 'ron'){
		var optn = document.createElement("option");optn.text = '< 150';optn.value = '150';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 200';optn.value = '200';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 250';optn.value = '250';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 300';optn.value = '300';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 350';optn.value = '350';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 450';optn.value = '450';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 500';optn.value = '500';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 600';optn.value = '600';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 700';optn.value = '700';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 800';optn.value = '800';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 900';optn.value = '900';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 1200';optn.value = '1200';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '< 1500';optn.value = '1500';price_f.options.add(optn);
		optn = document.createElement("option");optn.text = '> 2000';optn.value = '2000';price_f.options.add(optn);
	}
}//end function setPriceCost

/*
* if user select a speciific region, all the rest of fields with locations and destinations will be affected by this selecttion
*/
function changeRegions(obj){
	loadZone(sec, zoneID, obj.value);
}//end function changeRegions

/*
* Loading all available zone areas into a dropdown
*/
var regionID = 0;
var zoneID = 0;
var sec = 0;
function loadZone(sec, zoneID, regionID){
	this.regionID = regionID;	
	this.zoneID = zoneID;
	this.sec = sec;
	var url = '/index.php?componentCall=1&sec='+sec+'&cmd=loadZone&regionID='+regionID;
	AjaxRequest.get(
    {
      'url': url
	  ,'onLoading':function(req){ }
      ,'onSuccess':function(req){loadZoneElements(req.responseText);}
    }
  );
}
function loadZoneElements(data){
	var zone_f = document.getElementById('zone_f');
	zone_f.options.length = 0;
	var t = data.split('#!#');
	var optn = '';
	var info = Array();
	var selectedZone = 0;
	optn = document.createElement("option");optn.text = 'toate';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.zoneID && this.zoneID != ''){
			optn.selected = true;
		}
	}//end for
	loadJud(this.sec, '');
}//end function loadZoneElements

/*
* Changeing one zone
*/
function changeZone(sec, zoneID){
	this.zoneID = zoneID;
	loadJud(sec, '');
}
/*
* Loading all available cities for one selected zone area into a dropdown
*/
var judID = 0;
function loadJud(sec, judID){
	this.judID = judID;
	var url = '/index.php?componentCall=1&sec='+sec+'&cmd=loadJud&id='+this.zoneID+'&regionID='+this.regionID;
	AjaxRequest.get(
	{
	  'url': url
	  ,'onLoading':function(req){ }
	  ,'onSuccess':function(req){loadJudElements(req.responseText);}
	}
	);
}
function loadJudElements(data){
	var zone_f = document.getElementById('city_f');
	zone_f.options.length = 0;
	var t = data.split('#!#');
	var optn = '';
	var info = Array();
	optn = document.createElement("option");optn.text = 'toate';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.judID && this.judID != ''){
			optn.selected = true;
		}
		else if(this.judID == '' && this.zoneID == '')  {
			this.judID = info[1];
		}
	}//end for
	loadLoc(this.sec, '');
}//end function loadZoneElements
/*
* Changeing one zone
*/
function changeJud(sec, judID){
	this.judID = judID;
	loadLoc(sec, '');
}

/*
* Loading all available locations for one selected city from a one selected zone area into a dropdown
*/
var locID = 0;
function loadLoc(sec, locID){
	var url = '/index.php?componentCall=1&sec='+sec+'&cmd=loadLoc&judID='+this.judID+'&zoneID='+this.zoneID+'&regionID='+this.regionID;
	AjaxRequest.get(
    {
      'url': url
	  ,'onLoading':function(req){ }
      ,'onSuccess':function(req){loadLocElements(req.responseText);}
    }
  );
}
function loadLocElements(data){
	var zone_f = document.getElementById('town_f');
	zone_f.options.length = 0;
	var t = data.split('#!#');
	var optn = '';
	var info = Array();
	optn = document.createElement("option");optn.text = 'toate';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.locID && this.locID != ''){
			optn.selected = true;
		}
	}//end for
}//end function loadZoneElements

function hideImagesFromPage(){
	var imgs = document.getElementsByTagName('img'); 
	if(imgs.length > 0){
		for(i=0;i<imgs.length;i++){
			imgs[i].style.display = "none";
		}
		newImage = "url(/images/frontend/spacer.gif)";
		document.getElementById('bodyCmpLs').style.backgroundImage = newImage;
	}//end if
}

function resetEmailCmpLs(email_f){
	document.getElementById(email_f).value = '';
}//end function resetValues(fieldList)
/*
* Loading all available zone areas into a dropdown
*/
function loadZone2(sec, zoneID, judID, locID){
	this.zoneID = zoneID;
	this.locID = locID;
	this.judID = judID;
	this.sec = sec;
	var url = '/index.php?componentCall=1&sec='+sec+'&cmd=loadZone';
	AjaxRequest.get(
    {
      'url': url
	  ,'onLoading':function(req){ }
      ,'onSuccess':function(req){loadZoneElements2(req.responseText);}
    }
  );
}
function loadZoneElements2(data){
	var zone_f = document.getElementById('zone_f');
	var t = data.split('#!#');
	var optn = '';
	var info = Array();
	optn = document.createElement("option");optn.text = 'toate';optn.value = '';zone_f.options.add(optn);
	var selectedZone = 0;
	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.zoneID && this.zoneID != ''){
			optn.selected = true;
		}
		else if(this.zoneID == ''){
			this.zoneID = '0';//info[1];
		}
	}//end for
	loadJud(this.sec, this.judID);
	loadLoc(this.sec, this.locID);
}//end function loadZoneElements
