/**
 * Wil Wazka (syscomware) - 2010-02-19 Bogotá, Colombia
 */
function AddEventHandler (elem, evt, func) {
    if (elem == undefined) return;
    if (! elem ) return;
	try {
		if (elem.addEventListener)  // W3C DOM
			elem.addEventListener(evt, func, false);
		else if (elem.attachEvent) { // IE DOM
			 var r = elem.attachEvent("on"+evt, func);
			return r;
			}
		else throw 'No es posible añadir evento';
	}
	catch (ex)
	{
		if (typeof console != 'undefined' && console.error)
			console.error("Error adding event Handler: "+ex);
		else
			alert ("Error adding event Handler: "+ex);
	}
}

//FUNCION DE VALIDACION DE EMAIL
function ValidaEstructuraEmail(addr,man,db)
{
    if (addr == '' && man) {if (db) alert('El email es obligatorio.');return false;}
    if (addr == '') return true;
    var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
    for (i=0; i<invalidChars.length; i++) {
        if (addr.indexOf(invalidChars.charAt(i),0) > -1) {if (db) alert('El email contiene caracteres invalidos.');return false;}
    }
    for (i=0; i<addr.length; i++) {
        if (addr.charCodeAt(i)>127){if (db) alert("El email contiene caracteres no ascii.");return false;}
    }
    var atPos = addr.indexOf('@',0);
    if (atPos == -1){if (db) alert('El email debe contener el simbolo @');return false;}
    if (atPos == 0){if (db) alert('El email no debe iniciar con @');return false;}
    if (addr.indexOf('@', atPos + 1) > - 1) {if (db) alert('El email solo debe contener un simbolo @');return false;}
    if (addr.indexOf('.', atPos) == -1) {if (db) alert('El dominio del email es invalido.');return false;}
    if (addr.indexOf('@.',0) != -1) {if (db) alert('El simbolo \'@.\' no es valido.');return false;}
    if (addr.indexOf('.@',0) != -1){if (db) alert('El simbolo \'.@\' no es valido.');return false;}
    if (addr.indexOf('..',0) != -1) {if (db) alert('El simbolo \'..\' no es valido.');return false;}
    var suffix = addr.substring(addr.lastIndexOf('.')+1);
    if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
        if (db) alert('El dominio del email es invalido.');return false;}
    return true;
}


//VARIABLES DE DETECCION DE POSICION DEL MOUSE EN LA PANTALLA
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var xMousePosMax = 0; // Width of the page
var yMousePosMax = 0; // Height of the page



var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
	        || this.searchVersion(navigator.appVersion)
	        || "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i=0;i<data.length;i++)	{
	        var dataString = data[i].string;
	        var dataProp = data[i].prop;
	        this.versionSearchString = data[i].versionSearch || data[i].identity;
	        if (dataString) {
		        if (dataString.indexOf(data[i].subString) != -1)
			        return data[i].identity;
	        }
	        else if (dataProp)
		        return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
    },
    dataBrowser: [
        {
	        string: navigator.userAgent,
	        subString: "Chrome",
	        identity: "Chrome"
        },
        { 	string: navigator.userAgent,
	        subString: "OmniWeb",
	        versionSearch: "OmniWeb/",
	        identity: "OmniWeb"
        },
        {
	        string: navigator.vendor,
	        subString: "Apple",
	        identity: "Safari"
        },
        {
	        prop: window.opera,
	        identity: "Opera"
        },
        {
	        string: navigator.vendor,
	        subString: "iCab",
	        identity: "iCab"
        },
        {
	        string: navigator.vendor,
	        subString: "KDE",
	        identity: "Konqueror"
        },
        {
	        string: navigator.userAgent,
	        subString: "Firefox",
	        identity: "Firefox"
        },
        {
	        string: navigator.vendor,
	        subString: "Camino",
	        identity: "Camino"
        },
        {		// for newer Netscapes (6+)
	        string: navigator.userAgent,
	        subString: "Netscape",
	        identity: "Netscape"
        },
        {
	        string: navigator.userAgent,
	        subString: "MSIE",
	        identity: "Explorer",
	        versionSearch: "MSIE"
        },
        {
	        string: navigator.userAgent,
	        subString: "Gecko",
	        identity: "Mozilla",
	        versionSearch: "rv"
        },
        { 		// for older Netscapes (4-)
	        string: navigator.userAgent,
	        subString: "Mozilla",
	        identity: "Netscape",
	        versionSearch: "Mozilla"
        }
    ],
    dataOS : [
        {
	        string: navigator.platform,
	        subString: "Win",
	        identity: "Windows"
        },
        {
	        string: navigator.platform,
	        subString: "Mac",
	        identity: "Mac"
        },
        {
	        string: navigator.platform,
	        subString: "Linux",
	        identity: "Linux"
        }
    ]
};


/*************************FUNCION MUESTRA POPUP************************/
function Mostrar(UrlAbrir,AnchoVentana,AltoVentana)
{
    var iframeMostrar;
    var divImagenBig;
    var divImagenBigInner;

    //CAPTURA IFRAME A MOSTRAR
    iframeMostrar = document.getElementById('imgCapa');
    //CAPTURA DIV DE EFECTOS
    divImagenBig = document.getElementById('ImagenBig');
    divImagenBigInner = document.getElementById('ImagenBigInner');
    if(iframeMostrar != null && divImagenBig != null && divImagenBigInner != null)
    {
        //CAPTURA DISTANCIA Y DE LA VENTANA
        var dsoctop = document.all? iecompattest().scrollTop : pageYOffset
    	
	
        //ASIGNA PROPIEDADES AL IFRAME
        iframeMostrar.style.width = AnchoVentana + 'px';
        iframeMostrar.style.height = AltoVentana + 'px';
        iframeMostrar.src = UrlAbrir;
		
		

        //ASIGNA PROPIEDADES A DIV DE EFECTOS
        divImagenBig.style.visibility = "";
        divImagenBig.style.display='block';
        divImagenBig.style.height = (window.document.body.scrollHeight) + 'px';
		//alert("ok");
        divImagenBig.style.overflow = 'auto';
		

        divImagenBigInner.style.visibility = "";
	    divImagenBigInner.style.display='block';
	
	    //ASIGNA POSICION DEL IFRAME
	    divImagenBigInner.style.left = ((document.body.clientWidth/2) - (AnchoVentana/2))+'px';	
	    divImagenBigInner.style.top = (dsoctop + 50) + 'px';
    }
    //CAPTURA TODOS LOS SELECT QUE EXISTEN EN EL FORMULARIO
        var objSel = document.getElementsByTagName('select');

    //OCULTA LOS OBJETOS SELECT EN IE
            if(BrowserDetect.browser == 'Explorer')
            {
                if(objSel != null)
                {
                    for(i = 0; i < objSel.length; i++)
                    {
                        objSel[i].style['visibility'] = 'hidden';
                    }
                }
            }
    //CAPTURA TODOS LOS INPUT QUE EXISTEN EN EL FORMULARIO
        var objinp = document.getElementsByTagName('input');

    //OCULTA LOS OBJETOS INPUT EN IE
            if(BrowserDetect.browser == 'Explorer')
            {
                if(objinp != null)
                {
                    for(i = 0; i < objinp.length; i++)
                    {
                        objinp[i].style['visibility'] = 'hidden';
                    }
                }
            }
}
/*************************FIN FUNCION MUESTRA POPUP************************/

/*************************FUNCION PARA CAMBIAR EL TAMAÑO DEL POPUP ************************/
function redimFrame()
{
		var alturaPagina;
		var iframeMostrar = document.getElementById('imgCapa');
		alturaPagina=iframeMostrar.contentWindow.document.body.scrollHeight;
		//alert(alturaPagina);
		iframeMostrar.style.height=alturaPagina + 'px';
}
/*************************FIN FUNCION PARA CAMBIAR EL TAMAÑO DEL POPUP ************************/

/*************************FIN FUNCION MUESTRA POPUP************************/

/*************************FUNCION PARA CAMBIAR EL TAMAÑO DE IFRAMES ************************/
function RedimIframeCalen(IdIframe)
{
		var alturaPagina;
		var iframeMostrar = document.getElementById(IdIframe);
		alturaPagina = iframeMostrar.contentWindow.document.body.scrollHeight;
		alturaPagina = alturaPagina + 15;
		iframeMostrar.style.height=alturaPagina + 'px';
}
/*************************FIN FUNCION PARA CAMBIAR EL TAMAÑO DEL POPUP ************************/

/*************************FUNCION OCULTA POPUP************************/
function Ocultar()
{
    var divImagenBig;
    var divImagenBigInner;

    //CAPTURA DIV DE EFECTOS
    divImagenBig = document.getElementById('ImagenBig');
    divImagenBigInner = document.getElementById('ImagenBigInner');
	iframeMostrar = document.getElementById('imgCapa');

    if(divImagenBig != null && divImagenBigInner != null)
    {
        divImagenBig.style.display = 'none';
	    divImagenBigInner.style.display = 'none';
		if (iframeMostrar.document) 
			iframeMostrar.src = 'about:blank';
    }

    //CAPTURA TODOS LOS SELECT QUE EXISTEN EN EL FORMULARIO
        var objSel = document.getElementsByTagName('select');
    if(BrowserDetect.browser == 'Explorer')
            {
                if(objSel!= null)
                {
                    for(i = 0; i < objSel.length; i++)
                    {
                        objSel[i].style['visibility'] = '';
                    }
                }
            }
    //CAPTURA TODOS LOS INPUT QUE EXISTEN EN EL FORMULARIO
        var objinp = document.getElementsByTagName('input');
    if(BrowserDetect.browser == 'Explorer')
            {
                if(objinp!= null)
                {
                    for(i = 0; i < objinp.length; i++)
                    {
                        objinp[i].style['visibility'] = '';
                    }
                }
            }
}
/*************************FIN FUNCION OCULTA POPUP************************/

/*************************FUNCION CAPTURA ALTO DE VENTANA************************/
function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
/*************************FIN FUNCION CAPTURA ALTO DE VENTANA************************/


/*************************FUNCION DE CAMBIO PROPIEDAD DE CONTROL************************/

function FuncionCambioPropiedadControl(idControl, Propiedad, NuevoValor)
{
    var ctrl;
    //CAPTURA CONTROL
    ctrl = document.getElementById(idControl);
    if(ctrl != null && ctrl.attributes[Propiedad] != null)
    {
        //ASIGNA NUEVO VALOR A LA PROPIEDAD
        ctrl.attributes[Propiedad].nodeValue = NuevoValor;
    }
}
/*************************FIN FUNCION DE CAMBIO PROPIEDAD DE CONTROL************************/

/*************************FUNCION DE CAMBIO ESTILO DE CONTROL************************/

function FuncionCambioEstiloControl(idControl, Estilo, NuevoValor)
{
    var ctrl;
    //CAPTURA CONTROL
    ctrl = document.getElementById(idControl);
    if(ctrl != null)
    {
        //ASIGNA NUEVO VALOR AL ESTILO
        ctrl.style[Estilo] = NuevoValor;
    }
}
/*************************FIN FUNCION DE CAMBIO ESTILO DE CONTROL************************/



function cerrar()
	{
		window.parent.Ocultar();
		
	}

function Login(obj, usuario, clave)
	{
		 
		var oForm = obj.form;
		if (! oForm )
		{
		  alert("Error: Mal funcionamiento del formulario.")
		  return false;
		}
	   usuario = oForm[usuario].value;
	   clave = oForm[clave].value;
	   //alert(usuario);
	   //alert(clave);
	   if (usuario == "")
	   {
			//alert('Por favor, ingrese usuario.');
			//return false;
	   }	
	   else if (clave == "")
	   {	
	   	//	alert('Por favor, ingrese clave.');
			//return false;
	   }
	   else
	   {	
			var urllogin = 'login.asp?Email=' + usuario + '&Clave=' + clave + '&Recordar='+document.getElementById('Recordar').checked + '&linksiga=' +document.getElementById('linksiga').value;
			//alert(urllogin); //alert(document.getElementById('Recordar').checked);
			Mostrar('Blanco.asp','398','160')
			//Mostrar(urllogin,'398','160')
			oForm.action = 'login.asp'; oForm.target = 'imgCapa'; oForm.submit(); return true;
	   }
	}
	
	function LoginScala(usuario,clave)
	{
	   //alert(usuario);
	   //alert(clave);
	   var urllogin
     urllogin = 'IntermedialoginScala.asp?Email=' + usuario + '&Clave=' +document.getElementById('Clave').value + '&Recordar='+document.getElementById('Recordar').checked;
     //alert(urllogin); alert(document.getElementById('Recordar').checked);
		Mostrar(urllogin,'398','160')
	}
	
	function LoginLeo(obj, usuario, clave)
	{
		 
		var oForm = obj.form;
		if (! oForm )
		{
		  alert("Error: Mal funcionamiento del formulario.")
		  return false;
		}
	   usuario = oForm[usuario].value;
	   clave = oForm[clave].value;
	   //alert(usuario);
	   //alert(clave);
	   if (usuario == "")
	   {
			//alert('Por favor, ingrese usuario.');
			//return false;
	   }	
	   else if (clave == "")
	   {	
	   	//	alert('Por favor, ingrese clave.');
			//return false;
	   }
	   else
	   {	
			var urllogin = 'loginLeo.asp?Email=' + usuario + '&Clave=' + clave + '&Recordar='+document.getElementById('Recordar').checked + '&linksiga=' +document.getElementById('linksiga').value;
			//alert(urllogin); //alert(document.getElementById('Recordar').checked);
			Mostrar('Blanco.asp','398','160')
			//Mostrar(urllogin,'398','160')
			oForm.action = 'login.asp'; oForm.target = 'imgCapa'; oForm.submit(); return true;
	   }
	}
	
	
	/*******************************************FUNCION ACORDEON BUSQUEDA NOMBRES********************************************/
	AddEventHandler (document.getElementsByTagName('body')[0], 'load', function() 
	{
		jQuery(document).ready(function ($) {
			var content=$("div.content");
			var disp =$("tr.menu_expand_up,tr.menu_expand_down");
			content.hide();
		
		disp.click(function (event) {
			event.preventDefault();
			var disparador=$(event.currentTarget);
		
			for(i=0;i<=content.length-1;i++){
				var divcontenedor=$(content.eq(i));
				var datosdisparador=$(disparador.find("input[type='hidden']")).val().split(",");
				var cambiodiv=divcontenedor.find("input[type='hidden']").val();
				
				if(datosdisparador[0] == cambiodiv){
		
					var suscriptor=datosdisparador[1]
					var nombre=datosdisparador[2]
					var apellido=datosdisparador[3]

					if(disparador.hasClass("menu_expand_down")){
						disparador.removeClass("menu_expand_down");
						disparador.addClass("menu_expand_up");
						}
					else{
						disparador.removeClass("menu_expand_up");
						disparador.addClass("menu_expand_down");
					}
					
							divcontenedor.slideToggle("slow",function(){
							
								if (divcontenedor.find(".tabla_preview").length == 0){
								 divcontenedor.load("Buscarnombrewebresultadospreview.asp",{Id_Suscriptor:"", Nombre: nombre ,Apellido:apellido,txtinfo:cambiodiv});	
								}
							});
							
						break;
					}
				}
		
			});
		
		});
	});
	/*******************************************FIN FUNCION ACORDEON BUSQUEDA NOMBRES********************************************/
	/*******************************************INICIO VALIDACION CREAR ALERTA NOMBRES********************************************/
	function ValidarCategoria(){
		var categorias=document.getElementsByName("categoria");
		var nombre=document.getElementsByName("nombre")[0];

		if(vacio(nombre.value)==false){	
			alert("Debe ingresar un nombre valido");
			return false;
		}

		for (i = 0; chk = categorias[i]; i++) {
			if (chk.checked) {
				return true;
			}
		}
		alert('Debe seleccionar por lo menos una categoría');
		return false;
	}

	function vacio(txt) {  
        for ( i = 0; i < txt.length; i++ ) {  
                if ( txt.charAt(i) != " " ) {  
                        return true  
                }  
        }  
        return false  
	}
	/*******************************************FIN VALIDACION CREAR ALERTA NOMBRES********************************************/
