﻿function $(id){
	return document.getElementById(id);
}

stuHover = function() {
    var cssRule;
    var newSelector;
    for (var i = 0; i < document.styleSheets.length; i++)
        for (var x = 0; x < document.styleSheets[i].rules.length; x++) {
        cssRule = document.styleSheets[i].rules[x];
        if (cssRule.selectorText.indexOf("LI:hover") != -1) {
            newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
            document.styleSheets[i].addRule(newSelector, cssRule.style.cssText);
        }
    }
    var getElm = $("nav").getElementsByTagName("LI");
    for (var i = 0; i < getElm.length; i++) {
        getElm[i].onmouseover = function() {
            this.className += " iehover";
        };
        getElm[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp(" iehover\\b"), "");
        };
    }
};
if (window.attachEvent) window.attachEvent("onload", stuHover);

function WriteSwfID(img,wsize,hsize,id)
{
	document.write("<object id=\""+id+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+wsize+"\" height=\""+hsize+"\">");
	document.write("<param name=\"movie\" value=\""+img+"\">");
	document.write("<param name=\"quality\"  value=\"high\">");
	document.write("<param name=\"wmode\"  value=\"transparent\">");
	document.write("<embed src=\""+img+"\" name=\""+id+"\" wmode=\"transparent\" swliveconnect=\"true\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+wsize+"\" height=\""+hsize+"\"></embed>");
	document.write("</object>");
}

function WriteSwfIDVar(img,wsize,hsize,id,Var)
{
 document.write("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0\" WIDTH=\""+wsize+"\" HEIGHT=\""+hsize+"\" ID=\""+id+"\">");
 document.write("<PARAM NAME=\"MOVIE\" VALUE=\""+img+"\">");
 document.write("<PARAM NAME=\"PLAY\" VALUE=\"TRUE\">");
 document.write("<PARAM NAME=\"LOOP\" VALUE=\"TRUE\">");
 document.write("<PARAM NAME=\"WMODE\" VALUE=\"TRANSPARENT\">");
 document.write("<PARAM NAME=\"QUALITY\" VALUE=\"HIGH\">");
 document.write("<PARAM NAME=\"SCALE\" VALUE=\"showall\">");
 document.write("<PARAM name=\"FlashVars\" value=\"" + Var + "\" />"); 
 document.write("<embed src=\""+img+"\" width=\""+wsize+"\" height=\""+hsize+"\" quality=\"high\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" flashvars=\"" + Var + "\"></embed>");
 document.write("</OBJECT>");
}

//gallery//
var widthdiv;
var widthcon;

var stops = false;
function moveup() {
    if (parseInt(widthdiv.style.left) > (parseInt(widthcon.style.width) - parseInt(widthdiv.style.width)) && !stops) {
        widthdiv.style.left = (parseInt(widthdiv.style.left) - 5) + 'px';
        setTimeout('moveup()', 10);
    }
}

function movedown() {
    if (parseInt(widthdiv.style.left) < 0 && !stops) {
        widthdiv.style.left = (parseInt(widthdiv.style.left) + 5) + 'px';
        setTimeout('movedown()', 10);
    }
}

objImage = new Image();

function changeimg(path, type, content) {
    if (type == '0') {
        $('div_gal').innerHTML = '<div style="padding-left:178px; padding-top:120px;"><img src="resources/images/ajax_load.gif" /></div>';
        if (content == '0') {
            objImage.src = 'resources/imagesgalery/' + path;
        }
        else {
            objImage.src = 'resources/imagesnews/' + path;
        }
    }
    else {
        var html = new Array();
        html[html.length] = '<object width="395" height="290"><param name="movie" value="http://www.youtube.com/v/' + path + '&hl=es&fs=1&"></param>';
        html[html.length] = '<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>';
        html[html.length] = '<embed src="http://www.youtube.com/v/' + path + '&hl=es&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" ';
        html[html.length] = 'allowfullscreen="true" width="395" height="290"></embed></object>';
        $('div_gal').innerHTML = html.join("");
    }
}

objImage.onload = function() {
    $('div_gal').innerHTML = '<img width="395px" height="290px" src="' + objImage.src + '" border="0" />';
};

//gallery//
//participacion//
var status = 0;
function messageinfo() {
    switch ($('ifoption').value) {
        case "Seccion":
            return " esta sección";
        case "Contenido":
            return " este contenido";
        default:
            return " este usuario";
    }
}

function displayinfo(voption) {
    if ($('hf_isauthent').value == "1") {
        changevis();
        var divcontent = $('content_action');
        if (voption != $('statemove').value) {
            $('statemove').value = voption;

            if (status == 2 && parseInt(divcontent.style.height) == 0)
                status = 0;
            else if (status == 2 && parseInt(divcontent.style.height) == 150)
                status = 1;

            resize(150);
        }
        else {
            resizeup(150);
            $('statemove').value = '-1';
        }
    }
    else
        alerts('Para poder realizar esta acción debes estar logueado.');
}

function changevis(){
    $('content_action').style.visibility = 'hidden';
}

function changeinv(){
    $('content_action').style.visibility = 'visible';
}

function resizeup(height) {
    var divcontent = $('content_action');
    dh = parseInt(divcontent.style.height);
    if (dh > 0) {
        dh -= 10;
        divcontent.style.height = dh + 'px';
        setTimeout('resizeup(' + height + ')', 10);
    }
}

function resize(height) {
    var divcontent = $('content_action');
    dh = parseInt(divcontent.style.height);
    if (dh == 0)
        bindcontent();
    if (dh < height && status == 0) {
        dh += 10;
        divcontent.style.height = dh + 'px';
        setTimeout('resize(' + height + ')', 10);
    }
    else if (dh > 0 && status == 1) {
        dh -= 10;
        divcontent.style.height = dh + 'px';
        setTimeout('resize(' + height + ')', 10);
    }
    else if (parseInt(divcontent.style.height) <= 0) {
        status = 0;
        setTimeout('resize(' + height + ')', 10);
    }
    else {
        status = 2;
        changeinv();
    }
}

function loadajax() {
    $('content_action').innerHTML = '<div style="margin-top:55px;" align="center"><img width="20" height="20" src="resources/images/ajax_load_small.gif" /></div>';
}

function loadmessage(message) {
    $('content_action').innerHTML = '<div style="margin-top:55px; font-size:14px;" align="center"><strong>' + message + '</strong></div>';
}

function bindcontent() {
    var divcontent = $('content_action');
    voption = $('statemove').value;
    switch (voption) {
        case '0':
            divcontent.innerHTML = '<iframe id="frm_wy" scrolling="no" frameborder="0" width="620px" height="130px" src="general/wysiwyg.htm"></iframe><a href="javascript:comentar();"><img style="margin-left:5px;" border="0" src="resources/images/bt_com.gif" /></a>';
            break;
        case '1':
            divcontent.innerHTML = '<table width="100%" border="0"><tr><td>De:</td><td><strong>' + $('ifusername').value + '</strong></td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>Para:</td><td><input style="width:220px;" type="text" name="textfield" id="txt_para" /></td><td>Correo:</td><td><input style="width:220px;" type="text" name="textfield2" id="txt_correo" /></td></tr><tr><td>Comentario</td><td colspan="3"><textarea id="txtcom_a" style="width:530px; height:60px;"></textarea></td></tr><tr><td colspan="4"><a href="javascript:enviaamigo();"><img border="0" src="resources/images/bt_men.gif" /></a></td></tr></table>';
            break;
        case '2':
            divcontent.innerHTML = '<strong>Calificar</strong><br/><div style="padding:5px;"><img title="Muy malo" onclick="pool(1)" onmouseover="change(0)" onmouseout="limpia()" style="float:left;" id="img1" src="resources/images/btn_cal_o.jpg" /><img title="Malo" onclick="pool(2)" onmouseover="change(1)" onmouseout="limpia()" style="float:left;" id="img2" src="resources/images/btn_cal_o.jpg" /><img title="Regular" onclick="pool(3)" onmouseover="change(2)" onmouseout="limpia()" style="float:left;" id="img3" src="resources/images/btn_cal_o.jpg" /><img title="Bueno" onclick="pool(4)" onmouseover="change(3)" onmouseout="limpia()" style="float:left;" id="img4" src="resources/images/btn_cal_o.jpg" /><img title="Excelente" onclick="pool(5)" onmouseover="change(4)" onmouseout="limpia()" style="float:left;" id="img5" src="resources/images/btn_cal_o.jpg" /></div><div style="padding:6px;" id="div_res"></div>';
            break;
        case '3':
            var url = window.location;
            ucaction.redes(url, bindcontent_CallBack);
            break;
        case '4':
            divcontent.innerHTML = '<strong>Favoritos</strong><br/><br/><br/><div id="div_favorito">Para agregar este contenido a tus favoritos haz clic <a href="javascript:favoritos();">aquí</a></div>';
            break;
        case '5':
            divcontent.innerHTML = '<strong>Enviar mensaje</strong><br/>Asunto<br/><input maxlength="150" style="width:620px;" id="inpasunto" type="text" /><br/>Mensaje<br/><textarea onkeyup="valida_longitud(4000, \'txt_msg\')" id="txt_msg" rows="3" style="border:solid 1px #B0C1D0; width:620px; height:45px;" ></textarea><br/><iframe frameborder="0" scrolling="no" width="240px" height="20px" src="general/wffile.aspx" id="frmload"></iframe><br/><a href="javascript:buzon();"><img border="0" src="resources/images/bt_send.gif" /></a>';
            break;
        default:
            divcontent.innerHTML = '<strong>Agregar a mis compañeros</strong><br/><div id="div_favorito">Para agregar este usuario a tus compañeros haz clic <a href="javascript:addfriend();">aquí</a></div>';
            break;
    }
}

function bindcontent_CallBack(response) {
    imgs = response.value;
    var divcontent = $('content_action');
    divcontent.innerHTML = '<strong>Compartir</strong><br/><div style="padding-top:25px;" class="compartir">' + imgs + '</div>';
}

function pool(quality) {
    var idctn = $('ifid').value;
    var option = $('ifoption').value;
    loadajax();
    ucaction.pool(quality, option, idctn, pool_CallBack);
}

function pool_CallBack(response) {
    var result = response.value;
    if (result == -1)
        loadmessage('No se pudo ingresar tu calificación.');
    else if (result == 0)
        loadmessage('Ya calificaste' + messageinfo());
    else
        loadmessage('Gracias por calificar' + messageinfo());
    setTimeout("displayinfo(2);", 1500);
}

function addfriend() {
    var iduser = $('ifid').value;
    ucaction.addfriend(iduser, addfriend_CallBack);
}

function addfriend_CallBack(response) {
    var result = response.value;
    if (result == 2)
        loadmessage('Ya haz agregado a este usuario como amigo');
    else if (result == -1)
        loadmessage('No se pudo agregar a este usuario como amigo');
    else if (result == 3)
        loadmessage('No puedes agregarte como amigo');    
    else {
        loadmessage('Haz agregado al usuario como amigo!');
    }
    
    setTimeout("displayinfo(6);", 1500);
}

function change(va1) {
    var asd = new Array('img1', 'img2', 'img3', 'img4', 'img5');
    ruta1 = "resources/images/btn_cal.jpg";
    ruta2 = "resources/images/btn_cal_o.jpg";
    var cadena = '';
    for (i = va1 + 1; i < 5; i++) {
        $(asd[i]).src = ruta2;
    }
    for (j = va1; j >= 0; j--) {
        $(asd[j]).src = ruta1;
    }
    $('div_res').innerHTML = "&nbsp;"+$(asd[va1]).title;
}

function limpia() {
    var asd = new Array('img1', 'img2', 'img3', 'img4', 'img5');
    ruta2 = "resources/images/btn_cal_o.jpg";
    for (j = 0; j < 5; j++) {
        $(asd[j]).src = ruta2;
    }
    $('div_res').innerHTML = '';
}

function comentar() {
    var idctn = $('ifid').value;
    var option = $('ifoption').value;
    var coment = $('frm_wy').contentWindow.getvalue();
    var iduser = $('idusercontent').value != '' ? $('idusercontent').value : '0'; 
    var idreplica = $('ifreplica').value;
    if (coment != '') {
        loadajax();
        ucaction.comentar(coment, option, idctn, idreplica, iduser, comentar_CallBack);
    }
    else
        alerts('Debes ingresar un comentario.');
}

function comentar_CallBack(response) {
    var result = response.value;
    loadmessage('Tu comentario fue ingresado satisfactoriamente.');
    $('div_com').innerHTML = result.Html;
    $('ifreplica').value = '0';
    if (result.IsPagin) {
        $('apan').style.display = 'block';
    }
    else {
        $('apan').style.display = 'none';
    }
    setTimeout("displayinfo(0);", 1500);
}

function replic(idreplica) {
    if ($('hf_isauthent').value == "1") {
        $('ifreplica').value = idreplica;
        $('divres_' + idreplica).innerHTML = '<iframe id="frm_wy" scrolling="no" frameborder="0" width="620px" height="130px" src="general/wysiwyg.htm"></iframe><a href="javascript:replicar();"><img style="margin-left:5px;" border="0" src="resources/images/bt_com.gif" /></a>';
        $('divres_' + idreplica).style.display = 'block';
    }
    else
        alerts('Para poder realizar esta acción debes estar logueado.');
}

function replicar() {
    var idctn = $('ifid').value;
    var option = $('ifoption').value;
    var coment = $('frm_wy').contentWindow.getvalue();
    var iduser = $('idusercontent').value != '' ? $('idusercontent').value : '0';
    var idreplica = $('ifreplica').value;
    if (coment != '') {
        ucaction.comentar(coment, option, idctn, idreplica, iduser, replicar_CallBack);
    }
    else
        alerts('Debes ingresar un comentario.');
}

function replicar_CallBack(response) {
    var result = response.value;
    $('div_com').innerHTML = result.Html;
    $('ifreplica').value = '0';
    if (result.IsPagin) {
        $('apan').style.display = 'block';
    }
    else {
        $('apan').style.display = 'none';
    }
}

function votef(idcom, votos, tipo) {
    if ($('hf_isauthent').value == "1") {
        total = parseInt(votos) + 1;
        ucaction.voteup(idcom, total, tipo);
        $('lnk_f_' + idcom).innerHTML = '(' + total + ') Votos a favor';
        $('lnk_f_' + idcom).href = 'javascript:;';
        $('lnk_c_' + idcom).href = 'javascript:;';
    }
    else {
        alerts('Debes estar logueado para poder votar.')
    }
}

function votec(idcom, votos, tipo) {
    if ($('hf_isauthent').value == "1") {
        total = parseInt(votos) + 1;
        ucaction.votedown(idcom, total, tipo);
        $('lnk_c_' + idcom).innerHTML = '(' + total + ') Votos en contra';
        $('lnk_c_' + idcom).href = 'javascript:;';
        $('lnk_f_' + idcom).href = 'javascript:;';
    }
    else {
        alerts('Debes estar logueado para poder votar.')
    }
}

function favoritos() {
    var idctn = $('ifid').value;
    loadajax();
    ucaction.favorito(idctn, favoritos_CallBack);
}

function favoritos_CallBack(response) {
    var result = response.value;
    if (result == -1)
        loadmessage('No se pudo agregar el contenido a tus favoritos.');
    else if (result == 0)
        loadmessage('Este contenido ya se encuentra dentro de tus favoritos.');
    else
        loadmessage('Se a agregado este contenido a tus favoritos');
    setTimeout("displayinfo(4);", 1500);
}

function userinsert(cn) {
    if ($('hf_isauthent').value == "1") {
        var activo = $('hfprivado').value;
        var idgrupo = $('hfgroup').value;
        $('div_group').innerHTML = '<img src="resources/images/ajax_load.gif" />';
        ucgrupo.insertuser(activo, idgrupo, cn, userinsert_CallBack);
    }
    else
        alerts('Debes estar logueado para poder ingresar al grupo.')
}

function userinsert_CallBack(response) {
    var result = response.value;
    $('div_group').innerHTML = '';
    alerts(result);
}

function buzon(ctns) {
    if ($('txt_msg').value != '' && $('inpasunto').value != '') {
        var ctns = $('ifid').value;
        $('frmload').contentWindow.changeid(ctns);
    }
    else {
        alerts('Debes ingresar un asunto y un mensaje.');
    }
}

function buzonresult(result, strfile){
    if (result == -1)
        alerts('El tamaño del buzón supero el límite de almacenamiento para archivos.');
    else if (result == 1) {
        var str = $('txt_msg').value;
        var ctn = $('ifid').value;
        var asunto = $('inpasunto').value;
        loadajax();
        ucaction.insertbuzon(str, ctn, strfile, asunto, buzonresult_CallBack);
    }
}

function buzonresult_CallBack(response) {
    var action = response.value;
    if (!action)
        loadmessage('No se pudo enviar el mensaje al buzón');
    else
        loadmessage('Se ha enviado el mensaje de forma satisfactoria.');
    setTimeout("displayinfo(5);", 1500);        
}

function enviaamigo() {
    if ($('txt_para').value == '') {
        alerts('Debes ingresar el nombre de tu amigo');
        return;
    }
    else if ($('txt_correo').value == '') {
        alerts('Debes ingresar el correo de tu amigo');
        return;
    }
    else if ($('txtcom_a').value == '') {
        alerts('Debes ingresar un comentario');
        return;
    }
    else {
        var para = $('txt_para').value;
        var correo = $('txt_correo').value;
        var coment = $('txtcom_a').value;
        titulo = window.document.title;
        loadajax();
        ucaction.enviomsg(parseInt($('ifid').value), para, correo, window.location, coment, titulo, sendemail_CallBack);
    }
}

function sendemail_CallBack(response) {
    var result = response.value;
    if (result == -1) {
        loadmessage('No se pudo enviar el mensaje. Intentalo más tarde.');
    }
    else {
        loadmessage('Tu mensaje fue enviado satisfactoriamente.');
    }

    setTimeout("displayinfo(1);", 1000);
}

function reportcom(idcom) {
    if ($('hf_isauthent').value == "1") {
        var url = window.location.toString();
        var strurl = 'divlayer/dlreportar.aspx?idc=' + idcom + '&op=' + $('ifoption').value + '&url=' + url.replace(/&/gi, '%26');
        opendiv('400px', '200px', strurl, 0);
    }
    else {
        alerts('Para poder realizar esta acción debes estar logueado.')
    }
}

function recoverypassword() {
    opendiv('400px', '280px', 'divlayer/dlpassword.aspx', 0)
}

function deletecom(idcom) {
    if (confirm('¿Estas seguro que deseas eliminar el comentario?')) {
        var tipo = $('ifoption').value;
        var id = $('ifid').value;
        var iduser = $('idusercontent').value != '' ? $('idusercontent').value : '0';
        ucaction.delcomentario(idcom, tipo, id, iduser, deletecom_CallBack);
    }
}

function deletecom_CallBack(response) {
    var result = response.value;
    $('div_com').innerHTML = result.Html;
    if (result.IsPagin) {
        $('apan').style.display = 'block';
    }
    else {
        $('apan').style.display = 'none';
    }
}
//participacion//
function hideobj(idobj) {
    if ($(idobj).style.display == 'none')
        $(idobj).style.display = 'block';
    else
        $(idobj).style.display = 'none';
}

function divlayer() {
    document.write('<div id="divlayer"></div><div id="divframe">');
    document.write('<table style="height: 100%; width: 100%; _height:700px;" cellpadding="0" cellspacing="0">');
	document.write('<tr><td valign="middle" align="center"><div>');
	document.write('<div id="div_cont_alert">');
	document.write('<div id="div_cont_alert_cab"></div>');
	document.write('<img style="margin:15px;" width="64" height="60" src="resources/images/ico_alert.jpg" align="left"  />');
	document.write('<div id="div_alert" align="left"></div>');
	document.write('<div align="right" style="height:30px; width:100%; background-color:#D4D4D4;">');
	document.write('<input class="btn_base" type="button" value="Aceptar" onclick="closediv()" id="lnk_accept" />');
	document.write('</div></div><div style="height: 24px;" id="div_cls" align="right"></div>');
	document.write('<div id="div_cont_frame" style="position:relative;"><div align="left" style="position:absolute;top:0px;left:0px;background-color:white;" id="cargando"><img width="20" height="20" style="padding-top:10px;padding-left:10px;" src="resources/images/ajax_load_small.gif" />Cargando..</div><iframe style="background-color: Black;" scrolling="no" frameborder="0" id="ifrmlayer"></iframe></div>');
	document.write('</div></td></tr></table></div>');   
}

function opendiv(width, heigh, url, postback) {
    var alto;
    if (window.screen.height > document.body.scrollHeight)
        alto = window.screen.height;
    else
        alto = document.body.scrollHeight;
    
	$("div_cls").style.display = 'block';
    $("div_cont_alert").style.display = 'none';
	$("ifrmlayer").style.display = 'block';
	$('divlayer').style.display = 'block';
    $('divframe').style.display = 'block';
    $('divlayer').style.height = alto + 'px';
    $('divlayer').style.width = '100%';
    $("ifrmlayer").src = url;
    $("ifrmlayer").height = heigh;
    $("ifrmlayer").width = width;
    $("div_cont_frame").style.height = heigh;
    $("div_cont_frame").style.width = width;
    $("cargando").style.height = heigh;
    $("cargando").style.width = width;
    $("cargando").style.display = 'none';
	$("div_cls").style.width = width;
    window.scrollTo(0, 0);
}

function closediv() {
    $('divlayer').style.display = 'none';
    $('divframe').style.display = 'none';
    $("ifrmlayer").src = '';
}

function alerts(message)
{
    var alto;
    if (window.screen.height > document.body.scrollHeight)
        alto = window.screen.height;
    else
        alto = document.body.scrollHeight;

    $("divlayer").style.height = alto + 'px';
	$("divlayer").style.height = document.body.scrollWidth;
    $("divlayer").style.display = 'block';
	$("divframe").style.display = 'block';
	$("div_cls").style.display = 'none';
	$("div_cont_frame").style.display = 'none';
	$("ifrmlayer").style.display = 'none';
	$("div_cont_alert").style.display = 'block';
	$("div_alert").innerHTML = message;
	$("lnk_accept").focus();
	window.scrollTo(0, 0);
	
}

function findportal() {
    if ($('inp_find').value != '' && $('inp_find').value != 'Búsqueda unipiloto' && /^[\w* áéíóúÁÉÝÓÚñÑ]+$/.test($('inp_find').value)) {
        window.location = "?opt=ucbusqueda&key=" + $('inp_find').value;
    }
    else {
        alerts('Debes ingresar un criterio de búsqueda valido.');
    }
}

function validateimgs(value) {
    var b = value.split('.');
    var valid = /^(gif|jpg|png|jpeg)$/.test(b[b.length - 1].toLowerCase());
    return valid;
}

function validatefilesb(value) {
    var b = value.split('.');
    var valid = /^(exe|dll)$/.test(b[b.length - 1].toLowerCase());
    return !valid;    
}

function validatefiles(strcadena, strexpress) {
    var b = value.split('.');
    var re = new RegExp(strexpress);
    return re.test(b);
}

function findsubm(e) {
    var k = null;
    (e.keyCode) ? k = e.keyCode : k = e.which;
    if (k == 13) {
        findportal();
        e.cancelBubble = true;
        e.returnValue = false;
    }
}

function logInsub(e) {
    var k = null;
    (e.keyCode) ? k = e.keyCode : k = e.which;
    if (k == 13) {
        logIn();
        e.cancelBubble = true;
        e.returnValue = false;
    }
}

function logIn() {
    if ($('user').value != '' && $('pass').value != '') {
        $('div_log').style.display = 'block';
        loguin.authentic($('user').value, $('pass').value, logIn_CallBack);
    }
    else {
        alerts('Debes ingresar tu correo y contraseña.');
    }
}

function logIn_CallBack(response) {
    var result = response.value;
    if (result == 1)
        window.location = window.location;
    else if (result == 2)
        alerts('Verifica que tu correo y contraseña esten bien digitados.');
    else
        alerts('Ha ocurrido una inconsistencia, intentalo más tarde.');
    $('div_log').style.display = 'none';
}

function closesession() {
    loguin.closesesion();
    window.location = window.location;
}

function nameadmin(value) {
    if ($('spn_admin') != null) {
        $('spn_admin').innerHTML = value;
    }
}

contenido_textarea = "";
function valida_longitud(num_caracteres_permitidos, NameControl) {
    var objtxtArea = $(NameControl);
    num_caracteres = objtxtArea.value.length;

    if (num_caracteres <= num_caracteres_permitidos) {
        contenido_textarea = objtxtArea.value
    } else {
        objtxtArea.value = contenido_textarea
    }
}

//Examinar
addEvent = function(obj, type, fn) {
    if (obj.addEventListener)
        obj.addEventListener(type, fn, false);
    else if (obj.attachEvent) {
        obj["e" + type + fn] = fn;
        obj[type + fn] = function() { obj["e" + type + fn](window.event); };
        obj.attachEvent("on" + type, obj[type + fn]);
    }
};
bc_newElement = function(tag) {
    return document.createElement(tag);
};
bc_getElement = function(id) {
    return document.getElementById(id);
};

var field_count = 1;
var optionvald = 1;//1 imagen, 2 buzon
bc_init = function(fileId, displayId) {
    try {
        field = bc_getElement(fileId);
        field.display = bc_getElement(displayId);

        if (!field || !field.type || field.type != 'file' || !field.display) return;

        addEvent(field, 'change', bc_addField);
    } catch (ex) { bc_handleError(ex); }
};

bc_load = function(fileId, displayId, optio) {
    optionvald = optio;
    addEvent(window, 'load', new Function("bc_init('" + fileId + "', '" + displayId + "');"));
};
bc_addField = function() {
    var obj = $(this.id);
    if (optionvald == 1) {
        var namefile = obj.value.toString();
        if (!validateimgs(namefile)) {
            alerts("Solo se permiten archivos tipo imagen (jpg, gif o png).");
            return;
        }
    }
    else {
        if (!validatefilesb(obj.value)) {
            alerts("No se permiten archivos ejecutables.");
            return;
        }
    }

    if (this.id.indexOf('ifEx') == -1) {
        try {
            new_field = bc_newElement('INPUT');
            new_field.type = 'file';
            new_field.id = new_field.name = this.id.replace(/-@bc-.*$/g, "") + '-@bc-' + field_count++;
            new_field.className = 'file';
            new_field.display = this.display;
            addEvent(new_field, 'change', bc_addField);

            this.parentNode.insertBefore(new_field, this);

            li = bc_newElement('LI');

            img = bc_newElement('IMG');
            img.src = '/resources/images/ico_eliminar.gif';
            img.border = '0';

            a = bc_newElement('A');
            a.href = "javascript:;";
            a.title = "Eliminar imagen";
            a.appendChild(img);
            a.field_id = this.id;
            addEvent(a, 'click', bc_removeField);

            li.appendChild(a);
            li.appendChild(document.createTextNode('  ' + this.value.substring(this.value.search(/[^\/\\]+$/))));
            this.display.appendChild(li);

            this.style.position = 'absolute';
            this.style.left = '-1000px';
        } catch (ex) { bc_handleError(ex); }
    }
    else {
        document.getElementById('txtExaminar').value = this.value;
    }
};
bc_removeField = function(event) {
    try {
        (del = bc_getElement(this.field_id)).parentNode.removeChild(del);

        this.parentNode.parentNode.removeChild(this.parentNode);
        if (event && event.preventDefault)
            event.preventDefault();
        return false;
    } catch (ex) { bc_handleError(ex); }
};
bc_handleError = function(ex) { alert(ex); };

function dur() {
    var ids = document.getElementsByTagName('LI');
    alert(ids.length);
}
//Fin Examin
function agregaramigo(idrel) {
    if ($('hf_isauthent').value == '1')
        ucgrupos.agregaramigo(idrel, agregaramigo_CallBack);
    else
        alerts('Debes estar logueado para ejecutar esta acción.');
}

function agregaramigo_CallBack(response) {
    var result = response.value;
    if (result == 1)
        alerts('Has agregado satisfactoriamente como amigo.');
    else if (result == 2)
        alerts('Ya has agregado como amigo.');
    else if (result == 3)
        alerts('No puedes agregarte como amigo.');        
    else
        alerts('No se pudo agregar como amigo.');
}

function blurfind(obj) {
    if (obj.value == '')
        obj.value = 'Búsqueda unipiloto';
}

function ofertinsert(idctn) {
    ucoferta.aplicaoferta(idctn, ofertinsert_CallBack);
}

function ofertinsert_CallBack(response) {
    var result = response.value;
    if (result == 1)
        alerts('Has aplicado a la oferta satisfactoriamente.');
    else if (result == 2)
        alerts('Ya has aplicado a esta oferta.');
    else
        alerts('El sistema esta ocupado, intenta aplicar mas tarde.');
}

function changefilter(result, idoption, idbtn) {
    $(idoption).value = result;
    $(idbtn).click();
    $('al1').className = '';
    $('al2').className = '';
    $('al3').className = '';

    if (result == 0) {
        $('al1').className = 'selected';
    }
    else if (result == 1) {
        $('al2').className = 'selected';
    }
    else if (result == 2) {
        $('al3').className = 'selected';
    }
}

function editcont(scc, cn) {
    ucaction.urledit(scc, cn, editcont_CallBack);
}

function editcont_CallBack(response) {
    var url = response.value;
    window.location = url;
}

function pagincom() {
    ucaction.paginc($('ifoption').value, parseInt($('ifid').value), parseInt($('fhcount').value) + 1, pagincom_CallBack);
}

function pagincom_CallBack(response) {
    var result = response.value;
    if(result != null) {
        if (result != '') {
            $('div_com').innerHTML += result;
            $('fhcount').value = parseInt($('fhcount').value) + 1;
        }
        else
            $('apan').style.display = 'none';
    }
}

function getconv(val, name) {
    $('idu').value = val;
    loguin.getmessage(val, function(response) {
        var result = response.value;
        if (result != null) {
            $('dvmess').innerHTML = result;
            $('lblu').innerHTML = name;
            $('cnv').style.display = 'block';
            $('dvmess').scrollTop = $('dvmess').scrollHeight;
        }
    });
}

function setusers() {
    loguin.usercon(function(response) {
        var result = response.value;
        if (result != null) {
            $('listuser').innerHTML = result;
        }
    });
}

function sendmess() {
    var msg = $('txt').value;
    $('txt').value = '';
    loguin.setmessage(parseInt($('idu').value), msg, function(response) {
        var result = response.value;
        if (result != null) {
            $('dvmess').innerHTML = result;
            $('dvmess').scrollTop = $('dvmess').scrollHeight;
        }
    });
}

var nofoc = false;
function refreshmessage() {
    if ($('idu').value != "0") {
        loguin.getmessage(parseInt($('idu').value), function(response) {
            var result = response.value;
            if (result != null) {
                if ($('dvmess').innerHTML.length > 0 && $('dvmess').innerHTML.length != result.length && !nofoc) {
                    $('lblu').style.color = '#000000 !important';
                    $('lblu').style.backgroundColor = '#22E822 !important';
                    $('imgchat').src = 'resources/images/chatmess.png';
                }
                $('dvmess').innerHTML = result;
                $('dvmess').scrollTop = $('dvmess').scrollHeight;
            }
        });
    }
    setTimeout("refreshmessage()", 5000);
}

function sendm(e) {
    var k = null;
    (e.keyCode) ? k = e.keyCode : k = e.which;
    if (k == 13) {
        sendmess();
        e.cancelBubble = true;
        e.returnValue = false;
    }
}

function chat() {
    if ($('us').style.display == 'block') {
        $('us').style.display = 'none';
        $('cnv').style.display = 'none';
        $('dvgenchat').style.display = 'none';
    }
    else {
        $('dvgenchat').style.display = 'block';
        $('us').style.display = 'block';
        if ($('idu').value != "0") {
            $('cnv').style.display = 'block';
        }
        $('dvmess').scrollTop = $('dvmess').scrollHeight;
    }
}

function verifchat() {
    var result;
    if ($('us').style.display == 'block') {
        if ($('idu').value != "0")
            result = $('idu').value + '-1-' + ($('lblu').innerHTML.length == 0 ? '0' : $('lblu').innerHTML);
        else
            result = '0-1-' + ($('lblu').innerHTML.length == 0 ? '0' : $('lblu').innerHTML);
    }
    else
        result = '0-0-0';
    loguin.getinfochat(result);
}

function changecol(val) {
    nofoc = val;
    if (val) {
        $('lblu').style.color = 'white !important';
        $('lblu').style.backgroundColor = 'black !important';
        $('imgchat').src = 'resources/images/chat.png';
    }    
}
