﻿
   



    var c_start = 0, c_end = 0;
		
		function getCookie(c_name)
		{	 
			return ""			
		}		
		
		
		        	
	   var error; 
            
           function SearchAgain()
            {                 
                 if(!(ValidateSearch()))
                 { return false;}
                 else
                 {
                  window.location.href="/Categories.aspx?Phrase=" +  document.getElementById('txtPhrase').value + "&Local=" + document.getElementById('txtLocal').value ;                  
                 }
            }
    
           function ValidateSearch() 
            {                  
                    var ErrStr = "";
                    error = false;
                    if (document.getElementById("txtPhrase").value == '')
                    {
                        ErrStr = "You must enter a search phrase in the search Box.\n";
                        error = true;
                    };

                     if (document.getElementById("txtLocal").value == '') 
                     {
                        ErrStr = ErrStr + "You must enter a location in the city, state or Zipcode Box.";
                        error = true;
                    };

                    if (error) {
                        alert (ErrStr + '\n\nPlease enter this information to try your search again');	  
                        return false;                
                    } else {
                        return true;
                    }
            }
         
	
		var xmlHttp;
		function GetListings()
			{				
			
			 var temp = window.location.search.replace('?','');
			 temp = unescape(temp);	
			 
			// for filling the header search terms
			document.getElementById('divResults').style.display = "none";
			var Local ='';
			var Phrase = '';
		    var Zip='';
		    var jid='';
		    var path='';
		    var index1 = 0, index2 = 0;
		    
		    // Vars Created by Siva For Saving Adwords
		    var caid = '';
		    var clid = '';
		    var agid = '';
		    var crid = '';
		    var keyword = '';
		    //
		    
		    path = window.location.pathname;
		     		
		    index1 = path.indexOf("jid")
		    index2 = path.indexOf("-")		    
		    jid = path.substring(index1+3,index2)
		    index1 = 0;
		    index2 = 0;
		    index1 = temp.indexOf("Local=")
		    index2 = temp.indexOf("&Phrase")		
		    if (index1 != -1 && index2 != -1)
		    Local = temp.substring(index1+6,index2)
		    index1 = 0;
		    index2 = 0;
		    index1 = temp.indexOf("Phrase=")
		    index2 = temp.indexOf("&tid")		   
		    if (index1 != -1 && index2 != -1)
		    Phrase = temp.substring(index1+7,index2)
		    index1 = 0;
		    index2 = 0;
		    
		    // Code for Savig the Adwords Info -- Siva (29th Aug 2007)
		    
		    index1 = temp.indexOf("caid=")
		    index2 = temp.indexOf("&clid")		   
		    if (index1 != -1 && index2 != -1)
		    caid = temp.substring(index1+5,index2)
		    index1 = 0;
		    index2 = 0;
		    
		    index1 = temp.indexOf("clid=")
		    index2 = temp.indexOf("&agid")
		    if (index1 != -1 && index2 != -1)
		    Phrase = temp.substring(index1+5,index2)
		    index1 = 0;
		    index2 = 0;
		    
		    index1 = temp.indexOf("agid=")
		    index2 = temp.indexOf("&crid")
		    if (index1 != -1 && index2 != -1)
		    agid = temp.substring(index1+5,index2)
		    index1 = 0;
		    index2 = 0;
		    
		    index1 = temp.indexOf("crid=")
		    index2 = temp.indexOf("&keyword")
		    if (index1 != -1 && index2 != -1)
		    crid = temp.substring(index1+5,index2)
		    index1 = 0;
		    index2 = 0;
		    
		    index1 = temp.indexOf("keyword=")
		    index2 = temp.length;
		    if (index1 != -1 && index2 != -1)
		    keyword = temp.substring(index1+8,index2)
		    index1 = 0;
		    index2 = 0;
		    //End Of Siva Code
		    
		  	 var UseZipText="&nbsp; For";	
						Zip = Local;
            var charpos = Zip.search("[^0-9]");
            if(Zip.length > 0 &&  charpos >= 0)
            {
                Zip = "";
                 var UseZipText="&nbsp; for&nbsp; ";	
            }
            else {
             UseZipText="&nbsp; for&nbsp; ZipCode ";	
            }
			document.getElementById("ZipCode").value = Zip;
		              
			 if( Phrase==null || Local==null || Phrase=='undefined' || Local=='undefined' || Phrase=='' || Local=='')
			    {			
			         // Added by siva
			        if (caid != '')
			        {
			            saveAdwordInfo(temp);
			        }
			        document.getElementById('divResults').style.display = "none";
			        document.getElementById('form1').innerHTML += "<input type='hidden' name='hdnService' id='hdnService' value = 'Adwords' />";
			       		        
			    }
            else
			    {		
			    
			        // Added by siva
			        if (caid != '')
			        {
			            saveAdwordInfo(temp);
			        }
			        	     
			      var arr, temp1;
			      document.getElementById('divResults').style.display = "";
			      arr = document.getElementsByName('Phrase');
			      for(temp1 in arr)
			      {
			        arr[temp1].value = Phrase;
			      }
			      arr = document.getElementsByName('Local');
			      for(temp1 in arr)
			      {
			        arr[temp1].value = Local;
			      }
                  var el = document.getElementById("idForLocale");
                   if(charpos >= 0)
                   {
                        var strTemp = new String;
                        var arrTemp = new Array();
                        arrTemp = (PCase(Local)).split(",");
                        if(arrTemp.length > 0)
                        {
                            strTemp = arrTemp[arrTemp.length - 1];
                            arrTemp.pop();
                            strTemp = "," + strTemp.toUpperCase();
                        }
                        else
                            strTemp = "";
                        el.innerHTML=UseZipText + arrTemp.join(",") + strTemp;
                   }
                   else
                    {
                         el.innerHTML=UseZipText + Local;
                    }
                                    
				    var Request ="../GetMatchedResults.aspx?JobTypeID=" + jid + "&" + temp ;   
										
		            try
		            {
			            // Firefox, Opera 8.0+, Safari
			            xmlHttp=new XMLHttpRequest();
		            }
		            catch (e)
		            {
			            // Internet Explorer
			            try
			            {
				            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			            }
			            catch (e)
			            {
				            try
				            {
					            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				            }
				            catch (e)
				            {
					            alert("Your browser does not support AJAX!");
					            return false;
				            }
			            }
		            }
    			
				    GETMETHOD(xmlHttp,Request,handleresponse);
				  
			    }			 
			}
			
		function GETMETHOD(xmlobj,URL,handleresponse)  //here xmlobj is the xmlhttp object,handleresponse is the function to be called to handle the returned data from the server
			{                                              //URL is the URL  
				if(xmlobj != null)
					{
					if(document.all)
					{
						xmlobj.open("POST", URL, true);
						xmlobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
					}
					else
						{xmlobj.open("GET", URL, true); }	
					    
						xmlobj.onreadystatechange = handleresponse;
						xmlobj.send(null);
					}		
			}

		
		function handleresponse()
			{	
				if(xmlHttp.readyState == 4)
					{ 						
								// Displaying the results
								document.getElementById('divResults').innerHTML=xmlHttp.responseText;								
					}
			} //end handle response
		
		function MM_openBrWindow(theURL,winName,features)
			 { 
				window.open(theURL,winName,features);
			 }	
			 
    

        function MM_reloadPage(init) {  //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=='Netscape')&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


 function PCase(STRING)
        {
            var strReturn_Value = "";
            var iTemp = STRING.length;
            if(iTemp==0)
            {
                return"";
            }
            var UcaseNext = false;
            strReturn_Value += STRING.charAt(0).toUpperCase();
            for(var iCounter=1;iCounter < iTemp;iCounter++)
            {
                if(UcaseNext == true)
                {
                  strReturn_Value += STRING.charAt(iCounter).toUpperCase();
                }
                else
                {
                  strReturn_Value += STRING.charAt(iCounter).toLowerCase();
                }
                var iChar = STRING.charCodeAt(iCounter);
                if(iChar == 32 || iChar == 45 || iChar == 46 || iChar == 44 || iChar == 39)
                {
                     UcaseNext = true;
                }
                else
                {
                     UcaseNext = false
                }
                if(iChar == 99 || iChar == 67)
                {
                    if(STRING.charCodeAt(iCounter-1)==77 || STRING.charCodeAt(iCounter-1)==109)
                    {
                    UcaseNext = true;
                    }
                }
            } //End For

            return strReturn_Value;

        }
        
        //Added by Siva For Saving Adwords Info
        function saveAdwordInfo(temp)
        {
            
            var Request ="../GetMatchedResults.aspx?Function=SaveAdwords&OrigRefer=" + escape(document.referrer) + "&" + temp ; 
            //alert(Request)
             try
		            {
			            // Firefox, Opera 8.0+, Safari
			            xmlHttp=new XMLHttpRequest();
		            }
		            catch (e)
		            {
			            // Internet Explorer
			            try
			            {
				            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			            }
			            catch (e)
			            {
				            try
				            {
					            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				            }
				            catch (e)
				            {
					            alert("Your browser does not support AJAX!");
					            return false;
				            }
			            }
		            }
             GETMETHOD(xmlHttp,Request,handleresponses);
        }
        function handleresponses()
			{	
				if(xmlHttp.readyState == 4)
					{ 						
							// Successful Insertion;
							//alert("hi")		
					}
			} //end handle response

