if (!window.$){
	function $(id){
		return document.getElementById(id);
	}
	function $F(id){
		return document.getElementById(id).value;
	}
}
//Si se usa en conjunto con la biblioteca de prototype cambiar sinPrototype a false
//Si no se quiere loguear con enter, solo haciendo click poner loginEnter = False

function $_on(id){
	$(id).style.display='';
}
function $_off(id){
	$(id).style.display='none';
}
function $_onV(id){
	$(id).style.visibility='visible';
}
function $_offV(id){
	$(id).style.visibility='hidden';
}
function validarEMail(strValue) {
	var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
	return objRegExp.test(strValue);
}
function $_vaciar(id){
	$(id).value='';
}
function $_muo(id){//muo = Mostrar U Ocultar ;)
	if($(id).style.display=='none'){
		$_on(id);
	}else{
		$_off(id);
	}
}
function $_class(id,clase){//cambia la clase del objeto
	$(id).className=clase;
}
function $_alternaClase(id,clase1,clase2){
	if (!!$(id)){
		if($(id).className==clase1){
			$(id).className=clase2;
		}else{
			$(id).className=clase1;
		}
	}
}
function pintarTR(id, color){
	if (!borrando){
		var seguir=true;
		var i=0
		while (seguir){
			i++
			if (!!$('td'+i+'_'+id)){
				$('td'+i+'_'+id).style.backgroundColor = color;
			}else{
				seguir=false;
			}
		}

//			for (var i=1;i<=6;i++){
//				$('td'+i+'_'+id).style.backgroundColor = color;
//			}
	}
}	
//func básica ajax de uniAjax
function ejecutarUniAjax(titulo,funcion,parametros){
	var url = "ajax"+titulo+".asp?funcion="+funcion+"&campo="+campo+"&orden="+orden;
	var traeData = new uniAjax();
	traeData.leer(url);
}
function traer(lugar,titulo,funcion,parametros){
	if(campo==undefined) {
		campo='';
		orden='';
	}
	var url = "ajax"+titulo+".asp?funcion="+funcion+"&"+parametros;
	var traeData = new uniAjax();
	valores=traeData.leer(url);
	$(lugar).style.display='';
	$(lugar).innerHTML=valores;
}
//nuevas func Ajax NONO, G=get P=Post
function getHTTPObject() {
    var xmlhttp;
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
       try {
          xmlhttp = new XMLHttpRequest();
       } catch (e) { xmlhttp = false; }
    }
    return xmlhttp;
}
function ajax_P(url,formid){	
	var respuestaAjax='';
	var Formulario = $(formid);
	var longitudFormulario = Formulario.elements.length;
	var cadenaFormulario = "";
	var sepCampos = "";
	for (var i=0; i <= Formulario.elements.length-1;i++) {
		cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
		sepCampos="&";
	}
	var peticion = getHTTPObject();
	peticion.open("POST", url, false);
	peticion.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
	peticion.send(cadenaFormulario);
	return peticion.responseText;
}
function ajax_G(url){
	var peticion = getHTTPObject();
	peticion.open("GET", url, false);
	peticion.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
	peticion.send();
	return peticion.responseText;
}
//funcion para login con enter

//descubrir navegador
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
function ControlVersion()
{
	var version;
	var axo;
	var e;
	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";
			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";
			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}
//funcion diferencia entre fechas
function DateDiff(date1,date2){
	var fecha1  ;
	var fecha2 ;
	fecha1=parseInt(date1);
	fecha2=parseInt(date2);
	return fecha1-fecha2;
}
function abrirPopup(direccion, pantallacompleta, herramientas, direcciones, estado, barramenu, barrascroll, cambiatamano, ancho, alto, izquierda, arriba, sustituir){
     var opciones = "fullscreen=" + pantallacompleta +
                 ",toolbar=" + herramientas +
                 ",location=" + direcciones +
                 ",status=" + estado +
                 ",menubar=" + barramenu +
                 ",scrollbars=" + barrascroll +
                 ",resizable=" + cambiatamano +
                 ",width=" + ancho +
                 ",height=" + alto +
                 ",left=" + izquierda +
                 ",top=" + arriba;
     var ventana = window.open(direccion,"venta",opciones,sustituir);
//dir,0,0,0,0,0,0,0,415,390,200,200,1
}         
function irPagina(n, maxPags, pagina, como, tipo) {
	if (n == -1){
		n = parseInt('0'+prompt('Ingrese la pgina a la que quiere ir',maxPags),10);
		if (n > maxPags) n = maxPags;
		if (n < 1) n=1;
	}
	n--;
	var url = "ajax"+pagina+".asp?funcion=listado&como="+ como +"&tipo="+tipo+ "&nP="+n;
	var traeData = new uniAjax();	
	document.getElementById('listado').innerHTML=traeData.leer(url);
}
function $_color(id,color){
	if (!!$(id)){
		$(id).style.backgroundColor = color;
	}
}
function $_tof(id){//tof = true or false
	if (!!$(id)){
		if($F(id).toLowerCase() =='true'){
			$(id).value = 'false';
		}else{
			$(id).value = 'true';
		}
	}
}
function $_de(id){//de = disabled / enabled
	if (!!$(id)){
		if($(id).disabled){
			$(id).disabled = false;
		}else{
			$(id).disabled = true;
		}
	}
}
function chkForm(formid){
		
//  funcion para vereificar cualquier tipo de formulario, los campos obligatorios deben terminar en -o
//  cuando se trate de mail debe terminar en -m, verifica si es mail
//  cuando se trate de un numero debe terminar en -n, verifica si es numerico
//  cuando se trate de una fecha debe terminar en -f
//  si encuentra error lo escribe en un span con el mismo nombre pero sin -o o -m y con -s al final
//  si quiere que ademas de ser obligatorio, valide el mail o numero o fecha, debe poner -(m|n|f)-o
         var Formulario = $(formid);
         var longitudFormulario = Formulario.elements.length;
		 var campo, valor, nombreCampo,largoNombre,destinoAviso,ultimasdos,fallo='';
         sepCampos = "";
         for (var i=0; i <= Formulario.elements.length-1;i++) {
		 	campo=Formulario.elements[i].id ;
		 	valor=Formulario.elements[i].value ;
			
			largoNombre = String(campo).length-2 ;
			ultimasdos=Right(campo,2);
			if (ultimasdos=='-o'){
				ultimasdos=Left(Right(campo,4),2);
				if (ultimasdos=='-m' || ultimasdos=='-n' || ultimasdos=='-f' ) largoNombre = String(campo).length-4 ;
			}			
			nombreCampo = String(campo).substring(0,largoNombre);
			destinoAviso=nombreCampo+'-s';
			ultimasdos=Right(campo,2);
		 	if(ultimasdos=='-o') {
				if(valor==''){
					if(!!$(destinoAviso)) $(destinoAviso).innerHTML = 'Dato Obligatorio';
					eval("$('"+ campo +"').className='inputLOP2-error';")
					if(fallo=='') fallo=campo;
				}else{
					if(!!$(destinoAviso)) $(destinoAviso).innerHTML = '' ;
					eval("$('"+ campo +"').className='inputLOP2';")
					ultimasdos=Left(Right(campo,4),2)
				}
			}
			if(ultimasdos=='-m'){					
				if(validarEMail(valor)!= true){
					if(!!$(destinoAviso)) $(destinoAviso).innerHTML = 'Error en el mail';
					eval("$('"+ campo +"').className='inputLOP2-error';")
					if(fallo=='') fallo=campo;
				}else{
					if(!!$(destinoAviso)) $(destinoAviso).innerHTML = '' ;
					eval("$('"+ campo +"').className='inputLOP2';")
				}
			}
			if(ultimasdos=='-n'){
				valor = valor.replace(",",".");
				if (isNaN(valor)){
					if(!!$(destinoAviso)) $(destinoAviso).innerHTML = 'El dato tiene que ser numerico';
					eval("$('"+ campo +"').className='inputLOP2-error';")
					if(fallo=='') fallo=campo;
				}else{
					if(!!$(destinoAviso)) $(destinoAviso).innerHTML = '' ;
					eval("$('"+ campo +"').className='inputLOP2';")
				}
			}
			if(ultimasdos=='-f'){
				var analisisFecha = validafecha(valor).split('||');
				if(analisisFecha[0]=='ERROR'){
					if(!!$(destinoAviso)) $(destinoAviso).innerHTML = analisisFecha[1] + ' (dd/mm/aaaa)';
					eval("$('"+ campo +"').className='inputLOP2-error';")
					if(fallo=='') fallo=campo;
				}else{
					if(!!$(destinoAviso)) $(destinoAviso).innerHTML = '' ;
					eval("$('"+ campo +"').className='inputLOP2';")
				}
			}
		 }
		if(fallo!='') {
			eval("$('"+ fallo +"').focus();")
			return false;
		}
		return true;
}
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function validafecha(cadena){
	var Fecha= new String(cadena);   // Crea un string 
	var errorFecha='';
	// Cadena Año  
	var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length));
	// Cadena Mes  
	var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")));
	// Cadena Día  
	var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")));
	// Valido el año  
	if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){
		errorFecha='A&ntilde;o inv&aacute;lido';
	}  
	// Valido el Mes  
	if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){
		errorFecha='Mes inv&aacute;lido';
	}  
	// Valido el Dia  
	if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){
		errorFecha='D&iacute;a inv&aacute;lido';
	}  
	if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
		if (Mes==2 && Dia > 29 || Dia>30) {
			errorFecha='D&iacute;a inv&aacute;lido';
		}  
	}
	if (errorFecha==''){
		errorFecha='OK||';
	}else{
		errorFecha='ERROR||' + errorFecha;
	}
	return errorFecha;
}
function habilitarBotones(){
	//alert($('archivoSel').value);
	if($('file').value == null || $('file').value == '' ){
		$('bt_prod').disabled='disabled';
		$('bt_fabric').disabled='disabled';
		$('bt_tiendas').disabled='disabled';
		$('bt_categorias').disabled='disabled';
		$('bt_descargas').disabled='disabled';
		$('bt_links').disabled='disabled';
		$('bt_vendedores').disabled='disabled';
		$('bt_clientes').disabled='disabled';
		$('bt_Pwprod').disabled='disabled';
		$('bt_Vinculos').disabled='disabled';
	} else {
		$('bt_prod').disabled='';
		$('bt_fabric').disabled='';
		$('bt_tiendas').disabled='';
		$('bt_categorias').disabled='';
		$('bt_descargas').disabled='';
		$('bt_links').disabled='';
		$('bt_vendedores').disabled='';
		$('bt_clientes').disabled='';
		$('bt_Pwprod').disabled='';
		$('bt_Vinculos').disabled='';
	};
}
function eliminarArchivos(){
	if(confirm('Esta seguro que desea eliminar todos los archivos del directorio listado?'))
		ajax_G('ajaxVarios.asp?funcion=eliminarArchivos');
	listadoArchivos();
}
function eliminarArchivo(nombre){
	if(confirm('Esta seguro que desea eliminar este archivo?'))
		ajax_G('ajaxVarios.asp?funcion=eliminarArchivos&nombre='+nombre);
	listadoArchivos();
}
function listadoArchivos(){
	$('listado').innerHTML = ajax_G('../admin/ajaxArchivo.asp?funcion=listado');
}
function cambiarAction(bt){
	switch (bt){
		case 'bt_prod':
			document.parsear.action = "parseador.asp";
			break;
		case 'bt_fabric':
			document.parsear.action = "parseadorFabricantes.asp";
			break;
		case 'bt_tiendas':
			document.parsear.action = "parseadorTiendas.asp";
			break;
		case 'bt_categorias':
			document.parsear.action = "parseadorCategorias.asp";
			break;
		case 'bt_descargas':
			document.parsear.action = "parseadorDescargas.asp";
			break;
		case 'bt_links':
			document.parsear.action = "parseadorEnlaces.asp";
			break;
	}
	//alert(document.parsear.action)
}
function minimizar(id){
	var tab = document.createElement('div');
	tab.className = 'tab';
	tab.id = 'tab__'+id;
	$('barraTareas').appendChild(tab);
	tab.innerHTML = $('titulo'+id).innerHTML;
	$(tab.id).onclick = function(){ restaurar(tab.id)};
	jQuery('#'+id).hide('bind');
	jQuery('#tab__'+id).show('bind');
}
function restaurar(id){
	var nombres=id.split('__');
	jQuery('#'+nombres[1]).show('bind');
	jQuery('#'+id).detach();
}
function formuNoticias(){
	ajax_G('ajaxSetCookie.asp?n=formAbierto&v=true&id=0');
	var magia = ajax_G('abmNoticias.asp?funcion=alta&ventana='+$('nVentanas').value);
	var magiaAlMedio = magia.split('||');
	$('formu').innerHTML = $('formu').innerHTML + magiaAlMedio[0];
	//alert(magiaAlMedio[1]);
	eval(magiaAlMedio[1]+';');
	$('nVentanas').value = $('nVentanas').value + 1 ;
}
function formuNoticiasEditar(id){
	ajax_G('ajaxSetCookie.asp?n=formAbierto&v=true&id='+id);
	var magia = ajax_G('abmNoticias.asp?funcion=alta&id='+id);
	//alert(magia);
	var magiaAlMedio = magia.split('||');
	$('formu').innerHTML = $('formu').innerHTML + magiaAlMedio[0];
	//alert(magiaAlMedio[1]);
	eval(magiaAlMedio[1]+';');
	$('nVentanas').value = $('nVentanas').value + 1 ;
}
function wysiwyg(nro){
	jQuery(function()
	  {
		  jQuery('#wysiwyg-'+nro).wysiwyg({
			  controls: {
				  strikeThrough : { visible : true },
				  underline     : { visible : true },
				  
				  separator00 : { visible : true },
				  
				  justifyLeft   : { visible : true },
				  justifyCenter : { visible : true },
				  justifyRight  : { visible : true },
				  justifyFull   : { visible : true },
				  
				  separator01 : { visible : true },
				  
				  indent  : { visible : true },
				  outdent : { visible : true },
				  
				  separator02 : { visible : true },
				  
				  subscript   : { visible : true },
				  superscript : { visible : true },
				  
				  separator03 : { visible : true },
				  
				  undo : { visible : true },
				  redo : { visible : true },
				  
				  separator04 : { visible : true },
				  
				  insertOrderedList    : { visible : true },
				  insertUnorderedList  : { visible : true },
				  insertHorizontalRule : { visible : true },
				  
				  h4mozilla : { visible : true && jQuery.browser.mozilla, className : 'h4', command : 'heading', arguments : ['h4'], tags : ['h4'], tooltip : "Header 4" },
				  h5mozilla : { visible : true && jQuery.browser.mozilla, className : 'h5', command : 'heading', arguments : ['h5'], tags : ['h5'], tooltip : "Header 5" },
				  h6mozilla : { visible : true && jQuery.browser.mozilla, className : 'h6', command : 'heading', arguments : ['h6'], tags : ['h6'], tooltip : "Header 6" },
				  
				  h4 : { visible : true && !( jQuery.browser.mozilla ), className : 'h4', command : 'formatBlock', arguments : ['<H4>'], tags : ['h4'], tooltip : "Header 4" },
				  h5 : { visible : true && !( jQuery.browser.mozilla ), className : 'h5', command : 'formatBlock', arguments : ['<H5>'], tags : ['h5'], tooltip : "Header 5" },
				  h6 : { visible : true && !( jQuery.browser.mozilla ), className : 'h6', command : 'formatBlock', arguments : ['<H6>'], tags : ['h6'], tooltip : "Header 6" },
				  
				  separator07 : { visible : true },
				  
				  cut   : { visible : true },
				  copy  : { visible : true },
				  paste : { visible : true }
			  }
			
		   });
	  });
}
function enviaFormYTrae(queTrae,ddTrae,idForm,urlForm){
	ajax_G('ajaxSetCookie.asp?n=formAbierto&v=false');
	ajax_P(urlForm,idForm);
	document.getElementById(ddTrae).innerHTML = ajax_G(queTrae);
	location.reload(); // para IE
}
function traerAjax(que,donde){
	$(donde).innerHTML = ajax_G(que);
	jQuery('#'+donde).show('slow');
}
