function $ (element) 
{
	return document.getElementById(element);
}

function PopImages (sender, id) {
	var view = $("pages_"+id);
	var real_view = $("pages_view_"+id);
	
	// maybe set up width?
	var page_width = document.documentElement.scrollWidth;
	var width = page_width - (page_width / 10); // 10%
	real_view.style.width = width + "px";
	real_view.style.left = (page_width - width) / 2;
	
	var page_height = document.documentElement.offsetHeight; // use browser visible height
	var height = page_height - (page_height / 10); // 10%
	real_view.style.height = height + "px";
	real_view.style.top = (page_height - height) / 2;
	
	view.style.display = "block";
}

function close_pages (sender) {
	var divs = document.getElementsByTagName("div");
	var name = "";
	for (var i=0; i<divs.length; i++) {
		name = divs[i].getAttribute("name");
		if (name != null && name.match(/pages_[0-9]+/)) {
			divs[i].style.display = "none";
		}
	}
}

function RadioJump(pickup)
{
	window.location.href = pickup;
}
// Printing
function Printing(id){ 
	if(window.print()){
	var d=eval(id)==null||eval(id+".closed");
	if(!d){eval(id+".print()");}}
}

myPopup = '';

function PopupReturnWindow(file_id,w,h,scl,menu,stat,tool,full,locate,resize,tbar)
{

  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var PopUp = 'POPUP';
  
  settings = 'height='+h+',';
  settings += 'width='+w+',';
  settings +='top='+wint+',';
  settings +='left='+winl+',';
  settings +='scrollbars='+scl+',';
  settings +='menubar='+menu+',';
  settings +='statusbar='+stat+',';
  settings +='toolbar='+tool+',';
  settings +='fullscreen='+full+',';
  settings +='titlebar='+tbar+',';
  settings +='locationbar='+locate+',';
  settings +='resizable='+resize;
  
  myPopup = window.open(file_id,PopUp,settings);
    if (!myPopup.opener)
         myPopup.opener = self; 
}
function PopupWindow(file_id,w,h,scl,menu,tool,resize,tbar)
{

  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var PopUp = 'POPUP';
  
  settings = 'height='+h+',';
  settings += 'width='+w+',';
  settings +='top='+wint+',';
  settings +='left='+winl+',';
  settings +='scrollbars='+scl+',';
  settings +='menubar='+menu+',';
  settings +='toolbar='+tool+',';
  settings +='titlebar='+tbar+',';
  settings +='resizable='+resize;
  
  myPopup = window.open(file_id,PopUp,settings);
    if (!myPopup.opener)
         myPopup.opener = self; 
}

function PopupEvent(file_id)
{
  var h = 400;
  var w = 400;
  var sb = 'Yes';
  var rs = 'Yes';
  var mb = 'Yes';
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  
  settings = 'height='+h+',';
  settings += 'width='+w+',';
  settings +='top='+wint+',';
  settings +='left='+winl+',';
  settings +='scrollbars='+sb+',';
  settings +='menubar='+mb+',';
  settings +='resizable='+rs;
    
  finish = window.open(file_id,"",settings);
}

function confirm_delete(url)
{
	var message = 'Are you sure you want to delete this item'; 
	if(confirm(message)) location.href = url;
}

function jJumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function populate_selectmenu(current,optionid,data,values)
{	
	var dataarray = data.split(',');
	var valuearray = values.split(',');
	var element = document.getElementById(optionid);
	dataarray[current.selectedIndex] = dataarray[current.selectedIndex].split('|');
	valuearray[current.selectedIndex] = valuearray[current.selectedIndex].split('|');
	for (count = 0; count < element.options.length;count++) element.remove(count);
	element.options[0] = new Option("","",false,false);
	for (count = 0; count < dataarray[current.selectedIndex].length;count++) element.options[count+1] = new Option(dataarray[current.selectedIndex][count],valuearray[current.selectedIndex][count],false,false);
}

// function loadContent added by Mathew Carter on Friday, 4th August 2006
function loadContent(file)
{
  var head = document.getElementsByTagName('head').item(0)
  var scriptTag = document.getElementById('loadScript');
  if(scriptTag) head.removeChild(scriptTag);
  script = document.createElement('script');
  script.src = file;
	script.type = 'text/javascript';
	script.id = 'loadScript';
	head.appendChild(script)
}
function changeImage(filename)
{
	document.mainimage.src = filename;
}
function checkAll(box)
{
	var i = 0, el, f = box.form, bWhich = box.checked;
	while (el = f.elements[i++])
		if (box != el && /^remove/.test(el.name))
			el.checked = bWhich;
}
function toggledisplay(hiddenid,plusid)
{
	var element = document.getElementById(hiddenid);
	if (element.style.display == 'none') 
	{
		element.style.display = '';
		if (plusid != '') plusid.innerHTML = '-';
	}
	else 
	{
		element.style.display = 'none';
		if (plusid != '') plusid.innerHTML = '+';
	}
}

/* 
	disable a form (eg. on submit)
	sets all inputs to readonly and submits to disabled
*/
function disableForm (form)
{
	var f = document.getElementById(form);
	for (var i=0; i<f.length; i++)
	{
		if (f.elements[i].type == "input")
		{
			f.elements[i].readOnly = true;
			f.elements[i].style.backgroundColor = "#cccccc";
		}
		if (f.elements[i].type == "submit")
		{
			f.elements[i].disabled = true;
		}
	}
}
function add_smily(sender)
{
	var smile = sender.getAttribute("alt") ;
	$("txt").value += smile ;
	
}
function valid_guestbook(sender)
{
	var errors = "" ;
	if($("name").value == "") errors += " - Your name is blank\n" ;
	if($("country_id").value == "") errors += " - You must select your country\n" ;
	if($("email").value == "" || $("email").value.indexOf("@") == -1 || $("email").value.indexOf(" ") > -1) errors += " - You must have a email address\n" ;
	if($("txt").value == "") errors += " - You must have a message\n" ;
	if(errors != "") 
	{
		alert("Some errors have occurred:\n" + errors) ;
		return false ;
	}
}
function valid_accommodation_enquiry(sender)
{
	var errors = "" ;
	//alert($("accommodation_name").value + $("ac_id").value);
	//return false;
	
	if($("name").value == "") errors += " - Your name is blank\n" ;
	if($("email").value == "" || $("email").value.indexOf("@") == -1 || $("email").value.indexOf(" ") > -1) errors += " - You must have a email address\n" ;
	if($("message").value == "") errors += " - You must have a message\n" ;
	if(errors != "") 
	{
		alert("Some errors have occurred:\n" + errors) ;
		return false ;
	}
}
function valid_enquiry(sender)
{
	var errors = "" ;
	if($("first_name").value == "") errors += " - Your first name is blank\n" ;
	if($("last_name").value == "") errors += " - Your last name is blank\n" ;
	if($("email").value == "" || $("email").value.indexOf("@") == -1 || $("email").value.indexOf(" ") > -1) errors += " - You must have a email address\n" ;
	if($("comments").value == "") errors += " - You must have a message\n" ;
	if(errors != "") 
	{
		alert("Some errors have occurred:\n" + errors) ;
		return false ;
	}
}

function load () {
	var text = "2 St Martins Lane, <br />Airlie Beach 4802";
	
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		
		map.addControl(new GMapTypeControl());
		//map.addControl(new GSmallZoomControl());
		map.addControl(new GLargeMapControl());
		geocoder = new GClientGeocoder();  
		// -20.274562, 148.704197
		//alert(point.lat() + ", " + point.lng());
		var point = new GLatLng(-20.274562, 148.704197);
		map.setCenter(point, 16);
		//map.setCenter(point, 12, G_SATELLITE_MAP);
		var marker = new GMarker(point);
		map.addOverlay(marker);
		marker.openInfoWindowHtml(text);
		GEvent.addListener(marker, "click", function() 
		{
			marker.openInfoWindowHtml(text);
		});
	}
}
function detectBrowser()
{
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	
	return browser;
}

