
//
//	Arxiu funcions.js
// 	Conté els funcions de javascript globals
//


	function obreFinestre(pstrPagina)
	{
		var finestre = window.open(pstrPagina, "", "toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=0");
	}

	function adreca(usuari, domini) {
		document.write('<a href=\"mailto:' + usuari + '@' + domini + '\">' + usuari + '@' + domini + '</a>');
	}

	function clearText(field){
		if (field.defaultValue == field.value) field.value = '';
		else if (field.value == '') field.value = field.defaultValue;
	}

	function ValidaForm(EW_this) {
		if (EW_this.fnombre && !EW_hasValue(EW_this.fnombre, "TEXT" )) {
			if (!EW_onError(EW_this, EW_this.fnombre, "TEXT", "Nombre y Apellidos - Campo necesario/obligatorio sin rellenar"))
			return false;
		}

		if (EW_this.fcorreo && !EW_hasValue(EW_this.fcorreo, "TEXT" )) {
			if (!EW_onError(EW_this, EW_this.fcorreo, "TEXT", "Correo Electr&oacute;nico - Campo necesario/obligatorio sin rellenar"))
			return false;
		}
		if (EW_this.ftelf && !EW_hasValue(EW_this.ftelf, "TEXT" )) {
			if (!EW_onError(EW_this, EW_this.ftelf, "TEXT", "Tel&eacute;fono - Campo necesario/obligatorio sin rellenar"))
			return false;
		}

		return true;
	}

	function EW_hasValue(obj, obj_type) {
		if (obj_type == "TEXT" || obj_type == "PASSWORD" || obj_type == "TEXTAREA" || obj_type == "FILE")	{
			if (obj.value.length == 0) 	return false;
			else	return true;

		} else if (obj_type == "SELECT") {
			if (obj.type != "select-multiple" && obj.selectedIndex == 0) return false;
			else if (obj.type == "select-multiple" && obj.selectedIndex == -1) return false;
			else return true;
		} else if (obj_type == "RADIO" || obj_type == "CHECKBOX")	{
			if (obj[0]) {
				for (i=0; i < obj.length; i++) {
					if (obj[i].checked) return true;
				}
			} else return (obj.checked);
			return false;
		}
	}

	function EW_onError(form_object, input_object, object_type, error_message) {
		alert(error_message);
		if (object_type == "RADIO" || object_type == "CHECKBOX") {
			if (input_object[0]) input_object[0].focus();
			else input_object.focus();
		}	else if (!EW_isHiddenTextArea(input_object, object_type)) {
			input_object.focus();
		}

		if (object_type == "TEXT" || object_type == "PASSWORD" || object_type == "TEXTAREA" || object_type == "FILE") {
			if (!EW_isHiddenTextArea(input_object, object_type)) input_object.select();
		}
		return false;
	}

	function EW_isHiddenTextArea(input_object) {
		return (input_object && input_object.type && input_object.type == "textarea" &&
				input_object.style && input_object.style.display &&
				input_object.style.display == "none");
	}


