var isCSS, isW3C, isIE4, isNN4, isIE6CSS, isSafari; 
function initDHTMLAPI() {
	//alert("Calling initDHTMLAPI");
	if (document.images) {
		isCSS=(document.body && document.body.style) ? true : false;
		isW3C=(isCSS && document.getElementById) ? true : false;
		isIE4=(isCSS && document.all) ? true : false;
		isNN4=(document.layers) ? true : false;
		isIE6CSS=(document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
		isSafari=(navigator.userAgent.indexOf("Safari") != -1);
		
	}
	//alert('isCSS='+isCSS+', isSafari='+isSafari);
}
function getInsideWindowWidth() {
	//alert("Calling getInsideWindowWidth");
	if (window.innerWidth) return window.innerWidth;
	else if (isIE6CSS) return document.body.parentElement.clientWidth;
	else if (document.body && document.body.clientWidth) return document.body.clientWidth;
	return 0;

}
function getInsideWindowHeight() {
	//alert("Calling getInsideWindowHeight");
	if (window.innerHeight) return window.innerHeight;
	else if (isIE6CSS) return document.body.parentElement.clientHeight;
	else if (document.body && document.body.clientHeight) return document.body.clientHeight;
	return 0;

}
function getRawObject(obj) {
	var theObj;
	if (typeof obj == "string") {
	   if (isW3C) theObj=document.getElementById(obj);
	   else if (isIE4) theObj=document.all(obj);
	   else if (isNN4) theObj=seekLayer(document, obj);
	} else theObj=obj; // pass through object reference
	return theObj;
}
function getObject(obj) {
	var theObj=getRawObject(obj);
	if (theObj && isCSS) theObj=theObj.style;
	return theObj;
}
function getObjectWidth(obj)  {
	var elem=getRawObject(obj);
	var result=0;
	if (elem.offsetWidth) result=elem.offsetWidth;
	else if (elem.clip && elem.clip.width) result=elem.clip.width;
	else if (elem.style && elem.style.pixelWidth) result=elem.style.pixelWidth;
	return parseInt(result);
}
function getObjectHeight(obj)  {
	var elem=getRawObject(obj);
	var result=0;
	if (elem.offsetHeight) result=elem.offsetHeight;
	else if (elem.clip && elem.clip.height) result=elem.clip.height;
	else if (elem.style && elem.style.pixelHeight) result=elem.style.pixelHeight;
	return parseInt(result);
}
function windowlayout() {

	//alert("Calling window layout manager");

	// First calculate the window area for width and height
	pagewidth=getInsideWindowWidth();
	//alert(pagewidth);
	hmid=Math.round(pagewidth/2);
	//alert(hmid);
	pageheight=getInsideWindowHeight();
	//alert(pageheight);
	
	// Then set each piece of the display in position
	
	// This is the entire content area, including ALL items on the page
	// The entire content element is centered on pageload
	// Need to make an allowance for Firefox at some point for small monitors, because of FF's left margin bug
	left=hmid-(Math.round(780/2));
	document.getElementById("wrapit").style.left=left+"px";
	document.getElementById("wrapit").style.top="70px";
	
	// Put the color portion of the leftbar and the top footer bar in the right places
	showlayout();
	adjustlayout();
	
}

function adjustlayout() {
	var knowreturn=getObjectHeight("howlongtothepointofknowreturn");
	//alert("knowreturn="+knowreturn);
	var testsong=document.getElementById("songforamerica");
	if (testsong != null) {
		var song=getObjectHeight("songforamerica");
		//alert("song="+song);
	}
	var bounce=32;
	if (isIE6CSS) bounce=33;
	else bounce=34;
	
	if ( ((song+125) > knowreturn) || ((song+125) == knowreturn) ) {
		//alert ("song > knowreturn");
		document.getElementById("howlongtothepointofknowreturn").style.height=song+125+36+'px';
		document.getElementById("leftbar").style.height=song+125+36+'px';
		document.getElementById("leftbar").style.top=36+'px';
		document.getElementById("footbar").style.top=(song+bounce+125+36)+'px';
		document.getElementById("forceit").style.top=(song+bounce+12+125+36)+'px';
	} else {
		document.getElementById("leftbar").style.height=knowreturn+'px';
		document.getElementById("leftbar").style.top=36+'px';
		document.getElementById("footbar").style.top=(knowreturn+bounce)+'px';
		document.getElementById("forceit").style.top=(knowreturn+bounce+12)+'px';
	}
	document.getElementById("footbar").style.zIndex=25;
}

function showlayout() {
	document.getElementById("wrapit").style.visibility="visible";
}

function r(i,s) {
	if (s) document.getElementById(i).src='images/ROLL/'+i+'_ON.jpg';
	else document.getElementById(i).src='images/ROLL/'+i+'_OFF.jpg';
}

function rollwhite(l,s) {
	if (s) {
		document.getElementById(l).style.color='white';
		document.getElementById(l).style.textDecoration='underline';
	} else {
		document.getElementById(l).style.color='black';
		document.getElementById(l).style.textDecoration='none';
	}
}

function correctXP(l,s) {
	if (s) {
		document.getElementById(l).style.color='#990000';
		document.getElementById(l).style.textDecoration='underline';
	} else {
		document.getElementById(l).style.color='#666600';
		document.getElementById(l).style.textDecoration='none';
	}
}

function cancelorder(o) {
	//alert("Cancel order "+o);
	var proceed=confirm("Do you really want to cancel this order?");
	if (proceed) {
		document.getElementById('cancel_submit').submit();
	}
}

// menu print pop-up window
function menu_print(v) {
	window.open(v,"","top=20,left=20,width=640,height=640,scrollbars=yes,status=no,resizable=yes,menubar=no");
	return;
}

// date validation
function validateDate(fld) {
	var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
	var errorMessage = 'Please enter valid date as month, day, and four digit year. You may use a slash, hyphen or period to separate the values.';
	if ((fld.value.match(RegExPattern)) && (fld.value!='')) {
		// alert('Date is OK'); 
	} else {
		alert(errorMessage);
		fld.focus();
	} 
}

// hide and show div
function switchMenu(obj) {
	//alert("Calling switchMenu "+ obj);
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}
