/**
 * Generic Site Functions
 */

/* Used on Nav */
 sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/* Used in /contact/ */
function HearAboutUs_Change(block){
	if (document.getElementById("hearaboutus"+block+"").value==""){document.getElementById("block"+block+"").style.display="none";}
	if (document.getElementById("hearaboutus"+block+"").value=="Advertisement"){document.getElementById("block"+block+"").style.display="block";}
	if (document.getElementById("hearaboutus"+block+"").value=="Media Coverage"){document.getElementById("block"+block+"").style.display="block";}
	if (document.getElementById("hearaboutus"+block+"").value=="Previous Client"){document.getElementById("block"+block+"").style.display="block";}
	if (document.getElementById("hearaboutus"+block+"").value=="Search Engine"){document.getElementById("block"+block+"").style.display="block";}	
	if (document.getElementById("hearaboutus"+block+"").value=="Reference"){document.getElementById("block"+block+"").style.display="block";}
	if (document.getElementById("hearaboutus"+block+"").value=="Speaking Event"){document.getElementById("block"+block+"").style.display="block";}
	if (document.getElementById("hearaboutus"+block+"").value=="Other..."){document.getElementById("block"+block+"").style.display="block";}	
}

function countryUpdate(country, block) {
	if(country.value == "United States" || country.value == "Canada") {
		document.getElementById(""+block+"").style.visibility = "visible";
	}else{
		document.getElementById(""+block+"").style.visibility = "hidden";
	}

}

/* Used throughout the reservation side */
	function updateDaysInMonth( type ){
		var day = document.getElementById( 'f_day_' + type );
		var lastDay = day.value;
		var month = document.getElementById( 'f_mo_' + type ).value;
		var year = document.getElementById( 'f_yr_' + type ).value;
		day.options.length = 0;
		var numOfDays = daysInMonth( year,(month-1) );
		for(var i=1; i<=numOfDays; i++){
			if( i<=9 ) i="0"+i;
			day.options[i] = new Option(i,i);			
		}
		day.options[0]=null; // removes the empty option
		if( (lastDay-1)>numOfDays ) lastDay = numOfDays-1;
		day.options[(lastDay-1)].selected = true; // sets the day to the last date
	}
	
	function daysInMonth ( year,month ) {
		return 32 - new Date(year, month, 32).getDate();
	}
	
	function switchBG(type) {
		reservecont = document.getElementById("reservecont");
		if(type.value == "1") {
			reservecont.className = "left standard";
		}else if(type.value == "2") {
			reservecont.className = "left king";
		}else if(type.value == "3") {
			reservecont.className = "left corner";
		}else{
			reservecont.className = "left standard";
		}
	}
	function checkRes(element) {
		if(element.name == "checkin_day") {  // Checks for Check-in Day
			if(element.value < 9) {
				document.getElementById("f_day_co").value = ('0' + ((element.value*1) + 1));
			}/*else if(element.value > 9 && element.value < 31) {
				document.getElementById("f_day_co").value = ((element.value*1) + 1);
			}else if(element.value == 31) {
				document.getElementById("f_day_co").value = '01';
				document.getElementById("f_mo_co").value = ('0' + ((document.getElementById("f_mo_co").value*1) + 1))
			}*/
		}
		
		if(element == "submit") { // Form is submitting, let's check values
			now = new Date;
			var makeRes = true;
			var month = now.getMonth() + 1;
			var year = now.getFullYear();
			var day = now.getDate();
			var theform = document.getElementById("reserve_form");
			var checkin_mo = document.getElementById("f_mo_ci").value;
			var checkin_day = document.getElementById("f_day_ci").value;
			var checkin_yr = document.getElementById("f_yr_ci").value;
			var checkout_mo = document.getElementById("f_mo_co").value;
			var checkout_day = document.getElementById("f_day_co").value;
			var checkout_yr = document.getElementById("f_yr_co").value;
			
			if(checkin_yr > checkout_yr) {		
				alert('Check-In year cannot be later than Check-Out year');
				makeRes = false;
				return false;
			}else if(checkin_yr == checkout_yr && checkin_mo > checkout_mo) {
				alert('Check-In month cannot be after Check-Out month within same year');
				makeRes = false;
				return false;
			}else if(checkin_mo < month && checkin_yr == year) {
				alert('Check-In month cannot be before current month of this year');
				makeRes = false;
				return false;
			}else if(checkin_day < day && checkin_mo == month && checkin_yr == year) {
				alert('Check-In day cannot be before current day of this month/year');
				makeRes = false;
				return false;
			}
		}
		if( makeRes ) theform.submit();
	
	}

	
/* Used in multiple areas to show/hide divs */
var listx = new Array();

function hidediv(pass) {
	var divs = document.getElementsByTagName('div');
	for(i = 0; i < divs.length; i++) {
		if(document.getElementById("cont"+pass+"")) document.getElementById("cont"+pass+"").className = "cont";
		//if(document.getElementById("anch"+pass+"")) document.getElementById("anch"+pass+"").innerHTML = "<img src=\"/images/ico_plus.gif\" alt=\"[+]\" /> show me more";
		if(document.getElementById("anch"+pass+"")) document.getElementById("anch"+pass+"").style.visibility = "visible";
		if(document.getElementById("logo"+pass+"")) document.getElementById("logo"+pass+"").style.visibility = "hidden";
		if(document.getElementById("txt_title")) document.getElementById("txt_title").style.visibility = "hidden";
		if(document.getElementById("GMapEZ")) document.getElementById("GMapEZ").style.visibility = "visible";
		if(document.getElementById("kidsblock")) document.getElementById("kidsblock").style.visibility = "hidden";
		if(document.getElementById("Extra_Details")) document.getElementById("Extra_Details").style.visibility = "hidden";
		if (divs[i].id == (pass)) {
			if (document.getElementById) // DOM3 = IE5, NS6
				divs[i].style.display = 'none';
			else {
				if (document.layers) {
					document.layers[divs[i]].display = 'none';
					document.layers[divs[i]].position = 'absolute';
				}
				else {
					document.all.hideShow.divs[i].visibility = 'none';
					document.all.hideShow.divs[i].position = 'absolute';
				}
			}
		}
	}
	
	listx[pass] = "hidden";
}
function showdiv(pass) {
	if (listx[pass] == "shown") hidediv(pass);
	else {
		var divs = document.getElementsByTagName('div');
		if(document.getElementById("cont"+pass+"")) document.getElementById("cont"+pass+"").className = "cont g";
		//if(document.getElementById("anch"+pass+"")) document.getElementById("anch"+pass+"").innerHTML = "<img src=\"/images/ico_minus.gif\" alt=\"[-]\" /> show me less";
		if(document.getElementById("anch"+pass+"")) document.getElementById("anch"+pass+"").style.visibility = "hidden";
		if(document.getElementById("logo"+pass+"")) document.getElementById("logo"+pass+"").style.visibility = "visible";
		if(document.getElementById("itype1")) document.getElementById("itype1").style.visibility = "visible";
		if(document.getElementById("itype2")) document.getElementById("itype2").style.visibility = "visible";
		if(document.getElementById("txt_title")) document.getElementById("txt_title").style.visibility = "hidden";
		if(document.getElementById("GMapEZ")) document.getElementById("GMapEZ").style.visibility = "hidden";
		if(document.getElementById("recipient")) document.getElementById("recipient").value = '';
		if(document.getElementById("kidsblock")) document.getElementById("kidsblock").style.visibility = "visible";
		if(document.getElementById("Extra_Details")) document.getElementById("Extra_Details").style.visibility = "visible";
for(i = 0; i < divs.length; i++) {
			if (divs[i].id == (pass)) {
				if (document.getElementById) {
					// IE 6+/NN6
					divs[i].style.display = 'block';
				}
				else {
					if (document.layers) {
						//netscape 5
						document.layers[divs[i]].display = 'block';
						document.layers[divs[i]].position = 'relative';
					}
					else {
						// IE 4 and 5 not 5+
						document.all.hideShow.divs[i].visibility = 'block';
						document.all.hideShow.divs[i].position = 'relative';
					}
				}
			}
		}
		listx[pass] = "shown";
	}
}

// Used in Suites /suites/ */
function showLG(img, action, block) {
	if(action == "1") {
		document.getElementById(""+block+"").style.display = "block";
		document.getElementById(""+block+"_img").src = "/images/"+img;
	}else if(action == "2") {
		document.getElementById(""+block+"").style.display = "none";
		document.getElementById(""+block+"_img").src = "";
	}
}
function showTab(data, tab) {
	divs = document.getElementsByTagName("div");
	for (i = 0; i < divs.length; i++) {
		if(divs[i].className == "inner") {
			divs[i].style.display = "none";
		}
		if(divs[i].className == "tab" || divs[i].className == "tab w") {
			divs[i].className = "tab";
		}
	}
	tab.className = "tab w";
	document.getElementById("block"+data+"").style.display = "block";
}

function submitOptions(){
	document.getElementById("reserve_form").action = "/reservations/?o=1";
	document.getElementById("reserve_form").submit();						
}
					
var listx = new Array();
	function hidemenu(pass) {
			divs = document.getElementsByTagName("div");
			anchors = document.getElementsByTagName("a");
			for (i = 0; i < divs.length; i++) {
				
				if(divs[i].id == "cat_cont"+pass) {
					divs[i].className = "cat_cont";
				}
				if(divs[i].id == "sub_block"+pass) {
					divs[i].style.display = "none";
				}
			}

			for (i = 0; i < anchors.length; i++) {
				if(anchors[i].id == "a"+pass) {
					anchors[i].className = "green";
					anchors[i].innerHTML = "<img src=\"/images/ico_plus.gif\" alt=\"[+]\" /> view menu items";
					
				}
			}
		listx[pass] = "hidden";
	}
	function showmenu(pass) {
		if (listx[pass] == "shown") hidemenu(pass);
		else {
			divs = document.getElementsByTagName("div");
			anchors = document.getElementsByTagName("a");
			/*for (i = 0; i < divs.length; i++) {
				if(divs[i].className == "sub_block") {
					divs[i].style.display = "none";
				}
				if(divs[i].className == "cat_cont g") {
					divs[i].className = "cat_cont";
				}
			}
			for (i = 0; i < anchors.length; i++) {
				if(anchors[i].className == "red") {
					anchors[i].className = "green";
					anchors[i].innerHTML = "<img src=\"/images/ico_plus.gif\" alt=\"[+]\" /> view menu items";
				}
			}*/
			document.getElementById("cat_cont"+pass+"").className = "cat_cont g";
			document.getElementById("sub_block"+pass+"").style.display = "block";
			document.getElementById("a"+pass+"").className = "red";
			document.getElementById("a"+pass+"").innerHTML = "<img src=\"/images/ico_minus.gif\" alt=\"[-]\" /> hide menu items";
			listx[pass] = "shown";
		}
	}

// Used in /directions/ 
	function fillDest(block) {
		document.getElementById("directions").Street.value = document.getElementById("address"+block+"").value;
		document.getElementById("directions").City.value = document.getElementById("city"+block+"").value;
		document.getElementById("directions").State.value = document.getElementById("state"+block+"").value;
		document.getElementById("directions").Zip.value = document.getElementById("zip"+block+"").value;
	}

// This is used to embed Flash documents, because Internet Explorer sucks
function embedFlash(src, width, height) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+width+'" height="'+height+'">');
    document.write('<param name="movie" value="/flash/'+src+'" />');
    document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="transparent" />');
    document.write('<embed src="/flash/'+src+'" quality="high" wmode="transparent" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>');
	document.write('</object>');
}

var tls = null;
var inout = -1;

// Used for the faded popup
function popup(src, title, action) {

	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	
	
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	
	

	//var scr_h = screen.availHeight;
	var popup_cont = document.getElementById("popup_cont");
	var popup_form = document.getElementById("popup_form");
	var inner = document.getElementById("innerpop");
	

	popup_cont.style.display = "block";
	popup_cont.style.width = "100%";
	popup_cont.style.height = pageHeight + 'px';
	
	//popup_form.style.marginTop = pageHeight / 4 + 'px';
	popup_form.style.display = "block";
	popup_form.style.top = (yScroll + ((windowHeight - 35 - 550) / 2) + 'px');
	popup_form.style.left = (((pageWidth - 20 - 500) / 2) + 'px');
	
	if(navigator.javaEnabled()) { 
		inner.innerHTML = '<applet code="IpixViewer.class" width="500" height="320" archive="/scripts/ipix/IpixViewer.jar"><param name="URL" value="'+src+'" /><param name="Toolbar" value="small" /><param name="BackgroundColor" value="#ffffff" /><param name="SpinSpeed" value="-6" /><param name="SpinStyle" value="flat" /></applet><div class="title">'+title+'</div><div class="close"><a href="#" onclick="popup(\'\',\'\',\'close\'); return false;" title="Close Window"><img src="/scripts/lightbox/images/closelabel.gif" /></a></div>';
	}else{	
		inner.innerHTML = '<div onclick="popup(\'\'\, \'\', \'close\');" style="font-size: 16px; width: 500px; text-align: center;">Our detection process has discovered that you currently do not have Java enabled or installed on your web browser. <br /><br />Please visit the following link to download it. <br /><br /><a style="font-size: 16px" href="http://www.java.com/en/download/manual.jsp" title="http://www.java.com/en/download/manual.jsp" target="_blank">http://www.java.com/en/download/manual.jsp</a></div><div align="center" onclick="popup(\'\'\, \'\', \'close\');" ><img src="/images/ico_nojava.jpg" alt="NO JAVA"  /></div>';
	}
	
	if(action == 'close') {
		popup_cont.style.display = "none";
		popup_form.style.display = "none";
	}	
}

var mv_nf_pos = 0;
function mv_nf(elm, nxt_id) {
	// Don't allow non numerics
	if (!elm.value.match(/^\d+$/)) { elm.value = elm.value.replace(/[^\d]/g, ""); }
	
	if (nxt_id != null) {
		var nxt_elm = document.getElementById(nxt_id);
	
		switch (mv_nf_pos) {
			case 0:
				if (elm.value.length >= 3) {
					mv_nf_pos++;
					nxt_elm.focus();
				}
				break;
				
			case 1:
				if (elm.value.length >= 3) {
					mv_nf_pos++;
					nxt_elm.focus();
				}
				break;
		}
	}
}

/* Admin Stuff */
function remove(id, method) {
	document.getElementById("hdnID").value = id;
	document.getElementById("hdnAction").value = 'del'+method;
	var path = confirm("Really remove entry? \n(note: Removing categories will remove all entries within)");
	if(path == true) {
		document.adminForm.submit();
	}else{
		return 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;return curtop;}