<!--
//Declare variables
blanks = " \t\n\r"; 

// Removes leading blank chars (as defined by blanks) from s
function stripLeadingBlanks(s)
  { 
  var i = 0;
  while ((i < s.length) && (blanks.indexOf(s.charAt(i)) != -1))
     i++;
  return s.substring(i, s.length);
  }


// Removes trailing blank chars (as defined by blanks) from s
function stripTrailingBlanks(s)
  { 
  var i = s.length - 1;
  while ((i >= 0) && (blanks.indexOf(s.charAt(i)) != -1))
     i--;
  return s.substring(0, i+1);
  }


// Removes leading+trailing blank chars (as defined by blanks) from s
function stripLeadingTrailingBlanks(s)
  { 
  s = stripLeadingBlanks(s);
  s = stripTrailingBlanks(s);
  return s;
  }


// this checks if all questions have been answered, if true then shows the "submit" button  
function checkAndShowSubmit(objCurrentForm){
   var chk1 = objCurrentForm.radioLegal1[0].checked || objCurrentForm.radioLegal1[1].checked;
   var chk2 = objCurrentForm.radioLegal2[0].checked || objCurrentForm.radioLegal2[1].checked;
   var chk3 = objCurrentForm.radioLegal3[0].checked || objCurrentForm.radioLegal3[1].checked;
   if (chk1 && chk2 && chk3) { document.all.divsubmit.style.visibility = "visible" }
      else {document.all.divsubmit.style.visibility = "hidden"}   
}  
  
// This checks that all questions should be answered before submit form.
function checkQuestion(objCurrentForm){
	
    var answer=0;	
	//q1
	if (objCurrentForm.radioLegal1[0].checked){ answer +=1;}
	  else if (objCurrentForm.radioLegal1[1].checked){answer +=0;} 
	         else {alert ("Por favor, conteste todas las preguntas.");
			      return false;}
    
	//q2
	if (objCurrentForm.radioLegal2[0].checked){ answer +=1;}
	   else if (objCurrentForm.radioLegal2[1].checked){	answer +=0;} 
	        else {alert ("Por favor, conteste todas las preguntas.");
		         return false;}

   //q3
	if (objCurrentForm.radioLegal3[0].checked){ answer +=1;}
	   else if (objCurrentForm.radioLegal3[1].checked){	answer +=0;}
	         else {	alert ("Por favor, conteste todas las preguntas.");
			        return false;}

	//check	
	if (answer !=3){    
		if (confirm("Lo sentimos, pero tiene que tener prescrito Andriol para entrar en este sitio. \n\n¿Quiere ir al sitio web de Andropausia, para aprender más sobre ella? \nSi lo quiere, haga clic en \"Aceptar\", sino haga clic en \"Cancelar\" para cerrar este mensaje.")) {
		   document.location.href = "http://www.andropausia.info";
		   return false;  }
		   else { return false;}
	    } else { return true ;} 
	
} //end function

// function for those not signing in 
function signIn(){
	alert ("Para acceder a la información dentro este sitio, \ntiene que responder las preguntas \nabajo de \"la Renuncia Legal\".");
}

// This function checks the postive integer entry
function isPositiveInteger(inte2){
	 inte=stripLeadingTrailingBlanks(inte2)
	 ok=true;
	 if (inte.length==0)
	 { ok=false;
	 }
	  for (i=0;i<inte.length;i++ )
	  { 
		   theChar=inte.charAt(i);
		   if ((theChar<"0")||(theChar>"9"))
		   {
			   ok=false;
			   break;
		   } 
		   if (eval(inte)<=0)
		   {
			   ok=false;
			   break;
		   }
	  }
	  return ok;
}


// This function check email address (This function was tested by QA)
function isEmail(emailStr) {

/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */

   var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ] */

   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */

   var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */

   var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */

   var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of
   non-special characters.) */

   var atom=validChars + '+';

/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */

   var word="(" + atom + "|" + quotedUser + ")";

/* The following pattern describes the structure of the user */

   var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */

   var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */

   var matchArray=emailStr.match(emailPat);

/* Too many/few @'s or something; basically, this address doesn't
      even fit the general mould of a valid e-mail address. */

   if (matchArray==null) {
	 // alert("Please enter a valid e-mail address.");
	  return false;
   }

   var user=matchArray[1];
   var domain=matchArray[2];

/* See if "user" is valid */

   if (user.match(userPat)==null || user.indexOf("\"\"")>=0) {
      // user is not valid

      if (user.indexOf("@")>=0) {
       // alert("Your e-mail address contains more than one \'@\' symbol.\nPlease remove any additonal \'@\' symbols.");
      }
      else {
       // alert("Please enter a valid username.");
      }
      return false;
   }

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */

   var IPArray=domain.match(ipDomainPat);

   if (IPArray!=null) {
      // this is an IP address

	  for (var i=1;i<=4;i++) {

	     if (IPArray[i]>255) {
	       // alert("Please check that your IP address is correct.");
		    return false;
	     }

      }
      return true;
   }

/* Domain is symbolic name */

   var domainArray=domain.match(domainPat);

   if (domainArray==null) {
     // alert("Please enter a valid domain name or IP address.");
      return false;
   }

/* domain name seems valid, but now make sure that it ends in a
   minimum two-letter word and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */

   var atomPat=new RegExp(atom,"g");
   var domArr=domain.match(atomPat);
   var len=domArr.length;
   var domStr=domArr+"";
   var posDom=domStr.indexOf(",");

/* the address must end with a minimum of two letter domain. */

   if (domArr[domArr.length-1].length<2 && posDom>0) {
     // alert("The e-mail address must end with a minimum of two characters.");
      return false;
   }

/* Make sure there's a host name preceding the domain. */

   if (len<2) {
      //alert("Please enter a valid domain name.");
      return false;
   }

/* If we've gotten this far, everything's valid! */

   //alert("You have inputed a valid e-mail address.");
   return true;
}


//This function checks leap year
function isLeapYear(intYear) {
	if (intYear % 100 == 0){
		if (intYear % 400 == 0) {
			return true; 
		}
    }  else {
		if ((intYear % 4) == 0) { 
			return true; 
		}
    } //end if
	return false;
} //end function


//This checks that if valid date range checked
function isValidDate(smonth,sday,syear){
	if ((smonth=='')||(sday=='')||(syear==''))
	{
		return false;
	}
    if (((smonth==4)||(smonth==6)||(smonth==9)||(smonth==11))&&(sday>30)){
	return false;
	}
	
	//check leap year and Feb. entry
	if (smonth==2){
	  if ((isLeapYear(syear))&&(sday>29)){
	    return false;
	   } 
	    if ((!isLeapYear(syear))&&(sday>28)){
	    return false;
	   } 
	}	
   return true;
}


// Check the data entry
function checkEntry(form){
	if (!isPositiveInteger(form.textAge.value))
	{
		alert ("Por favor, registra su edad.");
		form.textAge.focus();
		return false;
	}

	if (!isValidDate(form.selectMonth.options[form.selectMonth.selectedIndex].value,form.selectDay.options[form.selectDay.selectedIndex].value,form.selectYear.options[form.selectYear.selectedIndex].value))
	{
		alert("Por favor, registra la fecha en que comenzó su tratamiento con Andriol.");
		form.selectMonth.focus();
		return false;
	}
	
	if (form.textEmail.value.length < 1)
	{
		alert ("Por favor registra su dirección e-mail.");
		return false;
	}

	if (!isEmail(form.textEmail.value))
	{
		alert ("Por favor, registra una dirección e-mail valida.");
		form.textEmail.focus();
		return false;
	}
}
//-->
