﻿
	String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
	
	function CallFunctionIfEnter(e, strfunction)
    {
        e = (e) ? e : event;
	    if(e.which || e.keyCode){
	        if ((e.which == 13) || (e.keyCode == 13)) {
		        //new CCallWrapper(this, 1, strfunction);
		        setTimeout(strfunction + '();',1);
			    e.returnValue = false;
			    e.cancel = true;
			    return false;
		    }
		    return true;
	    }
	    else 
	    {
	        return true;
	    }
    }
    
    function EnterPressed(e)
    {
        e = (e) ? e : event;
	    if(e.which || e.keyCode){
	        if ((e.which == 13) || (e.keyCode == 13)) {
		        e.returnValue = false;
			    e.cancel = true;
			    return true;
		    }
		    return false;
	    }
	    else 
	    {
	        return false;
	    }
    }
	
	function changetab(url) {
		location.replace(url);
		return false;
	}
	
	function setSearch(e) {
		var eCurr;
		var eAlt;
		if(e.className.indexOf('Off') > -1) {
			if(e.id == 'bizSrch') {
				window.parent.location = 'fpsearchlg680.asp?type=biz';
			}
			else {
				window.parent.location = 'fpsearchlg680.asp?type=res';
			}
		}
	}
	
	function BusinessSearch()	
	{
	    document.bizform.term.value = document.form1.term.value.trim();
	    
	    if(IsNumeric(document.form1.bus_location.value))
	    {	    	   
	        document.bizform.zip.value = document.form1.bus_location.value.trim();
	    }else
	    {
	        if(document.form1.bus_location.value.indexOf(",")>=0)
	        {
	            document.bizform.city.value = document.form1.bus_location.value.substr(0,document.form1.bus_location.value.indexOf(",")).trim();
	            document.bizform.state.value = document.form1.bus_location.value.substr(document.form1.bus_location.value.indexOf(",")+1, document.form1.bus_location.value.length ).trim();
	            
	        }else{
	        
	            document.bizform.city.value = document.form1.bus_location.value.trim();
	        
	        }
	    }
	    
	    document.bizform.submit();
	}
	
	function PersonSearch()	
	{
	    /*document.resform.F.value = document.form1.resfirst_name.value.trim();
	    document.resform.L.value = document.form1.reslast_name.value.trim();
	    
	    if(IsNumeric(document.form1.res_location.value))
	    {	    	   
	        document.resform.zip.value = document.form1.res_location.value.trim();
	    }else
	    {
	        if(document.form1.res_location.value.indexOf(",")>=0)
	        {
	            document.resform.T.value = document.form1.res_location.value.substr(0,document.form1.res_location.value.indexOf(",")).trim();
	            document.resform.S.value = document.form1.res_location.value.substr(document.form1.res_location.value.indexOf(",")+1, document.form1.res_location.value.length ).trim();
	            
	        }else{
	        
	            document.resform.T.value = document.form1.res_location.value.trim();
	        
	        }
	    }
	    
	    document.resform.submit();*/
	    
	    document.resform.qf.value = document.form1.resfirst_name.value.trim();
	    document.resform.qn.value = document.form1.reslast_name.value.trim();
	    
	    if(IsNumeric(document.form1.res_location.value))
	    {	    	   
	        document.resform.zip.value = document.form1.res_location.value.trim();
	    }else
	    {
	        if(document.form1.res_location.value.indexOf(",")>=0)
	        {
	            document.resform.qc.value = document.form1.res_location.value.substr(0,document.form1.res_location.value.indexOf(",")).trim();
	            document.resform.qs.value = document.form1.res_location.value.substr(document.form1.res_location.value.indexOf(",")+1, document.form1.res_location.value.length ).trim();
	            
	        }else{
	        
	            document.resform.qc.value = document.form1.res_location.value.trim();
	        
	        }
	    }
	    
	    document.resform.submit();
	}
	
	function ReverseLookup()	
	{
	    document.rsform.A.value = document.form1.area_code.value.trim();
	    document.rsform.X.value = document.form1.exchange.value.trim();
	    document.rsform.P.value = document.form1.phone.value.trim();
	    
	    
	    if(document.form1.search_type[0].checked)
	    {
	    document.rsform.type.value = 'RES';
          document.rsform.action = "http://frontier.intelius.com/redirect.php";
			document.rsform.ReportType.value = "33";
			document.rsform.sid.value = "2";
			document.rsform.PS.disabled = true;
			document.rsform.qp.value = document.rsform.A.value + document.rsform.X.value + document.rsform.P.value;
	    }else if(document.form1.search_type[0].checked)
	    {
	    document.rsform.type.value = 'BUS';
          document.rsform.action = "http://yellowpages.superpages.com/listings.jsp";
			document.rsform.ReportType.value = "";
			document.rsform.sid.value = "";
			document.rsform.qp.value = "";
			document.rsform.PS.disabled = false;
			
			document.rsform.PS.value = '30';
	    }else{
	     //How do we do both?
	    }
	    
	    
	    document.rsform.submit();
	}	

    function CategorySearch(term, city, state, location,fpmainurl,ypmainurl)	
	{
	    term=term.trim();
	    city=city.trim();
	    state=state.trim();
	    if(location != null)
	    location=location.value.trim();
	    
	    if(fpmainurl == null)
	    fpmainurl='http://www.frontierpages.com';
	    
	    if(ypmainurl == null)
	    ypmainurl='http://yptest.frontierpages.com';
	    
	    var searchCity = city;
	    var searchState = state;
	
	    
	       
	    if(location == null)
	    {
	        if(searchCity == '' && searchState == '')
	{
	            window.parent.location = fpmainurl;
	
	        }else
	    {
	        window.parent.location = ypmainurl + '/results.aspx?term=' + term + '&city=' + searchCity + '&state=' + searchState + '&Pagenumber=1&Termsearch=true&Partnerid=BRY-01&Portal=Frontier';    	            
	        }
        	
	    }else	    
	    {
	
	        if(location.value == "")
	        {
    	    
    	        if(searchCity == '' && searchState == '')
	            {
	                window.parent.location = fpmainurl;
        	        
	            }else
	            {
	        window.parent.location = ypmainurl + '/results.aspx?term=' + term + '&city=' + searchCity + '&state=' + searchState + '&Pagenumber=1&Termsearch=true&Partnerid=BRY-01&Portal=Frontier';    	            
        	    }
    	   
	        }else
	        {
    	
	            if(IsNumeric(location))
	            {	 
	                if(location == '')
	                {
	                    window.parent.location = fpmainurl;
	                }else
	                {
	                    window.parent.location = ypmainurl + '/results.aspx?term=' + term + '&zip=' + location + '&Pagenumber=1&Termsearch=true&Partnerid=BRY-01&Portal=Frontier';    	            
	                }
        	        
	            }else
	            {
	                if(location.indexOf(",")>=0)
	                {
	                    searchCity = location.substr(0,location.indexOf(","));
	                    searchState = location.substr(location.indexOf(",")+1, location.length );
    	                
	                    window.parent.location = ypmainurl + '/results.aspx?term=' + term + '&city=' + searchCity + '&state=' + searchState + '&Pagenumber=1&Termsearch=true&Partnerid=BRY-01&Portal=Frontier';
        	            
	                }else{
    	                window.parent.location = ypmainurl + '/results.aspx?term=' + term + '&city=' + location + '&Pagenumber=1&Termsearch=true&Partnerid=BRY-01&Portal=Frontier';    	            
        	        
	                }
	            }
	        }
	    }
	}
	
	function IsNumeric(sText)
    {
       var ValidChars = "0123456789";
       var IsNumber=true;
       var Char;

     
       for (i = 0; i < sText.length && IsNumber == true; i++) 
          { 
          Char = sText.charAt(i); 
          if (ValidChars.indexOf(Char) == -1) 
             {
             IsNumber = false;
             }
          }
       return IsNumber;
       
    }


	function verifyRS()
	{
		document.rsForm.PH.value = document.rsForm.at.value + document.rsForm.e.value + document.rsForm.n.value;
		return true;
	}

    function Redirect(url)
    {
        window.parent.location = url;
    }
	
    function AdvanceCursorByLengthChk(presentObj, moveToName, maxLgth)
    {
	    if (presentObj.value.length == maxLgth)
	    {
		    setFocusToObj(moveToName);
		    return;
	    }
    }
    function setFocusToObj(setFocusToName)
    {
	    var moveToObj = document.getElementById(setFocusToName);
    	
	    moveToObj.focus();
	    return;
    }
    
    //checks for city,State
    function validateLocation(location)
    {
            location=location.trim();
          //locationRegex = /^[a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+ *, *\w+$/i;
          locationRegex = /^ *[a-zA-Z]+ *[a-zA-Z]* *[a-zA-Z]* *\,* *[a-zA-Z]+ *[a-zA-Z]* *$/i;
          
          ZipRegex = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
      
     if( !location.match( locationRegex ) && !location.match( ZipRegex )) {
        if(location.indexOf(" ") >=0)
        {
          var location2 = location.substr(0,location.indexOf(" ")) + "," + location.substr(location.indexOf(" ")+1,location.Length);
          if( !location2.match( locationRegex )) {
            alert('please enter a valid City,State Or Zip');
            return false;
            }
        }else
        {
            alert('please enter a valid City,State Or Zip');
            return false;
        }
     }  
     
     if(location.indexOf(" ") <0 && location.indexOf(",") <0 && !location.match( ZipRegex ))
        {
         alert('please enter a valid City,State Or Zip');
            return false;
        }
        
     return true;
    }
    
    function IsValidZip( zip ) {
     zipRegex = /^\(\d\d\d\) \d\d\d-\d\d\d\d$/;
     if( !zip.match( zipRegex ) ) {
      return false;
     }
     return true;
    }
    
    function setCityStateZipFromLocation(city, state, zip, location)
    {
            
            location.value=location.value.trim();
          //locationRegex = /^[a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+ *, *\w+$/i;
          locationRegex = /^ *[a-zA-Z]+ *[a-zA-Z]* *[a-zA-Z]* *\,* *[a-zA-Z]+ *[a-zA-Z]* *$/i;
          
          ZipRegex = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
          
         if( location.value.match( locationRegex )) {
            city.value = location.value.substr(0,location.value.indexOf(",")).trim();
	        state.value = location.value.substr(location.value.indexOf(",")+1, location.value.length ).trim();
         }else
         {
          var location2 = location.value.substr(0,location.value.indexOf(" ")) + "," + location.value.substr(location.value.indexOf(" ")+1,location.value.Length);
          if( location2.match( locationRegex )) {
            city.value = location2.substr(0,location2.indexOf(",")).trim();
	        state.value = location2.substr(location2.indexOf(",")+1, location2.length ).trim();
         
          }
         }
         if(location.value.match( ZipRegex ))
         {
            zip.value = location.value.trim();
         }
         
         
         
    }
    
    
    


 