	function rtpopupbox(url) {
		newwindow=window.open(url,'name','height=400,width=400,location=no,status=no,toolbar=no,menubar=no');
		if (window.focus) {newwindow.focus()}
		return false;
	}



    function Replace(sender, account, zipCode, anchorLink)
    {
        var zip = document.getElementById(zipCode);
        if (zip != null)
            sender.href = (anchorLink + '?accnt=' + account + '&zipcode=' + zip.value + '&ziponly=true');
    }
    function ReplaceCity(sender, account, zipCode, ddlState, anchorLink)
    {
				var zip = document.getElementById(zipCode);
				var state = document.getElementById(ddlState);
				sender.href = (anchorLink + '?accnt=' + account + '&zipcode=' + zip.value + ', ' + state.value);
    }
		
    function ValidateZip(zipCode)
    {      
       var zip = document.getElementById(zipCode);
       
       if (zip.value == "") {
	        alert('Please enter your zip code.');
	        return false;
        }
		
	
        if (zip.value.length < 3 ) {
	        alert('Please enter at least 3 digits in the zip code field.');
	        return false;
        }
		
	    return true;
    }
    
	function CheckOnEnter(e, account, lk, zipCode, anchorLink, ddlState, sender)
	{
	    if ( !e ) e = event ;	    
	    
	    var iCode = (e.keyCode) ? e.keyCode : e.which;
	    
	    if(document.getElementById(zipCode).value != "")
	    {
	        //we caught the entered value in the textBox 
	        var getCharType = document.getElementById(zipCode).value;	    
	        
	        //if th euser has entered already a char we check if it is number or letter
	        switch(IsNumber(getCharType.charCodeAt(0)))
	        {
	            case 0:
	                var hh = document.getElementById(zipCode);
	                hh.maxLength = 50;
	                if(charsOnly(e))
	                {	                    
	                    if (iCode == 13)
	                    {
	                        CheckOnClick(sender, account, zipCode, anchorLink, ddlState)
	                    }
	                }
	                else
	                {
	                    return false;
	                }
	                break;
	            case 1:
	                //if we enter only numbers then we procede otherwise we return false
	                var hh = document.getElementById(zipCode);
	                hh.maxLength = 5;
	                if(numeralsOnly(e))
	                {   
	                    // validate ZIP code only when 'Enter' was pressed
	                    if (iCode == 13)
	                    {	        
	                       ZipLogic(account, lk, zipCode, anchorLink);
		                }
		            }
		            else
		            {		    
		                return false;
		            }
	                break;
	        }
	    }
	    if(document.getElementById(zipCode).value == "" && iCode == 13)
	    {
	        if(document.getElementById(ddlState).value == "")
	        {
	            var zp = document.getElementById(zipCode);
	                zp.maxLength = 17;
	            alert('Please enter City');
	            return false;
	        }
	    }
	    
	    
	}
	
	function IsNumber(charCode)
	{   
        if (charCode > 31 && (charCode < 48 || charCode > 57)) 
        {            
            return 0
        }
        return 1;
	}
	
	function CityStateLogic(account, lk, zipCode, anchorLink, ddlState)
	{
	    if(document.getElementById(ddlState).value == '')
	    {
	            alert('Please Select the State');
	            return false;
	    }
	    else
	    {
	        return true;
	    }
	}
 
	function ZipLogic(account, lk, zipCode, anchorLink)
	{
	     // if ZIP code is correct, than redirect to link
                var result = ValidateZip(zipCode);            
                if (result)
                {   
                    if (lk != null)
                    {
                        var zip = document.getElementById(zipCode);
                        var link = document.getElementById(lk);
                        
                        //change link
                        Replace(link, account, zipCode, anchorLink)
                        
                        window.open(link.href);
                    }
                }
                
                return false;	
	}
	
	function CheckOnClick(sender, account, zipCode, anchorLink, ddlState)
	{	     
	   
         if((document.getElementById(zipCode).value == 'Enter City or Zip' || document.getElementById(zipCode).value == 'Enter') && document.getElementById(ddlState).value == '')
         {
             alert('Please enter your zip code');              
             return false;
         }
         if((document.getElementById(zipCode).value == 'Enter City or Zip' || document.getElementById(zipCode).value == 'Enter') && document.getElementById(ddlState).value != '')
         {
             alert('Please enter City');            
             return false;
         }
         else
         {     
             //change link
             
          
	        //we caught the entered value in the textBox 
	        var getCharType = document.getElementById(zipCode).value;
	     
	        switch(IsNumber(getCharType.charCodeAt(0)))
	        {
	            case 0:
	              if(document.getElementById(zipCode).value != '' && document.getElementById(ddlState).value == '')
								{
									alert('Please select State');            
									return false;
								}
								ReplaceCity(sender, account, zipCode, ddlState, anchorLink)
                window.open(sender.href);
                return false;
                break;
                
                case 1:
                // if ZIP code is correct, than redirect to link
                Replace(sender, account, zipCode, anchorLink);
                var result = ValidateZip(zipCode);
                if (result)
                    window.open(sender.href);
                return false;
                break;
            }
        }
	}		
	
	//this function will check that we enter only numerals
	function numeralsOnly(evt) 
	{
        evt = (evt) ? evt : event;
        
        var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
        
        if (charCode > 31 && (charCode < 48 || charCode > 57)) 
        {            
            return false;
        }
        return true;
    }
    
    //this function will check that we enter only chars
	function charsOnly(evt) 
	{
        evt = (evt) ? evt : event;
        var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
        
        if (charCode == 13 || charCode == 32 || charCode == 127 || charCode == 8 ||(charCode > 31 && ((charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122))))
        {            
            return true;
        }
       
        return false;
    }
	
	function CheckOnLinkClick(sender, anchorLink)
	{
	    sender.href = anchorLink;
	    return true;
	}

function validate_popupform ( )
{
    valid = true;

    if ( document.information.LastName.value == "" || document.information.AreaCode.value == "" || document.information.PhonePrefix.value == "" || document.information.PhoneSuffix.value == "")
    {
        alert ( "Last name and phone number are required fields." );
        valid = false;
    }
  if (document.information.Email.value) 
  {
   if (emailadrcheck(document.information.Email.value)==false)
    {
        alert ( "Email address is invalid." );
        valid = false;
    }
  }
    return valid;
}



function emailadrcheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 //if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		 //   return false
		 //}

 		 return true					
	}

