// JavaScript Document
function getStyleObject(objectId){
    if(document.getElementById && document.getElementById(objectId)){
	    // W3C DOM
	    return document.getElementById(objectId);}else if (document.all && document.all(objectId)){
	    // MSIE 4 DOM
	    return document.all(objectId);} else if (document.layers && document.layers[objectId]){
	    // NN 4 DOM.. note: this won't find nested layers
	    return document.layers[objectId];}else{ return false;	}
}

// Java Sponsor function
var initialTop = 600;
function positionit(sElementId, itopAbsolute, iHeight){
    var dsoctop=document.all? document.documentElement.scrollTop : window.pageYOffset;
    var window_width=document.all? document.documentElement.clientWidth : window.innerWidth;
    var window_height=document.all? document.documentElement.clientHeight : window.innerHeight;
    var crossobj = getStyleObject(sElementId);
    var iTotalHeight = itopAbsolute + iHeight;
    var iNewTop;
    
    if(crossobj.style != null){
        if (document.all || document.getElementById)
        {
            if (window_height < iTotalHeight)
            {
                if (dsoctop <= (iTotalHeight - window_height))
                {
                    iNewTop = itopAbsolute;
                    //crossobj.style.top = itopAbsolute
                }
                else 
                {
                    iNewTop = ( dsoctop - (iHeight + window_height) );
                    //crossobj.style.top = ( dsoctop - iHeight + window_height )
                }
                
                crossobj.style.top = iNewTop + "px";
            }
            else
            {
                if(crossobj.offsetTop > dsoctop && initialTop==0)
                {
                    //initialTop = crossobj.offsetTop - 100;
                    initialTop = crossobj.offsetTop;
                }
                else if(crossobj.offsetTop > window_height)
                {
                    if(dsoctop < initialTop)
                    {
                        crossobj.style.top = "0px";
                    }
                    else
                    {
                        crossobj.style.top = dsoctop + "px";
                    }
                }
                
                if(dsoctop > initialTop)
                {
                    iNewTop = dsoctop - initialTop;
                    //crossobj.style.top = dsoctop - initialTop;
                    crossobj.style.top = iNewTop + "px";
                }
            }
        }
        else if (document.layers)
        {
            crossobj.top = dsoctop + itopAbsolute;
        }
    }
}
function getHeight(sElementId)
{
    var crossobj = getStyleObject(sElementId);  
    if(crossobj != null){return crossobj.height;}
    else{return 0;}
}
function hideElement(sElementId)
{
    var crossobj = document.getElementById(sElementId);    
    if(crossobj != null){crossobj.style.display = "none";}
}
function hideFlash(sElementName,sPanelId,iTime,bIsBigSponsor)
{
    var crossobj = document.getElementsByName(sElementName);
    if(!bIsBigSponsor){
        //It's a small sponsor of brazil, won't dissapear ever
        clearInterval(flashInterval); 
    }  
    else{
        //The sponsor will dissapear
        if(crossobj[0] != null){
            if(crossobj[0].readyState){
                if(crossobj[0].readyState==4){
                    setInterval("hideElement('" + sPanelId + "')", iTime);
                    clearInterval(flashInterval); 
                }
            }else{
                setInterval("hideElement('" + sPanelId + "')", iTime);
                clearInterval(flashInterval); 
            }
        }
    }   
}
function submitOnEnter(clientId, controlId,evt)
{
    var charCode;   
    if(evt.which != null)
     charCode = evt.which;
    else
     charCode = evt.keyCode;  
   
    
    if(charCode==13){
        evt.cancel = true;
        var button = document.getElementById(clientId);
        button.click();
        return false;
    }
    return true;
}

function preview(cad, texto, w, h, scroll)
{ 
    var windoew ;
    windoew = window.open(cad, texto, "location=no,height="+ h + ",width=" + w + ",scrollbars=" + scroll);
}
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
}
function ReturnFalse(){return false;}
function showHidePnl(pnl1,pnl2,imgId,urlCollapsed,urlExpanded){
    var opnl1 = document.getElementById(pnl1);
    var opnl2 = document.getElementById(pnl2);
    var oimg = document.getElementById(imgId);
    
    if(opnl1.style.display == "none")
    {
        opnl1.style.display = "block";
        opnl2.style.display = "none";
        oimg.src = urlCollapsed;
    }
    else if(opnl2.style.display == "none")
    {
        opnl1.style.display = "none";
        opnl2.style.display = "block";
        oimg.src = urlExpanded;
    }
}

function valResultWithServices(txtId,lstId,srv1Id,srv2Id,validateState,msg){
    var txt = document.getElementById(txtId);
    var lst = document.getElementById(lstId);
    var srv1 = document.getElementById(srv1Id);
    var srv2 = document.getElementById(srv2Id);
  //  var srv1 = document.getElementById('ctl00_C1_SBCtr_ddlChooseFoodType_comboBox_dmtxt');
 //   var srv2 = document.getElementById('ctl00_C1_SBCtr_ddlChoosePlaceType_comboBox_dmtxt');
                                        
    var res = true;
    if(txt){
        if(validateState == 'true')
        {
            // guia de hoteles y guia de bares
 	        if(srv1 != null && srv2 != null)
	        { 
	            res = (txt.value.length > 0 && lst.value.length > 0) || (srv1.value.length > 0 && lst.value.length > 0) || (srv2.value.length > 0 && lst.value.length > 0);
            }
            // guia general
            else{
		        res = (txt.value.length > 0 && lst.value.length > 0) ;
            }

        }
        else
        {
		// guia de hoteles y guia de bares
 	    	if(srv1 != null && srv2 != null)
	    	{
            		res = txt.value.length > 0 || srv1.value.length > 0 || srv2.value.length > 0 
		}
		// guia general
		else{
            		res = txt.value.length > 0
		}
        }
        if(!res)
        {
            alert(msg);
        }   
    }  
    return res;
}

function valResult(txtId,lstId,validateState,msg){
    var txt = document.getElementById(txtId);
    var lst = document.getElementById(lstId);
    var res = true;
    
    var lstServicesOne = document.getElementById("ctl00_C1_servicesDddCtrl_txtServiceBoxOne");
    var lstServicesTwo = document.getElementById("ctl00_C1_servicesDddCtrl_txtServiceBoxTwo");
    
    if(txt){
        if(validateState == 'true')
        {
		  res = (txt.value.length > 0 && lst.value.length > 0) ;
            		
        }
        else
        {
             res = txt.value.length > 0	
        }
        if (lstServicesOne!=null || lstServicesTwo !=null)
        {
            res=false;
        }
        else
        {
            if(!res)
            {
                alert(msg);
            }
        }  
    }  
    return res;
}

function valResultAdress(txtId,txtAdrs,lstId,validateState,msg){
    var txt = document.getElementById(txtId);
    var lst = document.getElementById(lstId);
    var txtAds = document.getElementById(txtAdrs)
    var res = true;
    if(txt){
        if(validateState == 'true')
        {
		    res = (txt.value.length > 0 && txtAds.value.length > 0 && lst.value.length > 0) ;
        }
        else
        {
             res = (txt.value.length > 0 && txtAds.value.length > 0	)
        }
        if(!res)
        {
            alert(msg);
        }   
    }  
    return res;
}


/*function valResult(txtId,lstId,validateState,msg){
    var txt = document.getElementById(txtId);
    var lst = document.getElementById('ctl00_C1_SBCtr_ddlChooseState_comboBox_dmtxt');
    var srv1 = document.getElementById('ctl00_C1_SBCtr_ddlChooseFoodType_comboBox_dmtxt');
    var srv2 = document.getElementById('ctl00_C1_SBCtr_ddlChoosePlaceType_comboBox_dmtxt');
    var res = true;
    if(txt){
        if(validateState == 'true')
        {
                    res = (txt.value.length > 0 && lst.value.length > 0) || (srv1.value.length > 0 && lst.value.length > 0) || (srv2.value.length > 0 && lst.value.length > 0);
          //  res = (txt.value.length > 0 && lst.value != '*') || (srv1.value.length > 0 && lst.value != '*') || (srv2.value.length > 0 && lst.value != '*');
        }
        else
        {
            res = txt.value.length > 0 || srv1.value.length > 0 || srv2.value.length > 0 
           // res = txt.value.length > 0
        }
        if(!res)
        {
            alert(msg);
        }   
    }  
    return res;
}*/



function valState(lstId,msg){
    var lst = document.getElementById(lstId);
    var res = lst.value != '';
    if(!res){alert(msg);}    
    return res;
}

/*The function moreDest is used to create more text boxes for their 
mail sent to more recipients. Are maximum five*/
num=0;
function moreDest()
{ 
  var tabla= document.getElementById("tableDatos");   
  
  if (tabla.rows.length<=4)
  {
      num++;
      var tr = document.createElement("tr"); 
      var fil='fila'+num;
      tr.setAttribute('id',fil);            
      var td = document.createElement("td"); 
      var td1 = document.createElement("td"); 
      var td2 = document.createElement("td");            
      var nd= 'tdNomeDest'+num;
      td.setAttribute('id',nd);      
      td.innerHTML='<input type='+'text'+' id='+'txtNomeDest'+num+' class='+'txtBox'+' runat='+'server'+'\>'      
      var ed= 'tdEmailDest'+num;
      td1.setAttribute('id',ed);      
      td1.innerHTML='<input type='+'text'+' id='+'txtEmailDest'+num+' class='+'txtBox'+' runat='+'server'+'\>'        
      var im='imgMenosDest'+num;      
      td2.setAttribute('id',im);      
      td2.innerHTML="<img src='../../App_Themes/GuiaMais/images/ico_remover_b.gif' onclick='menosDest()' alt=''>";               
      tr.appendChild(td);
      tr.appendChild(td1);
      tr.appendChild(td2);
      tabla.lastChild.appendChild(tr);  

  } 
  else
  {
    alert("Maximo 5!!!");

  }
 
}

/*The function menosDest is used to delete text boxes target for sending mail.
 Eliminate maximum four.*/
function menosDest()
{   
  var tabla= document.getElementById("tableDatos");     
  var nMro= tabla.rows.length -1;
  if (tabla.rows.length>1)
  {         
     var tr= document.getElementById("fila"+String(nMro));   
     var td = document.getElementById("tdNomeDest"+String(nMro));     
     var td1 = document.getElementById("tdEmailDest"+String(nMro));    
     var td2= document.getElementById("imgMenosDest"+String(nMro));   
     var padre = tr.parentNode;       
     tr.removeChild(td);
     tr.removeChild(td1);
     tr.removeChild(td2);         
     padre.removeChild(tr);       
     num--; 
  }  
  else
  {
    alert("No permitido.!!!");
  }

}

/*The function cargarEmails is used to store the data in a hidden field entered 
in the controls dynamic target and interact with this code .Net. The input 
parameters oSrc y args that are used to add a aspx control customvalidator  */
function cargarEmails(oSrc, args)
{   
  var tabla= document.getElementById("tableDatos");     
  var hidden = document.getElementById("hdEmails").value;
  var num= tabla.rows.length -1;
  
  for (i=1; i<=num; i++)
  {       
     var txtNomeDest = document.getElementById("txtNomeDest"+String(i)).value;     
     var txtEmailDest = document.getElementById("txtEmailDest"+String(i)).value;              
     hidden=  hidden + txtNomeDest+";"+txtEmailDest+"|";        
  }  
    document.getElementById("hdEmails").value=hidden;
}

/*The function actionsDdlListings is used to redirect options combo of listingControl.
 In this case for the option of sending emails, opens a popup loading page SendEmail.aspx. 
 The numListing input parameter is an integer that indicates the number of listing appearing 
 on the Results page and sCategoryTree results is a string that brings tree categories  */
function actionsDdlListings(numListing,sCategoryTree)
{   
  if(numListing*1<=9)
    var numLst="0"+numListing; 
  else
    var numLst=numListing   
   
  var ddlListings= document.getElementById("ctl00_C1_RR_ctl"+numLst+"_lst_selecEmail");

       var action=ddlListings.selectedIndex;        
       var texto = ddlListings.options[action].text;
       switch(texto)
       {
            case "Veja Ofertas":
                ddlListings.options[0].selected=true;  
                window.open(ddlListings.options[action].value,"_self");       
                break;
            case "Como chegar":
                ddlListings.options[0].selected=true;  
                window.open(ddlListings.options[action].value,"_self");
                break;
            //enviar email 
            case "Enviar por e-mail":
                  ddlListings.options[0].selected=true;  
                  window.open (ddlListings.options[action].value+"&CAT_TREE="+sCategoryTree,'CustomPopUp','width=700, height=450, menubar=no, resizable=no,top=-10px,scrollbars=yes')
               break;
            case "Saiba Mais":
                   ddlListings.options[0].selected=true;  
                   window.open(ddlListings.options[action].value,"_self");
                   break;
            case "Visite o Site":
                   ddlListings.options[0].selected=true;  
                   window.open(ddlListings.options[action].value);
                   break;
            case "Cupom":
                    ddlListings.options[0].selected=true;  
                    window.open(ddlListings.options[action].value,'Cupon', 'width=590, height=534, scrollbars=no');
                   break;
            case "Tour Virtual":
                   ddlListings.options[0].selected=true;  
                   window.open(ddlListings.options[action].value,"TourVirtual",'width=410,height=370, scrollbars=no');
                   break; 
            case "Hot Media":
                   ddlListings.options[0].selected=true;  
                   window.open(ddlListings.options[action].value,"HotMedia",'width=410,height=370, scrollbars=no');
                   break; 
            case "Meu GuiaMais":
                    ddlListings.options[0].selected=true;  
                    location.href=ddlListings.options[action].value;
                    break;
       }
      
  
   ddlListings.selectedIndex=0;
}

/*The function actionsDdlListProds is used to redirect options combo of Saiba Mais. */
function actionsDdlListProds()
{      var ddlListings= document.getElementById("ctl00_C1_listProducts");
       var action=ddlListings.selectedIndex;        
       var texto = ddlListings.options[action].text;
       switch(texto){
            //enviar email 
            case "Enviar por e-mail":
               var valor=ddlListings.options[action].value;   
               window.open ("/pagamanet/web/SendEmail.aspx?LST_COMPANY="+valor+"&CAT_TREE="+sCategoryTree,'CustomPopUp','width=700, height=450, menubar=no, resizable=no,top=-10px,scrollbars=yes');               
               break;
            case "Saiba Mais":
                   window.open(ddlListings.options[action].value,"_self");
                   break;
            case "Visite o Site":
                   window.open(ddlListings.options[action].value);
                   break;
            case "Cupom":
                    window.open(ddlListings.options[action].value,'Cupon', 'width=590, height=534, scrollbars=no');
                   break;
            case "Tour Virtual":
                   window.open(ddlListings.options[action].value,"TourVirtual",'width=410,height=370, scrollbars=no');
                   break; 
            case "Hot Media":
                   window.open(ddlListings.options[action].value,"HotMedia",'width=410,height=370, scrollbars=no');
                   break; 
            case "Veja Ofertas":
                window.open(ddlListings.options[action].value,"_self");       
                break;
            case "Como chegar":
                window.open(ddlListings.options[action].value,"_self");
                break;
                             
       }  
   ddlListings.selectedIndex=0;
}

/*The function printListings is used to scroll the page of results and 
take values come checkbox selected and well send them to the page PrintListings*/
function printListings()
{
  var companyLst="";
  var hdNumListings = document.getElementById("ctl00_C2_hdNumListings").value;  
  var hdMsgError = document.getElementById("ctl00_C2_hdMsgError").value;
  var hdCategoryTree = document.getElementById("ctl00_C2_hdcategoryTree").value;
  
  var flag=false;
  for (i=0; i<hdNumListings; i++)
  {       
     if (i<=9)
        var numLst="0"+i; 
      else
         var numLst=i;  
         
     var checkBox= document.getElementById("ctl00_C1_RR_ctl"+numLst+"_lst_chkListing");
     if (checkBox.checked == true )
     {
         companyLst=companyLst+checkBox.value+"|";  
         flag=true;
     }     
  }
  if (flag==true)  
     window.open ("/pagamanet/web/PrintListings.aspx?VALOR="+companyLst+"&CAT_TREE="+hdCategoryTree,'CustomPopUp','width=700, height=400, menubar=no, resizable=no,top=-10px,scrollbars=yes');
  else
    alert(hdMsgError);
}

/*The function printPageLst is used to print a page  */
function printPageLst()
{
   window.print();      
}
function changeStyle(){

}
function showList(listID){
 var list = document.getElementById(listID); 
 list.click();
}
function toggleAccordionTab( divTitleId, divContentId)
{
    var divAccordion = document.getElementById('advancedSearchAccordion');
    var arDivs = divAccordion.getElementsByTagName('div');
    var sId;

    for(i=0; i<arDivs.length; i++)
    {
        sId = arDivs[i].id;
        if(sId.indexOf("pnlTitle") != -1 && sId != divTitleId)
        {
            divOTitle = document.getElementById(sId);
            divOTitle.className = 'divTabTitle';
        }
        else if(sId.indexOf("pnlContent") != -1 && sId != divContentId)
        {
            divOContent = document.getElementById(sId);
            divOContent.style.visibility = 'hidden';
            divOContent.style.display = 'none';
        }
    }
    //Hide-Show the clicked layer
    var divTitle = document.getElementById(divTitleId);
    var divContent = document.getElementById(divContentId);
     
    if(divTitle.className == 'divTabTitle')
    {
        divTitle.className = 'divTabTitleS';
        divContent.style.visibility = 'visible';
        divContent.style.display = 'block';
    }
    else
    {
        divTitle.className = 'divTabTitle';
        divContent.style.visibility = 'hidden';
        divContent.style.display = 'none';
    }
}
var directory=''
var urlFromOthers=''
function toggleTitleDirTab(divTitle,divCategories,num,idDirectory,sUrlFrom )
{
    var divTitle = document.getElementById(divTitle);
    var divCategorie = document.getElementById(divCategories);       
    var showContentId = "showContent"+num;
    var divShowContent = document.getElementById(showContentId);
    directory=idDirectory; 
    urlFromOthers=sUrlFrom;
    
    if(!divShowContent)    
    {
        divCategorie.style.visibility = 'visible';
        divCategorie.style.display = 'block';        
        divCategorie.className = 'divContentCatVis';                         
        findCategoriesOthers("ctl00_SBoxControl_TextBoxWhat","ctl00_SBoxControl_TextBoxCity",divCategories,idDirectory,sUrlFrom);                 
        var div =CreateShowContentDiv(showContentId,divTitle,divCategorie); 
        div.className = 'divContentShow';      
    }
    else
    {
        divCategorie.style.visibility = 'hidden';
        divCategorie.style.display = 'none';
        divCategorie.className = 'divContentCat';       
        document.body.removeChild(divShowContent);		
     
    }
}	

/*****method which calls the handler of ajax to perform consulting business to 
control search for refinements by others directories*****/
var pnlContOthers='';
function findCategoriesOthers(txtWhatId,txtWhereId,pnlContainerID,idDirectory,sUrlFrom)
{
    var txtSearch = document.getElementById(txtWhatId);
    var txtWhere = document.getElementById(txtWhereId);    
    divContainer = document.getElementById(pnlContainerID);    
    pnlContOthers= pnlContainerID;  
    var hdPageParams = document.getElementById("ctl00_C2_hdPageParams").value;       
    var listParams= hdPageParams.split('|');
    var tipo = getURLParam("tipo");  
    var state=''; var country=''; var lng=''; var query='';var page='';var dir='';var catId=''; var what=''; var where='';      
        
    for (var i=0; i<listParams.length;i++)
    {
      var params= listParams[i].split('*'); 
      var paramName=params[0];
      if (params[1]!='')
      {
          if (paramName=='STATE')
                state=params[1];
          else if (paramName=='COUNTRY')
                country=params[1];                  
          else if (paramName=='LNG')
                 lng=params[1];
          else if (paramName=='QUERY')
                 query=params[1];
          else if (paramName=='DIR')
                 dir=params[1];                      
          else if (paramName=='PAGE')
                 page=params[1];  
          else if (paramName=='CATID')
                 catId=params[1];     
          else if (paramName=='WHAT')
                 what=params[1];         
          else if (paramName=='WHERE')
                 where=params[1];      
      }
    }      
    
    var params="OP=findWordRelate&search="+what+"&where="+where+"&state="+state+"&country="+country+"&lng="+lng+"&query="+query+"&dir="+idDirectory+"&catId="+catId+"&UR="+sUrlFrom+"&tipo="+tipo;   
    var urls=location.protocol+"//"+location.host+"/"+"Handlers/AjaxHandler.ashx?";  
    loadXMLDoc(urls+params,"CatsOthers");  
    
    //loadXMLDoc("Handlers/AjaxHandler.ashx?OP=findWordRelate&search="+what+"&where="+where+"&state="+state+"&country="+country+"&lng="+lng+"&query="+query+"&dir="+idDirectory+"&catId="+catId+"&UR="+sUrlFrom+"&tipo="+tipo,"CatsOthers"); 
    
}


/*****method which calls the handler of ajax to perform consulting business to 
control search for refinements*****/
var pnlContainer='';
var dirGeneral='';
var urlFrom='';
function findCategories(txtWhatId,txtWhereId,pnlContainerID,sUrlFrom)
{
    var txtSearch = document.getElementById(txtWhatId);
    var txtWhere = document.getElementById(txtWhereId);    
    divContainer = document.getElementById(pnlContainerID);    
    pnlContainer= pnlContainerID;  
    urlFrom=sUrlFrom;
    var hdPageParams = document.getElementById("ctl00_C2_hdPageParams").value;       
    var listParams= hdPageParams.split('|');
    var tipo = getURLParam("tipo");  
    
    var state=''; var country=''; var lng=''; var query='';var page='';var dir='';var catId=''; var what=''; var where='';   
        
    for (var i=0; i<listParams.length;i++)
    {
      var params= listParams[i].split('*'); 
      var paramName=params[0];
      if (params[1]!='')
      {
          if (paramName=='STATE')
                state=params[1];
          else if (paramName=='COUNTRY')
                country=params[1];                  
          else if (paramName=='LNG')
                 lng=params[1];
          else if (paramName=='QUERY')
                 query=params[1];
          else if (paramName=='DIR')
          {
              dir=params[1];                      
              dirGeneral=dir;
          }
          else if (paramName=='PAGE')
                 page=params[1];  
          else if (paramName=='CATID')
                 catId=params[1];
          else if (paramName=='WHAT')
                 what=params[1];         
          else if (paramName=='WHERE')
                 where=params[1];      
      }
    }     
    var params="OP=findWordRelate&search="+what+"&where="+where+"&state="+state+"&country="+country+"&lng="+lng+"&query="+query+"&dir="+dir+"&catId="+catId+"&UR="+sUrlFrom+"&tipo="+tipo;   
    var urls=location.protocol+"//"+location.host+"/"+"Handlers/AjaxHandler.ashx?";  
    loadXMLDoc(urls+params,"categories");  
  
   //loadXMLDoc("Handlers/AjaxHandler.ashx?OP=findWordRelate&search="+what+"&where="+where+"&state="+state+"&country="+country+"&lng="+lng+"&query="+query+"&dir="+dir+"&catId="+catId+"&UR="+sUrlFrom+"&tipo="+tipo,"categories");     
  
    
    
}

/*This function is used to change the big image in Saiba Mais*/
function changeImgSrc(pImgObject, pFilename) {
		document.getElementById(pImgObject).src = pFilename;
	}

/*This method is used by the hanlder and class XMLHTTP*/
var xmlhttp;
function loadXMLDoc(url,page)
{
    xmlhttp=null;
    if (window.XMLHttpRequest)
    {
      // code for Firefox, Opera, IE7, etc.
      xmlhttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
       // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (xmlhttp!=null)
    {
      if (page=="sections")
        xmlhttp.onreadystatechange=state_Change;
      else if (page=="categories")
        xmlhttp.onreadystatechange=state_Categories;  
      else if (page=="CatsOthers")
        xmlhttp.onreadystatechange=state_CatOthers;             
      else if(page=="locationData")
        xmlhttp.onreadystatechange=state_GetLocations;
      else if(page=="statistics")
        xmlhttp.onreadystatechange=state_GetStatisticsResult;    
      xmlhttp.open("GET",url,true);
      xmlhttp.send(null);
    }
    else
    {
        alert("Your browser does not support XMLHTTP.");
    }
}
/*****method that reaches the handler's response to sections*****/
function state_Change()
{
      
    if (xmlhttp.readyState==4)
    {
      if (xmlhttp.status==200)
      {
         var numLisCnt=(numList*1)+1;
         if(numLisCnt*1<=9)
            numLisCnt="0"+numLisCnt;                   
        
        var lCategories=xmlhttp.responseText;              
        var divContent = document.getElementById("ctl00_C1_RR_ctl"+numList+"_lst_oPanelCategory2");      
        var divSelectedSig = document.getElementById("ctl00_C1_RR_ctl"+numLisCnt+"_lst_oPanelTitleTwo");
        var hdParamsLink= document.getElementById("ctl00_C1_RR_ctl"+numList+"_lst_hdParamsLink");   
        
        var hdParamsSee= document.getElementById("ctl00_C2_hdWordParams").value;                         
        var listParams= hdParamsSee.split('|');
        var dominio17='';
            
        for (var i=0; i<listParams.length;i++)
        {
            var params= listParams[i].split('*'); 
            var paramName=params[0];
            if (params[1]!='')
            {
               if (paramName=='DOMINIO17')
                  dominio17=params[1];                  
            }
       }               
        
        if (lCategories!='')
        {    
            var lSection='';
            divContent.innerHTML='';
            lSection= lCategories.split(';');
            for (var j=0; j<lSection.length-1;j++)
            {
                var lCatId= lSection[j].split('/');    
                var link=dominio17+hdParamsLink.value+"&ica="+lCatId[1]+"&stc=staticSection"+"&ie="+sCompanyId;                 
                var div = document.createElement('div');     
                div.id='oPanelCategoryCont'+j;
                if (j>=1)
                   div.className='CmpSectionCat';  
                div.innerHTML='<a  class=CmpSection href='+link+'>'+lCatId[0]+'</a>';            
                //div.innerHTML='<a  class=CmpSection onclick=saveStatistics() href='+link+'>'+lCatId[0]+'</a>';           
                divContent.appendChild(div);   
             }           
               
        }
        var divSelected = document.getElementById("ctl00_C1_RR_ctl"+numList+"_lst_oPanelCategory");
        var showContentId = "showContent" + numList;
        var div = CreateShowContentDiv(showContentId,divSelected,divContent);
        div.innerHTML=divContent.innerHTML;
      }      
    }
}

/**methos of reaching the response handler for control of sections**/
function saveStatistics()
{
    var directory = getURLParam("dir");
    var searchType = getURLParam("tbu");
    var countryId = getURLParam("ipa");
    var stateId = getURLParam("ies");
    var cityId = getURLParam("ici"); 
    var query=getURLParam("qid");    
       
   loadXMLDoc("Handlers/AjaxHandler.ashx?OP=Statistics&idCmp="+sCompanyId+"&dir="+directory+"&tbu="+searchType+"&ipa="+countryId+"&ies="+stateId+"&ici="+cityId+"&qid="+query,"statistics");
}

/***method of reaching the response handler for control of a search refinements***/
function state_Categories()
{     
    if (xmlhttp.readyState==4)
    {
      if (xmlhttp.status==200)
      {
        var lCategories=xmlhttp.responseText;         
        if (lCategories!='')
        {
            var listTerms= lCategories.split('|');        
            
            var vName;
                     
            divContainer = document.getElementById(pnlContainer);            
            if (divContainer==null)
                divContainer=pnlContainer;                     
          
            //Starts to create the HTML
            //Creates the main element for the list
            var arLinks = divContainer.getElementsByTagName('a');           
            var a=arLinks.length*1;        
            while(divContainer.hasChildNodes())
            {	
                if (a>0)
                {
                    a=a-1;
                    divContainer.removeChild(arLinks[a]);                                        
                }
                else
                    break;
                
            }  
            //label and Image remove
            divContainer.removeChild(divContainer.lastChild);             
            
            var hdParamsSee= document.getElementById("ctl00_C2_hdWordParams").value;                         
            var listParams= hdParamsSee.split('|');
            var wordParams=''; var dominio17=''; var dominio18=''; var dominio20='';var dominioGuias='';
            
            for (var i=0; i<listParams.length;i++)
            {
                var params= listParams[i].split('*'); 
                var paramName=params[0];
                if (params[1]!='')
                {
                    if (paramName=='WORDPARAMS')
                        wordParams=params[1];
                    else if (paramName=='DOMINIO17')
                        dominio17=params[1];                  
                    else if (paramName=='DOMINIO18')
                        dominio18=params[1];
                    else if (paramName=='DOMINIO20')
                        dominio20=params[1];    
                    else if (paramName=='DOMINIOGUIAS')
                        dominioGuias=params[1];    
                       
                 }
            
            }               
            var url='';      
            if (dirGeneral=='18')
                url=dominio18;
            else if (dirGeneral=='20')
                url=dominio20;
            else if (dirGeneral=='17' && urlFrom=='~/Results.aspx')
                url=dominio17;
            else 
                url=dominioGuias;                                
           
            var tipo = getURLParam("tipo");     
            //add new hyperlink
            for (var i=0; i<listTerms.length;i++)
            {       
               if (listTerms[i]!='')
               { 
                   var listCatID= listTerms[i].split('/');        
                   vA = document.createElement('a');      
                   if (urlFrom=='~/Results.aspx')             
                    vA.href=url+wordParams+"&ica="+listCatID[1]+"&shr=2&tid=3";
                   else
                   {
                     var listCatName=listCatID[0].split(':');    
                     vA.href=url+wordParams+"&ica="+listCatID[1]+"&shr=2&tid=3"+"&tipo="+tipo+"&CatName="+listCatName[0];
                   }
                   vName = "| "+listCatID[0];
                   vA.title = vName;
                   vA.innerHTML = vName;
                   vA.className="txtSmallGray";
                   divContainer.appendChild(vA);                  
               }
            } 
             
             
           // add new image
            var arImage = divContainer.getElementsByTagName('input');           
            var img=arImage.length*1;
            var urlImg=location.protocol+"//"+location.host+"/";
             
            vI = document.createElement('div'); 
            vI.innerHTML="<img src='"+ urlImg +"App_Themes/GuiaMais/images/i-SeeLess.gif' onclick='findCategoriesR()' alt=''>";
            vI.className="imageMore";
            vI.id="imgMenos";
            divContainer.appendChild(vI);                         
             
             
        }               
      }      
    }
}
/****method that makes the event to see fewer words related****/
function findCategoriesR() 
{
    divContainer = document.getElementById(pnlContainer);     
              
    if (divContainer==null)
        divContainer=pnlContainer;   
    var arLinks = divContainer.getElementsByTagName('a');           
    var a=arLinks.length*1;        
    while(divContainer.hasChildNodes())
    {	
       if (a>4)
       {
          a=a-1;
          divContainer.removeChild(arLinks[a]);                                        
       }
       else
           break;
            
    } 
 
    divContainer.removeChild(divContainer.lastChild);      
    var urlImg=location.protocol+"//"+location.host+"/";
    vI = document.createElement('div'); 
    vI.innerHTML="<img src='"+urlImg+"App_Themes/GuiaMais/images/i-SeeMore.gif' onclick='findCSeeMore()' alt=''>";
    vI.className="imageMore";
    vI.id="imgMenos";
    divContainer.appendChild(vI);   
    
}
/****method used by the method findCategoriesR****/
function findCSeeMore()
{ 
  findCategories("ctl00_SBoxControl_TextBoxWhat","ctl00_SBoxControl_TextBoxCity",pnlContainer,urlFrom);  
}

/***method of reaching the response handler for control of a search refinements others directories***/
function state_CatOthers()
{     
    if (xmlhttp.readyState==4)
    {
      if (xmlhttp.status==200)
      {
        var lCategories=xmlhttp.responseText;         
        if (lCategories!='')
        {
            var listTerms= lCategories.split('|');      
            var vName;
                                 
            divContainer = document.getElementById(pnlContOthers);
            if (divContainer==null)
                divContainer=pnlContOthers;            
            
            var hdParamsSee= document.getElementById("ctl00_C2_hdWordParams").value;              
            var listParams= hdParamsSee.split('|');
            var wordParams=''; var dominio17=''; var dominio18=''; var dominio20=''; var dominioGuias='';
        
            for (var i=0; i<listParams.length;i++)
            {
                var params= listParams[i].split('*'); 
                var paramName=params[0];
                if (params[1]!='')
                {
                    if (paramName=='WORDPARAMS')
                        wordParams=params[1];
                    else if (paramName=='DOMINIO17')
                        dominio17=params[1];                  
                    else if (paramName=='DOMINIO18')
                        dominio18=params[1];
                    else if (paramName=='DOMINIO20')
                        dominio20=params[1];  
                    else if (paramName=='DOMINIOGUIAS')
                        dominioGuias=params[1];         
                 }
            }         
            //Starts to create the HTML
            //Creates the main element for the list
            var arLinks = divContainer.getElementsByTagName('a');           
            var a=arLinks.length*1; 
            var url='';      
            if (directory=='18' && urlFromOthers=='~/Results.aspx')
                url=dominio18;
            else if (directory=='20'&& urlFromOthers=='~/Results.aspx')
                url=dominio20;
            else if (directory=='17' && urlFromOthers=='~/Results.aspx')
                url=dominio17;
            else 
                url=dominioGuias;   
            
            if (a==0)
            {          
                //add new hyperlink
                for (var i=0; i<listTerms.length;i++)
                {       
                   if (listTerms[i]!='')
                   { 
                       var listCatID= listTerms[i].split('/');                                                 
                       vA = document.createElement('a');
                       if (urlFromOthers=='~/Results.aspx')                        
                         vA.href=url+wordParams+"&ica="+listCatID[1]+"&shr=2&tid=3";
                       else
                       {
                         var listCatName=listCatID[0].split(':');    
                         vA.href=url+wordParams+"&ica="+listCatID[1]+"&shr=2&tid=3&CatName="+listCatName[0];
                       }
                       vName = "| "+listCatID[0];
                       vA.title = vName;
                       vA.innerHTML = vName;
                       vA.className="txtSmallGray";
                       divContainer.appendChild(vA);                      
                   }
                }          
            }
        }   
       
      }      
    }
}

/****method that makes the event for graphic sections and calls the handler of ajax
 for consultation of categories****/
var numList='';   
var sCompanyId = "";
function toggleOptions(numListing,idCmp,idBrch)
{   
    sCompanyId = idCmp;
     if(numListing*1<=9)
         var numLst="0"+numListing;           
     else
         var numLst=numListing   
    numList=numLst;
    var divSelected = document.getElementById("ctl00_C1_RR_ctl"+numLst+"_lst_oPanelCategory");
    var divContent = document.getElementById("ctl00_C1_RR_ctl"+numLst+"_lst_oPanelCategory2");    
    var hdPageParams = document.getElementById("ctl00_C2_hdPageParams").value;     
    var hdParamsLink= document.getElementById("ctl00_C1_RR_ctl"+numLst+"_lst_hdParamsLink");        
    var divSelectedSig = document.getElementById("ctl00_C1_RR_ctl"+numLst+"_lst_oPanelTitleTwo");
    var showContentId = "showContent"+numLst;
	var divShowContent = document.getElementById(showContentId);
    var listParams= hdPageParams.split('|');
    
 
    
    if(!divShowContent)
    {
         divSelected.className = 'divSectionS';
         divContent.style.visibility = 'visible';         
       
        var city=''; var state=''; var country=''; var search=''; var lng=''; var query='';var page='';    
        
        for (var i=0; i<listParams.length;i++)
        {
             var params= listParams[i].split('*'); 
             var paramName=params[0];
             if (params[1]!='')
             {
                 if (paramName=='CITY')
                    city=params[1];         
                 else if (paramName=='STATE')
                    state=params[1];
                 else if (paramName=='COUNTRY')
                    country=params[1];         
                 else if (paramName=='SEARCH')
                    search=params[1];
                 else if (paramName=='LNG')
                    lng=params[1];
                 else if (paramName=='QUERY')
                    query=params[1];
                 else if (paramName=='PAGE')
                    page=params[1];                
             }
        } 
        
        var params="OP=findBranchCategories&idCmp="+idCmp+"&idBrch="+idBrch+"&city="+city+"&state="+state+"&country="+country+"&search="+search+"&lng="+lng+"&query="+query;
        var urls=location.protocol+"//"+location.host+"/"+"Handlers/AjaxHandler.ashx?"+params;  
        
        var div =CreateShowContentDiv(showContentId,divSelected,divContent);
        if (divContent.innerHTML=='')
        {
//            if (page=='Results')
//                loadXMLDoc("Handlers/AjaxHandler.ashx?OP=findBranchCategories&idCmp="+idCmp+"&idBrch="+idBrch+"&city="+city+"&state="+state+"&country="+country+"&search="+search+"&lng="+lng+"&query="+query,"sections");
            
            loadXMLDoc(urls,"sections");  
//            else 
//            {
//                page="http://"+page;
//                loadXMLDoc(page+"/Handlers/AjaxHandler.ashx?OP=findBranchCategories&idCmp="+idCmp+"&idBrch="+idBrch+"&city="+city+"&state="+state+"&country="+country+"&search="+search+"&lng="+lng+"&query="+query,"sections");
//             }               
        }
		div.innerHTML=divContent.innerHTML;
		divContent.style.visibility = 'hidden';         
        
    }
    else
    {
        divSelected.className = 'divSectionN';
        divContent.style.visibility = 'hidden';               
		document.body.removeChild(divShowContent);		

    }   
   
    
}
/*****************************************************************
*Call page Services popup ddd and ddi
*****************************************************************/
function ServicesOpenWin(nameControl,errorMsg)
{
    if (nameControl=='ddd')//control de ddd
    {
        var txtCidadeDdd =document.getElementById("ctl00_C1_servicesDddCtrl_txtServiceBoxOne").value;
        var txtStateDdd =document.getElementById("ctl00_C1_servicesDddCtrl_txtServiceBoxTwo").value;
        if (txtCidadeDdd==""||txtStateDdd=="" )
           alert(errorMsg); 
        else
        {
           window.open ("/pagamanet/web/ServicesDDD.aspx?nes="+txtStateDdd+"&nci="+txtCidadeDdd,'CustomPopUp','width=390, height=102, menubar=no, resizable=no,top=250px,scrollbars=no');     
          document.getElementById("ctl00_C1_servicesDddCtrl_txtServiceBoxOne").value="";
          document.getElementById("ctl00_C1_servicesDddCtrl_txtServiceBoxTwo").value="";
        }
    }
    else if (nameControl=='ddi')
    {
        var ddlCountry =document.getElementById("ctl00_C1_ddlCountry");
        var action=ddlCountry.selectedIndex;        
        var texto = ddlCountry.options[action].value; 
        if (texto!="*" )
        {
            window.open ("/pagamanet/web/ServicesDDI.aspx?idCountry="+texto,'CustomPopUp','width=390, height=102, menubar=no, resizable=no,top=250px,scrollbars=no');     
            ddlCountry.selectedIndex=0; 
        }
        else
           alert(errorMsg);  
    }
    
}

/****method hidden and visible service control childs***/
var pnlChildServ='';
function toggleTitleServTab(divTitle,divServices,num,idDirectory,servicesID)
{
    var divTitle = document.getElementById("ctl00_C2_SrvCtrl_"+divTitle);
    var divServices = document.getElementById("ctl00_C2_SrvCtrl_"+divServices);       
    var showContentId = "showContent"+num;
    var divShowContent = document.getElementById(showContentId);
    pnlChildServ=divServices;
    directoryServ=idDirectory;     
    
    if(!divShowContent)    
    {
        divServices.style.visibility = 'visible';
        divServices.style.display = 'block';        
        divServices.className = 'divContentCatVis'; 
        if (divServices.innerHTML=="")                        
            findChildrenServices(divTitle,divServices,idDirectory,servicesID);                 
        var div =CreateShowContentDiv(showContentId,divTitle,divServices); 
        div.className = 'divContentShow';      
    }
    else
    {
        divServices.style.visibility = 'hidden';
        divServices.style.display = 'none';
        divServices.className = 'divContentCat';       
        document.body.removeChild(divShowContent);		
     
    }
}	


/*****method which calls the handler of ajax to perform consulting business to 
control search for refinements services children*****/
var dirServices=''
function findChildrenServices(pnSerFatherID,pnSerChildID,idDirectory,servicesID)
{
    divContainer = document.getElementById(pnSerFatherID);  
    var sText=getURLParam("txb");
    var sCity = getURLParam("nci");
    var sAdress= getURLParam("sa");
    var sPhone = getURLParam("sp");
    var sState = getURLParam("ies");
    var sCountry = getURLParam("ipa");    
    var sIca = getURLParam("ica");
    var sLetter = getURLParam("let");    
    var sLanguage = getURLParam("idi");
    var sQuery = getURLParam("qid");
    var otherParams = Location_GetDataParams(1);
    dirServices=idDirectory;
    
    var params="OP=findServices&city="+sCity+"&adrs="+sAdress+"&phone="+sPhone+"&letter="+sLetter+"&services="+servicesID+"&country="+sCountry+"&state="+sState+otherParams;
    var urls=location.protocol+"//"+location.host+"/"+"Handlers/AjaxHandler.ashx?"+params;  
    loadXMLDoc(urls,"services");       
  
    
    //loadXMLDoc("Handlers/AjaxHandler.ashx?OP=findServices&city="+sCity+"&adrs="+sAdress+"&phone="+sPhone+"&letter="+sLetter+"&services="+servicesID+"&country="+sCountry+"&state="+sState+otherParams,"services");       
}

/***method of reaching the response handler for control of a search refinements***/
function state_servicesRfmt()
{     
    if (xmlhttp.readyState==4)
    {
      if (xmlhttp.status==200)
      {
        var lServices=xmlhttp.responseText;         
        if (lServices!='')
        {
            var listServs= lServices.split('|');        
            
            var vName;
                     
            divServices = document.getElementById(pnlChildServ);            
            if (divServices==null)
                divServices=pnlChildServ;                     
          
                  
            var hdParamsSee= document.getElementById("ctl00_C2_hdWordParams").value;                         
            var listParams= hdParamsSee.split('|');
            var wordParams=''; var dominio17=''; var dominio18=''; var dominio20='';var dominioGuias='';
            
            for (var i=0; i<listParams.length;i++)
            {
                var params= listParams[i].split('*'); 
                var paramName=params[0];
                if (params[1]!='')
                {
                    if (paramName=='WORDPARAMS')
                        wordParams=params[1];
                    else if (paramName=='DOMINIO17')
                        dominio17=params[1];                  
                    else if (paramName=='DOMINIO18')
                        dominio18=params[1];
                    else if (paramName=='DOMINIO20')
                        dominio20=params[1];    
                    else if (paramName=='DOMINIOGUIAS')
                        dominioGuias=params[1];    
                       
                 }
            
            }   
            
                 
           var hdPageParams = document.getElementById("ctl00_C2_hdPageParams").value;       
           var listPageCat= hdPageParams.split('|');      
           var catId='';          
           for (var i=0; i<listPageCat.length;i++)
           {
              var paramsCat= listPageCat[i].split('*'); 
              var paramNameCat=paramsCat[0];
              if (paramsCat[1]!='')
              {                 
                  if (paramNameCat=='CATID')
                    catId=paramsCat[1];                         
              }
           } 
                        
            var url='';      
            if (dirServices=='18')
                url=dominio18;
            else if (dirServices=='20')
                url=dominio20;
            else if (dirServices=='17')
                url=dominio17;      
                            
            var sText=getURLParam("txb");                                 
            //add new hyperlink
            for (var i=0; i<listServs.length;i++)
            {       
               if (listServs[i]!='')
               {             
                   var listServID= listServs[i].split('/');        
                   vA = document.createElement('a');                   
                   vA.href=url+wordParams+"&srv="+listServID[1]+"&shr=3"+"&txb="+sText+"&ica="+catId;;
                   vName = "| "+listServID[0];
                   vA.title = vName;
                   vA.innerHTML = vName;
                   vA.className="txtSmallGray";
                   divServices.appendChild(vA);                  
               }
            }      
        }               
      }      
    }
}
/******************************************************************
 *Adds a div to the body to show categories
 *****************************************************************/
function CreateShowContentDiv(showContentId,divSelected,divContent)
{
        div = document.getElementById(showContentId);
        if(!div)
        {
            posX1 = findPosX(divSelected);
	        posY1 = findPosY(divSelected);
	        posY1 =posY1 + divSelected.offsetHeight;
	        div = document.createElement("DIV");
	        div.className=divContent.className;
	        div.style.display = "block";
	        div.style.visibility="visible";
	        div.style.position="absolute";
	        div.style.top=posY1+"px";
	        div.style.left=posX1+"px";
	        div.style.overflow="auto";
	        div.id=showContentId;
	        div.style.zIndex = "9999";
	        document.body.appendChild(div);
	    }
	    return div;	    
}

/*******************************************************************************************
 *ComboBoxControl Functions
 *
 *	ComboBox
 *	By Jared Nuzzolillo
 *
 *	Updated by Erik Arvidsson
 *	http://webfx.eae.net/contact.html#erik
 *	2002-06-13	Fixed Mozilla support and improved build performance
 *
 *  Modified for Publicar S.A by Odahir Rolando Salcedo Tangarife o-salcedo@publicar.com
 *
 *******************************************************************************************/
//ComboBoxControl array
Global_combo_array    = new Array();
//z-index for item list
Global_combo_COMBOBOXZINDEX = 9999; 
//Current active option list
Global_optlist_id    = '';

Global_run_event_hook = true;

Global_combo_selectedIntex = -1;

Global_combo_item_id = '_ComboBox_item_';

/**************************************************
 * Adds a comboBox into a global array of controls
 **************************************************/
function ComboBox_addCombo(combo)
{
	Global_combo_array[combo.id]=combo
}
/**************************************************
 * Creates a new comboBox instance
 * @param comboBoxName, name of the current comboBoxControl
 * @param optListId, item list id
 * @param txtViewId, display text control id
 * @param txtValId, value text control id
 * @param parentId, parent component id
 * @param itemListClass, item list css class name
 * @param itemClass, individual item css class name
 * @param itemOverClass, individual item css class name, when onMouseOver is fired
 * @param comboBoxOptions, comboBox options format as an string
 *        each item= <list text>|<value>|<selected display text>   
 *        option list=<item>;<item>;<item>, etc...
 **************************************************/
function ComboBox(comboBoxName,optlistId,txtViewId,txtValId,parentId,itemListClass,itemClass,itemOverClass,comboBoxOptions)
{
	this.id = comboBoxName;
	this.optlistId = optlistId;
	this.txtViewId = txtViewId;
	this.txtValId = txtValId;
	this.parentId = parentId;
	this.itemListClass = itemListClass;
	this.itemClass = itemClass;
	this.itemOver = itemOverClass;
	this.options = new Array();
	this.expops = new Array();
	ComboBox_addItemsToArray(this.options,comboBoxOptions);
	
}   

/**************************************************************************
 * Process a items string into item objects and puts it into an array of options
 * @param optionArray, array of options to be filled
 * @param comboBoxOptions, formated string with options information
 **************************************************************************/
function ComboBox_addItemsToArray(optionArray,comboBoxOptions)
{
	//gets an array of items
	var items = new Array();
	var itemElems = new Array();
	items = comboBoxOptions.split(';');
	for(i=0;i<items.length;i++)
	{
		itemElems = items[i].split('|');
		optionArray[optionArray.length] = new ComboBoxItem(itemElems[0],itemElems[1],itemElems[2]);
	}
}

/****************************************************************************
 *Creates a comboBox and adds it to a comboBox array
 *@param comboId, comboBox identifier
 *@param optlistId, comboBox item list id
 * @param txtViewId, display text control id
 * @param txtValId, value text control id
 * @param parentId, parent component id
 * @param listClassName, item list css class name
 * @param itemClassName, individual item css class name
 * @param itemOverClass, individual item css class name, when onMouseOver is fired
 * @param comboOptions, comboBox options format as an string
 *        each item= <list text>|<value>|<selected display text>   
 *        option list=<item>;<item>;<item>, etc...
 ****************************************************************************/
function ComboBox_initializeCombo(comboId,optlistId,txtViewId,txtValId,parentId,listClassName,itemClassName,itemOverClass,comboOptions)
{
	//var comboOptions ="Acre|1|AC;Alagoas|2|AL;Amapá|3|AP;Amazonas|4|AM;Bahia|5|BA;Ceará|6|CE;Distrito Federal|7|DF;Espírito Santo|8|ES;Goiás|9|GO;Maranhão|10|MA;Mato Grosso|11|MT;Mato Grosso do Sul|12|MS;Minas Gerais|13|MG;Pará|14|PA;Paraíba|15|PB;Paraná|16|PR;Pernambuco|17|PE;Piauí|18|PI;Rio de Janeiro|19|RJ;Rio Grande do Norte|20|RN;Rio Grande do Sul|21|RS;Rondônia|22|RO;Roraima|23|RN;Santa Catarina|24|SC;São Paulo|25|SP;Sergipe|26|SE;Tocantins|27|TO";
	combo = new ComboBox(comboId,optlistId,txtViewId,txtValId,parentId,listClassName,itemClassName,itemOverClass,comboOptions);
	ComboBox_addCombo(combo);
	ComboBox_changeZIndexOne();

}
/********************************************************************************
 *Displays the combo item list
 *@param comboBoxId, list owner id
 ********************************************************************************/
function ComboBox_toggle(comboBoxId)
{
	this.combo = Global_combo_array[comboBoxId];
	this.opslist = document.getElementById(this.combo.optlistId);
	this.view = document.getElementById(this.combo.parentId);
	this.update = ComboBox_update;
	this.build = ComboBox_build;
	this.options = this.combo.options;

	this.opslistGeneral= document.getElementById(Global_optlist_id);
	if(this.opslistGeneral && Global_optlist_id!=this.combo.optlistId)
		document.body.removeChild(this.opslistGeneral);

    if(this.opslist)
    {
		 document.body.removeChild(this.opslist);    
//        if(this.opslist.style.display=="block")
//        {
//            
//            this.opslist.style.display="none"
//			this.view.style.zIndex=0;
//			//set current option list id
//			Global_optlist_id = '';
//			Global_combo_selectedIntex = -1;
//						
//        }
//        else
//        {
//            this.update(this.combo);
//            this.build(this.options,this.combo);
//            this.view.style.zIndex = ++Global_combo_COMBOBOXZINDEX
//            this.opslist.style.display="block"
//			//set current option list id
//			Global_optlist_id=this.opslist.id;
//        }
    }
    else
    {
        this.update(this.combo);
        this.build(this.options,this.combo);
        this.view.style.zIndex = ++Global_combo_COMBOBOXZINDEX
        
        this.opslist.style.display="block"
        //set current option list id
		Global_optlist_id=this.opslist.id;		
    }
}

/************************************************************************
 *Updates a comboBox
 *@comboBox, comboBox control to be updated
 ************************************************************************/
function ComboBox_update(comboBox)
{
    var opart,astr,alen,opln,i,boo;
    boo=false;
	this.options = comboBox.options;
	this.txtview = document.getElementById(comboBox.txtViewId);
	this.expops = comboBox.expops;
	Global_combo_selectedIntex = -1;	
    opln = this.options.length
    astr = this.txtview.value.toLowerCase();
    alen = astr.length
    if(alen==0)
    {
        for(i=0;i<opln;i++)
        {
            this.expops[this.expops.length]=this.options[i];boo=true;
        }
    }
    else
    {
        for(i=0;i<opln;i++)
        {
            opart=this.options[i].text.toLowerCase().substring(0,alen)
            if(astr==opart)
            {
                this.expops[this.expops.length]=this.options[i];boo=true;
            }
        }
    }
    if(!boo){this.expops[0]=new ComboBoxItem("(No matches)","")}
}

/**********************************************************************************
 *Builds a combo list
 *@param arr with info to be build
 *@param comboBox control owner of the list
 **********************************************************************************/
function ComboBox_build(arr,comboBox)
{
    var str,arrlen,selectedClassName
    arrlen=arr.length;
    str = '<table cellpadding=0 cellspacing=0>';
    var strs = new Array(arrlen);
	this.opslist = document.getElementById(comboBox.optlistId);
	this.view = document.body;//document.getElementById(comboBox.parentId);
	this.txtView = document.getElementById(comboBox.txtViewId);
	
    for(var i=0;i<arrlen;i++)
    {
		selectedClassName = comboBox.itemClass;
        strs[i] = '<tr>' + '<td id="'+comboBox.id+ Global_combo_item_id + arr[i].value +'"';
			if(this.txtView.value == arr[i].displayText)
				selectedClassName = comboBox.itemOver;
		strs[i]+=' class="'+selectedClassName+'" onClick="ComboBox_choose(\''+arr[i].value+'\',\''+arr[i].displayText+'\',\''+comboBox.id+'\'); document.body.removeChild(document.getElementById(\''+comboBox.optlistId+'\'));	"' +
		'onMouseOver="this.className=\''+comboBox.itemOver+'\';" onMouseOut="this.className=\''+comboBox.itemClass+'\'" >&nbsp;'+arr[i].text+'&nbsp;</td>' +
		'</tr>';
    }
    str = str + strs.join("") + '</table>'
	
	if(this.opslist){
		this.view.removeChild(this.opslist);
		Global_optlist_id = '';
	}
    var txtX = findPosX(this.txtView);
	var txtY = findPosY(this.txtView);
	txtY +=this.txtView.offsetHeight;
    this.opslist = document.createElement("DIV")
	this.opslist.id = comboBox.optlistId;
    this.opslist.innerHTML=str;
    this.opslist.style.display='none';
    this.opslist.className = comboBox.itemListClass;
	this.opslist.style.position="absolute";
	this.opslist.style.left = txtX+"px";
	this.opslist.style.top = txtY+"px";    
    this.opslist.onselectstart=returnFalse;
    this.view.appendChild(this.opslist);   
    
}
/******************************************************************************************
 *Choose a value within a comboBox list
 *@param realVal, comboBox hidden value
 *@param txtVal, comboBox display text value
 *@param comboBoxId, current comboBox id 
 *****************************************************************************************/
function ComboBox_choose(realval,txtval,comboBoxId)
{	
	this.combo = Global_combo_array[comboBoxId];
    this.value         = realval;
	this.valcon = document.getElementById(this.combo.txtValId);
	this.assing = ComboBox_assingValue;
    window.setTimeout('this.assing(\''+txtval+'\',\''+this.combo.id+'\')',1)
    this.valcon.value  = realval;
    Global_combo_selectedIntex=-1;
    
}
/*****************************************************************************************
 *Assigns text value to a comboBox
 *@param val, value to be assigned
 *@param comboBoxId, current comboBox id
 ****************************************************************************************/
function ComboBox_assingValue(val,comboBoxId)
{
	this.combo = Global_combo_array[comboBoxId];
	this.txtView = document.getElementById(this.combo.txtViewId);
	this.txtView.value = val;
}
/*****************************************************************************************
 *Creates a new comboBox item
 *@param text, text to be assigned
 *@param value, value to be assigned
 *@param displayText, displayText if the item is selected 
 ****************************************************************************************/
function ComboBoxItem(text,value,displayText)
{
    this.text  = text;
    this.value = value;
	this.displayText=displayText;
}
/*****************************************************************************************
 *Fired when mouseDown, manages the display block or none of the current itemList
 *@param e, event
 ****************************************************************************************/
function ComboBox_mouseDown(e)
{
	var obj,len,el,i;
    el = e.target ? e.target : e.srcElement;
	
	if(el.id.indexOf("_ComboBox_item_")==-1 && el.id.indexOf("comboBox_itemlist")==-1 && el.id.indexOf("comboBox_button")==-1)
	{
		this.opslist = document.getElementById(Global_optlist_id);

		if(this.opslist)
		{
			//this.opslist.style.display='none';
			document.body.removeChild(this.opslist);
			Global_optlist_id ='';
			Global_combo_selectedIntex = -1;
		}
	}
}
/*****************************************************************************************
 *Fired when a key is pressed, manages the comboBox search and item list display when a key
 *is pressed within the comboBox display text
 *@param e, event
 ****************************************************************************************/
function ComboBox_handleKey(e)
{
    var key,obj,eobj,el,strname;
    eobj = e;
    key  = eobj.keyCode;
    el = e.target ? e.target : e.srcElement;
	var index = el.id.indexOf("_comboBox_dmtxt");
	if(index>0)
	{
			var comboId =ComboBox_getComboId(el.id,index);
//			this.combo = Global_combo_array[comboId];
//			this.expops = this.combo.expops;
			this.update = ComboBox_update;
			this.build = ComboBox_build;
            ComboBox_manageKey(key,comboId,this.update,this.build);
     }
}
/***************************************************************************************
 *Manges keyCode events individually
 **************************************************************************************/
function ComboBox_manageKey(keyCode,comboId,update,build)
{
	
	var item = null;
	this.combo = Global_combo_array[comboId];
	var index = Global_combo_selectedIntex;	
	this.expops = this.combo.expops;
	this.opslist = document.getElementById(this.combo.optlistId);
	this.valcon = document.getElementById(this.combo.txtValId);
	this.view = document.getElementById(this.combo.parentId);
	this.txtView = document.getElementById(this.combo.txtViewId);
	this.update=update;
	this.build = build;	
    //up and down arrows
	if(keyCode==40||keyCode==38)
	{
		if(this.opslist && this.opslist.style.display=='block')
		{		
				if(index>0)
				{	
					item = document.getElementById(this.combo.id+Global_combo_item_id+this.expops[index].value);
					item.className = this.combo.itemClass;
				}
				if(keyCode==40)
					index++;
				else
					index--;
				if(index>=this.expops.length)
					index = this.expops.length-1;
				else if(index<0)
					index = 0;
					
				Global_combo_selectedIntex = index;
				//current element in the list
				item = document.getElementById(this.combo.id+Global_combo_item_id+expops[index].value);
				item.className = this.combo.itemOver;
				this.txtView.value = expops[index].displayText;
				this.valcon.value = expops[index].value;
		}
		else
		{
			this.expops.length = 0;
			this.update(this.combo);
			this.build(this.expops,this.combo);
			if(this.expops.length==1&& this.expops[0].text=="(No matches)"){}//empty
			else{
			    
				this.opslist.style.display='block';
				Global_optlist_id = this.opslist.id;
				this.view.style.zIndex = ++Global_combo_COMBOBOXZINDEX
				if(index>0)
				{	
					item = document.getElementById(this.combo.id+Global_combo_item_id+this.expops[index].value);
					item.className = this.combo.itemClass;
				}
				if(keyCode==40)
					index++;
				else
					index--;
				if(index>=this.expops.length)
					index = this.expops.length-1;
				else if(index<0)
					index=0;
				Global_combo_selectedIntex = index;
				//current element in the list
				item = document.getElementById(this.combo.id+Global_combo_item_id+expops[index].value);
				item.className = this.combo.itemOver;
				this.txtView.value = expops[index].displayText;
				this.valcon.value = expops[index].value;
			}
		
		}
		this.opslist.scrollTop = 20*index;


	}
	//Tab Key
	else if(keyCode==9 )
	{
		this.optlist = document.getElementById(Global_optlist_id)
		if(this.optlist)
			document.body.removeChild(this.optlist);
	}
    //Tab Key
	else if((keyCode==8 ||keyCode==46))
	{
		if(this.txtView.value=="")
		    this.valcon.value = "";
	    		this.expops.length = 0;
		this.update(this.combo);
		this.build(this.expops,this.combo);
		if(this.expops.length==1&& this.expops[0].text=="(No matches)"){}//empty
		else{
			this.opslist.style.display='block';
			Global_optlist_id = this.opslist.id;
			this.view.style.zIndex = ++Global_combo_COMBOBOXZINDEX	
		}
	}
	else
	{
		this.expops.length = 0;
		this.update(this.combo);
		this.build(this.expops,this.combo);
		if(this.expops.length==1&& this.expops[0].text=="(No matches)"){}//empty
		else{
			this.opslist.style.display='block';
			Global_optlist_id = this.opslist.id;
			this.view.style.zIndex = ++Global_combo_COMBOBOXZINDEX	
		}
		//this.valcon.value = el.value;
	}
}
/*****************************************************************************************
 *Obtains te combobox id, processing som of his child controls id
 *@param controlId, comboBox child control id
 ****************************************************************************************/
function ComboBox_getComboId(controlId,index)
{
    return controlId.substr(0,index);
}



/*****************************************************************************************
 *Initialize events
 ****************************************************************************************/

function ComboBox_init() 
{
	if (document.addEventListener) {
		document.addEventListener("keyup", ComboBox_handleKey, false );
		document.addEventListener("mousedown", ComboBox_mouseDown, false );
	}
	else if (document.attachEvent) {
		document.attachEvent("onkeyup", function () { ComboBox_handleKey(window.event); } );
		document.attachEvent("onmousedown", function () { ComboBox_mouseDown(window.event); } );
	}
	
    Global_run_event_hook = false;
}
/*****************************************************************************************
 *Returns False
 ****************************************************************************************/
function returnFalse(){
    return false
}
/*****************************************************************************************
 *Sets all divs to a z-index of 1, this is because there is a bug in IE that not respect
 *the z-index order when the page is rendered
 ****************************************************************************************/
function ComboBox_changeZIndexOne()
{
//    divs = document.getElementsByTagName("DIV");
//	for(i=0; i<divs.length;i++)
//	{
//	        divs[i].style.zIndex = 1;
//	}
}
/*****************************************************************************************
 *Sets all divs to its original z-index, this is because there is a bug in IE that not respect
 *the z-index order when the page is rendered
 ****************************************************************************************/



/******************************************************************************************
 *End of ComboBoxControl Functions
 *****************************************************************************************/
 

//función para rotar la imagen de Saiba Mais

var timer = null
var	 counter = 0

function alternar_banner() {
	counter++;
	timer=setTimeout("alternar_banner()", 5000);
		if (counter >= pic.length) 
		counter = 0;
	if(document.getElementById("ctl00_C1_SMimg")!= null){	
	    document.getElementById("ctl00_C1_SMimg").src = pic[counter].src;
	}
}

function GuiaRuasRedirectToHome()
{
    var ctrCountries = document.getElementById('ctrCountries');
    var selectedOption = ctrCountries.options[ctrCountries.selectedIndex].value;
    
    switch(selectedOption)
    {
        case '1':
            location.href = 'http://www.paginasamarillas.com/Colombia/TodoslosEstados/ES/PaginasAmarillas-Colombia.aspx';
        break;
        case '22':
            location.href = 'http://www.paginasamarillas.com/Bolivia/TodoslosEstados/ES/PaginasAmarillas-Bolivia.aspx';
        break;
        case'8':
            location.href = 'http://www.paginasamarillas.com/CostaRica/TodoslosEstados/ES/PaginasAmarillas-CostaRica.aspx';
        break;
        case '6':
            location.href = 'http://www.paginasamarillas.com/Ecuador/TodoslosEstados/ES/PaginasAmarillas-Ecuador.aspx';
        break;
        case '2':
            location.href = 'http://www.paginasamarillas.com/ElSalvador/TodoslosEstados/ES/PaginasAmarillas-ElSalvador.aspx';
        break;
        case '3': 
            location.href = 'http://www.paginasamarillas.com/Guatemala/TodoslosEstados/ES/PaginasAmarillas-Guatemala.aspx';
        break;
        case '7': 
            location.href = 'http://www.paginasamarillas.com/Honduras/TodoslosEstados/ES/PaginasAmarillas-Honduras.aspx';
        break;
        case '9': 
            location.href = 'http://www.paginasamarillas.com/Mexico/TodoslosEstados/ES/PaginasAmarillas-Mexico.aspx';
        break;
        case '5':
            location.href = 'http://www.paginasamarillas.com/Nicaragua/TodoslosEstados/ES/PaginasAmarillas-Nicaragua.aspx';
        break;
        case '4':
            location.href = 'http://www.paginasamarillas.com/Panama/TodoslosEstados/ES/PaginasAmarillas-Panama.aspx';
        break;
        case '20':
            location.href = 'http://www.paginasamarillas.com/Peru/TodoslosEstados/ES/PaginasAmarillas-Peru.aspx';
        break;
        case '14':
            location.href = 'http://www.paginasamarillas.com/PuertoRico/TodoslosEstados/ES/PaginasAmarillas-PuertoRico.aspx';
        break;
        case '23':
            location.href = 'http://www.paginasamarillas.com/RepDominicana/TodoslosEstados/ES/PaginasAmarillas-RepublicaDominicana.aspx';
        break;
        case '15':
            location.href = 'http://www.paginasamarillas.com/Venezuela/TodoslosEstados/ES/PaginasAmarillas-Venezuela.aspx';
        break;
        case '*':
            location.href = 'http://www.paginasamarillas.com/TodoslosPaises/TodoslosEstados/ES/PaginasAmarillas-TodoslosPaises.aspx';
        break;
    }
}

/*****************************************************************************************
 *Gets the x absolute position of an element
 ****************************************************************************************/
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }
/*****************************************************************************************
 *Gets the y absolute position of an element
 ****************************************************************************************/
  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  function getURLParam(strParamName){
      var strReturn = "";
      var strHref = window.location.href;
      if ( strHref.indexOf("?") > -1 ){
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
          if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
            var aParam = aQueryString[iParam].split("=");
            strReturn = aParam[1];
            break;
          }
        }
      }
      return unescape(strReturn);
 }
  /*************************************************************************
   * Obtains data for a location comboBox
   *************************************************************************/
  var global_selectedText=""; 
  function Location_getData(notSelectionString,loadingText,ctrlName,ctrlIndex,url,states, bServices)
  {
    var ctrl = document.getElementById(ctrlName);
    var itemsCount = ctrl.options.length;
    var length = ctrl.options.length;
    var selectedIndex = ctrl.selectedIndex;
    var selectedValue = notSelectionString;
    var country = getURLParam("ipa");
    var state = getURLParam("ies");
    var city = getURLParam("nci");
    var ica = getURLParam("ica");
    var tipo = getURLParam("tipo");    
    var srv= getURLParam("srv");  
    {
        selectedValue = ctrl.options[selectedIndex].value;
        global_selectedText = ctrl.options[selectedIndex].text;
    }
    
    var hdPageParams = document.getElementById("ctl00_C2_hdPageParams").value;       
    var listParams= hdPageParams.split('|');
    
    if (state=="" && city=="" && country=="")  
    {
        var catId='';     
        for (var i=0; i<listParams.length;i++)
        {
            var params= listParams[i].split('*'); 
            var paramName=params[0];
            if (params[1]!='')
            {
                if (paramName=='STATE')
                    state=params[1];
                else if (paramName=='COUNTRY')
                    country=params[1];        
                else if (paramName=='CITY')
                    city=params[1];                              
                else if (paramName=='CATID')
                    catId=params[1];            
             }
         } 
    }
    if (ica==""&&catId!=""){ica=catId;}
    
    if(selectedValue==notSelectionString && itemsCount==1)
    {
      
        ctrl.options[selectedIndex].text = loadingText;
        
        if (country=="" && state==""&& ica=="")          //viene de seo
        {
           var otherParams = Location_GetDataParams(0);
           var paramseo= "OP=getLocationData&ctrlName="+ctrlName+"&UR="+url+"&index="+ctrlIndex+"&ies=$"+"&nci=$"+"&tipo="+tipo+otherParams+"&lstStates="+states+"&bService="+bServices+"&srv="+srv;
           var urlseo=location.protocol+"//"+location.host+"/"+"Handlers/AjaxHandler.ashx?"+paramseo;  
            loadXMLDoc(urlseo,"locationData");   
        }
        else if (country=="" && state!=""&& ica=="" && city =="")          //viene de seo
        {
           var otherParams = Location_GetDataParams(0);
           var paramseo= "OP=getLocationData&ctrlName="+ctrlName+"&UR="+url+"&index="+ctrlIndex+"&ies="+state+"&nci=$"+"&tipo="+tipo+otherParams+"&lstStates="+states+"&bService="+bServices+"&srv="+srv;
           var urlseo=location.protocol+"//"+location.host+"/"+"Handlers/AjaxHandler.ashx?"+paramseo;  
            loadXMLDoc(urlseo,"locationData");   
        }
        else if (country=="" && state!=""&& ica=="" && city!="")          //viene de seo
        {
           var otherParams = Location_GetDataParams(0);
           var paramseo= "OP=getLocationData&ctrlName="+ctrlName+"&UR="+url+"&index="+ctrlIndex+"&ies="+state+"&nci="+city+"&tipo="+tipo+otherParams+"&lstStates="+states+"&bService="+bServices+"&srv="+srv;
           var urlseo=location.protocol+"//"+location.host+"/"+"Handlers/AjaxHandler.ashx?"+paramseo;  
            loadXMLDoc(urlseo,"locationData");   
        }
        else
        {
            var otherParams = Location_GetDataParams(1);
            var params="OP=getLocationData&ctrlName="+ctrlName+"&UR="+url+"&index="+ctrlIndex+"&ipa="+country+"&ies="+state+"&nci="+city+"&tipo="+tipo+otherParams+"&lstStates="+states+"&bService="+bServices+"&srv="+srv;
            var urls=location.protocol+"//"+location.host+"/"+"Handlers/AjaxHandler.ashx?"+params;  
            loadXMLDoc(urls,"locationData");   
        }
        
//        var params="OP=getLocationData&ctrlName="+ctrlName+"&UR="+url+"&index="+ctrlIndex+"&ipa="+country+"&ies="+state+"&nci="+city+"&tipo="+tipo+otherParams+"&lstStates="+states+"&bService="+bServices+"&srv="+srv;
//        var urls=location.protocol+"//"+location.host+"/"+"Handlers/AjaxHandler.ashx?"+params;  
//        loadXMLDoc(urls,"locationData");   
//        
        //loadXMLDoc("Handlers/AjaxHandler.ashx?OP=getLocationData&ctrlName="+ctrlName+"&UR="+url+"&index="+ctrlIndex+"&ipa="+country+"&ies="+state+"&nci="+city+"&tipo="+tipo+otherParams+"&lstStates="+states,"locationData");    
    }
  }

  /*****************************************************************************
   * Manages the readySatateChange for a GetLocationData xmlHttpRequest
   ****************************************************************************/
  function state_GetLocations()
  {     
    if(xmlhttp.readyState==4)
    {
        if(xmlhttp.status==200)
        {
            var locationsData =xmlhttp.responseText.split(";"); 
            //get control name
            var ctrlName = locationsData[0];
            //get the control
            var locations = document.getElementById(ctrlName);
            var count = locations.options.length;
            var fOption = null;
            var sumIndex = 0;
            if(count>0)
            {
                var txt =global_selectedText;//locations.options[0].text;
                var val = locations.options[0].value;
                fOption = new Option(txt,val,false);
                sumIndex = 1;
            }
            locations.options.length=0;
            if(fOption)
            {
                locations.options[0]=fOption;
            }
            
            //options list data
            var optsData = locationsData[1].split("|");
            //select options
            for(i=0;i<optsData.length;i++)
            {
                if(optsData[i]!=null && optsData[i]!="")
                {
                    var data = optsData[i].split("^");
                    var option = new Option(data[0],data[1],false);
                    if(option.value!=null && option.value!="undefined")
                        locations.options[i+sumIndex] = option;
                    
                }
            }
            locations.selectedIndex=0;
            
        }
    }

  }
  
  /*****************************************
  Manages the readySatateChange for a GetStatisticsResult xmlHttpRequest
  *******************************************/
  function state_GetStatisticsResult()
  {     
    if(xmlhttp.readyState==4)
    {
        if(xmlhttp.status==200)
        {
            var sStatisticsSaved = xmlhttp.responseText;  
        }
        
     }
  }
  
  
  
  
  /***************************************************************************
   *Manages onChange event for a location comboBox
   ***************************************************************************/
  function Location_OnChange(ctrlName, ctrlPrefix,comboIndex, noSelection,resultsLink)
  {
        var ctrl = document.getElementById(ctrlName);
        
        var countryId = getURLParam("ipa");
        var countryName = getURLParam("npa");
        var stateId = getURLParam("ies");
        var stateName = getURLParam("nes");
        var stateLongName = getURLParam("nles")
        var text = getURLParam("txb");
        var lang = getURLParam("idi");
        var city = getURLParam("nci");
        var neigh = getURLParam("nbid");
        var neighName = getURLParam("nbn")
        var catId = getURLParam("ica");
        var srv = getURLParam("srv");
        var ici = getURLParam("ici");
        var tid = getURLParam("tid");
        var shr=getURLParam("shr");
        var no1=getURLParam("no1");
         
         var urlSeo='';      
        
        if (countryId==""&&stateId==""&&catId=="")
        {
            var hdPageParams = document.getElementById("ctl00_C2_hdPageParams").value;     
            var listParams= hdPageParams.split('|');
            var city=''; var state=''; var country=''; var search=''; var lng=''; var query='';var page='';var dir='';    
            
            for (var i=0; i<listParams.length;i++)
            {
                 var params= listParams[i].split('*'); 
                 var paramName=params[0];
                 if (params[1]!='')
                 {
                     if (paramName=='CITY')
                        city=params[1];         
                     else if (paramName=='STATE')
                        state=params[1];
                     else if (paramName=='COUNTRY')
                        countryId=params[1];         
                     else if (paramName=='SEARCH')
                        search=params[1];
                     else if (paramName=='LNG')
                        lang=params[1];
                     else if (paramName=='QUERY')
                        query=params[1];
                     else if (paramName=='PAGE')
                        page=params[1];     
                     else if (paramName=='DIR')
                       dir=params[1];  
                     else if (paramName=='CATID')
                       catId=params[1];                                                                           
                 }
            } 
            
            var hdParamsSee= document.getElementById("ctl00_C2_hdWordParams").value;                         
            var listParams= hdParamsSee.split('|');
            var wordParams=''; var dominio17=''; var dominio18=''; var dominio20='';var dominioGuias='';
            
            for (var i=0; i<listParams.length;i++)
            {
                var params= listParams[i].split('*'); 
                var paramName=params[0];
                if (params[1]!='')
                {
                    if (paramName=='WORDPARAMS')
                        wordParams=params[1];
                    else if (paramName=='DOMINIO17')
                        dominio17=params[1];                  
                    else if (paramName=='DOMINIO18')
                        dominio18=params[1];
                    else if (paramName=='DOMINIO20')
                        dominio20=params[1];    
                    else if (paramName=='DOMINIOGUIAS')
                        dominioGuias=params[1];    
                       
                 }
            
            }               
           
            if (dir=='18')
                urlSeo=dominio18;
            else if (dir=='20')
                urlSeo=dominio20;
            else if (dirGeneral=='17' && resultsLink=='~/Results.aspx')
                urlSeo=dominio17;
            else 
                urlSeo=dominioGuias;                  
        
        }
      
        //search by state
        if(stateId=="" || stateId==noSelection || stateId=="$")
        {
            stateId = ctrl.value;
            stateLongName = ctrl.options[ctrl.selectedIndex].text;
        }
        //search by city
        else if(city=="" || city==noSelection || city=="$")
        {
            city = ctrl.options[ctrl.selectedIndex].text;
            ici = ctrl.value;
            var ctrState = document.getElementById(ctrlPrefix+"2");
            stateLongName = ctrState.options[ctrState.selectedIndex].text;
        }
        //search by neighborhoods
        else
        {
            neigh = ctrl.value;
            neighName = ctrl.options[ctrl.selectedIndex].text;
            
            var ctrState = document.getElementById(ctrlPrefix+"2");
            stateLongName = ctrState.options[ctrState.selectedIndex].text;
            
            var ctrCity = document.getElementById(ctrlPrefix+"1");
            ici = ctrCity.value;
            
        }

        var url="";
        if(catId!="")
            url +="ica="+catId;
        if(countryId!="")
        {   if(url!="")
                url+="&";
            url +="ipa="+countryId;
        }
        if(countryName!="")
        {   if(url!="")
                url+="&";
            url+="npa="+countryName;
        }
        if(stateId!="")
        {   if(url!="")
                url+="&";
            url+="ies="+stateId;
        }
        if(stateName!="")        
        {   
            if (stateLongName==stateName)
            {
                if(url!="")
                    url+="&";
                url+="nes="+stateName;
            }
        }
        if(lang!="")
        {   if(url!="")
                url+="&";
            url+="idi="+lang;
        }
        if(text!="")
        {   if(url!="")
                url+="&";
            url+="txb="+text;
        }
        if(city!="")
        {   if(url!="")
                url+="&";
            url+="nci="+city;
        }
        if(neigh!="")
        {   if(url!="")
                url+="&";
            url+="nbid="+neigh;
        }
        if(stateLongName!="")
        {   if(url!="")
                url+="&";
            url+="nles="+stateLongName;         
         }
        if(neighName!="")
        {   if(url!="")
                url+="&";            
            url+="nbn="+neighName;
         }
         if(tid!="")
         {
            if(url!="")
                url+="&"
            url +="tid="+tid;
         }
        if(srv!="")
        {   if(url!="")
                url+="&";
            url+="srv="+srv;
         }
         if (no1!="")
         {
            if(url!="")
                url+="&";
            url+="no1="+no1;
         }
         if(url!="")
                url+="&";
          url+="esth=4&tid=4";          
//        if(ctrl.value!=noSelection && ctrl.value!="")
//        {
//            if (resultsLink=="~/ResultsGP.aspx")
//              location.href="ResultsGP.aspx?"+url+"&tipo=17";
//            else
//              location.href="Results.aspx?"+url;
//        }
//        
        if(ctrl.value!=noSelection && ctrl.value!="")
        {
            if (resultsLink=="~/ResultsGP.aspx" && urlSeo=="")
              location.href="ResultsGP.aspx?"+url+"&tipo=17";
            else if (resultsLink=="~/Results.aspx" && urlSeo=="")
              location.href="Results.aspx?"+url;
            else if (resultsLink=="~/Results.aspx" && urlSeo!="")
              location.href=urlSeo+"Results.aspx?"+url;
            else if (resultsLink=="~/ResultsGP.aspx" && urlSeo!="")
              location.href=urlSeo+"ResultsGP.aspx?"+url+"&tipo=17";
        }
            //location.href="Results.aspx"+"?ica="+catId+"&ipa="+countryId+"&npa="+countryName+"&ies="+stateId+"&nes="+stateName+"&idi="+lang+"&txb="+text+"&nci="+city+"&nbid="+neigh+"&nles="+stateLongName+"&nbn="+neighName+"&srv="+srv;
  }
 
 
  
  /*******************************************************************************************************
   *Obtains parameters that are into a hidden field, containing other page params
   *******************************************************************************************************/
  function Location_GetDataParams(iFlag)
  {
        var hdPageParams = document.getElementById("ctl00_C2_hdPageParams").value;       
        var result='';
        var listParams= hdPageParams.split('|');
      
        var state=''; var country=''; var lng=''; var query='';var page='';var dir='';var catId=''; var what=''; var where='';   
         var grupo='';   
        for (var i=0; i<listParams.length;i++)
        {
              var params= listParams[i].split('*'); 
              var paramName=params[0];
              if (params[1]!='')
              {
                  if (paramName=='STATE')
                        state=params[1];
                  else if (paramName=='COUNTRY')
                        country=params[1];                  
                  else if (paramName=='LNG')
                         lng=params[1];
                  else if (paramName=='QUERY')
                         query=params[1];
                  else if (paramName=='DIR')
                  {
                      dir=params[1];                      
                      dirGeneral=dir;
                  }
                  else if (paramName=='PAGE')
                         page=params[1];  
                  else if (paramName=='CATID')
                         catId=params[1];
                  else if (paramName=='WHAT')
                         what=params[1];         
                  else if (paramName=='WHERE')
                         where=params[1];  
                  else if (paramName=='GRUPO')
                         grupo=params[1];  
                          
              }

        } 
        if (iFlag==0)
            result +="&idi="+lng+"&qid="+query+"&sdid="+dir+"&ica="+catId+"&txb="+what+"&gid="+grupo+"&ipa="+country;
        else
            result +="&idi="+lng+"&qid="+query+"&sdid="+dir+"&ica="+catId+"&txb="+what+"&gid="+grupo;
        return result;
}


function CreateBookmarkLink(url,title)
{

  if (window.sidebar)
  { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external )
	{ // IE Favorite
		window.external.AddFavorite( url, title); 
	}
	else if(window.opera && window.print) 
	{ // Opera Hotlist
		return true; 
	}
}
//puts the focus of the page on a determinated control
function putFocus(ctrlName){
    var ctrl = document.getElementById(ctrlName);
    ctrl.focus();
}
function searchAdress()  
{
    var product=document.getElementById("divBckgBarraIq");
    var adress=document.getElementById("dBckgBIA");
    product.style.visibility='hidden';
    adress.style.visibility='visible';
   // adress.className = 'divBckgBarraIzqAdressVis';  
    //product.className = 'divBckgBarraIzqHidden';       
}
function searchProduct()
{
    var product=document.getElementById("divBckgBarraIq");
    var adress=document.getElementById("dBckgBIA");
    product.style.visibility='visible';
    adress.style.visibility='hidden';         
//    product.className = 'divBckgBarraIzq'
}
function backRegCompany()
{
   history.back(1);
}

function loadMsAdrs()
{
    var sSa=getURLParam("sa");
    
//    if (sSa=="")
//    {
//        var hdPageParams = document.getElementById("ctl00_C2_hdPageParams").value;       
//        var listParams= hdPageParams.split('|');     
//      
//        for (var i=0; i<listParams.length;i++)
//        {
//              var params= listParams[i].split('*'); 
//              var paramName=params[0];
//              if (params[1]!='')
//              {
//                  if (paramName=='ADRESS')
//                  {
//                        sSa=params[1];                   
//                        break;
//                  }                    
//              }
//        }    
//    }    
    
    if (sSa!="")
    {
        var product=document.getElementById("divBckgBarraIq");
        var adress=document.getElementById("dBckgBIA");
        product.style.visibility='hidden';
        adress.style.visibility='visible';
    }
    else
    {
        var product=document.getElementById("divBckgBarraIq");
        var adress=document.getElementById("dBckgBIA");
        product.style.visibility='visible';
        adress.style.visibility='hidden';       
    }

}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function encodeUrl(url) {
    if (url.indexOf("?") > 0) {
        encodedParams = "?";
        parts = url.split("?");
        params = parts[1].split("&");
        for (i = 0; i < params.length; i++) {
            if (i > 0) {
                encodedParams += "&";
            }
            if (params[i].indexOf("=") > 0) //Avoid null values  
            {
                p = params[i].split("=");
                encodedParams += (p[0] + "=" + escape(encodeURI(p[1])));
            }
            else {
                encodedParams += params[i];
            }
        }

        url = parts[0] + encodedParams;
    }
    return url;

}

function showBadFormatError() {
    alert("Formato Incorrecto");
    return false;
}

function validateMail(field) {

    var emails = field.value.split(';');
    var ok = true;

    for (var i = 0; i < emails.length; i++) {

        var emailStr = emails[i].trim();
        var checkTLD = 1;
        var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
        var emailPat = /^(.+)@(.+)$/;
        var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
        var validChars = "\[^\\s" + specialChars + "\]";
        var quotedUser = "(\"[^\"]*\")";
        var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
        var atom = validChars + '+';
        var word = "(" + atom + "|" + quotedUser + ")";
        var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
        var domainPat = new RegExp("^" + atom + "(\\." + atom + ")*$");
        var matchArray = emailStr.match(emailPat);

        if (matchArray == null) {
            return showBadFormatError();
        }

        var user = matchArray[1];
        var domain = matchArray[2];

        for (i = 0; i < user.length; i++) {
            if (user.charCodeAt(i) > 127) {
                return showBadFormatError();
            }
        }

        for (i = 0; i < domain.length; i++) {
            if (domain.charCodeAt(i) > 127) {
                return showBadFormatError();
            }
        }

        if (user.match(userPat) == null) {
            return showBadFormatError();
        }

        var IPArray = domain.match(ipDomainPat);
        if (IPArray != null) {
            for (var i = 1; i <= 4; i++) {
                if (IPArray[i] > 255) {
                    return showBadFormatError();
                }
            }
            ok = ok && true;
        }


        var atomPat = new RegExp("^" + atom + "$");
        var domArr = domain.split(".");
        var len = domArr.length;
        for (i = 0; i < len; i++) {
            if (domArr[i].search(atomPat) == -1) {
                return showBadFormatError();
            }
        }

        if (len < 2) {
            return showBadFormatError();
        }

        if (!ok) {
            return showBadFormatError();
        }
    }

    return ok;
}

function autoIframe(frameId) {
    if (frameId != "saveShareIFrame") {
        try {
            frame = document.getElementById(frameId);
            innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
            //objToResize = (frame.style) ? frame.style : frame;
            frame.height = innerDoc.body.scrollHeight + 15;
        }
        catch (err) {
            window.status = err.message;
        }
    }
}