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_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_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 showRules () {
	window.open('rules.html','Rules', "height=400, width=500, location=0, toolbars=0,status=1,resizable=yes, scrollbars=1");
}
function enterSweepstakes () {
	if(checkForm()) document.sweepstakesForm.submit();
}
function checkForm () {
	var f = document.sweepstakesForm;
	if(f.firstname.value.length && f.lastname.value.length && f.agency.value.length && f.zip.value.length && f.phone.value.length && f.email.value.length) {
		var emailValidate = validateEmail(f.email.value);
		if(emailValidate === true) {
		} else {
			alert(emailValidate);
			return false;
		}
		var ladiesChecked = false;
		for(var i=0; i<f.ladies.length; i++) {
			if(f.ladies[i].checked) ladiesChecked = true;
		}
		if(!ladiesChecked) {
			alert("You must choose one of the ladies at the top of the page.");
			return false;
		}
		if(!f.chkbox1.checked) {
			alert("You must check the box that says you have read and understood the Official Rules");
			return false;
		}
		return true;
	} else {
		alert("You must fill out all of the required fields in the form");
		return false;
	}
	return false;
}
function validateEmail(str) {
	if (str.length<5) {
		return "Please enter a valid email.";
	}
	var iChars = "*|,\":<>[]{}`;()&$#%";
	var eLength = str.length;
	for (var i = 0; i<eLength; i++) {
		if (iChars.indexOf(str.charAt(i)) != -1) {
			return "Invalid Email Address : Illegal Character in Email Address :-->"+str.charAt(i)+"<--.";
		}
	}
	var atIndex = str.lastIndexOf("@");
	if (atIndex<1 || (atIndex == eLength-1)) {
		return "Invalid Email Address : Email Address must contain @ as at least the second chararcter.";
	}
	var pIndex = str.lastIndexOf(".");
	if (pIndex<4 || (pIndex>=eLength-2)) {
		return "Invalid Email Address : Email Address must contain at least one . (period) in a valid position";
	}
	if (atIndex>pIndex) {
		return "Invalid Email Address : Email Address must be in the form of name@domain.domaintype";
	}
	return true;
}

// No Need to Change
var icbCursor='pointer';
if (document.all){ icbCursor='hand'; }


function icbCBoxtoImgCB(icb,icbs,icbT,icbF,icbw,icbh){
  // Create Image Element, Append Before the Check Box, Add OnClick Event & Load Correct Image
 icbNewImg=document.createElement('img');
 icbNewImg.id='icb'+icb;
 icbcb=document.getElementById(icb);
 icbcb.parentNode.insertBefore(icbNewImg,icbcb);
 icbNewImg.style.cursor=icbCursor;
 if (icbw!=null&&icbh!=null){ icbNewImg.width=icbw; icbNewImg.height=icbh; }
 icbNewImg.cb=icbcb;
 icbNewImg.icbT=icbT;
 icbNewImg.icbF=icbF;
 icbNewImg.onclick=function(){ icbImgCBox(this); };
 if (icbs){ icbNewImg.src=icbT; } else { icbNewImg.src=icbF; }
 // Hide the real Check Box
 icbcb.checked=icbs;
 icbcb.style.position='absolute';
 icbcb.style.visibility='hidden';
}

function icbImgCBox(icb){
 if (icb.cb.checked){
  icb.src=icb.icbF;
  icb.cb.checked=false;
 }
 else {
  icb.src=icb.icbT;
  icb.cb.checked=true;
 }
}
function faq() {
	window.open("bravotoyou_faq.php","affluencers.com","width=500, height=530, status=1,toolbar=1");
}