
// avoid conflicts between jQuery and other libraries
	jQuery.noConflict();

// function validateSpanishPhoneNumber
// return true if it's a spanish phone number (an optional +34 plus 9 digits) or false otherwise
// accepts a multiple phone numbers separate by commas

	function validateSpanishPhoneNumer(value)
	{
		var result = false;
		
		rePhoneNumber = new RegExp(/^(\+34)?\d{9}(,(\+34)?\d{9})*$/);
		
		result = rePhoneNumber.test(value);
	
		return result;
	}
	
		
// function checkCamposObligatorios
// comprueba que los campos con id terminado en '_required' no esten vacios
// si detecta un campo vacio, muestra un mensaje de error escondido y pone el foco en el campo

	function checkCamposObligatorios(formulario, mensaje_error)
	{	
		var resultado = true;
		var focus_set = false;
		
	// todos los inputs con name acabado en _required
	
		jQuery("#" + formulario.id + " :input").each(function(){
				
		// check required fields	
		
			if( jQuery(this).is("[id$='_required']") )
			{
			// comprobamos si el campo esta vacio (obviando espacios en blanco y helptips)
		
				if( jQuery(this).val() == ''
				 || jQuery(this).val() == jQuery(this).attr('helptip'))
				{
				// mostramos el mensaje de error
				
					// alert(mensaje_error);
					jQuery(this).parent()
								.find('#' + this.name + '_mandatory')
								.show()
								.effect('highlight',{},1000);
				
				// ponemos el foco en el campo
					
					if( focus_set == false ) {
						jQuery(this).focus();
						focus_set = true;
					}					
								
				// constatamos de que hay un campo vacio
				
					resultado = false;
				}
			}
		// campos no obligatorios pero con helptip
			else if( jQuery(this).val() == jQuery(this).attr('helptip') )
			{
				jQuery(this).focus();
			}
			
		});
		
		return resultado;
	}
	

// function formHelptips
// necesita un identificador de formulario
	function formHelptips(form_id)
	{
	// hide real password fields
	
		jQuery('#' + form_id + ' :input[fake_password]').hide();

	// process heltips
	
		jQuery('#' + form_id).find(':input[helptip]').each(function(){
			
			if( jQuery(this).val() == '' )
			{
				jQuery(this).val( jQuery(this).attr('helptip') );
			}
			
		}).focus(function(){
			
		// if it's a fake password field
		
			if( jQuery(this).attr('real_password') != undefined )
			{
			// hide fake password field
				jQuery(this).hide();
				
			// show real password field
				jQuery('#' + jQuery(this).attr('real_password')).show().focus();
			}
			else if( jQuery(this).val() == jQuery(this).attr('helptip') )
			{
				jQuery(this).val('');
			}
			
		}).blur(function(){
			
			if( jQuery(this).val() == '' )
			{
			// if it's a real password field
		
				if( jQuery(this).attr('fake_password') != undefined )
				{
				// hide real password field
					jQuery(this).hide();
					
				// show fake password field
					jQuery('#' + jQuery(this).attr('fake_password')).show();
				}
				else
				{
					jQuery(this).val( jQuery(this).attr('helptip') );
				}
			}
		});
	}

// function getUrlVars
// Read a page's GET URL variables and return them as an associative array.
	function getUrlVars()
	{
	    var vars = [], hash;
	    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

	    for(var i = 0; i < hashes.length; i++)
	    {
	        hash = hashes[i].split('=');
	        vars.push(hash[0]);
	        vars[hash[0]] = hash[1];
	    }

	    return vars;
	}
