/**
 * Generic Site Functions
 */

 

/* 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";
	}

}


function formfocus(id) {
	document.getElementById("ContactForm")[id].focus();
	
}


/* 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 (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";
		
		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";
	}
}


					


// 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/refer a friend
function popup(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");


	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 - 500) / 2) + 'px');
	popup_form.style.left = (((pageWidth - 20 - 700) / 2) + 'px');
	
	selects = document.getElementsByTagName("select");
	for (i = 0; i < selects.length; i++) {
			selects[i].style.visibility = "hidden";
	}
	
	popupselects = document.getElementById("popup_form").getElementsByTagName("select");
	for (i = 0; i < popupselects.length; i++) {
			popupselects[i].style.visibility = "visible";
	}
	
	
	if(action == 'close') {
		for (i = 0; i < selects.length; i++) {
			selects[i].style.visibility = "visible";
		}
		popup_cont.style.display = "none";
		popup_form.style.display = "none";
	}	
}

function checkRefer(form) {
	if(!form.ref_Name1.value) {
		alert('Enter your full name.');
		form.ref_Name1.focus();
		return false;
	}else if(!form.ref_Email1.value) {
		alert('Enter your email address.');
		form.ref_Email1.focus();
		return false;
	}else if(!form.ref_Name2.value) {
		alert('Enter your friend\'s full name.');
		form.ref_Name2.focus();
		return false;
	}else if(!form.ref_Email2.value) {
		alert('Enter your friend\'s email address.');
		form.ref_Email2.focus();
		return false;
	}else{
		return true;
	}
	return false;
}


/* 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;}