// Detect Client Browser type
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;}
	} else if (obj.x)
		curleft += obj.x;
		return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;}
	} else if (obj.y)
		curtop += obj.y;
	if (isIE && isWin) {
		// NOTHING
	} else {
		curtop = parseInt(curtop)-2;
	}
	return curtop;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

// use this to reference an object
function oe(eid){
	ob = document.getElementById(eid);
	return ob;
}

	function property_print(qrystr){
		window.open('property_detail_print.php?'+qrystr,'print','width=850,height=650,menubar,scrollbars');
	}
	function property_enquiry(idnum){
		window.open('property_enquiry.php?propertyid='+idnum,'enquiry','width=650,height=650,scrollbars');
	}
	function property_book(idnum){
		window.open('property_book.php?propertyid='+idnum,'book','width=650,height=650,scrollbars');
	}
	function property_tariffs(idnum){
		window.open('property_tariffs.php?propertyid='+idnum,'tariffs','width=650,height=450,scrollbars');
	}
	function property_availability(idnum){
		window.open('property_availability.php?propertyid='+idnum,'availability','width=650,height=520,scrollbars');
	}
	function show_terms(){
		window.open('terms.php','terms','width=650,height=520,scrollbars');
	}
	function search_help(){
		window.open('search_help.php','searchhelp','width=650,height=520,scrollbars');
	}
	function property_emailfriend(idnum){
		window.open('property_emailfriend.php?propertyid='+idnum,'email','width=650,height=500,scrollbars');
	}
	function property_guestbook(idnum){	
		window.open('property_guestbook.php?propertyid='+idnum,'guestbook','width=650,height=600,scrollbars');
	}
	function property_images(idnum){	
		window.open('property_images.php?propertyid='+idnum,'images','width=650,height=600,scrollbars');
	}
	
	function favourites_add(idnum,pname){
		window.open('favourites_add.php?propertyid='+idnum+'&pname='+pname,'favourites','width=350,height=250');
	}
	
	function search_add(fname){	
		oe(fname).action='search_save.php';
		oe(fname).target="searches";
		window.open('', 'searches', 'width=650,height=300,status=yes'); 
		oe(fname).submit();
		
		//var a = window.setTimeout("frm.submit();",500); 
	}
	
	function search_run(fname){	
		// check if dates are filled out
		if ((oe("arrdate").value=="")&&(oe("depdate").value!="")) {
			alert ("You must select both an arrival and departure date (or neither).");
			return false;}
		else if ((oe("arrdate").value!="")&&(oe("depdate").value=="")) {
			alert ("You must select both an arrival and departure date (or neither).");
			return false;}
		else if ((oe("arrdate").value!="")&&(oe("depdate").value!="")) {
			// get dates into format
			d1a=oe("arrdate").value.split("/");
			d2a=oe("depdate").value.split("/");
			var d1=new Date(d1a[2],d1a[1]-1,d1a[0]);
			var d2=new Date(d2a[2],d2a[1]-1,d2a[0]);
			// validate dates
			if (d1 >= d2) {
				alert ("Your departure date must be after your arrival date.");
				return false;
				}
		}
		// run search results
		oe(fname).action='search.php';
		oe(fname).target='_self';
		return true;
	}
	
	function search_page(fname,pnum){	
		
		var dosearch=1;
		// check if dates are filled out
		if ((oe("arrdate").value=="")&&(oe("depdate").value!="")) {
			alert ("You must select both an arrival and departure date (or neither).");
			var dosearch=0;
			}
		else if ((oe("arrdate").value!="")&&(oe("depdate").value=="")) {
			alert ("You must select both an arrival and departure date (or neither).");
			var dosearch=0;
			}
		else if ((oe("arrdate").value!="")&&(oe("depdate").value!="")) {
			// get dates into format
			d1a=oe("arrdate").value.split("/");
			d2a=oe("depdate").value.split("/");
			var d1=new Date(d1a[2],d1a[1]-1,d1a[0]);
			var d2=new Date(d2a[2],d2a[1]-1,d2a[0]);
			// validate dates
			if (d1 >= d2) {
				alert ("Your departure date must be after your arrival date.");
				var dosearch=0;
				}
		}
		// run search results to next page
		if (dosearch==1){
			oe(fname).action='search.php?pg='+pnum;
			oe(fname).target='_self';
			oe(fname).submit();
			}
	}
	
	function search_new(fname){	
		document.location.href='search.php';
	}
	
	function show_calendar(fieldname,calDate){
		fldstr="";
		if (calDate!=""){
		// get dates into format
			dcal=calDate.split("/");
			calMonth = dcal[1];
			calYear = dcal[2];
			fldstr = '&calMonth='+calMonth+'&calYear='+calYear;
		}
		window.open('calpopup.php?fieldname='+fieldname+fldstr,'dates','status=yes,scrollbars=no,resizable=yes,width=350,height=400');
	}
	
	
	
	
	

