window.executeScript = function(text){
    var startPos = text.indexOf('<script');
    if (startPos >= 0) 
        startPos = text.indexOf('>', startPos) + 1;
    while (startPos >= 0) {
        var endPos = text.indexOf('<\/script>', startPos);
        var script = text.substring(startPos, endPos);
        if (window.execScript) 
            window.execScript(script);
        else 
            window.eval(script);
        if (endPos > startPos) {
            startPos = text.indexOf('<script', endPos);
            if (startPos >= 0) 
                startPos = text.indexOf('>', startPos) + 1;
        }
    }
}

function enableDetails(pref){
    document.location = '#startResults';
    if (pref == undefined) 
        pref = "detail";
    var a = document.getElementById(pref + 'Content');
    var b = document.getElementById(pref + 'Search');
    a.style.display = "block";
    b.style.display = "none";
    var fr_page = document.getElementById("from_page");
    if (fr_page) 
        fr_page.value = "2";
}

function disableDetails(pref){
    if (pref == undefined) 
        pref = "detail";
    var a = document.getElementById(pref + 'Content');
    var b = document.getElementById(pref + 'Search');
    b.style.display = "block";
    a.style.display = "none";
}

function getelement(form, name){
    var k;
    var elements = form.elements;
    for (k = 0; k < elements.length; k++) {
        if (elements[k].name == name) 
            return elements[k];
    }
}

function changeFormValue(formName, name, value, idContent, mode){
    var idform = document.getElementById(formName);
    if (idform == undefined) {
        //alert ("Formulario Inexistente");
        return;
    }
    var component = getelement(idform, name);
    if (component == undefined) {
        //alert ("Atributo Inexistente");
        return;
    }
    component.value = value;
    sendForm(formName, idContent, mode);
}

function sendForm(formObject, idContent, mode){
    var idcont = document.getElementById(idContent);
    var idform = document.getElementById(formObject);
    if (idcont == undefined) {
        //alert ("Zona de Contenido no Existe");
        return;
    }
    if (idform == undefined) {
        //alert ("Formulario no Existe");
        return;
    }
    var callback = {
        success: function(o){
            idcont.innerHTML = o.responseText;
            executeScript(o.responseText);
        },
        failure: function(o){
            idcont.innerHTML = (mode != 'silent' ? 'Error en la Comunicacion.' : '');
        }
    }
    YAHOO.util.Connect.setForm(idform);
    var cObj = YAHOO.util.Connect.asyncRequest('POST', idform.action, callback);
    
    mode != 'silent' ? idcont.innerHTML = "<img src='" + INTRA_BASE_URL+ "site/include/ppa/images/indicator.gif' border='0'>" : idcont.innerHTML = ' '
}

window.videosHide = new Array();

function ShowNomina(calendar, zone, form, general, detail){
    n1 = document.getElementById(general);
    n2 = document.getElementById(detail);
    if (n1) 
        n1.style.display = 'none';
    if (n2) 
        n2.style.display = 'block';
    changeFormValue(form, 'calendar', calendar, zone);
}

function hideNomina(general, detail){
    n1 = document.getElementById(general);
    n2 = document.getElementById(detail);
    if (n1) 
        n1.style.display = 'block';
    if (n2) 
        n2.style.display = 'none';
}

function showPreviewPlayer(id, form, iddiv, e){
    var div = document.getElementById(iddiv);
    if (div) {
        pos_y = (browser() == 'NT' ? e.pageY : (browser() == 'IE' ? e.y + document.body.scrollTop : 0));
        pos_x = (browser() == 'NT' ? e.pageX : (browser() == 'IE' ? e.x + document.body.scrollLeft : 0));
        div.style.display = 'block';
        div.style.top = pos_y - 175 + 'px';
        div.style.left = pos_x - 140 + 'px';
        var component = getelement(document.getElementById(form), 'idFile');
        if (component.value != id) {
            document.getElementById(iddiv + 'Content').innerHTML = '';
            changeFormValue(form, 'idFile', id, iddiv + 'Content');
        }
    }
}

function hidePreviewPlayer(iddiv){
    var div = document.getElementById(iddiv);
    if (div) {
        div.style.display = 'none';
    }
}

var ctltime = 0;

function reloadForm(formName, name, value, idContent, mode, time){
    if (ctltime != undefined) {
        changeFormValue(formName, name, value, idContent, mode);
        ctltime = setTimeout('reloadForm("' + formName + '", "' + name + '", "' + value + '", "' + idContent + '", "' + mode + '", ' + time + ')', time);
    }
}

function stopReload(){
    clearTimeout(ctltime);
    ctltime = undefined;
}

function reloadChat(formName, name, value, idContent, mode, time){
    changeFormValue(formName, name, value, idContent, mode);
    setTimeout('reloadChat("' + formName + '", "' + name + '", "' + value + '", "' + idContent + '", "' + mode + '", ' + time + ')', time);
}

function mostrarOcultar(id){
    if (document.getElementById(id).style.display == 'none') 
        document.getElementById(id).style.display = '';
    else 
        document.getElementById(id).style.display = 'none';
}

function changeEyelashes(id, count, name_eyelash, name_zone){
    for (var i = 0; i < count; i++) {
        var pt = document.getElementById(name_eyelash + i);
        var zn = document.getElementById(name_zone + i);
        if (pt && zn) {
            if (i == id) {
                zn.style.display = 'block';
                YAHOO.util.Dom.replaceClass(pt.id, 'notSelected', 'selected');
            }
            else {
                zn.style.display = 'none';
                YAHOO.util.Dom.replaceClass(pt.id, 'selected', 'notSelected');
            }
        }
    }
}

function nuevaVentana(URL){
    window.open(URL, "nueva", "")
}

function menuOver(pos, object){
    td1 = document.getElementById('td_' + pos);
    new_pos = pos + 1;
    td2 = document.getElementById('td_' + new_pos);
    
    object.className = 'pestanamenu_1';
    td1.className = 'tdmenu_selecc_1';
    td2.className = 'tdmenu_selecc_2';
}

function menuOut(pos){
    td1 = document.getElementById('td_' + pos);
    new_pos = pos + 1;
    td2 = document.getElementById('td_' + new_pos);
    
    td1.className = 'tdmenu';
    td2.className = 'tdmenu';
}

function popUpGol(URL, w, h) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + w + ",height=" + h + "\');");
}
