function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function checkSwitch(boxes,toggle) {
	
	var elems = boxes.elements;
	var action = document.getElementById('selector').innerHTML;
	if (action=='Select All') toggle = 'check';
		else toggle='uncheck';
	for (i = 0; i < elems.length; i++) 
		if (elems[i].type == "checkbox") {
			if (toggle == 'check') {
				elems[i].checked = true ;
				document.getElementById('selector').innerHTML = 'Deselect All';
			}
			if (toggle == 'uncheck') {
				elems[i].checked = false;
				document.getElementById('selector').innerHTML = 'Select All';
			}
		}
}
function contest_select(id, thumbnail, name, pphoto){
	$('#contest_selected_image').attr('src', thumbnail);
	$('#selected_id').val(id);
	$('#selectedItem_text').html(name);
	if(pphoto == true){
		$.prettyPhoto.close();
	}
	
	return false;
}
function isEmailAddress (string) {
    var addressPattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
    return addressPattern.test(string);
}
function validateUSZip(strValue) {
	var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	return objRegExp.test(strValue);
}
function notEmptyStr(strValue) {
	var objRegExp  = /[^ \t\v\f\n\r]$/;
	return objRegExp.test(strValue);
}
function validateContestForm(f) {
	$('#contestSubmitBtn').val('SUBMITTING...');
	$('input[type="submit"]').attr('disabled','disabled');
	var err ="";
	var requiredArr = Array("fname", "lname", "selected_id");
	var requiredArrName = Array("First Name", "Last Name", "Selection");
	if (isEmailAddress(f.email.value)==false) {
		err+="Your Email is invalid"+"\r\n";
	} 
	for (var i=0; i<requiredArr.length; i++) {
		var curInput = eval("f."+requiredArr[i]);
		if(notEmptyStr(curInput.value)==false) {
			err+=("Your "+requiredArrName[i]+" is blank or invalid"+"\r\n");
		}
	}
	if (err!="") { 	
		alert(err);
	    $('input[type="submit"]').removeAttr('disabled');
		$('#contestSubmitBtn').val('SUBMIT');
		return false;
	} else {
	    return true;
    }
}

function processCardAmount(){
	var quantity;
	var value;	
	var checked_status = $('#tnc').is(':checked');
	var location_status = $('#cardLocation').val();
	
	if (checked_status == true && location_status != '') {
		$("#paypalSubmit").removeAttr("disabled");
		$("#paypalSubmit").css({"opacity" : "1", "cursor" : "pointer", 'filter' : 'alpha(opacity=100)'});			
		$('#paypalMsg').html('Thank you!').css('color', 'green');
	} else if(checked_status == true && location_status == ''){
		$("#paypalSubmit").attr("disabled", "disabled");
		$("#paypalSubmit").css({"opacity" : "0.4", "cursor" : "default", 'filter' : 'alpha(opacity=40)'});							
		$('#paypalMsg').html('Please select a pickup location to continue.').css('color', 'red');							
	}			
	else {
		$("#paypalSubmit").attr("disabled", "disabled");
		$("#paypalSubmit").css({"opacity" : "0.4", "cursor" : "default", 'filter' : 'alpha(opacity=40)'});							
		$('#paypalMsg').html('Please accept the terms and conditions to continue.').css('color', 'red');				
	}	
	
	quantity = $('#cardQuantity').val();
	value = $('#cardValue').val();	
	
	if(!isNaN(quantity)){		
		$('#ppQuantity').val(quantity);			
	}
	if(!isNaN(value)){	
		$('#ppAmount').val(value);
	}
	
	$('#ppLocation').val($('#cardLocation').val());
	
	if(!isNaN(value)){
		$('#cardTotal').html('$'+quantity*value+'.00');
	}
	
	if(value > 400){	
		alert('The maximum purchase amount is $400.00');
		$('#cardTotal').html('$0.00');
		$('#cardQuantity').val(1);
		$('#cardValue').val(0);
		$('#ppQuantity').val(1);	
	}
	
	
}


// version: beta
// created: 2005-08-30
// updated: 2005-08-31
// mredkj.com
/*
function changePage(newLoc) {
   nextPage = newLoc.options[newLoc.selectedIndex].value	
   		if (nextPage != "") {
      	document.location.href = nextPage}
}
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
*/
