﻿// JScript File
//debugger

function contains(a, obj)
{
    for(var i = 0; i < a.length; i++)
    {
        if(a[i] === obj)
        {
            return true;
        }
    }
    return false;
}

 function buildBox()
 {
    //if (validate())
    // {
            var style = document.getElementById("searchBox").value;
            window.frames["contenido"].document.getElementById("box").src = style+".html";
    // }
}

function callForm(idForm)
{
    var form = document.getElementById(idForm);
    var radios = window.frames["contenido"].document.getElementsByName("frmCtrlValue");

    for (i=0;i<radios.length;i++){
        if (radios[i].checked==true)
            document.forms["aspnetForm"].elements["searchBox"].value = radios[i].value;
    }

    form.submit();
}

function CallPrint(strid, level, landscape)
{
    var prtContent = document.getElementById(strid);
    var WinPrint = window.open('','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');

    //window.open(level + 'print.aspx','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
    WinPrint.document.write(prtContent.innerHTML);

    if (landscape)
        alert('Seleccione el modo de impresi¢n HORIZONTAL antes de imprimir para que el mapa se visualice correctamente.');
    else
        sleep(2000);

    //WinPrint.document.getElementById("Principal").innerHTML = prtContent.innerHTML;
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print()
    WinPrint.close();
    //prtContent.innerHTML=strOldOne;
}

function sleep(millisegundos) {
    var inicio = new Date().getTime();
    
    while((new Date().getTime() - inicio) < millisegundos){
    }
}

function addMetaTag(nombre){
     var meta; 
     
      if (meta = document.getElementsByName("description").item(0)) {
         // set properties
         meta.content = "Comparto contigo a: "+nombre+". Visualiza en este link su teléfono, dirección, sitio web y otras informaciones de interés.";
      }
 }

 function installSearchEngine() {
    var path = document.getElementById("hdPath").value;
    
    if (window.external && ("AddSearchProvider" in window.external)) {
        // Firefox 2 and IE 7, OpenSearch
        window.external.AddSearchProvider(path+"paelSearchBox.xml");
    } else {
        // No search engine support (IE 6, Opera, etc).
        alert("Este navegador no admite la instalación de la aplicación, \npor restricciones establecidas en el mismo.");
    }
} 

function setValor(id, value) {
    document.getElementById(id).value = value;
    
}

// Menu de la seccion Nosotros
function initMenu(item)
{
     for (i = 1; i <= 5; i++) {
         var elem = "elem" + i
        
         if (document.getElementById(elem) != null) {
             if ((elem == item) && (document.getElementById(elem).style.display == 'none')) {
                 document.getElementById(elem).style.display = 'block';

             } else {
                 document.getElementById(elem).style.display = 'none';
             }
         }
     }
 }

// Seccion Menu - Abri pregunta
 function openQuestion(item) {
     for (i = 1; i <= 15; i++) {
         var elem = "Question" + i

         if (document.getElementById(elem) != null) {
             if ((elem == item) && (document.getElementById(elem).style.display == 'none')) {
                 document.getElementById(elem).style.display = 'block';

             } else {
                 document.getElementById(elem).style.display = 'none';
             }
         }
     }
 }

    function getElement(aID)
    {
        return (document.getElementById) ? document.getElementById(aID) : document.all[aID];
    }

    function getIFrameDocument(aID){ 
        var rv = null; 
        var frame=getElement(aID);
        // if contentDocument exists, W3C compliant (e.g. Mozilla) 
        if (frame.contentDocument)
            rv = frame.contentDocument;
        else // bad Internet Explorer  ;)
            rv = document.frames[aID].document;
        return rv;
    }

//    function adjustMyFrameHeight()
//    {
//        var frame = getElement("ui_ifrmeClassBanner");
//        var frameDoc = getIFrameDocument("ui_ifrmeClassBanner");
//        frame.height = frameDoc.body.scrollHeight;
//    }

    /** Valida el formulario para enviar un mensaje al cliente en el Microsite **/
    function valMsj() {
        var nombre = document.getElementById("nombre");
        var apellido = document.getElementById("apellido");
        var email = document.getElementById("email");
        var mensaje = document.getElementById("mensaje");
        var error = "";


        if (nombre == null || trim(nombre.value) == '')
            error = "Campo nombre obligatorio.";
        else if (apellido == null || trim(apellido.value) == '')
            error = "Campo apellido obligatorio.";
        else if (!checkEmail(email.value))
            error = "Campo email invalido.";
        else if (mensaje == null || trim(mensaje.value) == '')
            error = "Campo mensaje obligatorio.";

        if (error != "") {
            document.getElementById("errorMsj").innerHTML = error;
        }
        else {
            document.getElementById("validMsj").value = "1";
            var form = document.getElementById("aspnetForm");
            form.submit();
        }
    }

