function trimString(str) {
	while (str.charAt(0) == ' ') { str = str.substring(1); }
	while (str.charAt(str.length - 1) == ' ') { str = str.substring(0, str.length - 1); }
	return str;
}

if (document.images){
	path = '../images/footer/';

	footer_submit_on = new Image();footer_submit_on.src = path + "footer_submit_on.jpg";
	footer_secure_shopping_on = new Image();footer_secure_shopping_on.src = path + "footer_secure_shopping_on.jpg";
		
	footer_submit = new Image();footer_submit.src = path + "footer_submit.jpg";
	footer_secure_shopping = new Image();footer_secure_shopping.src = path + "footer_secure_shopping.jpg";		
}

function imgOn(imgName){
	if (document.images) { $(imgName).src = eval(imgName + "_on.src"); }
}

function imgOff(imgName){
	if (document.images) { $(imgName).src = eval(imgName + ".src"); }
}

function validEmailFooter(){
	var str=document.emailFormFooter.emailAddress.value
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	if (filter.test(str)){
		return true
	}else{
		return false;
	}
}

function ValidateEFormFooter(frm){
	if (!validEmailFooter()){
		alert('Please enter a valid email.');
		return false;
	}else{
		//post to responsys
		var ftrID = trimString(document.emailFormFooter._ID_.value)
		var ftrEmail = trimString(document.emailFormFooter.emailAddress.value)
		var ftrresponsysURL = "http://Levis.rsys1.net/servlet/campaignrespondent" + "?EMAIL_ADDRESS=" + ftrEmail + "&_ID_=" + ftrID;
		
		var newIframeftr = '<iframe src="' + ftrresponsysURL + '" height="1" width="1"></iframe>';
		//alert("Submitting to responsys = " + ftrresponsysURL);
		document.getElementById('hiddenIframeFtr').innerHTML = newIframeftr;
		//alert("Submitting to GSI");
		setTimeout("submitFooterEmail()", 4000);
		return false;
	}
}

function submitFooterEmail()
{
	new Ajax.Request('/emailHandler/index.jsp',
			{
				
		method:'post',
		parameters: {_ID_:'levi.150',contest:document.emailFormFooter.CONTEST.value, emailPref:'Y', targetPage:'/include/entry_confirmation.jsp', footerEmailSignup:'true', emailAddress:document.emailFormFooter.emailAddress.value, store:document.emailFormFooter.store.value}, 
		
		onSuccess: function(transport){

$('emailSignupFooter').innerHTML = '<img src="../images/footer/footer_OAS_thanks.gif" alt="Thanks for Signing Up!" /><img src="https://secure.ed4.net/GSI/dualpost/?c=10600&e=' + document.emailFormFooter.emailAddress.value +'&src=footerEmailSignup&la=Y" height="1" width="1" /><img height="1" width="1" src="' + document.emailFormFooter.isSecure.value +'://view.atdmt.com/action/2009_Email_Submission_Button_Footer"/>';

			var actualOas = $('oasResponse').innerHTML;
			var addendum = $('oasResponseAddendum').innerHTML;

			$('emailSignupFooter').innerHTML = actualOas + addendum;

		},
		onFailure: function(){ alert("'We're sorry, we could not sign you up at this time.\n\nPlease try again later.") }
	});
}

