/*************************************************************************
PREDICTIVO
*************************************************************************/
var focused=-1;
var lastFocused;
var filter;
var finded=false;
var permiteCerrado=0;
var idTimeout;
function limpiaHiddens(val){
    if(val!=37 && val!=38 && val!=39 && val!=40 && val!=13){
        document.getElementById('color').value="";
        document.getElementById('ref').value="";
    }
}
function selectFromPredictive(field, TRpattern){
	if(focused>=0){
	    var capa=focused+"_ref-color-select";
	    if(document.getElementById(capa)){
		  field.value=document.getElementById(capa).value;
	    }

		var capa2=focused+"_ref-select";
		if(document.getElementById(capa2)){
    		document.getElementById('ref').value=document.getElementById(capa2).value;
		}

		var capa3=focused+"_color-select";
		if(document.getElementById(capa3)){
    		document.getElementById('color').value=document.getElementById(capa3).value;
		}
		displayCapa ("predictRef","none");
	}
}
function getFocus(lastTR, TRpattern, lastFocused){
	document.getElementById('predictRef').scrollTop = lastTR*110;
	changeColor('0a246a',lastTR, TRpattern);
	if((typeof(lastFocused)!="undefined") && (lastFocused>=0)){ changeColor('FFFFFF',lastFocused, TRpattern); }
}
function moveFocus(n,  TRpattern) {
	if(typeof(focused)=="undefined"){ focused=0; getFocus(focused,TRpattern, 0); return true; }
	if(n){
		focused++;
		if(focused<totalTR){
			lastFocused=focused-1;
			getFocus(focused,TRpattern,lastFocused);
		}else{ focused--; }
	}else{
		focused--;
		if(focused>=0){
			lastFocused=focused+1;
			getFocus(focused,TRpattern,lastFocused);
		}else{ focused++; }
	}
}
function checkArrows (field, evt, action, capa, TRpattern, lang){
	var keyCode =
	document.layers ? evt.which :
	document.all ? event.keyCode :
	document.getElementById ? evt.keyCode : 0;
    var valorCampo = field.value;
	if (keyCode == 40){
		if(finded==false){
		    if(valorCampo.length>2){ predict(field, action, capa, lang); }
		}else{ moveFocus(1,TRpattern); }
	}else if (keyCode == 38){
		if(finded==true){ moveFocus(0,TRpattern); }
	}else if ((keyCode != 37 && keyCode != 39 && keyCode != 13)){
		if(valorCampo.length>2){ predict(field, action, capa, lang); }
	}
	return true;
}
function noSend (field, evt,  TRpattern) {
	var keyCode =
	document.layers ? evt.which :
	document.all ? event.keyCode :
	document.getElementById ? evt.keyCode : 0;
	if(keyCode==13) {
		selectFromPredictive(field, TRpattern);
		if(typeof(saltarFocus)!="undefined"){ document.getElementById('cantidad').focus(); }
		return false;
	}
	return true;
}
function predict(el, action, capa, lang){
    if(el.value.length>0){
        var q = el.value;
        carga_url('ajax.php?ac='+action+'&lang='+lang+'&q='+escape(q),capa);
    }
}
function changeColor(color,i, TRpattern){
    document.getElementById(TRpattern+i+"0").style.background="#"+color;
    if(color=="0a246a"){
        document.getElementById(TRpattern+i+"text").style.color="#FFFFFF";
    }else{
        document.getElementById(TRpattern+i+"text").style.color="#000000";
    }
}
function cierraDefinitivo(){
    document.getElementById('predictRef').style.display="none";
    permiteCerrado=0;
    clearTimeout(idTimeout);
}
function cerrando(){
    if(permiteCerrado){
        document.getElementById('predictRef').style.display="none";
        permiteCerrado=0;
    }
}
function noCierres(){
    permiteCerrado=0;
    clearTimeout(idTimeout);
}
function cierraCapa(){
    permiteCerrado=1;
    idTimeout = setTimeout("cerrando()", 2000);
}

function BrowserCheck() {
  var b = navigator.appName;
  if (b=="Netscape") this.b = "ns";
  else if (b=="Microsoft Internet Explorer") this.b = "ie";
  else this.b = b;
  this.version = navigator.appVersion;
  this.v = parseInt(this.version);
  this.ns = (this.b=="ns" && this.v>=4);
  this.ns4 = (this.b=="ns" && this.v==4);
  this.ns6 = (this.b=="ns" && this.v==5);
  this.ie = (this.b=="ie" && this.v>=4);
  this.ie4 = (this.version.indexOf('MSIE 4')>0);
  this.ie5 = (this.version.indexOf('MSIE 5')>0);
  this.ie7 = (this.version.indexOf('MSIE 7')>0);
  this.min = (this.ns||this.ie);
}
is = new BrowserCheck();

function carga_url (URL,capa,noOcultar) {
	if(typeof($)!="undefined"){
	    if(!noOcultar){ document.getElementById(capa).style.display="none"; }
		$(document.getElementById(capa)).html('');
		  $(document.getElementById(capa)).load(URL,function(){
			//$(document.getElementById(capa)).slideDown("slow");
			$(document.getElementById(capa)).fadeIn(1000);
			//datos=preloaderOff();
		  });
    }
}
function carga_urlOpener (URL,capa,atthened) {
	$(window.opener.document.getElementById(capa)).html('');
	  $(window.opener.document.getElementById(capa)).load(URL,function(){
		$(window.opener.document.getElementById(capa)).slideDown("slow");
		eval(atthened);
	  });
}

function msg_change (capa,htmltext) {
	$(document.getElementById(capa)).html(htmltext);
}

function displayCapa (capa,status) {
    if(document.getElementById(capa)){
    	if (status!=undefined && status!='') {
    		document.getElementById(capa).style.display=status;
    	} else {
    		if (document.getElementById(capa).style.display=="block") {
    			document.getElementById(capa).style.display="none";
    		} else {
    			document.getElementById(capa).style.display="block";
    		}
    	}
    }
}

function displayCapaSlide (capa,status) {
	if (status!=undefined && status!='') {
		document.getElementById(capa).style.display=status;
	} else {
		if (document.getElementById(capa).style.display=="block") {
			$(document.getElementById(capa)).slideUp("slow");
			//document.getElementById(capa).style.display="none";
		} else {
			//document.getElementById(capa).style.display="block";
			$(document.getElementById(capa)).slideDown("slow");
		}
	}
}

/* End Efecto Links */


function giveCSS (capa,clase) {
	$(document.getElementById(capa)).addClass(clase);
}
function removeCSS (capa,clase) {
	$(document.getElementById(capa)).removeClass(clase);
}

function locateGPS (direccion_tipo,direccion_field,municipio_field,provincia_field, latitud, longitud, formularioNombre) {
	var formulario=document.forms[formularioNombre];
	var tipovia=formulario[direccion_tipo].value;
	var direccion=formulario[direccion_field].value;
	var municipio=formulario[municipio_field].value;
	var provincia=formulario[provincia_field].value;
	var url="popup.php?ac=geolocate&tipovia="+tipovia+"&direccion="+direccion+"&municipio="+municipio+"&provincia="+provincia+"&formulario="+formularioNombre+"&latitud="+latitud+"&longitud="+longitud;
	popUp (url,800,600,'geolocate')	;
}
function locateGPS2Form (latitud, longitud, formularioNombre, lat_value, long_value, formularioNombre2) {
	var formulario=document.forms[formularioNombre2];
	var latitud_value=formulario[lat_value].value;
	var longitud_value=formulario[long_value].value;

	var formulario2=window.opener.document.forms[formularioNombre];
	formulario2[latitud].value=latitud_value;
	formulario2[longitud].value=longitud_value;
	window.close();
}
/*************************************************************************
NOTICIAS
*************************************************************************/
function noticiasGestImgs (noticia, accion, id, mod, filter, target, lang) {
	var url="popup.php?ac=gestImgs&noticia="+noticia+"&acc="+accion+"&rid="+id;
	if (mod != "" && mod != null) {
		url += "&mod="+mod;
	}
	if (filter != "" && filter != null) {
		url += "&filter="+filter;
	}
	if (target != "" && target != null) {
		url += "&target="+target;
	}
	if (lang != "" && lang != null) {
		url += "&lang="+lang;
	}
	popup_w = popUp (url,800,600,'gestnoticias');
}
function noticiasGestDownloads (noticia, accion, id, mod, filter, target, lang) {
	var url="popup.php?ac=gestDownloads&noticia="+noticia+"&acc="+accion+"&rid="+id;
	if (mod != "" && mod != null) {
		url += "&mod="+mod;
	}
	if (filter != "" && filter != null) {
		url += "&filter="+filter;
	}
	if (target != "" && target != null) {
		url += "&target="+target;
	}
	if (lang != "" && lang != null) {
		url += "&lang="+lang;
	}
	popup_w = popUp (url,800,600,'gestnoticias');
}
function noticiasGestLinks (noticia, accion, id, mod, filter, target, lang) {
	var url="popup.php?ac=gestLinks&noticia="+noticia+"&acc="+accion+"&rid="+id;
	if (mod != "" && mod != null) {
		url += "&mod="+mod;
	}
	if (filter != "" && filter != null) {
		url += "&filter="+filter;
	}
	if (target != "" && target != null) {
		url += "&target="+target;
	}
	if (lang != "" && lang != null) {
		url += "&lang="+lang;
	}
	popup_w = popUp (url,800,600,'gestnoticias');
}
/**
  * FUNCIONES PARA
  * GESTI�N DE ILUSTRADORES
  * EN GESTOR
  */
function ilustradoresGestIlustraciones (il_ID, accion, mod, target) {
	var url="popup.php?ac=gestIlustraciones&ilustracion="+il_ID+"&acc="+accion;
	if (mod != "" && mod != null) {
		url += "&mod="+mod;
	}
	if (target != "" && target != null) {
		url += "&target="+target;
	}
	popup_w = popUp (url,800,600,'gestilustraciones');
}
function ilustradoresGestNoticias (noticia_ID, accion, mod, target) {
	var url="popup.php?ac=gestNoticias&noticia="+noticia_ID+"&acc="+accion;
	if (mod != "" && mod != null) {
		url += "&mod="+mod;
	}
	if (target != "" && target != null) {
		url += "&target="+target;
	}
	popup_w = popUp (url,800,600,'gestnoticias');
}
/******************************************************************************************
PREDICTIVO DE CIUDADES
******************************************************************************************/
function locCityPredictive (string, predDiv, cityField, stateField, countryField) {
	if (string.length>3) {
		carga_url ('ajax.php?ac=locCityPredictive&string='+string+'&predDiv='+predDiv+'&cityField='+cityField+'&stateField='+stateField+'&countryField='+countryField,predDiv);
	}
	return true;
}
function locCityAutocomplete (predDiv, cityField, stateField, countryField, city, cityID, state, stateID, country, countryID) {
	var predictiveDiv = document.getElementById (predDiv);
	var ciudad = document.getElementById (cityField);
	var provincia = document.getElementById (stateField);
	var pais = document.getElementById (countryField);
	ciudad.value=city;
	provincia.value=state;
	pais.value=country;
	predictiveDiv.style.display="none";
}
/****************************************************************************************
JS DAMIA
****************************************************************************************/
function makeURL(str) {
    var strAux = str.toLowerCase();
    strAux = strAux.replace(/-/g," ");
    strAux = strAux.replace(/^\s*|\s*$/g,"");
    while(strAux.indexOf("/")!=-1) strAux = strAux.replace("/","-");
    while(strAux.indexOf("(")!=-1) strAux = strAux.replace("(","");
    while(strAux.indexOf(")")!=-1) strAux = strAux.replace(")","");
    while(strAux.indexOf("*")!=-1) strAux = strAux.replace("*","");
    while(strAux.indexOf(".")!=-1) strAux = strAux.replace(".","");
    strAux = strAux.replace(/ /g,"-");
    strAux = strAux.replace(/á/g,"a");
    strAux = strAux.replace(/é/g,"e");
    strAux = strAux.replace(/í/g,"i");
    strAux = strAux.replace(/ó/g,"o");
    strAux = strAux.replace(/ú/g,"u");
    strAux = strAux.replace(/ñ/g,"n");
    strAux = strAux.replace(/à/g,"a");
    strAux = strAux.replace(/è/g,"e");
    strAux = strAux.replace(/ì/g,"i");
    strAux = strAux.replace(/ò/g,"o");
    strAux = strAux.replace(/ù/g,"u");
    while(strAux.indexOf("--")!=-1) strAux = strAux.replace("--","-");
    return strAux;
}
function changeSection(){
    var pregunta = window.confirm("Atención! Está a punto de cambiar de sección, los datos que tiene escritos no se guardarán.\n¿Desea redirigirse a la nueva sección?");
    if(pregunta){ return true; }
    else { return false; }
}
function cs(){ return changeSection(); }
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function displayErrorSQL(){
    $(document.getElementById("blockError")).fadeIn("slow");
}function marcAll(capa, total){	var i=0;	for(i=0;i<total;i++){		document.getElementById(capa+'_'+i).checked=true;	}}function unmarcAll(capa, total){	var i=0;	for(i=0;i<total;i++){		document.getElementById(capa+'_'+i).checked=false;	}}