	/****************************************************/
	// GENERAL										  	//
	/****************************************************/

	var isIE = (navigator.appName.indexOf("Microsoft Internet Explorer") != -1);

	var Browser = {
		getVersion: function() {
			return ((navigator.appVersion.indexOf("MSIE") != -1)? parseFloat(navigator.appVersion.split("MSIE")[1]) : 999);
		}
	}	
	
	if (isIE){
		onerror = hdlError;
		function hdlError(msg, url, l){
			var txt="";
			txt="There was an error on this page.\n\n";
			txt+="Error: " + msg + "\n";
			txt+="URL: " + url + "\n";
			txt+="Line: " + l + "\n\n";
			//alert(txt);
			return true;
		}
	}


	function getTop(){			return parent;	}
	function getContext(){		return getTop().context;	}
	function getResources(){	return getTop().resources;	}
	function getTitleBar(){		return getTop().titleBar;	}
	function getToolBar(){		return getTop().toolBar;	}
	function getMngWindow(){	return getTop().mngWindow;	}
	function getMenu(){			return getTop().menu;		}

	function getUserConfig(){	return getTop().userConfig;	}
	function setUserConfig(userConfiguration){
		return getTop().userConfig = userConfiguration;
	}
	
	function getMessage(idMsg){
		return getTop().msg[idMsg];
	}

	function getEvent(event){
		return (event ? event : window.event);
	}

	function getKeyCode(event){
		return (event.keyCode ? event.keyCode : event.which);
	}

	function deleteElementById(id){
		var element = document.getElementById(id);
		if (element != null && element.parentNode != null) element.parentNode.removeChild(element);
	}

	function deleteElement(element){
		if (element != null && element.parentNode != null) element.parentNode.removeChild(element);
	}

	function insertAfter(newNode, refNode){
		refNode.parentNode.insertBefore(newNode, refNode.nextSibling);
	}

	function showProcessing(){
		if (getTop().nPetProcess == 0) getTop().document.getElementById("processing").style.display = "";
		getTop().nPetProcess ++;
	}

	function hideProcessing(force){
		if (force == null) force = false;
		getTop().nPetProcess--;
		if (getTop().nPetProcess == 0 || force) {
			getTop().setDefaultProcessing();
			getTop().document.getElementById("processing").style.display = "none";
		}
		if (force) getTop().nPetProcess = 0;
		if (getTop().nPetProcess < 0) getTop().nPetProcess = 0;
	}

	function chgResourceProcessing(src, width, height) {
		getTop().chgProcessing(src, width, height);
	}

	function showCalendar(input){
		if (getTop().initCalendar != null)
			getTop().initCalendar(input);
		else
			initCalendar(input);
	}

	function showClock(input){
		var params = new Params();
		params.put("field", input);
		mngWindow.showWindow("CLOCK", params);
	}

	function showElement(id, show){
		if (document.getElementById(id) != null) document.getElementById(id).style.display = (show? "" : "none");
	}

	function isEmpty(object){
		if (object == null || object == undefined) return true;
		if (object.replace != null) return ((object == "") || (object.replace(/ /g, "") == ""));
		else return (object.toString().replace(/ /g, "") == "");		
	}

	//**************************//
	//		 CONSOLE.LOG	 	//
	//**************************//
	function Console(){}
	Console.prototype.log = function(s){return null;}

	try {
		console.log();
	} catch(e){
		console = new Console();
	}

	//**************************//
	//		 CLASE PARAM	 	//
	//**************************//
	function Param(name, value){
		this.name = name;
		this.value = value;
	}
	Param.prototype.getName = function(){return this.name;}
	Param.prototype.setName = function(name){this.name = name;}
	Param.prototype.getValue = function(){return this.value;}
	Param.prototype.setValue = function(value){this.value = value;}

	//**************************//
	//		 CLASE PARAMS   	//
	//**************************//
	function Params(){
		this.aParams = new Array();
	}
	Params.prototype.put = function(name, value){this.aParams.push(new Param(name, value));}
	Params.prototype.putByName = function(name, value){
		var success = false;
		for(var i = 0; i < this.aParams.length; i++){
			if (this.aParams[i].getName() == name){
				this.aParams[i].setValue(value);
				success = true;
			}
		}
		if(!success) this.aParams.push(new Param(name, value));
	}
	Params.prototype.putValues = function(name, aValues){
		for(var i = 0; i < aValues.length; i++){
			this.aParams.push(new Param(name, aValues[i]));
		}
	}
	Params.prototype.remByName = function(name){
		for(var i = 0; i < this.aParams.length; i++){
			if(this.aParams[i].getName() == name) this.aParams.splice(i,1);
		}
	}
	Params.prototype.append = function(params){this.aParams = this.aParams.concat(params.getParams());}
	Params.prototype.getParams = function(){return this.aParams;}
	Params.prototype.getParamValue = function(name){
		for(var i = 0; i < this.aParams.length; i++){
			var param = this.aParams[i];
			if(param.getName() == name) return param.getValue();
		}
		return null;
	}
	Params.prototype.getParamValues = function(name){
		var result = new Array();
		for(var i = 0; i < this.aParams.length; i++){
			var param = this.aParams[i];
			if(param.getName() == name) result.push(param.getValue());
		}
		return result;
	}
	Params.prototype.clean = function(){this.aParams() = new Array();}
	Params.prototype.toString = function(){
		var result = "?";
		for(var x = 0; x < this.aParams.length; x++){
			if(x > 0) result += "&";
			result += this.aParams[x].getName() + "=" + window.encodeURIComponent(this.aParams[x].getValue());
		}
		return result;
	}
	Params.prototype.cloneNode = function() {
		var params = new Params();
		for (var i in this.aParams) params.put(this.aParams[i].getName(), this.aParams[i].getValue());
		return params;
	}
	Params.prototype.isEmpty = function(name) {
		return (this.getParamValue(name) == null || this.getParamValue(name) == "");
	}


	/****************************************************/
	//		VERIFICACION Y FORMATO						//
	/****************************************************/

	function pad2(number) {
		return (number < 10 ? '0' : '') + number
	}
	
	function formatPrice(priceUsr, price, currency, target){
		target.innerHTML = "&nbsp;";
		target.align = "right";
		target.style.whiteSpace = "nowrap";

		var span;
		if (priceUsr != null && priceUsr != "") {
			span = document.createElement("span");
			span.style.color = "#D67300";
			span.innerHTML = "(" + priceUsr + " " + getCurrencySymbol(getUserConfig().getCurrency()) + ") ";
			target.appendChild(span);
		}
		span = document.createElement("span");
		span.innerHTML = price + " " + getCurrencySymbol(currency);
		target.appendChild(span);
	}

	function getFormattedString(values, separator, group){
		var result = "";
		for(var i = 0; i < values.length; i++){
			if(i > 0) result += separator + " ";
			result += values[i];
		}
		if(result.length > 0){
			if(group == "POINT") result += ".";
			else if(group == "BRAKETS") result = "(" + result + ")";
		}
		return result;
	}

	function replaceParam(textSource, numParam, textParam){
		return (textSource.replace("{" + numParam + "}", textParam));
	}
	
	/* CLASE FORMAT NUMBER */
	/* Clase para el formato de numeros */
	function FormatNumber(numberDecimals){

		this.DOT = ".";
		this.COMMA = ",";

		this.sepM;
		this.sepD;
		this.numberDecimals = 0;
		this.minValue;
		this.maxValue;
		
		this.formatted = true;
		this.onformatRound = false;		
		
		if (!isNaN(numberDecimals)) this.numberDecimals = numberDecimals;

		if (getUserConfig().getNumberFormat() == "DC"){
			this.sepM = this.DOT;
			this.sepD = this.COMMA;
		} else {
			this.sepM = this.COMMA;
			this.sepD = this.DOT;
		}
	}
	FormatNumber.prototype.setOnformatRound = function(onformatRound){this.onformatRound = onformatRound;}
	FormatNumber.prototype.setFormatted = function(formatted){this.formatted = formatted;}
	FormatNumber.prototype.setNumberDecimals = function(numberDecimals){this.numberDecimals = numberDecimals;}
	FormatNumber.prototype.setMinValue = function(minValue){this.minValue = minValue;}
	FormatNumber.prototype.setMaxValue = function(maxValue){this.maxValue = maxValue;}
	FormatNumber.prototype.applyRanges = function(value){
		if(this.minValue != null && value < this.minValue) return this.minValue;
		else if(this.maxValue != null && value > this.maxValue) return this.maxValue;
		else return value;
	}
	FormatNumber.prototype.fillZero = function(value){
		if (isEmpty(value) || this.numberDecimals == 0) return value;
		
		var aux = String(value).split(this.sepD);
		if (aux[1] == null){
			value += this.sepD + new Array(this.numberDecimals + 1).join('0');
		} else if (aux[1].length < this.numberDecimals){
			value += new Array(this.numberDecimals - aux[1].length + 1).join('0');
		}

		return value;
	}
	FormatNumber.prototype.round = function(value){
		if(this.numberDecimals > 0){
			var aux = Math.pow(10, this.numberDecimals);
			return (Math.round(value * aux) / aux);
		} else {
			return value;
		}
	}
	FormatNumber.prototype.parse = function(value){
		var aBase = value.split(this.sepM);
		var result = aBase.join("");
		if(this.sepD == this.COMMA) result = result.replace(/,/g, this.DOT);
		return this.round(parseFloat(result, 10));
	}
	FormatNumber.prototype.format = function(value, number, ranges){		
		var aux1 = null; var comma = false; var minus = false; var decim = null;
		
		if (number){
			aux1 = this.round(value);
			comma = (String(value).indexOf('.') > -1 && this.numberDecimals > 0);
			minus = (aux1 < 0);
		} else {
			if (value == null || value.length == 0) return ''; 		
			if (value.charAt(0) == this.sepD) value = "0"+ value;

		    aux1 = this.parse(value);
			comma = (value.indexOf(this.sepD) > -1 && this.numberDecimals > 0);
			minus = (value.charAt(0) == '-');
			decim = (comma? value.split(this.sepD)[1] : null);			
		}

	    var result = (((this.minValue == null || this.minValue < 0) && minus)? '-':'');		
	    if (!isNaN(aux1)){
	       if (ranges) aux1 = this.applyRanges(aux1);	       
	       var aux2 = String(Math.abs(aux1)).split('.');
	       if (this.formatted){
	    	   var alength = aux2[0].length;
		       for (var i = 0; i < alength; i++){
		           result += aux2[0][i];
		           if (aux2[0].slice(i+1).length % 3 == 0 && i < alength-1) result += "#";
		       }		       
	       } else {
	    	   result += aux2[0];
	       }

	       if (comma) result += "."
	       if (decim != null && !isNaN(decim)) aux2[1] = decim;
	       if (aux2[1] != null) result += ((aux2[1].length > this.numberDecimals)? aux2[1].slice(0, this.numberDecimals) : aux2[1])

	       result = result.replace(/\./g, this.sepD).replace(/#/g, this.sepM);
	   }
		
	   if (number) result = this.fillZero(result);
	   return result;
	}
	FormatNumber.prototype.check = function(value){
		if(value == null || value.length == 0) return true;
		if(value.charAt(value.length - 1) == this.sepD) return false;
		try{this.parse(value);}catch(ex){return false;}
		return true;
	}
	FormatNumber.prototype.cloneNode = function(){
		var fnumber = new FormatNumber();
		fnumber.sepM = this.sepM;
		fnumber.sepD = this.sepD;
		fnumber.numberDecimals = this.numberDecimals;
		fnumber.minValue = this.minValue;
		fnumber.maxValue = this.maxValue;
		fnumber.formatted = this.formatted;
		return fnumber;
	}

	function getCurrencySymbol(currency){		
		return currency;
	}

	//	Funcion que valida dos contrasenyas
	function checkPassword(val1, val2){

		var cad1 = val1;
		var cad2 = val2
		var len1 = cad1.length;
		var len2 = cad2.length;

		if (val1 != val2){
			alert(getMessage("msg09")); return false;
		} else if ((len1 < 6) || (len2 < 6)){
			alert(getMessage("msg10")); return false;
		}
		
		return true;
	}

	function metersToFeet(field1, field2){
		field2.setValueFromFloat(field1.getValueAsFloat() * 3.281);
	}

	function feetToMeters(field1, field2){
		field2.setValueFromFloat(field1.getValueAsFloat() / 3.281);
	}

	function meters2ToFeet2(field1, field2){
		field2.setValueFromFloat(field1.getValueAsFloat() * 10.764);
	}

	function feet2ToMeters2(field1, field2){
		field2.setValueFromFloat(field1.getValueAsFloat() / 10.764);
	}

	function parseDecimal(integer){
		return (integer != null && !isNaN(integer.replace(/,/g,'.')))? (parseFloat(integer.replace(/,/g,'.') * 100) / 100) : 0;
	}

	// TODO Hacer clase que FormatDate
	function strToDate(str){
		if (str != null && str.split != null && str.length > 0){			
			var rgx = new RegExp("[0-9]*[0-9]+/[0-9]*[0-9]+/[0-9][0-9][0-9][0-9]");

			var sdate = rgx.exec(str);
			if (sdate != null){
				var aDate = String(sdate).split("/");
				var myDay;
				var myMonth;
				
				var formatDate = getUserConfig().getFormatDate();				
				if (formatDate == "ESP"){
					myDay = parseInt(aDate[0], 10);
					myMonth = parseInt(aDate[1], 10) - 1;
				} else if(formatDate == "ENG"){
					myDay = parseInt(aDate[1], 10);
					myMonth = parseInt(aDate[0], 10) - 1;
				}
				
				var myYear = aDate[2];
				var myDate = new Date(myYear, myMonth, myDay);
				myDate.setHours(0);
				myDate.setMinutes(0);
				myDate.setSeconds(0);
				myDate.setMilliseconds(0);
	
				return myDate;
			}
		}
		
		return null;
	}

	function dateToStr(date){		
		if  (date == null || date.getTime == null) return null;
		
		var formatDate = getUserConfig().getFormatDate();

		var day = date.getDate(); if(day < 10) day = "0" + day;
		var month = date.getMonth(); month++; if(month < 10) month = "0" + month;
		var year = date.getFullYear();

		var value = "";
		if (formatDate == "ESP") value = day + "/" + month + "/" + year;
		else if (formatDate == "ENG") value = month + "/" + day + "/" + year;

		return value;
	}

	function compareDates(fInicio, fFin, op){
		if (op == null) op = "<=";

		var tInicio = fInicio.getTime();
		var tFin = fFin.getTime();
		
		return ((tInicio == 0 || tFin == 0)? true : (eval("tInicio "+ op +" tFin")));
	}

	function numDays(fInicio, fFin){
		try {
			var tInicio = ((fInicio.getTime == null)? strToDate(fInicio).parse() : fInicio.getTime());
			var tFin = ((fFin.getTime == null)? strToDate(fFin).parse() : fFin.getTime());

			var numN = Math.round((tFin - tInicio) / (1000 * 60 * 60 * 24)) + 1;
			if (parseFloat(numN, 10) >= 0) return new String(numN);
		} catch (ex){ }
		
		return new String(0);
	}

	function numNights(fInicio, fFin){
		
		try {
			var fecInicio;
			var fecFin;

			if (fInicio instanceof Date) 		fecInicio = fInicio;
			else if (fInicio.getDate == null) 	fecInicio = strToDate(fInicio);
			else fecInicio = fInicio.getDate();

			if (fFin instanceof Date) 			fecFin = fFin;
			else if (fFin.getDate == null) 		fecFin = strToDate(fFin);
			else fecFin = fFin.getDate();
			
			var numN = Math.round((fecFin.getTime() - fecInicio.getTime()) / (1000 * 60 * 60 * 24));
			
			if (parseFloat(numN, 10) < 0) return new String(0);
			return new String(numN);
		} catch (ex) {
			return new String(0);
		}
	}

	function addDays(date, numDays) {
		var formatDate = getUserConfig().getFormatDate();
		var myDay, myMonth, myYear;

		if (date.getDate == null) date = strToDate(date);

		date.setHours(9);
		date.setTime(date.getTime() + (numDays * 24*60*60*1000));
		myDay = date.getDate();
		if (myDay <= 9) myDay = '0' + myDay;
		myMonth = date.getMonth()+1;
		if (myMonth < 9) myMonth ='0' + myMonth;
		if (formatDate == "ESP") {
			date = myDay + '/' + myMonth + '/' + date.getFullYear();
		} else if (formatDate == "ENG")	{
			date = myMonth + '/' + myDay + '/' + date.getFullYear();
		}
		
		return (strToDate(date));
	}

	function getWeekDay(date){
		if (date.getDay() == 0) return getTop().msg["msg16"];
		else if (date.getDay() == 1) return getTop().msg["msg17"];
		else if (date.getDay() == 2) return getTop().msg["msg18"];
		else if (date.getDay() == 3) return getTop().msg["msg19"];
		else if (date.getDay() == 4) return getTop().msg["msg20"];
		else if (date.getDay() == 5) return getTop().msg["msg21"];
		else if (date.getDay() == 6) return getTop().msg["msg22"];
	}

	function monthLenghtCurrentYear(mes) {
		var date = new Date();
		return monthLenght(mes, date.getFullYear());
	}

	function monthLenght(mes, anyo) {
		var days = new Array (0,31,28,31,30,31,30,31,31,30,31,30,31);
		if (mes == 2 && ((anyo % 4 == 0) && ((anyo % 100 != 0) || (anyo % 400 == 0)))) return 29;
		else return days[mes];
	}

	function checkDate(input, format){
		hoy = new Date();
		var d = hoy.getDate();
		var m = hoy.getMonth() + 1;
		var y = hoy.getFullYear();
		var auxYear = "" + y;
		if(parseInt(d,10)<10) d = "0"+d;
		if(parseInt(m,10)<10) m = "0"+m;

		var valor = input.value;
		if(valor == "h" || valor == "H" || valor == "t" || valor == "T"){ 
			input.value = (format != "ESP")?m+"/"+d+"/"+y:d+"/"+m+"/"+y; 
			return false;
		}
		var charsDate = "1234567890/";
		for(var i = 0; i < valor.length; i++) if(charsDate.indexOf("" + valor.charAt(i)) == -1) return fechaNoValida(input);

		if(valor.indexOf("/") == -1){
			if(valor.length == 3 || valor.length == 5 || valor.length == 7 || valor.length > 8) d = 0;
			else if(valor == "") return false;
			else if(valor.length < 3){
				d = valor;
				if(d.length == 1) d = "0" + d;
				if(format != "ESP") m = hoy.getDate();
			} else if(valor.length >= 4){
				m = valor.substring(2, 4);
				d = valor.substring(0, 2);
				if(valor.length == 6) y = "20" +  valor.substring(4);
				else if(valor.length == 8) y = valor.substring(4);
			}
		} else {
			d = valor.substring(0, valor.indexOf("/"));
			valor = valor.replace(valor.substring(0, valor.indexOf("/") + 1), "");
			m = valor.substring(0, valor.indexOf("/"));
			y = valor.replace(valor.substring(0, valor.indexOf("/") + 1), "");
			if (y.indexOf("/") != -1) d = 0;
			if(d.length <= 1) d = "0"+d;
			if(m.length <= 1) m = "0"+m;
			if(y.length <= 1) y = auxYear.substring(0, 3) + y;
			else if(y.length == 2) y = auxYear.substring(0, 2) + y;
			else if(y.length == 3) y = auxYear.substring(0, 1) + y;
		}

		if(format != "ESP" && !testDate(m, d, y, input)) return false;
		else if(format == "ESP" && !testDate(d, m, y, input)) return false;

		input.value = d+"/"+m+"/"+ ((parseInt(y, 10) < 2000)? 2000 : y);
	}

	function testDate(day, month, year, input){
		if(parseInt(day,10) != 0 && parseInt(day,10) <= monthLenght(parseInt(month,10), year) && parseInt(month,10) <= 12 && parseInt(month,10) >= 1) return true;
		else return fechaNoValida(input);
	}

	function fechaNoValida(input){
		alert(getTop().msg["msg23"]);
		input.value = "";
		return false;
	}

	function hideProcessingIfNecessary(){
		if(getTop().nPetProcess == 0){
			getTop().document.getElementById("processing").style.display = "none";
		}
	}

	function fieldsAffectedValue(fieldA, fieldB){
		fieldsAffected(fieldA, fieldB);
		fieldA.getObj().onchange = function(){
			fieldsAffected(fieldA, fieldB);
		};
	}

	function fieldsAffected(fieldA, fieldB){
		if (fieldA.getValue() == ""){
			fieldB.setValue("");
			fieldB.setReadOnly(true);
		} else if(!fieldA.isReadOnly()) {
			fieldB.setReadOnly(false);
		}
	}

	function quitAccents(s){
		á="a";
		é="e";
		í="i";
		ó="o";
		ú="u";
		accents=/[áéíóú]/g;
		return s.replace(accents,function($1){return eval($1)});
	}

	function sleep(milliseconds) {
		var start = new Date().getTime();
		for (var i = 0; i < start; i++) {
			if ((new Date().getTime() - start) > milliseconds){
				break;
			}
		}
	}

	function checkTime(input) {
		var valor = input.value;
		var aux = "";

		if(valor == "") return true;
		var charsDate = "1234567890:";
		for(var i = 0; i < valor.length; i++) if(charsDate.indexOf("" + valor.charAt(i)) == -1) return horaNoValida(input);

		if(valor.indexOf(":") == -1){
			if(valor.length == 1) aux = "0" + valor + ":00";
			else if(valor.length == 2 && parseInt(valor,10) < 24) aux = valor + ":00";
			else if(valor.length == 4 && parseInt(valor.substr(0, 2),10) < 24 && parseInt(valor.substr(2, 4),10) < 60) aux = valor.substr(0, 2) + ":" + valor.substr(2, 4);
		} else {
			var horas = valor.substr(0, valor.indexOf(":"));
			var minutos = valor.replace(valor.substr(0, valor.indexOf(":") + 1), "");
			if (minutos.indexOf(":") != -1) return horaNoValida(input);
			if(horas == "") aux = "00:";
			else if(parseInt(horas,10) < 24) (horas.length == 1)? aux += "0" + horas + ":":aux += horas + ":";
			if(minutos == "") aux += "00";
			else if(parseInt(minutos,10) < 60) (minutos.length == 1)? aux += "0" + minutos:aux += minutos;
		}

		if(aux.length != 5) return horaNoValida(input);
		else input.value = aux;

		return true;
	}

	function horaNoValida(input){
		alert(getTop().msg["msg24"]);
		input.value = "00:00";
		return false;
	}

	//	Funcion para comprobar que el NIF introducido es correcto
	function checkNIF(input, showAlert){

		var s = ((input.length != null)? input : input.value);

		var filter = new RegExp("^([0-9]{8})[a-z]$", "i");
		if ((s.length > 0) && (filter.test(s))){
			var code = "TRWAGMYFPDXBNJZSQVHLCKE";
			var number = s.substring(0, 8);
			var letter = s.substring(8);

			var index = parseInt(number) % 23;
			if (code.charAt(index) == letter.toUpperCase()) return true;
		}

		if (showAlert){
			alert(getMessage("msg01"));
			if (input.select != null) input.select();
		}
		return false;
	}

	//	Funcion para comprobar que el CIF introducido es correcto
	function checkCIF(input, showAlert){

		alert(input);

		var s = ((input.length != null)? input : input.value);

		var filter = new RegExp("^([0-9]{8})[a-z]$", "i");
		if ((s.length > 0) && (filter.test(s))){
			var code = "TRWAGMYFPDXBNJZSQVHLCKE";
			var number = s.substring(0, 8);
			var letter = s.substring(8);

			var index = parseInt(number) % 23;
			if (code.charAt(index) == letter.toUpperCase()) return true;
		}

		if (showAlert){
			alert(getMessage("msg01"));
			if (input.select != null) input.select();
		}

		return false;
	}

	//	Funcion para comprobar que el email introducido es correcto
	function checkEmail(input, showAlert){
		var s = ((input.length != null)? input : input.value);

		var filter = new RegExp("^[a-zA-Z0-9._-]+([+][a-zA-Z0-9._-]+){0,1}[@][a-zA-Z0-9._-]+[.][a-zA-Z]{2,6}$", "i");
		if ((s != null) && (s.length > 0) && (!filter.test(s))){
			if (showAlert){
				alert(getMessage("msg25"));
				if (input.select != null) input.select();
			}

			return false;
		}

		return true;
	}

	//	Funcion de chequeo del numero de tarjeta de credito	
	function checkCard(input, showAlert){
		var s = ((input.length != null)? input : input.value);
		var result = ((s != null) && (s.length > 0));
		
		// ER de las tarjetas
		var patterns = new Array(
        "5[1-5][0-9]{14}",			 			 // MasterCard - Eurocard
        "(5020|5038|6304|6579|6761)[0-9]{12}",	 // Maestro
        "4(?:[0-9]{12}|[0-9]{15})", 			 // Visa
        "3[47][0-9]{13}"			 			 // AMEX
        //"3(?:0[0-5][0-9]{11}|[68][0-9]{12})',  // DinersClub - CarteBlanche
        //"6011[0-9]{12}',						 // Discover
        //"(?:3[0-9]{15}|(2131|1800)[0-9]{11})", // JCB
        //"er':'2(?:014|149)[0-9]{11}"			 // Enroute
        )

		if (((s != null) && (s.length > 0))){
			for (p in patterns){
				var f = new RegExp(patterns[p]); 
				if (f.test(s)){
					var even = (s.length % 2);
					var suma = 0;
	
					for (var i = 0; i < s.length; i ++){
						var cifra = parseInt(s.charAt(i));
						if ((!even && i%2 == 0) || (even && i%2 == 1)) cifra = cifra * 2;
						if (cifra > 9) cifra = (cifra - 9);
	
						suma += cifra;
					}
	
					// Controla si el numero cumple el algoritmo
					if ((suma % 10) == 0) return true; else break;
				}
			}
		}
		
		if (showAlert) alert(getMessage("msg26"));
		return false;
	}

	//	Funcion de chequeo de cuenta bancaria IBAN
	function checkAccount(input, showAlert){
		var s = ((input.length != null)? input : input.value);
		var ok = true;

		if (s != null && s.length > 0){
			
			var size = s.length;
			var iban = s.substring(0, 4);

			var rexp = new RegExp("\\W+|[_]", "i");
			ok = ok && !rexp.test(s);
			ok = ok && (size < 35);

			var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

			// Validamos el numero IBAN
			if (isNaN(iban)){
				var account = (s.substring(4) + iban).toUpperCase();
				for (i=0; i < code.length; i++){ account = account.replace(code.charAt(i), String(i+10)); }

				if (!isNaN(account)){
					var m = "";
					for(i=0; i < account.length; i++){ m = (parseInt(m + account.charAt(i)) % 97); }

					ok = ok && (parseInt(m) == 1);
				} else {
					ok = false;
				}
			}

			
			// Si es IBAN español validamos la cuenta y si no tiene el codigo IBAN lo generamos
			if (ok && iban.indexOf("ES") == 0 || (!isNaN(iban) && size == 20)){
				var cuenta = s.substring(size - 10, size);
				var control = s.substring(size - 12, size - 10);
				var sucursal = 	s.substring(size - 16, size - 12);
				var entidad = s.substring(size - 20, size - 16);

				if (!isNaN(cuenta) && !isNaN(control) && !isNaN(sucursal) && !isNaN(entidad)){

					// Codigo de control de la cuenta ************************************
					var check1 = new Array(1, 2, 4, 8, 5, 10, 9, 7, 3, 6);
					var control1 = 0;
					for (i=0; i<=9; i++) control1 += parseInt(cuenta.charAt(i)) * check1[i];
					control1 = 11 - (control1 % 11);
					if (control1 == 11) control1 = 0; else if (control1 == 10) control1 = 1;

					// Codigo de control de la entidad-sucursal **************************
					var check2 = new Array(4, 8, 5, 10, 9, 7, 3, 6);
					var control2 = 0;
					for (i=0; i<=7; i++) control2 += parseInt(entidad.concat(sucursal).charAt(i)) * check2[i];
					control2 = 11 - (control2 % 11);
					if (control2 == 11) control2 = 0; else if (control2 == 10) control2 = 1;

					ok = ok && (control == String(control2).concat(String(control1)));

					// Generamos el codigo IBAN en caso necesario*************************
					if (!isNaN(iban) && input.length == null){
						var account = s + "ES00";
						for (i=0; i < code.length; i++){ account = account.replace(code.charAt(i), String(i+10)); }

						if (!isNaN(account)){
							var m = "";
							for(i=0; i < account.length; i++){ m = (parseInt(m + account.charAt(i)) % 97); }

							m = 98 - parseInt(m);
							input.value = ("ES"+ ((parseInt(m) < 10)? "0"+m : m) + s);
						}
					}
				}

			} else if ((!isNaN(iban) && size != 20)){
				ok = false;
			}
		}

		if (!ok && showAlert){
			alert(getMessage("msg27"));
			if (input.focus != null) input.focus();
		}

		return ok;
	}
	
	function opacity(elm, value) {
		elm.style.opacity = (value / 10);
	    elm.style.MozOpacity = (value / 10);
	    elm.style.KhtmlOpacity = (value / 10);
	    elm.style.filter = "alpha(opacity=" + (value * 10) + ")";
	    elm.style.MsFilter = " 'progid:DXImageTransform.Microsoft.Alpha(opacity=" + (value * 10) + ")' ";
	}		
	
	
	
	
