function SI_positionFooter() {
	//politely borrowed from Shaun Inman (http://www.shauninman.com)
	var d = document,w=window,dE=d.documentElement,dB=d.body;;
	if (!d.getElementById || !d.body.offsetHeight) return;
	
	// Reset our footer's margin-top...
	var footer = d.getElementById('footer');
	var mt = (footer.style.marginTop)?parseInt(footer.style.marginTop):15;
	
	var windowH		= (typeof(w.innerHeight)=='number')?w.innerHeight:(dE&&dE.clientHeight)?dE.clientHeight:(dB&&dB.clientHeight)?dB.clientHeight:0;
	var contentH	= d.getElementById('content').offsetHeight - mt;
	//alert(contentH);
	
	
	var footerMT	= (contentH <= windowH)?windowH-contentH:15;
	
	if (footerMT>15) {
		d.getElementById('footer').style.marginTop = footerMT + 'px';
		
	}
}

function positionBg() {
	//politely borrowed from Shaun Inman (http://www.shauninman.com)
	var d = document,w=window,dE=d.documentElement,dB=d.body;;
	if (!d.getElementById || !d.body.offsetHeight) return;
	
	var windowH		= (typeof(w.innerHeight)=='number')?w.innerHeight:(dE&&dE.clientHeight)?dE.clientHeight:(dB&&dB.clientHeight)?dB.clientHeight:0;
	var contentH	= (d.getElementById('content').offsetHeight > d.getElementById('rightColumn').offsetHeight)?d.getElementById('content').offsetHeight:d.getElementById('rightColumn').offsetHeight;
	//alert('Window: ' + windowH + '\nContent: ' + contentH + '\nSidebar: ' + sidebarH);
	if (d.getElementById('sidebar')) {
		var sidebarH	= d.getElementById('sidebar').scrollHeight + 300;
		if (windowH >= contentH && windowH >= sidebarH) {d.getElementById('container').style.height = windowH - 25 + 'px';}
		else if (windowH < 628 && contentH < 628 && sidebarH < 628) {d.getElementById('container').style.height = '628px';}
		else {
			if (sidebarH > contentH) {
				d.getElementById('container').style.height = sidebarH + 'px';
			}
			else {
				d.getElementById('container').style.height = contentH + 'px';
			}
		}
	}
	else {
		//alert('Window: ' + windowH + '\nContent: ' + contentH + '\nScrollHeight ' + d.body.offsetHeight);
		if (windowH >= contentH && windowH > 628) {d.getElementById('container').style.height = windowH - 25 + 'px';}
		else if (windowH <= 628 && contentH <= 628) {d.getElementById('container').style.height = '650px';}
		else {
				d.getElementById('container').style.height = contentH + 'px';
			}
		}
	}

//function windowLoad(){
//	//removeText(); //removed because of print stylesheet
//	SI_positionFooter();
//	if(document.getElementById('name')){
//		document.getElementById('name').focus();
//	}
//}

function windowLoad(){
	//removeText(); //removed because of print stylesheet
	positionBg();
	if(document.getElementById('name') && document.getElementById('address')){
		document.getElementById('name').focus();
	}
}

function showDiv(divToShow){
	var object = document.getElementById(divToShow);
	object.style.display = 'block';
}

function hideDiv(divToHide){
	//alert(divToHide);
	var object = document.getElementById(divToHide);
	object.style.display = 'none';
}

function moveDiv(divToMove,pixels){
	var object = document.getElementById(divToMove);
	object.style.left = pixels + 'px';
}

function changeClass(divToChange,className){
	//alert(className);
	var object = document.getElementById(divToChange);
	object.className = className;
}

function showFullScreen(){
	if(document.body.className != 'withoutSidebar'){
		hideDiv('sidebar');
	}
	if(document.getElementById('subnav')){
		hideDiv('subnav');
	}
	hideDiv('content_header');
	hideDiv('bodycopy');
	//changeClass('CW_full_screen','CW_full_screen_show');
	SI_positionFooter();
}

function hideFullScreen(){
	if(document.body.className != 'withoutSidebar'){
		showDiv('sidebar');
	}
	if(document.getElementById('subnav')){
		showDiv('subnav');
	}
	showDiv('content_header');
	showDiv('bodycopy');
	//changeClass('CW_full_screen','CW_full_screen_hide');
	SI_positionFooter();
}

function removeText(){
	var d = document;
	var i = 0;
	//if(!d.getElementsByTagName){ return;}
	var h2s = d.getElementsByTagName('h2');
	var h3s = d.getElementsByTagName('h3');
	//sIFR.replaceElement("h2", "/westphal/flash/futuralight.swf", "#353535", null, null, null, 0, 0, 0, 0, null, "lower", null);
	//sIFR.replaceElement("h3", "/westphal/flash/tradegothic.swf", "#909090", null, null, null, 0, 0, 0, 0, null, "upper", null);
	if(typeof sIFR == "function"){
		sIFR.replaceElement("h2", "/westphal/flash/futuralight.swf", "#353535", null, null, null, 0, 0, 0, 0, null, "lower", null);
		sIFR.replaceElement("h3", "/westphal/flash/tradegothic.swf", "#909090", null, null, null, 0, 0, 0, 0, null, "upper", null);
	}
	for(var i=0; i<h2s.length; i++){
		//h2s[i].innerHTML = h2s[i].childNodes[1].innerHTML;
		//h2s[i].childNodes[1].innerHTML= "";
	}
	
	//alert(h2s[0].childNodes[1].innerHTML);
	for(var i=0; i<h3s.length; i++){
		//h3s[i].childNodes[1].innerHTML= "";
	}
	
	//============================= NOTE ==========================
	// printing pages with print.css will not print H2's and H3's
}

function checkForm(){
	var requiredFields, i, status, emailMessage;
	status = "none empty";
	if(document.getElementById('required')){
		requiredFields = document.getElementById('required').value.split(','); //creates an array based on the required fields specified in the "hidden" input value
	}
	
	var itemCount = 0;
	var message = "Please fill in your";
	var emailTest = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	
	//highlighting empty fields
	for(i=0; i<requiredFields.length; i++){
		if(document.getElementById(requiredFields[i]).value == ''){
			status = "something empty";
			if(itemCount == 0){
				message = message + " " + requiredFields[i];
				itemCount++;
			}else{
				message = message + " and " + requiredFields[i];
			}
			highlightField(requiredFields[i]);
		}
	}
	
	//setting focus
	if(itemCount > 0){
		document.getElementById('name').focus();
	}
	
	//unhighlighting
	for(i=0; i<requiredFields.length; i++){
		if(document.getElementById(requiredFields[i]).value != '' && document.getElementById(requiredFields[i]).className == 'required_field'){
			unhighlight(requiredFields[i]);
		}
	}
	
	//conditions specifically for the email field
	if(emailTest.test(document.getElementById('email').value)){
		emailStatus = "valid";
	}else if(!emailTest.test(document.getElementById('email').value) && document.getElementById('email').value != ""){
		emailStatus = "invalid";
	}else if(document.getElementById('email').value == ""){
		emailStatus = "blank";
	}
	
	//alert messages conditions
	if(status == "none empty"){
		if(emailStatus == "invalid"){
			alert("Please enter a valid email address.");
			highlightField('email');
			return false;
		}else if(emailStatus == "valid"){
			return true;
		}
	}else if(status == "something empty"){
		if(emailStatus == "invalid"){
			alert(message + ". Also, please enter a valid email address.");
			highlightField('email');
		}else if(emailStatus == "valid" || emailStatus == "blank"){
			alert(message + ".");
		}
		return false;
	}
}

function emailCheck()
{

	var emailTest = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	if(emailTest.test(document.getElementById('email').value))
		return true;
	else {
		alert("Please enter a valid email address.");
		highlightField('email');
		return false;
	}
	
}

function highlightField(fieldID){
	document.getElementById(fieldID).className = "required_field";
	document.getElementById(fieldID).focus();
}

function unhighlight(fieldID){
	document.getElementById(fieldID).className = "";
}

function rowOver(fid) {
	document.getElementById('f'+fid).className += " rowOver";
}
function rowOut(fid) {
	document.getElementById('f'+fid).className = document.getElementById('f'+fid).className.replace(/ rowOver/, "")
}
function rowClick(fid) {
	window.location="?id="+fid
}


//window.onload = windowLoad;
//window.onresize = SI_positionFooter;

window.onload = windowLoad;
window.onresize = positionBg;