// JavaScript Document


function redimensiona() {
	/*alert('aaa');*/
	if (document.getElementById("ContenidoLeft")) {
			h = document.getElementById("Main").offsetHeight - (170 + document.getElementById("Header").offsetHeight);
			if (h<document.getElementById("ContenidoLeft").offsetHeight) h = document.getElementById("ContenidoLeft").offsetHeight;
			//alert ("h= " + h + " pantalla= " + document.getElementById("Main").offsetHeight );
			document.getElementById("ContenidoLeft").style.height = h.toString() + 'px';
	}
	if (document.getElementById("SubContenido")) {
			h = document.getElementById("Main").offsetHeight - (170 + document.getElementById("Header").offsetHeight) ;
			//if (h<510) h = 510;
			//alert ("h= " + h + " pantalla= " + document.getElementById("Main").offsetHeight );
			if (document.getElementById("SubContenido").offsetHeight < 520) document.getElementById("SubContenido").style.height = h.toString() + 'px';
	}
}

function preparaLoggin() {
	
	tb_init('a.thick, area.thick, input.thick');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
}

function preparaThickbox () {
	//tb_remove();
	
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
}


function ValidaCampoTXT (campo) {
	if (campo.value.length==0){
		   //alert("Tiene que escribir sus APELLIDOS")
		   //document.frmFirma.ctApellidos.focus()
		   //campo.style.outlineStyle = "solid";
		   campo.style.outline = "1px solid red";
		   return false;
	} 
	return true;
}

function ValidaCampoDNI (campo) {

	
	if (campo.value.length==0){
		   campo.style.outline = "1px solid red";
		   return false;
	} 
	dni = campo.value;
	numero = dni.substr(0,dni.length-1);
	let = dni.substr(dni.length-1,1);
	numero = numero % 23;
	letra='TRWAGMYFPDXBNJZSQVHLCKET';
	letra=letra.substring(numero,numero+1);
	//alert(let.toUpperCase() + " aaaa " + letra);
	if (letra!=let.toUpperCase()) {
		//alert("Tiene que escribir un DNI válido: 00000000L")
		campo.style.outline = "1px solid red";
		return false;	
	}
	return true;
}

function ValidaCampoTLF (campo) {
	if (campo.value.length==0){
		   campo.style.outline = "1px solid red";
		   return false;
	} 
	var Template = /^[+|-]?d+$/ //Formato de numero entero
	if ((Template.test(campo)) || (campo.value.length<9)) {
		campo.style.outline = "1px solid red";
		return false;
	}
	return true;
}

function ValidaCampoCP (campo) {
	var Template = /^[+|-]?d+$/ //Formato de numero entero
	if ((Template.test(campo)) || (campo.value.length!=5)) {
		campo.style.outline = "1px solid red";
		return false;
	}
	return true;
}

function ValidaCampoMAIL (campo) {
	
	if (campo.value.length==0){
		   campo.style.outline = "1px solid red";
		   return false;
	} 	
	var s = campo.value;
	var filter=/^((\w|\.|\-){2,}@)\w{2,}\.\w{2,4}((\.(\w{2}))?)?$/;
	
	if (!s.match(filter)) {
		campo.style.outline = "1px solid red";
		return false;
	}
	return true;	
	
}
function ValidaCampoCHK (campo) {
	
	if (!campo.checked){
		   //alert("Tiene que escribir sus APELLIDOS")
		   //document.frmFirma.ctApellidos.focus()
		   //campo.style.outlineStyle = "solid";
		   campo.style.outline = "1px solid red";
		   return false;
	} 
	return true;
}


/*PARSER QUERY STRING*/


function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}
