
function ajax(){
    var objAjax = false;
    if (window.XMLHttpRequest){
      objAjax = new XMLHttpRequest ();
    }else{
      if (window.ActiveXObject){
        try{
              objAjax = new ActiveXObject ("Msxml2.XMLHTTP");
              objAjax = new ActiveXObject ("Microsoft.XMLHTTP");
          }catch (e){
          }
      }else{
            objAjax = false;
      }
    }
    return objAjax;
}
function resumeAjax (url,typeContent,id){
      if(url==""){
      }else{
          var objAjax = ajax();
          objAjax.open("POST", "Management/control.php",true);
          objAjax.onreadystatechange=function() {
                if (objAjax.readyState == 4) {
                      document.getElementById("main-content").innerHTML = objAjax.responseText
                }else{
                }
          }
         
          objAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
          objAjax.send("page_requested="+url+"&typeContent="+typeContent+"&id="+id);

      }
}
function temporal (id){
      var objAjax = ajax();
      objAjax.open("POST", "map/temporal.php",true);
      objAjax.onreadystatechange=function() {
            if (objAjax.readyState == 4) {
                  document.getElementById("loginform").innerHTML = objAjax.responseText;
            }else{
            }
      }
      objAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      objAjax.send("id="+id);
}
function cerrar(){
    mapa.removerPopups();
}
var mapa;
function mapAjax (type){

    _address_1 = "";
    _city = "";
    _phone = "";
    _typeSites = "";

    if(type==1){
        _address_1 = document.getElementById("address_1").value;
        _city = document.getElementById("city").value;
    }else if(type==2){
        _phone = document.getElementById("phone").value;
        _city = document.getElementById("city").value;
    }else if(type==3){
        _address_1 = document.getElementById("address_1").value;
        _city = document.getElementById("city").value;
        _typeSites = document.getElementById("sities").value;
    }

    address_2 = "cll 44c 45 28";
    country = "CO";

    document.getElementById("loginform").innerHTML = "";
    document.getElementById("main-content").innerHTML = "";
    document.getElementById("main-content").style.height = "600px";
    
    mapa = new ServiMapPersonal('main-content',null, [CAPASMAPA.CAPAPOLIGONOS,CAPASMAPA.CAPALINEAS,CAPASMAPA.CAPAPUNTOS],true);
    mapa.zoomTo(12);

    var objAjax = ajax();
    objAjax.open("POST", "map/control.php",true);
    objAjax.onreadystatechange=function()
    {
            if (objAjax.readyState == 4)
            {
                res = objAjax.responseText;
                eval(res);
//                 document.getElementById("main-content").innerHTML = objAjax.responseText;
            }
            else{}
      }
      objAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      objAjax.send("type="+type+"&phone="+_phone+"&address_1="+_address_1+"&address_2="+address_2+"&city="+_city+"&typeSites="+_typeSites+"&country="+country);
}


//****************************************
function contactos(){
    try{
        asunto = document.getElementById("name_6").value;
        mensaje = document.getElementById("name_7").value;
    }catch(e){
        return;
    }
    if(asunto==""){
        alert('Asunto');
    }else if(mensaje==""){
        alert('Mensaje');
    }else {
        title = document.getElementById("name_0").value;

        if(title=="opt0"){
            title= "Señor";
        }else if(title=="opt1"){
            title= "Señora";
        }
        name = document.getElementById("name_1").value;
        apellido = document.getElementById("name_2").value;
        direccion = document.getElementById("name_3").value;
        ciudad = document.getElementById("name_4").value;
        pais = document.getElementById("name_5").value;
        if(pais=="opt3"){
            pais="Colombia";
        }else if(pais=="opt4"){
            pais="panama";
        }else if(pais=="opt5"){
            pais="peru";
        }
        contact = "Nombre : "+name+"\n Apellido : "+apellido+"\n Direccion : "+direccion+"\n Ciudad : "+ciudad+"\n Pais : "+pais+"\n Asunto : "+asunto+"\n Mensaje : "+mensaje;
        ajaxContact(contact);
    }
}
function ajaxContact(contact){
      var objAjax = ajax();
      objAjax.open("POST", "correo/envioMail.php",true);
      objAjax.onreadystatechange=function() {
           /* if (objAjax.readyState == 4) {
                res = objAjax.responseText;
                eval(res);               
            }else{

            }*/
            
      }
      objAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      objAjax.send("message="+contact);
      
      //temporalmente ya que no garantiza si el correo se envio
      resumeAjax('Management/components/class.news.php','9','5');
}

