//index page scripts

function convertDiacrits(theThing) {
 var dd=document.createElement("textarea");
 dd.innerHTML=theThing.replace(/</g,"&lt;").replace(/>/g,"&gt;");
 return dd.value;
}

var theCount=0; var picksOfTheList = new Array(10);

function getTheCount(){
 var total = 0; var qq=document.pick5form;
 for (var ii = 0; ii < qq.pick5item.length; ii++) {
  if (eval("qq.pick5item[" + ii + "].checked") == true){ 
   total+=1; 
   picksOfTheList[ii]=1;
  }else{ picksOfTheList[ii]=0; }
 }
 return total;
}

function checkEmailAddress(theEmail){
 if (theEmail){
 var theChar =
/^(([^<>()[\]\\.,;:\s@\”]+(\.[^<>()[\]\\.,;:\s@\”]+)*)|(\”.+\”))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  if( theChar.test(theEmail) == false ){
   alert(convertDiacrits("Favor de entrar un correo electr&oacute;nico v&aacute;lido.")); 
   return false;
  }
 }
}

function updateCount() {
 var oChild = document.getElementById("theCountNode");
 var oNewChild = document.createElement('P');
 oNewChild.id = oChild.id;
 oNewChild.style.color="#000000";
 oNewChild.style.fontWeight="normal";
 theCount = getTheCount(); var thePunct="..."; var spPunct="";
 if(theCount >= 5){ thePunct = "!"; spPunct="&iexcl;"; oNewChild.style.fontWeight="bold"; }
 theCountText=convertDiacrits(spPunct + "S&oacute;lo ha seleccionado " + theCount + thePunct);
 oNewChild.innerHTML = theCountText; 
 oChild.parentNode.replaceChild(oNewChild,oChild);
}

function theValidate(){
 var qq=document.pick5form; 
 if(getTheCount() < 5){
  var alertBit="";
  alert(convertDiacrits("Favor de escoger al menos 5.\n\nS&oacute;lo ha seleccionado " + getTheCount() + "."));
  return false;
 }
 if(qq.zipcode.value){
	if ( qq.zipcode.value.length < 5 || !Number(qq.zipcode.value) ){
    alert(convertDiacrits("Favor de entrar los cinco d&iacute;gitos del c&oacute;digo postal."));
	return false;
 }}
 if (qq.emailaddress.value){
  if ( qq.emailaddress.value.indexOf("@") <= 0 || qq.emailaddress.value.indexOf(".") <= 2 ){ 
   alert(convertDiacrits("Favor de entrar un correo electr&oacute;nico v&aacute;lido."));
   return false;
 }}
 //OK TO PLEDGE!
 var picksPasser="";
 for (var ii = 0; ii < qq.pick5item.length; ii++) {
  picksPasser += picksOfTheList[ii];
 }
 var sessCook = "EPASeleccione5=" + picksPasser + "; expires=";
 document.cookie=sessCook;
 var zippart = qq.zipcode.value; if(zippart=="" ){ zippart="-"; }
 var emailpart = qq.emailaddress.value; if(emailpart=="" ){ emailpart="-"; }
 qq.Subject.value = "seleccione5submittal|" + picksPasser +"|"+ zippart +"|"+ emailpart;
}

