var isOpen="0"
function preLoad() {
	reBox();
	window.onresize = reBox;
}
function reBox() {
	var TheCheat = document.getElementById('theFrame');
	var theBG = document.getElementById('theBG');
	var RealSizeH = TheCheat.offsetHeight;
	var RealSizeW = TheCheat.offsetWidth;
	var TheMiddle = Math.round((RealSizeW / 2)-1.4);
	var theBG_W = 2700;
	var theBG_H = 1610;  // 1.677
	var bgRatio = theBG_W / theBG_H;
	//if (RealSizeH < 780) { RealSizeH = 780; }
	//document.getElementById('theBGDiv').style.height: RealSizeH+'px';
	var daRatio = RealSizeW / RealSizeH;
	if (bgRatio >= daRatio) {
		theBG.style.width = RealSizeH * bgRatio +"px";
		theBG.style.height = RealSizeH+"px";
	} else {
		theBG.style.width = RealSizeW+"px";
		theBG.style.height = RealSizeW / bgRatio +"px";
	} // document.getElementById('navItemA').innerHTML= bgRatio +" >= "+ daRatio;
	document.getElementById('theGrad').style.width = RealSizeW - 400+"px";
	document.getElementById('theSite').style.width = RealSizeW - 520+"px";
	//document.getElementById('theSite').style.height = RealSizeH - 95+"px";
}
function showSub(num) {
	document.getElementById('navSub'+num).style.visibility = "visible";
}
function hideSub(num) {
	document.getElementById('navSub'+num).style.visibility = "hidden";
}
function openSub(num) { 
	if (isOpen != num) { 
		if (isOpen != 0) { doHeightChange(document.getElementById('contBox'+isOpen),document.getElementById('contBox'+isOpen).offsetHeight,1,30,1,1); }
		doHeightChange(document.getElementById('contBox'+num),document.getElementById('contBox'+num).offsetHeight,430,30,1,1);
		isOpen = num;
	} else { 
		doHeightChange(document.getElementById('contBox'+num),document.getElementById('contBox'+num).offsetHeight,1,30,1,1);
		isOpen = 0;
	}
}
function doAlphaChange(elem,startAlpha,endAlpha,steps,intervals,powr) {
	if (elem.alphaChangeInt) window.clearInterval(elem.alphaChangeInt);
	var actStep = 0;
	elem.alphaChangeInt = window.setInterval(
		function() {
			elem.currentAlpha = easeInOut(startAlpha,endAlpha,steps,actStep,powr);
			elem.style.filter = "alpha(opacity="+elem.currentAlpha+")";
			elem.style.KHTMLOpacity = elem.currentAlpha/100;
			elem.style.MozOpacity = elem.currentAlpha/100;
			elem.style.opacity = elem.currentAlpha/100;
			//elem.style.alpha = elem.currentAlpha+"px";
			actStep++;
			if (actStep > steps) { window.clearInterval(elem.alphaChangeInt); reBox();}
		},intervals)
}
function doHeightChange(elem,startHeight,endHeight,steps,intervals,powr) {
	if (elem.heightChangeInt) window.clearInterval(elem.heightChangeInt);
	var actStep = 0;
	elem.heightChangeInt = window.setInterval(
		function() {
			elem.currentHeight = easeInOut(startHeight,endHeight,steps,actStep,powr);
			elem.style.height = elem.currentHeight+"px";
			actStep++;
			if (actStep > steps) { window.clearInterval(elem.heightChangeInt); /* alert('done');  reBox(); */ }
		},intervals)
}
function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) {
	var delta = maxValue - minValue;
	var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	return Math.ceil(stepp)
}

// check that AJAX is possible and define an AJAX object. 
function GetXmlHttpObject() {
	var MyAjax=null;
	try {
  		// Firefox, Opera 8.0+, Safari
  		MyAjax=new XMLHttpRequest();
  	}
	catch (e) {
  		// Internet Explorer
  		try { MyAjax=new ActiveXObject("Msxml2.XMLHTTP"); }
  		catch (e) { MyAjax=new ActiveXObject("Microsoft.XMLHTTP"); }
  	}
	return MyAjax;
} 


/*******************************************
Script used to display current date.
********************************************/
function addToArray(ar, str) {
	var l
	l = ar[0] + 1
	ar[l] = str
	ar[0] = l
}
function makeArray() {
	array = new Object();
	array[0] = 0;
	return array;
}
var dayNames = makeArray()
addToArray(dayNames, " Sun")
addToArray(dayNames, " Mon")
addToArray(dayNames, " Tue")
addToArray(dayNames, " Wed")
addToArray(dayNames, " Thu")
addToArray(dayNames, " Fri")
addToArray(dayNames, " Sat")

function ShowDay() {
	var ryear = document.r.ResYear.selectedIndex;
	if(ryear < 0)
		ryear= 0;
	ryear= document.r.ResYear.options[ryear].value - 0;
	var rmonth = document.r.ResMonth.selectedIndex;
	var rdate = document.r.ResDate.selectedIndex + 1;
	var rnow = new Date(ryear,rmonth,rdate);
	var now = new Date();

	var rday = rnow.getDay() + 1;
	document.r.dayweek.value = dayNames[rday]
}

function setmyDate() {			
	var now = new Date();
	var closestTime = (now.getTime() + (30 * 60000));
	var nearest = new Date(closestTime)
	var nearmonth = nearest.getMonth();
	var neardate = nearest.getDate();
	var nearyear = nearest.getFullYear();
	
	document.r.ResMonth.selectedIndex = nearmonth
	document.r.ResDate.selectedIndex = neardate - 1
	document.r.ResYear.selectedIndex = nearyear-2005;
}	


//----------------------------------------------
// FORM VALIDATION - IntelligentLiveForms (ILF) v1.0 by rudy@digifx.tv
// vType Legend (validationType~MinChars~maxChars~mustMatchID
// IF you use this script, please leave my credit intact. 
//----------------------------------------------
function mustMatch(me,you){
	if (me.value != document.getElementById(you).value){
	me.value="";
	borderThis(me,1);
	borderThis(document.getElementById(you),1);
	document.getElementById(you).value="";
	document.getElementById(you).focus();
	}

}
function borderThis(theObj,mode){
	if (mode == 0) { 
		theObj.style.border = "1px #000000 solid";
	//	theObj.style.background = "#FFFFFF";
	} else if (mode == 1){ 
		theObj.style.border = "1px #ff0033 solid";
	//	theObj.style.background = "#fee9e9";
	} else if (mode == 2){ 
		theObj.style.border = "1px #33cc33 solid";
	//	theObj.style.background = "#eeffd9";
		//theObj.style.background = "#eeffd9";
		//setTimeout("theObj.style.background = '#FFFFFF'",2000);
	} //repeat as required.
	
}
function getIndex(theObj) {
	var index = -1, i = 0, found = false;
	while (i < theObj.form.length && index == -1) {
		if (theObj.form[i] == theObj) { index = i; } else { i++; }
	}
	return index;
}
function checkField(theObj) {
	document.getElementById('myspan').innerHTML = "";
//	var reAlpha = /!|@|#|\$|%|`|~|\^|&|\*|\(|\)|_|\-|=|\+|'|"|:|;|\]|\[|\{|\}|,|<|\.|>|\\|\?|\||\/|\d/;  // my regular expression - in the works.     reAlpha.exec(elemVal)
//	var reNumba = /!|@|#|\$|%|`|~|\^|&|\*|\(|\)|_|\-|=|\+|'|"|:|;|\]|\[|\{|\}|,|<|\.|>|\\|\?|\||\/|\D/
//	var reEmail = /!|#|\$|%|`|~|\^|&|\*|\(|\)|_|\-|=|\+|'|"|:|;|\]|\[|\{|\}|,|<|>|\\|\?|\||\//; // same as Alpha but . @ and numbers are permitted
	var reAlpha = /[^A-Za-z]/;
	var reEmail = /[^A-Za-z@._0-9\-]/;
	var reNumba = /[^0-9]/;
	var reAlphaNum = /[^A-Za-z0-9]/;
	var reAlphaNumS = /[^A-Za-z\ 0-9]/;
	var rePostalA = /[^A-Za-z]/;
	var rePostal1 = /[^0-9]/;
	//var reSelect = /[^A-Za-z0-9 ]/;	
	var preChkStr = theObj.className.split(" ");
	var chkStr = preChkStr[1].split("~"); 	
	var elemVal = theObj.value;
	var q = 0, f = 0;
	if(elemVal.length >= chkStr[2]) { theObj.value = elemVal.slice(0, chkStr[2]); theObj.form[(getIndex(theObj)+1) % theObj.form.length].focus(); } // TOO LONG
	if (elemVal.length < chkStr[1]){ borderThis(theObj,1);  q=q+1;} // TOO SHORT 
	if (chkStr[0] == 'numba') { if ( reNumba.exec(elemVal) != null) { theObj.value = elemVal.slice(0, elemVal.indexOf(reNumba.exec(elemVal))); q=q+1;}
	} else if (chkStr[0] == 'email') { 
			if ( reEmail.exec(elemVal) != null) { theObj.value = elemVal.slice(0, elemVal.indexOf(reEmail.exec(elemVal))); q=q+1;}
			if ((elemVal.indexOf('.') == -1) || (elemVal.indexOf('@') == -1)) { q=q+1;
			} else if (elemVal.split("@").length > 2){ theObj.value = elemVal.slice(0, elemVal.indexOf("@")); q=q+1;
			} else { if (elemVal.split("@").length == 2) { tVarA=elemVal.split("@");
							if (tVarA[1].split(".").length != -1) { tVarB=tVarA[1].split(".");
								if ((tVarB[1].length < 2) || (tVarB[1].length > 6)) { q=q+1; }
							} else { q=q+1;}
					} else { q=q+1;}
			}
	} else if (chkStr[0] == 'alpha') { if ( reAlpha.exec(elemVal) != null) { theObj.value = elemVal.slice(0, elemVal.indexOf(reAlpha.exec(elemVal))); q=q+1;}
	} else if (chkStr[0] == 'alphaNum') { if ( reAlphaNum.exec(elemVal) != null) { theObj.value = elemVal.slice(0, elemVal.indexOf(reAlphaNum.exec(elemVal))); q=q+1;}
	} else if (chkStr[0] == 'alphaNumS') { if ( reAlphaNumS.exec(elemVal) != null) { theObj.value = elemVal.slice(0, elemVal.indexOf(reAlphaNumS.exec(elemVal))); q=q+1;}
	} else if (chkStr[0] == 'postalA') { if (elemVal.split("").length == 3) { tVarA=elemVal.split(""); if ( rePostalA.exec(tVarA[0])+rePostal1.exec(tVarA[1])+rePostalA.exec(tVarA[2]) != 0){q=q+1;}}
	} else if (chkStr[0] == 'postalB') { if (elemVal.split("").length == 3) { tVarA=elemVal.split(""); if ( rePostal1.exec(tVarA[0])+rePostalA.exec(tVarA[1])+rePostal1.exec(tVarA[2]) != 0){q=q+1;}}
	} else if (chkStr[0] == 'select') { /* if ( reSelect.exec(elemVal) != null) { theObj.value = elemVal.slice(0, elemVal.indexOf(reSelect.exec(elemVal))); q=q+1;} */
	} else { // borderThis(theObj,0); alert("did nothing");		alert("q="+q+"f="+f+"objName="+theObj.id);
	} 
	if (q > 0){ borderThis(theObj,1); if (f < 0){ alert("f was 0");	document.getElementById(theObjid).focus(); f=1;} return 'no'; } else { borderThis(theObj,2); return 'ok';}
}
function formCheck(obj,goesTo,showsIn) {
	var getstr = "";
	var myOkStr = "";
	for (i=0; i<obj.form.length; i++) {
		if (obj.form[i].tagName == "INPUT") {
			if (obj.form[i].type == "text") {  //ok
				myOkStr = myOkStr+checkField(obj.form[i])+",";
				getstr += obj.form[i].id + "=" + obj.form[i].value + "&";
			}	
			if (obj.form[i].type == "password") { //ok
				myOkStr = myOkStr+checkField(obj.form[i])+",";
				getstr += obj.form[i].id + "=" + obj.form[i].value + "&";
			}			
			if (obj.form[i].type == "checkbox") {
				if (obj.form[i].checked) {
					getstr += obj.form[i].id + "=" + obj.form[i].value + "&";
				} else {
					getstr += obj.form[i].id + "=&"; // could possibly omit`
				}
			}
			if (obj.form[i].type == "radio") {
				if (obj.form[i].checked) {
					getstr += obj.form[i].id + "=" + obj.form[i].value + "&";
				}
			}
		}  
		if (obj.form[i].tagName == "SELECT") {
			myOkStr = myOkStr+checkField(obj.form[i])+",";
			var sel = obj.form[i];
			getstr += sel.id + "=" + sel.options[sel.selectedIndex].value + "&";
		}   
		if (obj.form[i].tagName == "textarea") {
			myOkStr = myOkStr+checkField(obj.form[i])+",";
			getstr += obj.form[i].id + "=" + obj.form[i].value + "&";
		}         
	}     
	// alert(chkStr); 	
	// alert(myOkStr);
	// alert(getstr);
	if (myOkStr.indexOf('no') == -1){ // postRequest(goesTo, getstr); 
		if (showsIn == '_top') { // document.getElementById('myspan').innerHTML = getstr;
			return true;
		} else { getData(goesTo, showsIn, getstr); } // this calls the form submission method  alert('ok');
			return false
	} else {
		document.getElementById('myspan').innerHTML = "An error occured with your request. Please ensure that no fields are highlighted red"; //document.getElementById('myspan').innerHTML + 
		reBox();
		return false
	}
		return false
}

var formJax
   function getData(goesTo, showsIn, postStr) {
 		formJax=GetXmlHttpObject();
		var postStr  = postStr+"randy="+Math.random();
		// alert("going to send:"+postStr+" to "+goesTo);
		formJax.open("POST",goesTo,true);
		formJax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		formJax.onreadystatechange = function() {
			if (formJax.readyState == 4 && formJax.status == 200) { //	alert("i changed state");
			// document.getElementById(showsIn).innerHTML = formJax.responseText;
				if (formJax.responseText.indexOf('<!-- ok -->') != -1){  document.getElementById(showsIn).innerHTML = formJax.responseText; 
				} else { document.getElementById('myspan').innerHTML = formJax.responseText;
				} reBox();
			} else if( formJax.readyState == 4 && formJax.status != 200){
			alert(formJax.responseText);
				document.getElementById('myspan').innerHTML = "an internal error has occured, please retry your request.<br>If this problem persists, please contact a system administrator."; 
				// formJax.responseText;
			}
         }
       formJax.send(postStr);
     }  
// ###############################
// E-Commerce functions
// ###############################
function doShipInfo() {  
	if (document.getElementById('shipInfo').offsetHeight == '0') { 
		document.getElementById('shipInfo').style.height = '200px';
	} else {
		document.getElementById('shipInfo').style.height = '0px';
	}
}
function doOAmt() {  
	if (document.getElementById('truAmt').style.visibility == 'hidden') { 
		document.getElementById('truAmt').style.visibility = 'visible';
		document.getElementById('50box').style.height = '0px';
		document.getElementById('100box').style.height = '0px';
		document.getElementById('150box').style.height = '0px';
		document.getElementById('200box').style.height = '0px';
	} else {
		document.getElementById('truAmt').style.visibility = 'hidden';
		document.getElementById('50box').style.height = '20px';
		document.getElementById('100box').style.height = '20px';
		document.getElementById('150box').style.height = '20px';
		document.getElementById('200box').style.height = '20px';
		
	}
}
function doAmt(value) {  
	document.getElementById('theOAmt').value = value+".00";
}
