 function SetCookie(name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
      ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
      ((path == null) ? "" : ("; path=" + path)) +
      ((domain == null) ? "" : ("; domain=" + domain)) +
      ((secure == true) ? "; secure" : "");
  }

  function getCookieVal(offset) {
    var endstr = document.cookie.indexOf(";",offset);
    if (endstr == -1)
      endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
  }

  function GetCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
        return getCookieVal(j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0)
        break;
    }
    return null;
  }

	var saveData = null;
	var loadData = null;

	function at(name, value) {
		if (saveData == null) {
			saveData = "";
		}
		saveData += name + "=" + value + "#";
		SetCookie("saveData", saveData);		
  }

	function gf(givenName) {
		if (loadData == null) {
			loadData = GetCookie("saveData");
		}
		var tmpData = loadData;
		if (tmpData == null) {
			return null;
		}		
		var index = tmpData.indexOf("#");
		while (index != -1) {
			var curData = tmpData.substring(0, index);
			var index2 = curData.indexOf("=");
			if (index2 != -1) {		
				var name = curData.substring(0, index2);
				if (name == givenName) {
					return curData.substring(index2 + 1);
				} else {
					tmpData = tmpData.substring(index + 1); 
					index = tmpData.indexOf("#");
				}
			} else {
				index = -1;
			}
		}	
		return null;
	}

// For searchform
function show(id, state) {
 var gId = "g" + id;
 gObj = document.getElementById(gId);
 if (gObj.style) {
  gObj = gObj.style;
 }
 if (state == 0) {
  gObj.visibility = "hidden";
 } else {
  gObj.visibility = "visible";
 }
}

function highLightArea(id) {
 var ids = new Array();
 ids[0] = "11";
 ids[1] = "12";
 ids[2] = "13";
 ids[3] = "14";
 ids[4] = "15";
 ids[5] = "16";
 if (id == "") {
  for (i = 0; i < ids.length; i++) {
   show(ids[i], 0);
  }
 } else {
  for (i = 0; i < ids.length; i++) {
   if (ids[i] == id) {
    show(ids[i], 1);
   } else {
    show(ids[i], 0);
   }
  }
 }
}

function cpChange() {
  cpChangeSpecial(1);
}

function cpChangeSpecial(update) {
	var obj = document.getElementById("dot");
	if (!obj) return;
	if (obj.style) {
		obj = obj.style;
	}
	obj.visibility = "hidden";
	obj = document.search.area;
	if (!obj) return;
	var index = obj.selectedIndex;
	var value = obj.options[index].value;
	highLightArea(value);
	objArea = document.search.area;  
	if (objArea.length == 1) {
		updateSubAreas();
	} else if (update == 1) {
		updateSubAreas();
	}
}

function populateAreas() {
 obj = document.search.area;
 if (obj) {
  obj.length = a.length;
  for (i = 0; i < obj.length; i++) {
   obj.options[i].text = a[i][1];
   obj.options[i].value = a[i][0];
  }
 }
}

function updateSubAreas() {
	objArea = document.search.area;  
	index = document.search.area.selectedIndex;
	obj = document.search.subArea;
	if (objArea.options[index].value == '') {
		obj.length = 0;
		return;
	}
	obj.length = as[index].length;
	for (i = 0; i < obj.length; i++) {
		obj.options[i].text = as[index][i][1];
		obj.options[i].value = as[index][i][0];
	}
	obj.selectedIndex = 0;
	showSubArea();
}

function saveValues() {
f = document.search;
if (f.area) at("area",f.area.selectedIndex);
if (f.subArea) at("subArea",f.subArea.selectedIndex);
at("startDate",f.startDate.selectedIndex);
at("weeks",f.weeks.selectedIndex);
at("persons",f.persons.selectedIndex);
at("price",f.maxPrice.selectedIndex);
at("minRooms",f.minRooms.selectedIndex);
at("toWater",f.toWater.selectedIndex);
at("pets",f.pets.checked);
at("stove",f.stove.checked);
at("seaView",f.seaView.checked);
at("dishWasher",f.dishWasher.checked);
at("sauna",f.sauna.checked);
at("pool",f.pool.checked);
at("jacuzzi",f.jacuzzi.checked);
at("satellite",f.satellite.checked);
if (f.fuzzy) at("fuzzy",f.fuzzy.checked);
at("washingMachine",f.washingMachine.checked);
//at("phone",f.phone.checked);
at("freezer",f.freezer.checked);
//at("solarium",f.solarium.checked);
if (f.outCount) at("outCount",f.outCount.selectedIndex);
if (f.discounts) {
at("discounts",f.discounts.checked);
}
}

function loadValues() {
f = document.search;	
if (f.area) {
 if (gf("area") != null) {
  f.area.selectedIndex = gf("area");
  cpChange();
 } 
}
if (f.subArea) {
 if (gf("subArea") != null) {
  f.subArea.selectedIndex = gf("subArea");
  showSubArea();
 }
}
if(gf("startDate")!=null)f.startDate.selectedIndex = gf("startDate");
if(gf("weeks")!=null)f.weeks.selectedIndex = gf("weeks");
if(gf("persons")!=null)f.persons.selectedIndex = gf("persons");
if(gf("price")!=null)f.maxPrice.selectedIndex = gf("price");
if(gf("minRooms")!=null)f.minRooms.selectedIndex = gf("minRooms");
if(gf("toWater")!=null)f.toWater.selectedIndex = gf("toWater");
if(gf("pets")=="true")f.pets.checked = 1;
if(gf("stove")=="true")f.stove.checked = 1;
if(gf("seaView")=="true")f.seaView.checked = 1;
if(gf("dishWasher")=="true")f.dishWasher.checked = 1;
if(gf("sauna")=="true")f.sauna.checked = 1;
if(gf("pool")=="true")f.pool.checked = 1;
if(gf("jacuzzi")=="true")f.jacuzzi.checked = 1;
if(gf("satellite")=="true")f.satellite.checked = 1;
if(gf("washingMachine")=="true")f.washingMachine.checked = 1;
//if(gf("phone")=="true")f.phone.checked = 1;
if(gf("freezer")=="true")f.freezer.checked = 1;
//if(gf("solarium")=="true")f.solarium.checked = 1;
if(gf("outCount")!=null)f.outCount.selectedIndex = gf("outCount");
var fuzzySave=gf("fuzzy");
if(fuzzySave==null) {
	// do nothing use default value of fuzzy box
} else if(fuzzySave=="true") {
	f.fuzzy.checked = 1;
} else {
	f.fuzzy.checked = 0;
} 
if(f.discounts && gf("discounts")=="true")f.discounts.checked = 1;
}

function showSubArea() {
 var form = document.search;
 mainIndex = form.area.selectedIndex;
 subIndex = form.subArea.selectedIndex;
 var obj = document.getElementById("dot");
 if (obj && obj.style) {
  obj = obj.style;
 }
 if (form.subArea.length > 0 && form.subArea.options[subIndex].value != '') {
  var name = as[mainIndex][subIndex][1];
  var x = as[mainIndex][subIndex][2];
  var y = as[mainIndex][subIndex][3];
  obj.visibility = "visible";		
  obj.top = y + "px";
  obj.left = x + "px";			
 } else {
  obj.visibility = "hidden";
 }
}

function shiftPage(base, more) {	
if(base.indexOf('?')!=-1)more=more.substr(1);
document.location.href = base + more;
}

function fbLI(name, base, file) {
	obj = document.getElementById(name);
//alert("2");
	if (obj != null) {
//	alert("1");
		theUrl = base + file;
		img = new Image();
		img.src = theUrl; 
		obj.src = img.src;
	}
}

var bookingInProgress = false;

function handleBooking() {
	if (bookingInProgress) {
		return false;
	} else {
		bookingInProgress = true;
		waitForBooking();
		document.book.action=fbBook;
		//document.book.submit();
		return true;
	}
}

function waitForBooking() {
	var height = "1000";
	var width = "1000";
	if (document.height) {
		height = document.height;
		width = document.width;
	} else {
		height = 2000;
		width = document.body.offsetWidth;
	}
	// Hide form elements to avoid IE problems
	var form = document.forms[0];
	for (var i = 0; i < form.elements.length; i++) {
		if (form[i].style) {
			form[i].style.visibility = "hidden";
		} else {
			form[i].visibility = "hidden";
		}
	}
	obj = document.getElementById('waitDiv');
	if (obj != null) {
		obj = obj.style;
		obj.height = height;
		obj.width = width;	
		obj.visibility = 'visible';
	}	
	window.scroll(0,0);
}

