function comprueba_datos(form){
	var retorno = 1;
	var formulario = document.getElementById(form);
	var elementos = formulario.elements.length - 1;//quitamos el oculto
	if((document.getElementById('contrasena') != null) && (document.getElementById('contrasena2') != null)){
		var contrasena = document.getElementById('contrasena');
		var contrasena2 = document.getElementById('contrasena2');
		if((contrasena.value != contrasena2.value)){
			contrasena.className = 'input_error';
			contrasena2.className = 'input_error';
			document.getElementById('texto_error').className = 'visible';
			document.getElementById('texto_error').innerHTML = "Las contraseas no coinciden";
			retorno = 0;
		}
	}
	for(i=0; i < elementos; i++){
		if(formulario.elements[i].value == ""){
			formulario.elements[i].className = 'input_error';
			document.getElementById('texto_error').className = 'visible';
			document.getElementById('texto_error').innerHTML = "Debes introducir todos los datos";
			retorno = 0;
		} else{
			formulario.elements[i].className = '';
		}
	}
	if(retorno == 1){
		formulario.submit();
	}	
}
function comprueba_login(form){
	var retorno = 1;
	var formulario = document.getElementById(form);
	var elementos = formulario.elements.length - 1;//quitamos el oculto
	for(i=0; i < elementos; i++){
		if(formulario.elements[i].value == ""){
			formulario.elements[i].className = 'input_error';
			document.getElementById('texto_error').className = 'visible';
			document.getElementById('texto_error').innerHTML = "Debes introducir todos los datos";
			retorno = 0;
		} else{
			formulario.elements[i].className = '';
		}
	}
	if(retorno == 1){
		formulario.submit();
	}		
}
function comprueba_nuevo_descuento(form){
	var retorno = 1;
	var formulario = document.getElementById(form);
	var elementos = formulario.elements.length;
	var nombre;
	var valor;
	for(i=0; i < elementos; i++){
		nombre = formulario.elements[i].name;
		valor = formulario.elements[i].value;
		if(((nombre == 'id_tipo_descuento') && (valor == ''))
			|| ((nombre == 'descuento') && (document.getElementById('id_tipo_descuento').value != 3) && (valor == ''))
			|| ((nombre == 'servicio') && (valor == ''))){
			formulario.elements[i].className = 'input_error';
			document.getElementById('texto_error').className = 'visible';
			document.getElementById('texto_error').innerHTML = "Debes introducir los datos marcados";
			retorno = 0;
		} 
		else if((nombre == 'descuento') && (!IsNumeric(valor))){
			formulario.elements[i].className = 'input_error';
			document.getElementById('texto_error').className = 'visible';
			document.getElementById('texto_error').innerHTML = "El descuento debe ser un valor numérico";
			retorno = 0;
			}
		else{
			formulario.elements[i].className = '';
		}
	}
	if(retorno == 1){
		formulario.submit();
	}		
}
function nuevo_servicio(num_servicio){
	if(num_servicio == 1){
		document.getElementById('servicio_precio').className = 'visible';
		document.getElementById('tr_servicios').className = 'visible';
	}
	
	if(num_servicio == 4){
		document.getElementById('anadir_servicio').className = 'invisible';
	}
	
	if(num_servicio <= 4){
		var contenedor = document.getElementById('td_servicio');	
		var input = document.createElement('input');
		var space = document.createTextNode("\u00a0");
		var br1 = document.createElement("br");
		var br2 = document.createElement("br");
		
		input.setAttribute('type', 'text');
		input.setAttribute('size', '30');
		input.setAttribute('id', 'servicio'+num_servicio);
		
		
		var td_precio = document.createElement('td');
		var input_precio = document.createElement('input');
		
		input_precio.setAttribute('type', 'text');
		input_precio.setAttribute('size', '5');
		input_precio.setAttribute('id', 'precio'+num_servicio);
		input_precio.setAttribute('name', 'precio'+num_servicio);
		
		contenedor.appendChild(input);
		contenedor.appendChild(space);
		contenedor.appendChild(input_precio);
				
		var tr = document.createElement('tr');
		var td = document.createElement('td');
		
		contenedor.appendChild(br1);
		contenedor.appendChild(br2);
		
		num_servicio_global++;	
	} 
}
function IsNumeric(sText){
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++) 
  { 
  Char = sText.charAt(i); 
  if (ValidChars.indexOf(Char) == -1) 
	 {
	 IsNumber = false;
	 }
  }
return IsNumber;
}
function intercambiar_visibilidad(nombre_div){
	var clase_div = document.getElementById(nombre_div).className;
	if(clase_div == 'visible'){
		nueva_clase = 'invisible';
	} else if(clase_div == 'invisible'){
		nueva_clase = 'visible';
	}
	document.getElementById(nombre_div).className = nueva_clase;
}
function marcar_leido(id_mensaje){
	new Ajax.Request('/ajax_marcarleido.php', {
	method: 'post',
	parameters:'id_mensaje='+id_mensaje
	});
}
function marcar_leido_cambios(id_mensaje){	
	$('fila'+id_mensaje).className = '';
	$('imagen_mensaje'+id_mensaje).src = '/iconos/mail2_16x16.gif';
	$('imagen_borrar_mensaje'+id_mensaje).src = '/iconos/mail2_(delete)_16x16.gif';
}
function marcar_borrado(id_mensaje){
	new Ajax.Request('/ajax_marcarborrado.php', {
	method: 'post',
	parameters:'id_mensaje='+id_mensaje
	});
}