﻿// JavaScript Document

/************************************************/
/*************************************************/
function replaceHover(){
        var hoverDivs = document.getElementsByTagName("div");
        for(var i=0; i<hoverDivs.length; i++){
            if(hoverDivs[i].className.indexOf('hover') != -1){
                //  ...guardamos las clases del DIV...
                var classes = hoverDivs[i].className;
                //  ...en onmouseover le a?adimos una clase extra, 'hoverclass'...
                hoverDivs[i].onmouseover = function(){
                    this.className += ' hoverclass';
                }
                //  ...y se la quitamos en onmouseout
                hoverDivs[i].onmouseout = function(){
                    this.className = classes;
                }
            }
        }
    }

/************************************************
 bool ValidateEmail(string input)
 Return true or false
 if the email is valid or not.
 checks for @ and .
**************************************************/
function ValidateEmail(theinput){
 var s=theinput;
 if(s.search)
  return (s.search(new RegExp("^([-!#$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}$","gi"))>=0);
 if(s.indexOf)
 {
  at_character=s.indexOf('@');
  if(at_character<=0 || at_character+4>s.length)
   return false;
 }
 if(s.length<6)
  return false;
 else
  return true;
}
 
/************************************************
 bool ValidateName(string input)
 Return true or false
 if the email is valid or not.
**************************************************/
function ValidateName(theinput){
 var s=theinput;
 if(s.search)
  return (s.search(new RegExp("^[^&'^`]+$","gi"))>=0);
 if(s.length<3)
  return false;
 else
  return true;
}
 
/************************************************
 bool ValidatePhone(string input)
 Return true or false
 if the phone number is valid or not.
 acepts - and + symbols
**************************************************/
function ValidatePhone(theinput){
 var s=theinput;
 if(s.search)
  return (s.search(new RegExp("[-+0-9]+","gi"))>=0);
 if(s.length<5)
  return false;
 else
  return true;
}
 





function CheckPharmForm(){
	var error="";
	if(!ValidateEmail(document.frmPHARM.email1.value))
		error+="An email address is required.\n";
	if(!ValidateEmail(document.frmPHARM.email2.value))
		error+="The email addresses must match. Please correct.\n";
	if(!document.frmPHARM.phone.value)
		error+="Your phone number is required to help us verify your refill.\n";
	if(!document.frmPHARM.rxnum1.value)
		error+="At least one prescription refill is required.\n";
	if(!document.frmPHARM.zip.value)
		error+="Your zip code is required to help us verify your refill.\n";
	if(!document.frmPHARM.Total_of_Refills.value)
		error+="Please enter the total number of refills you have requested.\n";

		
		
	if(error!="") 
	alert("Error! Please verify the following information:\n"+error);
	else if(document.frmPHARM.email1.value!=document.frmPHARM.email2.value)
	alert("Please make sure that your email address matches the email address in the Confirm Email box.");
		
		
	else
		document.frmPHARM.submit();
	
	return;
}

