


function openpop(URL,fr,vari){
  if (document.images) {
    window.open(URL,fr,vari);
  }
}	
function openwin(URL,fr,w,h){
  if (document.images) {
    window.open(URL,fr,'resizable=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,toolbar=0,width='+w+',height='+h);
  }
}
function openwindown(URL,fr){
openwin(URL,fr,390,210);
}

function openclasificacion(URL,fr){
openwin(URL + "&popup=1",fr,660,450);
}

function imprimir(pag_imprimir, fr){
	window.open(pag_imprimir,fr,'toolbar=yes,location=no,directories=no,status=no, menubar=yes,scrollbars=yes,resizable=no,width=720,height=470');	
}

function imprimir_title(pag_imprimir, title, fr){
	
	 
	 if (BrowserDetect.browser == "Firefox") {
		 title = escape(title);
	 } 	
	window.open(pag_imprimir+title,fr,'toolbar=yes,location=no,directories=no,status=no, menubar=yes,scrollbars=yes,resizable=no,width=640,height=470');	
}
	
function addSymbol(symbol, formulario) {
	document.forms[0].general.value=document.forms[0].general.value + " " + symbol + " ";
	document.forms[0].general.focus();

}	

function setCheckedValue(radioObj, newValue) {
	if(!radioObj) {
		return;
	}
	var radioLength = radioObj.length;
	if(radioLength === undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function addSymbolG(symbol) {
	document.forms[0].sp.value=document.forms[0].sp.value + " " + symbol + " ";
	document.forms[0].sp.focus();
}	
function addSymbolMain(symbol) {
	parent.document.forms[0].sp.value=parent.document.forms[0].sp.value + " " + symbol + " ";
	parent.document.forms[0].sp.focus();
}

function clickPC(){
	if (document.AdvSearch.pc.checked && document.AdvSearch.prox.checked) {
		document.AdvSearch.prox.click();
    }
} 

function clickProx(){
	if (document.AdvSearch.prox.checked && document.AdvSearch.pc.checked) {
		document.AdvSearch.pc.click();
	}
} 

function validarEmail(valor, form) {
	
  // Validamos primero las passwords 
  if (!validarPasswd(form)) {
  	return false;
  }
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
    return true;
  } else {
    alert("La dirección de correo es incorrecta.");
    return false;
  }
}

function validarPasswd (form1) {

 var p1 = form1.contra1.value;
 var p2 = form1.contra2.value;

 var espacios = true;
 var cont = 0;

	
 // Este bucle recorre la cadena para comprobar que no todo son espacios
 while (espacios && (cont < p1.length)) {
    if (p1.charAt(cont) != " ") {
      espacios = false;
    }
    cont++;
  }
	
  if (espacios) {
    alert ("La contraseña no puede ser todo espacios en blanco");
    return false;
  }

  if (p1.length == 0 || p2.length == 0) {
    alert("Los campos de la contraseña no pueden quedar vacios");
    return false;
  }
  
  if (p1 != p2) {
    alert("Las passwords deben de coincidir");
    return false;
  }
  
  // La longitud minima es de 6 caracteres
  if (p1.length < 6 || p2.length < 6) {
    alert("La contraseña debe tener al menos 6 caracteres");
    return false;
  } else {
    return true;
  } 
}

function cambiarTipografia(sentido) {
 	var texto = document.getElementById("texto-doc");
 	if (texto.style.fontSize == ""){
 		texto.style.fontSize="75%";
 	}
 	
 	if (sentido == "3") {
 		texto.style.fontSize = "75%";
 	}
 	else if (sentido == "2") {
 		texto.style.fontSize = disminuir(texto.style.fontSize);
 	}
 	else if (sentido == "1") {
 		texto.style.fontSize = aumentar(texto.style.fontSize);
 	}
}

function aumentar(size) {
  var newSize = size;
  if (size == "45%") {
    newSize="55%";
  }
  else if (size == "55%") {
    newSize="65%";
  }
  else if (size == "65%") {
    newSize="75%";
  }
  else if (size == "75%") {
    newSize="85%";
  }
  else if (size == "85%") {
    newSize="95%";
  }
  else if (size == "95%") {
    newSize="105%";
  }
  else if (size == "105%") {
    newSize="115%";
  }
  else if (size == "115%") {
    newSize="125%";
  }
  else if (size == "125%") {
    newSize="135%";
  }
  else if (size == "135%") {
    newSize="145%";
  }
  else if (size == "145%") {
    newSize="155%";
  }
 return newSize;
}

function disminuir(size) {
 var newSize = size;
  if (size == "155%") {
   newSize="145%";
  }
  else if (size == "145%") {
   newSize="135%";
  }
  else if (size == "135%") {
    newSize="125%";
  }
  else if (size == "125%") {
    newSize="115%";
  }
  else if (size == "115%") {
    newSize="105%";
  }
  else if (size == "105%") {
    newSize="95%";
  }
  else if (size == "95%") {
    newSize="85%";
  }
  else if (size == "85%") {
    newSize="75%";
  }
  else if (size == "75%") {
    newSize="65%";
  }
  else if (size == "65%") {
 	  newSize="55%";
 	}
  else if (size == "55%") {
 	  newSize="45%";
 	} 	
 	return newSize;
}

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",
				versionSearch: "Version"
			},
			{
				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.userAgent,
				   subString: "iPhone",
				   identity: "iPhone/iPod"
		    },
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]

	};
	BrowserDetect.init();

