// JavaScript Document

String.prototype.get = function(p){
	var res = this.match(new RegExp("[?|&]?" + p + "=([^&]*)"));
	if(res)
		return res[1];
	return '';
}

String.prototype.replaceAll = function(pat, reemp){
	var idx = this.indexOf(pat);
	var str = this;
	while (idx != -1) {
		str = str.replace(pat, reemp);
		idx = str.indexOf(pat);
	}
	return str;
}
var mensaje = unescape(window.location.search.get('m').replaceAll('+', ' '));

if(mensaje != '') alert(mensaje);

function $(objid){
	if(typeof(objid) == 'string')
		return document.getElementById(objid);
	return objid;
}

function addEvent(obj, evento, funcion){
	if(obj)
		if (obj.addEventListener)
		  obj.addEventListener(evento, funcion, true);
		else if (obj.attachEvent)
		  obj.attachEvent('on'+evento, funcion);
}

function validarFormCargar(form){
	var errores = restricciones.validar("Nombre completo", form.nombre_completo.value, "minlong:1,maxlong:255");
	errores += restricciones.validar("Nombre real", form.nombre_real.value, "minlong:1,maxlong:255");
	if(errores != ''){
		alert(errores);
		return false;
	}
	form.descripcion.value = obtenerContenido();
	return true;
}

function validarFormContacto(form){
	var errores = restricciones.validar("Nombre", form.nombre.value, "minlong:1,maxlong:100");
	errores += restricciones.validar("Empresa", form.empresa.value, "minlong:1,maxlong:100");
	errores += restricciones.validar("Código postal", form.codigo_postal.value, "minlong:1,maxlong:10");
	errores += restricciones.validar("Dirección de email", form.email.value, "mail:1");
	if(errores != ''){
		alert(errores);
		return false;
	}
	return true;
}

function validarFormMailing(form){
	var errores = restricciones.validar("Asunto", form.asunto.value, "minlong:1");
	errores += restricciones.validar("Mensaje", form.mensaje.value, "minlong:1");
	
	if(errores != ''){
		alert(errores);
		return false;
	}
	return true;
}

function validarFormCargarCategoria(form){
	var errores = restricciones.validar("Titulo", form.titulo.value, "minlong:1,maxlong:255");
	if(errores != ''){
		alert(errores);
		return false;
	}
	return true;
}

function eliminar_hijo(ref_contenedor, id_objeto){
	if(ref_contenedor){
		var len = ref_contenedor.childNodes.length;
		for(var i = 0; i < len; i++)
			if(ref_contenedor.childNodes[i])
				if(ref_contenedor.childNodes[i].id == id_objeto && ref_contenedor.childNodes[i].style.display != 'none')
					ref_contenedor.removeChild(ref_contenedor.childNodes[i]);
	}
}

function obtener_hijo(id_contenedor, id_objeto){
	var Node1 = document.getElementById(id_contenedor);
	var len = Node1.childNodes.length;
	for(var i = 0; i < len; i++)
		if(Node1.childNodes[i])
			if(Node1.childNodes[i].id == id_objeto)
				return Node1.childNodes[i];
	return null;
}

function imgViewer(nombre, urls, urls_grandes, id_cont, dir_base, dir_base_grandes){
	this.nombre = nombre;
	this.nombre_base = 'imgViewer'+nombre;
	this.contenedor = document.getElementById(id_cont);
	this.urls = urls.split(',');
	this.urls_grandes = urls_grandes.split(',');
	this.nro_actual = 0;
	this.dir_base = dir_base;
	this.dir_base_grandes = dir_base_grandes;
	this.print = function (){
		if(this.contenedor && this.urls.length > 0){
			var img = '<center>';
			img += '<img id="'+this.nombre_base+'" src="'+this.dir_base_grandes+this.urls[0]+'" /><br />';
			img += '<input type="button" onclick="javascript:;'+this.nombre+'.previous()" value="&lt;&lt;" />';
			img += '&nbsp;<input type="button" onclick="javascript:;'+this.nombre+'.next()" value="&gt;&gt;" /><br />';
			for(var n = 0; n < this.urls.length; n++){
				img += '<a href="javascript:;" onclick="'+this.nombre+'.show('+n+')">';
				img += '<img src="'+this.dir_base+this.urls[n]+'"';
				img += ' style="display:;"';
				img += ' id="'+this.nombre_base+'_'+n+'" />';
				img += '</a>';
			}
			img += '</center>';
			this.contenedor.innerHTML = img;
		}
	};
	this.show = function (nro){
		if(this.contenedor){
			var img = document.getElementById(this.nombre_base);
			if(img)
				img.src = this.dir_base_grandes+this.urls[nro];
		}
	};
	this.next = function (){
		if(this.contenedor){
			if(this.nro_actual+1 == this.urls.length)
				this.nro_actual = 0;
			else
				this.nro_actual++;
			this.show(this.nro_actual);
		}
	};
	this.previous = function (){
		if(this.contenedor){
			if(this.nro_actual-1 == -1) 
				this.nro_actual = this.urls.length-1;
			else
				this.nro_actual--;
			this.show(this.nro_actual);
		}
	};
	return this;
}

function popUpWindow(URLStr, ancho, alto){
	var left = 20;
	var top = 20;
	open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+ancho+',height='+alto+',left='+left+',top='+top+',screenX='+left+',screenY='+top+'');
}

function show(obj){
	obj = $(obj);
	if(obj)
		obj.style.display = '';
}

function hide(obj){
	obj = $(obj);
	if(obj)
		obj.style.display = 'none';
}

function toggle(obj){
	obj = $(obj);
	if(obj)
		if(obj.style.display == '')
			obj.style.display = 'none';
		else
			obj.style.display = '';
}
