var tprod = "";
var tarea = "";

function apriProd(id,lan) {
  
 if (lan == "it") {
  tprod = "Prodotto/Principio Attivo"; tarea = "Area/Indicazione Terapeutica";
 } else {
  tprod = "Brand/Active Ingredient"; tarea = "Therap. Area/Disease";
 }

 if (id == "perProdotto") {
  id2 = "perProdottoRes"; 
  id3 = "perArea";
  id4 = "perAreaRes";
 } else {
  id2 = "perAreaRes"; 
  id3 = "perProdotto";
  id4 = "perProdottoRes";
 }
  if (document.getElementById(id).style.display == "none" ) {
    document.getElementById(id).style.display = "";
    document.getElementById(id2).style.display = "none";
    document.getElementById(id2).innerHTML = "";
    document.getElementById(id).focus();     
  } else {
    document.getElementById(id).style.display = "none";
    document.getElementById(id2).style.display = "none";
    document.getElementById(id2).innerHTML = "";
  
    if (id == "perProdotto") {
     document.getElementById("searchSel2").value = ""; document.getElementById("searchSel2").text = tprod;
    } else {
     document.getElementById("searchSel1").value = ""; document.getElementById("searchSel1").text = tarea;
    }  
  


  }
    document.getElementById(id3).style.display = "none";
    document.getElementById(id4).style.display = "none";
    document.getElementById(id4).innerHTML = "";

}

var prod;
var ar;
var prod2;
var ar2;

function closeP(id,lan) {

 if (lan == "it") {
  document.tprod = "Prodotto/Principio Attivo"; document.tarea = "Area/Indicazione Terapeutica";
 } else {
  document.tprod = "Brand/Active Ingredient"; document.tarea = "Therap. Area/Disease";
 }

  if (id == "perArea") {
   ar = setTimeout(function(){document.getElementById("perArea").style.display = "none"; document.getElementById("searchSel1").options[0].value = ""; document.getElementById("searchSel1").options[0].text = document.tarea;} ,"2000");
   ar2 = setTimeout(function(){document.getElementById("perAreaRes").style.display = "none";} ,"2000"); 
  } else {
   clearTimeout(ar);clearTimeout(ar2);
   prod = setTimeout(function(){document.getElementById("perProdotto").style.display = "none"; document.getElementById("searchSel2").options[0].value = ""; document.getElementById("searchSel2").options[0].text = document.tprod;} ,"2000");
   prod2 = setTimeout(function(){document.getElementById("perProdottoRes").style.display = "none";} ,"2000");
  }
}

function closenoP(id) {

  if (id == "perArea") {
    clearTimeout(ar);
    clearTimeout(ar2);
  } else {
    clearTimeout(prod);
    clearTimeout(prod2);
  }
}

function res(id,num,lan) {
  
    document.getElementById(id).style.display = "";
    //eval("selItem('"+id+"-"+num+"');"); 
    eval("loadLevel('/opencms/AJAX_SEARCH/"+lan+"/"+id+"-"+num+".jsp','"+id+"','"+id+"');");

}

function submi(id,num) {
  
  if (num == 1) {
   document.getElementById("searchSel1").options[0].value = id;
   document.getElementById("searchSel1").options[0].text = eval("deco(\""+document.getElementById(id).innerHTML+"\",2);");
  } else {
   document.getElementById("searchSel2").options[0].value = id;
   document.getElementById("searchSel2").options[0].text = eval("deco(\""+document.getElementById(id).innerHTML+"\",2);");
  }

  document.getElementById("perArea").style.display = "none";
  document.getElementById("perProdotto").style.display = "none";
  document.getElementById("perAreaRes").style.display = "none";
  document.getElementById("perProdottoRes").style.display = "none";
  document.getElementById("perAreaRes").innerHTML = "";
  document.getElementById("perProdottoRes").innerHTML = "";

  //  eval("loadLevel2('/opencms/AJAX_SEARCH/"+lan+"/products/"+id+".jsp','result');");

}

function zoomMap(id){
  eval("loadLevel('/opencms/AJAX_SEARCH/subs/"+id+".jsp','result','result');");
}

function loadRes(id,lan){
  eval("loadLevel('/opencms/AJAX_SEARCH/"+lan+"/products/"+id+".jsp','result','result');");
}

function searchProd(lan) {

  if (document.getElementById("searchSel1").options[0].value == "" && document.getElementById("searchSel2").options[0].value  == "" ) {
   alert("Choose Product or Area");
  } else {

   if (document.getElementById("searchSel1").options[0].value != "")
     document.location="/opencms/"+lan+"/service/prodSearch.html?id="+document.getElementById("searchSel1").options[0].value+"&lan="+lan+"&se=1&nm="+eval("deco(\""+document.getElementById("searchSel1").options[0].text+"\",1);");
   else 
     document.location="/opencms/"+lan+"/service/prodSearch.html?id="+document.getElementById("searchSel2").options[0].value+"&lan="+lan+"&se=2&nm="+eval("deco(\""+document.getElementById("searchSel2").options[0].text+"\",1);");
  }


}


function loadLevel(url, target, id){
        document.getElementById(target).innerHTML = '<div align="left" valign="middle" style="z-index:10;margin:0px; padding:0px; padding-top:10px;background-image:none; background-color:white;  position:relative; width:100px; height:50px"><img border="0" src="/opencms/img/spinner.gif"/></div>';
        setTimeout('makeRequest2(\'' + url + '\',\'' + id + '\',\'' + target + '\')',500);
}

function makeRequest2(url, target,id){

        var http_request = false;
        
        if (window.XMLHttpRequest) {
                http_request = new XMLHttpRequest();
                if (http_request.overrideMimeType) {
                        http_request.overrideMimeType('text/xml');
                }
        }
        else if (window.ActiveXObject) {
                try {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try {
                                http_request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e) {}
                }
        }
        
        if(!http_request){
                alert("XMLHTTPRequest not supported.");
                return false;
        }

        eval("http_request.onreadystatechange = function(){ displayLevel(http_request,'" + target + "'); };");

        http_request.open("GET", url, true);
        http_request.send(null);

}

function displayLevel(http_request,target){

        if(http_request.readyState == 4){
                if(http_request.status == 200){
                        var xmldoc = http_request.responseXML;
                        document.getElementById(target).innerHTML = http_request.responseText;
                }else{
                        alert("Connection problems.");
                }
        }
}

function deco(test, tipo) {

  resu = "";

  if (tipo == 2) {
   
   resu = test.replace(/&nbsp;/ig," ");
   resu = resu.replace(/<br>/gi," ");
  
  } else {

   resu = test.replace(/ /gi,"%20");

  }
   
  return resu; 
}