String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
//
var minHeight = 0;
addLoadListener(setupHeights);
//
function retrieveComputedStyle(element, styleProperty)
{
		var computedStyle = null;

		if (typeof element.currentStyle != "undefined")
		{
			computedStyle = element.currentStyle;
		}
		else
		{
			computedStyle = document.defaultView.getComputedStyle(element, null);
		}
		return computedStyle[styleProperty];
}
//
function addLoadListener(fn)
{
	if (typeof window.addEventListener != 'undefined')
	{
	window.addEventListener('load', fn, false);
}
else if (typeof document.addEventListener != 'undefined')
{
	document.addEventListener('load', fn, false);
}
else if (typeof window.attachEvent != 'undefined')
{
	window.attachEvent('onload', fn);
}
else
{
	var oldfn = window.onload;
	if (typeof window.onload != 'function')
	{
	window.onload = fn;
	}
	else
	{
	window.onload = function()
	{
	oldfn();
	fn();
	};
	}
	}
}
//
function setupHeights() {
	minHeight = $("cnt").offsetHeight;
	equalHeight();
}
//
function getWindowHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
   myHeight = document.body.clientHeight;
  }
  return myHeight;
}
//
function equalHeight() {
	var iHeight = getWindowHeight();
	var myLeftColumn = $("cnt");
	var myLeftHeight = myLeftColumn.offsetHeight;
	var myLeftBorderTopPixels = retrieveComputedStyle(myLeftColumn, "borderTopWidth");
	var myLeftBorderBottomPixels = retrieveComputedStyle(myLeftColumn, "borderBottomWidth");
	var myLeftPaddingTopPixels = retrieveComputedStyle(myLeftColumn, "paddingTop");
	var myLeftPaddingBottomPixels = retrieveComputedStyle(myLeftColumn, "paddingBottom");
	var myLeftBorderNumber = Number(myLeftBorderTopPixels.replace("px", "")) + Number(myLeftBorderBottomPixels.replace("px", ""));
	var myLeftPaddingNumber = Number(myLeftPaddingTopPixels.replace("px", "")) + Number(myLeftPaddingBottomPixels.replace("px", ""));
	var myLeftExtras = myLeftBorderNumber + myLeftPaddingNumber;
	if (iHeight > minHeight) {
			$("cnt").style.height = iHeight + "px";
	} else {
			$("cnt").style.height = minHeight + "px";
	}
}
//
function errFunc(t) {
    alert('Error ' + t.status + ' -- ' + t.statusText);
    alert(t.responseText);
}
//
function submitEntry() {
	showSaving();
	var bValid = true;
	if (!validate("t",true,$F("fldFname"),"fldFname","lblFname")) { bValid = false; }
	if (!validate("t",true,$F("fldLname"),"fldLname","lblLname")) { bValid = false; }
	if (!validate("e",true,$F("fldEmail"),"fldEmail","lblEmail")) { bValid = false; }
	if (!validate("p",true,$F("fldPhone"),"fldPhone","lblPhone")) { bValid = false; }
	if (!validate("t",true,$F("fldAddress"),"fldAddress","lblAddress")) { bValid = false; }
	if (!validate("t",true,$F("fldCity"),"fldCity","lblCity")) { bValid = false; }
	if (!validate("s",true,$F("fldState"),"fldState","lblState")) { bValid = false; }
	if (!validate("z",true,$F("fldZip"),"fldZip","lblZip")) { bValid = false; }
	if (bValid) {
		var data = "fname="+encodeURIComponent($F("fldFname"));
		data+="&lname="+encodeURIComponent($F("fldLname"));
		data+="&email="+encodeURIComponent($F("fldEmail"));
		data+="&phone="+encodeURIComponent($F("fldPhone"));
		data+="&address="+encodeURIComponent($F("fldAddress"));
		data+="&address2="+encodeURIComponent($F("fldAddress2"));
		data+="&city="+encodeURIComponent($F("fldCity"));
		data+="&st="+encodeURIComponent($F("fldState"));
		data+="&zip="+encodeURIComponent($F("fldZip"));
		data+="&optin="+encodeURIComponent($("fldOptin").checked);
		data+="&r="+Math.random();
		var url = "/sixpack/put-entry.asp";
		var myAjax = new Ajax.Request(url,{asynchronous:true, method:'post', parameters:data, onSuccess:submitEntrySC, onFailure:errFunc });
	} else {
		alert("Please see the highlighted fields as they are required.");	
		showForm();
	}
}
//
function submitBonus() {
	showSaving();
	var bValid = false;
	var sAddresses = $F("fldEmails");
	// validate email address(es)
	var aAddresses = sAddresses.split(",");
	if (aAddresses.length > 0) {
		bValid = true;
		for (var i = 0; i < aAddresses.length; i++) {
			aAddresses[i] = aAddresses[i].trim();
			if (!validateEmail(aAddresses[i],true)) { bValid = false; }
		}
	}
	if (bValid) {
		var data = "id="+encodeURIComponent($F("fldID"));
		data+="&addresses="+encodeURIComponent(sAddresses);
		data+="&r="+Math.random();
		var url = "/sixpack/put-entry-bonus.asp";
		var myAjax = new Ajax.Request(url,{asynchronous:true, method:'post', parameters:data, onSuccess:submitBonusSC, onFailure:errFunc });
	} else {
		alert("There was a problem with the email address(es) you have entered. Please check them and try again.");	
		showForm();
	}
}
//
function showSaving() {
	$("cntSaving").style.display = "block";
	$("cntErrorMsg").style.display = "none";
	try {
		$("cntForm").style.display = "none";
	} catch(e) {
		$("cntFormFriend").style.display = "none";
	}
}
//
function showForm() {
	$("cntSaving").style.display = "none";
	$("cntErrorMsg").style.display = "none";
	try {
		$("cntForm").style.display = "block";
	} catch(e) {
		$("cntFormFriend").style.display = "block";
	}
}
//
function showErr(t) {
	$("cntErrorMsg").innerHTML = t;
	$("cntSaving").style.display = "none";
	try {
		$("cntForm").style.display = "none";
	} catch(e) {
		$("cntFormFriend").style.display = "none";
	}
	$("cntErrorMsg").style.display = "block";
	replaceFonts();
}
//
function submitEntrySC(r) {
	var iResponse = parseInt(r.responseText);
	if (iResponse > 0) {
		window.location = "thankyou.asp?ri="+iResponse;
	} else {
		if (iResponse < 0) {
			showErr("<h1 class='pageHeader'>An error occurred.</h1><p>Please <a href='javascript:showForm()'>click here</a> to try again.</p>");
		} else {
			showErr("<h1 class='pageHeader'>You are only allowed to enter once per day. Please come back tomorrow to try again.</p>");
		}
	}
}
//
function submitBonusSC(r) {
	var iResponse = parseInt(r.responseText);
	if (iResponse > 0) {
		window.location = "thankyou-friend.asp";
	} else {
		alert("There was a problem with the email address(es) you have entered. Please check them and try again.");
		showForm();
	}
}