var currNav = ''; // Set current nav id

// Replace a text field with a value
function replaceValue(target, defaultText, newValue)
{
	if (target.value == defaultText) target.value = newValue;
}

// Set top and sometimes left nav
function setNav(topNav)
{
	if (topNav != undefined) {
		if (document.getElementById(topNav)) {
			document.getElementById(topNav).className = 'selected';
		}	
	}
}


// Everybody's friend, the Dreamweaver Image Preloader
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];}}
}

// Popup window - give me the url, width, and height, and I'll give you a popup
function popUp(url, x, y)
{
	if (isIE() == true)
	{
		y += 40;
	}
    var args = "width=" + x + ",height=" + y;
    var date = new Date();
    var now = date.getTime();
    var newName = (now).toString(10);

    window.open(url,newName,args);
}


/*** Form checking functions ***/
function checkField (val, field)
{
    var error = "";
    if (val == "")
    {
      error = "You must enter a value in the " + field + " field.\n";
    }
    return error;
}
function checkEmail(val, field)
{
    var error = "";
    if ((val == "" || val.length < 3) ||
        (val.indexOf("@") == "-1") ||
        (val.indexOf(".") == "-1"))
    {
        error = "Please enter a valid " + field + " address.\n";
    }

    return error;
}

// For popup thing
function isIE()
{
	//Detect IE5.5+
	version=0;
	if (navigator.appVersion.indexOf("MSIE")!=-1) {
		temp=navigator.appVersion.split("MSIE");
		version=parseFloat(temp[1]);
	}
	if (version >= 5.5)
	{ //NON IE browser will return 0
		return true;
	} else {
		return false;
	}	
}

function showDiv(target)
{
	document.getElementById(target).style.display = 'block';
}
function hideDiv(target)
{
	document.getElementById(target).style.display = 'none';
}



/*** Property functions ***/
function loadGoogleSideMap()
{
  if (GBrowserIsCompatible())
  {
    var lat = 32.7127666224112;
    var lon = -117.164906414709;
    map = new GMap2(document.getElementById("sidemap"));
    
    var topRight = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0,30));

    map.setCenter(new GLatLng(lat, lon), 16);
    var marker = new GMarker(map.getCenter());
    map.addOverlay(marker);
  }
}

function offsetAgentInfo() {
  var table_unfurnished = document.getElementById('table_unfurnished');
  var agent_info = document.getElementById('agent_furnished');
  var offset = table_unfurnished.clientHeight + "px";
  agent_info.style.setProperty('margin-top', offset, null);
}

function switchMonth(month,year,url)
{
	$.post(url, { month: month, year: year },
    function(data){
     renderCalendar(data, true);
   });
}

function renderCalendar(content, success)
{
	$("#reservationCalendar").fadeOut(1, function() {
		if (success == true)
			$("#reservationCalendar").html(content).fadeIn(1);
	    else
		  	$("#reservationCalendar").html('oops').fadeIn(1);
	});
}

/*** Blasted IE 6 PNG transparency support ***/
// Copyright 2001, Aaron Boodman
// This code is public domain. Please use it for good, not evil.

if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	//document.writeln('<style type="text/css">img { visibility:hidden; } </style>');
	window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			var src = img.src;
			var div = document.createElement("DIV");
			div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')"
			div.style.width = img.width + "px";
			div.style.height = img.height + "px";
			img.replaceNode(div);
		}
		img.style.visibility = "visible";
	}
}