function check_string(obj, len, name){
	if (obj.length<=len){
		alert("ERROR: campo '"+name+"' incorrecto.");
		return 1;
	}
	return 0;
}

function check_number(obj, name){
	if (obj=="" || isNaN(obj)){
		alert("ERROR: campo '"+name+"' incorrecto.");
		return 1;
	}
	return 0;
}

function check_passwords(p1, p2, name){
	if (p1!=p2){
		alert("ERROR: campo '"+name+"' incorrecto.");
		return 1;
	}
	return 0;
}

function check_email(obj, name){
	if (obj.length<5 || obj.indexOf("@")<3){
		alert("ERROR: campo '"+name+"' incorrecto.");
		return 1;
	}
	return 0;
}

function check_date(fecha){
	var error=false;
	if ((fecha.substr(2,1) != "/") || (fecha.substr(5,1) != "/"))
		error=true;
	for (i=0; i<10; i++)
		if (((fecha.substr(i,1)<"0") || (fecha.substr(i,1)>"9")) && (i != 2) && (i != 5))
			error=true;
	if (fecha.length>10)
		error=true;
	a = fecha.substr(6,4);
	m = fecha.substr(3,2);
	d = fecha.substr(0,2);
	if((a < 1900) || (a > 2050) || (m < 1) || (m > 12) || (d < 1) || (d > 31))
		error=true;
	if((a%4 != 0) && (m == 2) && (d > 28))
		error=true;
	if ((((m == 4) || (m == 6) || (m == 9) || (m==11)) && (d>30)) || ((m==2) && (d>29)))
		error=true;
	if (error){
		//alert("ERROR: campo '"+name+"' incorrecto.");
		return 0;
	}else{
		return 1;
	}
}



function imprimir(id){
	form_imprimir.id.value=id;
	form_imprimir.submit();
}
function carga_seccion(id, enlace, idioma){
	if (enlace.length>0){
		window.open(enlace);	
	}else{
		if (id==55)
			id="contacto";
		self.location="./index.php?seccion="+id+"&idioma="+idioma;
	}
}
function carga_contenido(seccion, contenido, idioma, destacado, buscar){
	if (isNaN(destacado))
		destacado="";
	str_buscar="";
	if (typeof(buscar)!="undefined")
		str_buscar="&buscar="+buscar;
	self.location="./index.php?seccion="+seccion+"&contenido="+contenido+"&idioma="+idioma+"&destacado="+destacado+str_buscar;
}
function marca(id){
	obj=document.getElementById("td_"+id);
	obj.background="images/textura_boton_fondo3.gif";
}
function desmarca(id){
	obj=document.getElementById("td_"+id);
	obj.background="images/textura_boton_fondo2.gif";
}
function creditos(idioma){
	window.open("creditos.php?idioma="+idioma, "creditos", "width=243, height=203, scrollbars=0");
}

function draw_flash(name, swf, width, height, bgcolor, wmode){
	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\""+width+"\" height=\""+height+"\" id=\""+name+"\" name=\""+name+"\" align=\"middle\">");
	document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\" />");
	document.write("<param name=\"movie\" value=\""+swf+"\" />");
	document.write("<param name=\"quality\" value=\"high\" />");
	document.write("<param name=\"menu\" value=\"false\" />");
	if (wmode != undefined){
		document.write("<param name=\"wmode\" value=\""+wmode+"\" />");
	}
	document.write("<param name=\"bgcolor\" value=\""+bgcolor+"\" />");
	document.write("<embed src=\""+swf+"\" quality=\"high\" bgcolor=\""+bgcolor+"\" width=\""+width+"\" height=\""+height+"\" name=\""+name+"\" id=\""+name+"\" wmode=\"opaque\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />");
	document.write("</object>");
}

function number_format (number, decimals, dec_point, thousands_sep){
	var exponent = "";
	var numberstr = number.toString ();
	var eindex = numberstr.indexOf ("e");
	if (eindex > -1){
		exponent = numberstr.substring (eindex);
		number = parseFloat (numberstr.substring (0, eindex));
	}
	
	if (decimals != null){
		var temp = Math.pow (10, decimals);
		number = Math.round (number * temp) / temp;
	}
	var sign = number < 0 ? "-" : "";
	var integer = (number > 0 ?  Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
	
	var fractional = number.toString ().substring (integer.length + sign.length);
	dec_point = dec_point != null ? dec_point : ".";
	fractional = decimals != null && decimals > 0 || fractional.length > 1 ? 
			   (dec_point + fractional.substring (1)) : "";
	if (decimals != null && decimals > 0){
	for (i = fractional.length - 1, z = decimals; i < z; ++i)
		fractional += "0";
	}
	
	thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? 
				  thousands_sep : null;
	if (thousands_sep != null && thousands_sep != ""){
		for (i = integer.length - 3; i > 0; i -= 3)
			integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
	}
	
	return sign + integer + fractional + exponent;
}

function buscar_changed(obj){
	if (obj.value==""){
		obj.value=general_buscar;	
	}	
}

function buscar_focus(obj){
	if (obj.value==general_buscar){
		obj.value="";	
	}	
}
function validar_reservas(form){
	if (check_date(form.en.value) && check_date(form.sa.value)){
		form.submit();	
	}else{
		alert(error_fecha);
	}
}
