// VALIDATOR.JS by frequency-decoder.com (http://www.frequency-decoder.com/form-validator/)
// Modified to add 'select' parsing, 'group' elements support
// and compatibility with Internet Explorer v5.x
// by Emanuele Rodriguez @ TangentDigital (http://www.tangent.es)

var cargado=false;
var missatgesError="";

if(!Array.prototype.push) { // Array.push code by www.peterbailey.net
   Array.prototype.push = function() {
      for ( var i = 0; i < arguments.length; i++ ) { this[this.length] = arguments[i]; }
      return this.length;
   }
}

if(!String.prototype.trim) String.prototype.trim = function() { return this.replace(/^\s*/,'').replace(/\s*$/, ''); }

function formValidator(formid) {
   this.formid = formid;
   this.rules = new Array();
   this.styleLabelOnErr = true;
   this.invalidClass = "invalid";
   this.warningClass = "warn";
   this.validateAsErr = false;
   this.ensenyarMissatge  = false;
   this.localitat = false;

   this.init = function() {
      var nodes = new Array();
      // getElementsByTagName returns an object collection which doesn't have a .concat() method
      var tempnodes = document.getElementById(self.formid).getElementsByTagName('input');

      for(var i = 0; i < tempnodes.length; i++) if(tempnodes.item(i).type.toUpperCase() == 'TEXT' || tempnodes.item(i).type.toUpperCase() == 'PASSWORD' || tempnodes.item(i).type.toUpperCase() == 'CHECKBOX') nodes.push(tempnodes.item(i));

      tempnodes = document.getElementById(self.formid).getElementsByTagName('textarea');
      for(i = 0; i < tempnodes.length; i++) nodes.push(tempnodes.item(i));

      tempnodes = document.getElementById(self.formid).getElementsByTagName('select');
      for(i = 0; i < tempnodes.length; i++) nodes.push(tempnodes.item(i));
      
      for(i = 0; i < nodes.length; i++) {
         var current = nodes[i];
         
         // Only if the INPUT/TEXTAREA/SELECT has an id;
         if(typeof current.id != 'undefined' && current.id != "") {
            while(current.previousSibling) {
               current = current.previousSibling;
               if(!(current.nodeName.toUpperCase().indexOf('TEXT') != -1 || current.nodeName.toUpperCase().indexOf('COMMENT') != -1 || current.nodeName.toUpperCase().indexOf('!') != -1)) { break; }
               // IE 5.x does not read correctly comment nodes widh nodeValue- use innerHTML instead
               var currNodeValue = '';
               if(current.nodeName.toUpperCase().indexOf('!') != -1) currNodeValue = current.innerHTML.replace("<!--","").replace("-->","");
               else if(current.nodeName.toUpperCase().indexOf('COMMENT') != -1) currNodeValue = current.nodeValue;
	       var missatgeRequerit='';
	       var missatgeFormat='';
	       var missatgeRepetit='';
               if(currNodeValue.trim().indexOf(nodes[i].id) == 0) {
		  if (currNodeValue.indexOf("missatgeRequerit")!=-1){
			missatgeRequerit=self.extreureMisstage(currNodeValue,currNodeValue.indexOf("missatgeRequerit"),"missatgeRequerit")
			}
		  if (currNodeValue.indexOf("missatgeFormat")!=-1){
			missatgeFormat=self.extreureMisstage(currNodeValue,currNodeValue.indexOf("missatgeFormat"),"missatgeFormat")
			}
		  if (currNodeValue.indexOf("missatgeRepetit")!=-1){
			missatgeRepetit=self.extreureMisstage(currNodeValue,currNodeValue.indexOf("missatgeRepetit"),"missatgeRepetit")
			}
		  // Si nomes te missatgeRequerit
		  if (currNodeValue.indexOf("missatgeRequerit")!=-1){
			var currNodeValueTmp=currNodeValue.substring(0,currNodeValue.indexOf("missatgeRequerit"))		
			currNodeValue=currNodeValueTmp+"//";
			}
		  // Si nomes te missatgeFormat
		  else if (currNodeValue.indexOf("missatgeFormat")!=-1){
			var currNodeValueTmp=currNodeValue.substring(0,currNodeValue.indexOf("missatgeFormat"))
			currNodeValue=currNodeValueTmp+"//";					  				  
		        }
		  // Si nomes te missatgeRepetit
		  else if (currNodeValue.indexOf("missatgeRepetit")!=-1){
			var currNodeValueTmp=currNodeValue.substring(0,currNodeValue.indexOf("missatgeRepetit"))
			currNodeValue=currNodeValueTmp+"//";					  				  
		        }
                  var argList = currNodeValue.trim().split(" ");
                  // Only if we can create a RegExp with the second argument
                  if(argList.length > 3 && typeof new RegExp(argList[1]) != 'undefined') self.addRule(nodes[i], argList[1], (argList[2].trim() == "true" ? true : false), (argList[3].trim() == "true" ? true : false), (typeof(argList[4])!='undefined')?argList[4].trim().replace(/\/\/$/g,''):'', (typeof(argList[5])!='undefined')?argList[5].trim().replace(/\/\/$/g,''):'',missatgeRequerit,missatgeFormat,missatgeRepetit);
                  //DEBUG: alert('Added RegExp ' + argList[1] + ' for element id: '+nodes[i].id)
	          if (nodes[i].id.indexOf("localitat")!=-1){
			this.localitat=true;
                  	}
               }
            }
         }
      }
      // Call the user defined initialisation
      self.extendedInitialisation();
   }
   
   this.styleFields = function(which) {
   
      var label = null;
      if(self.styleLabelOnErr) {
         // Get the implicit label if any (f.y.i. depreciated as from HTML4)
	         if(self.rules[which].element.parentNode.tagName.toUpperCase() == 'LABEL') {
            label = self.rules[which].element.parentNode;
         // No implicit label then search explicit label list
         } else {
            var labelList = document.getElementById(self.formid).getElementsByTagName('label');
            // loop through label array attempting to match each 'for' attribute to the id of the current element
            for(var lbl = 0; lbl < labelList.length; lbl++) {
               // Internet Explorer requires the htmlFor test
               if(labelList[lbl]['htmlFor'] && labelList[lbl]['htmlFor'] == self.rules[which].element.id) {
                  label = labelList[lbl];
               // All other compliant browsers
               } else if(labelList[lbl].getAttribute('for') == self.rules[which].element.id) {
                  label = labelList[lbl];
               }
            }
         }
      }
   
      if(self.rules[which].valid == false) {
         var classout;
         var classin;
         if(!self.validateAsErr || !self.rules[which].required) {
            classout = self.invalidClass;
            classin  = self.warningClass;
         } else {
            classout = self.warningClass;
            classin  = self.invalidClass;
         }
         self.rules[which].element.className = self.rules[which].element.className.replace(classout, "");
         if(self.rules[which].element.className.search(classin) == -1) { self.rules[which].element.className += " " + classin; }
         
         if(self.styleLabelOnErr && label != null) {
            label.className = label.className.replace(classout, "");
            if(label.className.search(classin) == -1) label.className += " " + classin;
         }
      } else {
         self.rules[which].element.className = self.rules[which].element.className.replace(self.invalidClass, "");
         self.rules[which].element.className = self.rules[which].element.className.replace(self.warningClass, "");
         if(self.styleLabelOnErr && label != null) {
            label.className = label.className.replace(self.invalidClass, "");
            label.className = label.className.replace(self.warningClass, "");
         }
      }
   }
   this.validateRegEx = function(which) {
      var isValidated = false;
      if (self.rules[which].element.type.toUpperCase()=='CHECKBOX'){
      	  if(!self.rules[which].required){
	      isValidated = true
	  }
	  else{
	      isValidated = self.rules[which].element.checked	  
          }
      }
      else{
	  var missatgeTmp="";
          isValidated = !(self.rules[which].element.value.search(self.rules[which].regex) == -1);
	  if (self.ensenyarMissatge && isValidated==false && self.rules[which].element.value.trim() != ''){
		missatgeTmp=self.rules[which].missatgeFormat;
		}
         // Validate if empty and not a required field
         if(!self.rules[which].required && self.rules[which].element.value.trim() == '') isValidated = true;
         if (self.rules[which].required && self.rules[which].element.value.trim() == ''){
	    missatgeTmp=self.rules[which].missatgeRequerit;
	    }
	  if (missatgesError.indexOf(missatgeTmp)==-1)
		  missatgesError+=missatgeTmp;
          }
      return isValidated;
   }
   this.validateSingleRule = function(which) {
      // If the element is part of a group, it must be checked together with the other elements of the same group
      if ((self.rules[which].group != '') && (self.rules[which].group != '.')) {
         var groupIsEmpty = self.isInEmptyGroup(which);
         var i=0;
         while(i<self.rules.length) {
            if (self.rules[i].group == self.rules[which].group) {
               // If all the elements in the group are empty, mark as invalid, otherwise validate as normally
               self.rules[i].valid = (groupIsEmpty)?false:self.validateRegEx(i);
		self.styleFields(i);
            }
            i++;
         }
      }
      else {
         // Check if the element value must be the same as some other element
         if ((self.rules[which].equal != '') && (self.rules[which].equal != '.')) {
            var elemsDiffer = self.valuesDiffer(self.rules[which].element_id, self.rules[which].equal);
            var i=0;
            var i1 = 0;
            var i2 = 0;
            while (i<self.rules.length) {
               if (self.rules[which].element_id == self.rules[i].element_id)  i1 = i;  // current element
               if (self.rules[which].equal == self.rules[i].element_id)       i2 = i;  // element to compare
               i++;
            }
	    var missatgeTmp='';
	    if (elemsDiffer){
		missatgeTmp=self.rules[i2].missatgeRepetit;
		}
//	    if (missatgesError.indexOf(self.rules[i2].missatgeRepetit)==-1 && missatgesError.indexOf(self.rules[i2].missatgeFormat)==-1 && missatgesError.indexOf(self.rules[i2].missatgeRequerit)==-1 && missatgesError.indexOf(self.rules[i1].missatgeFormat)==-1 && missatgesError.indexOf(self.rules[i1].missatgeRequerit)==-1){
		    if (self.validateRegEx(i1)){
			self.rules[i1].valid = true;
			}
		    if (self.validateRegEx(i2)){
			if (elemsDiffer==true){
				missatgesError+=missatgeTmp;
				self.rules[i1].valid = false;
				self.rules[i2].valid = false;
				}
			else{
				self.rules[i2].valid = true;
				}
			}
		    else{
			self.rules[i2].valid = false;
			}
//		}
//            self.rules[i2].valid = (elemsDiffer)?false:self.validateRegEx(i2);
            self.styleFields(i1);
            self.styleFields(i2);
         }
         else {
            // Otherwise proceed normally
            self.rules[which].valid = self.validateRegEx(which);
         }
      }

      // Call the user defined validation routine
      self.extendedValidateSingleRule(self.rules[which].element_id, which);
      // Style the input and label
      self.styleFields(which);
      // Carry out any post validation processing
      self.postSingleRuleValidation(self.rules[which].element_id, which);
   }
   // event handler for individual input fields (activated onblur/onchange)
   this.validateSingle = function(e) {

      var i = 0;
      while(i<self.rules.length) {
         if(this.id == self.rules[i].element.id) {
            self.validateSingleRule(i,'');
         }
         i++;
      }
      
      return true;
   }
   // event handler for the submit button
   this.validateAll = function(e) {
      self.validateAsErr = true;
      missatgesError="";
      for(var i = 0; i < self.rules.length; i++) {
	 self.ensenyarMissatge  = true;
         self.validateSingleRule(i);
      }
      self.ensenyarMissatge  = false;
      self.postSubmitValidation();
      var correcte=false;
      if (self.extendedValidate() && self.isValid()) correcte=true;
      if (correcte==false && missatgesError!="") popUp(urlFinestra);
//alert(self.extendedValidate()+'   '+self.isValid()+'   '+(self.extendedValidate() && self.isValid()))
      return correcte;
   }
   this.valuesDiffer = function(e1,e2){
      var v1 = document.getElementById(e1).value;
      var v2 = document.getElementById(e2).value;
      return (v1!=v2);
   }
   // chech if the element is in a group where no elements has a value defined
   this.isInEmptyGroup = function(which) {
      var g=self.rules[which].group;
      var allEmpty=true;
      var i=0;
      var ig=0;
      while(i<self.rules.length) {
         if (self.rules[i].group == g) {
            ig++;
            if (self.rules[i].element.type.toUpperCase() == 'CHECKBOX'){
		if (self.rules[i].element.checked==true) allEmpty=false;
		}
  	   else {
		if (self.rules[i].element.value.trim() != '') allEmpty=false;
		}
         }
         i++;
      }
	//alert(allEmpty);
      // If the element is the only one in the group, the condition is not verified
      if (ig<=1) allEmpty=false;
      return allEmpty;
   }

   // Are all (required) form elements valid
   this.isValid = function() {
         var valid = true;
         for(var i = 0; i < self.rules.length; i++) {
            //if(!self.rules[i].valid && self.rules[i].required) { valid = false; }
            if(!self.rules[i].valid) { valid = false; }
         }
         return valid;
   }
   
   // Create private variable 'self'
   var self = this;
   
   // Attach onsubmit event handler to the form
   document.getElementById(this.formid).onsubmit = self.validateAll;
   
   return this;
}

formValidator.prototype.extreureMisstage = function(cadenaArguments,posicio,missatge){
	//alert('Trobo posicio missatge: '+cadenaArguments.indexOf('\"',posicio+missatge.length+2)+'   '+cadenaArguments)
	return cadenaArguments.substring(posicio+missatge.length+2,cadenaArguments.indexOf('%',posicio+missatge.length+2));
	}

formValidator.prototype.addRule = function(element, regex, useblur, required, group, equal,missatgeRequerit,missatgeFormat,missatgeRepetit) {
   var obj = new Object();
   obj.element = element;
   obj.element_id = element.id;

   // Use onchange or onblur, it's up to you..
   if (obj.element.type.toUpperCase() != 'CHECKBOX'){
	if(useblur) obj.element.onblur   = this.validateSingle;
	else        obj.element.onchange = this.validateSingle;
	}

   // Is this a required form field?
   obj.required = required;
   obj.group    = group;
   obj.equal    = equal;
   obj.regex    = regex.trim();
   obj.valid    = false;
   obj.missatgeRequerit = (missatgeRequerit!='')?"<li>"+missatgeRequerit+"</li>":"";
   obj.missatgeFormat = (missatgeFormat!='')?"<li>"+missatgeFormat+"</li>":"";
   obj.missatgeRepetit = (missatgeRepetit!='')?"<li>"+missatgeRepetit+"</li>":"";
   this.rules.push(obj);
}

formValidator.prototype.buscarRulesValidator = function(id){
		//DEBUG:alert('entro: '+this.rules.length+'  '+this.formid)
		for (var i=0;i<this.rules.length;i++){
			//DEBUG:alert(i+'   '+this.rules[i].element_id+'   '+id)
			if (this.rules[i].element_id==id){
				return i;
				}
			}
		return false;
		}

formValidator.prototype.posarInvalidCamp = function(numRule) { 
	var requerit=this.rules[numRule].required;
	this.rules[numRule].valid=false;
	this.rules[numRule].required=true;
	this.styleFields(numRule);
	this.rules[numRule].required=requerit;
	}

formValidator.prototype.posarMissatgeMunicipi = function (numRule,numRuleCodiPostal){
	var missatgeFinsCPRequiered=missatgesError.substring(0,missatgesError.indexOf(this.rules[numRuleCodiPostal].missatgeRequerit));
	missatgeFinsCPRequiered+=missatgesError.substring(missatgeFinsCPRequiered.length,missatgeFinsCPRequiered.length+this.rules[numRuleCodiPostal].missatgeRequerit.length);
	var missatgeDespresCPRequired=missatgesError.substring(missatgeFinsCPRequiered.length,missatgesError.length);
	missatgesError=missatgeFinsCPRequiered+this.rules[numRule].missatgeFormat+missatgeDespresCPRequired;
	}

formValidator.prototype.comprovaCodiPostal = function (codiPoblacio,codiPostal){
	var j=0;
	for (j=0;j<myCPc.length;j++){
		if (codiPoblacio==myCPc[j].codiMunicipi){
			if (myCPc[j].codiPostal.length==1){
				if (codiPostal==myCPc[j].codiPostal[0]) return true;
				return false;
				}
			else {
				for (var i=0;i<myCPc[j].codiPostal.length;i++){
					if (codiPostal==myCPc[j].codiPostal[i]) return true;
					}
				return false;
				}
			}
		}
		return false;
	}

// Override the following prototypes on a page by page basis if needs be
formValidator.prototype.extendedInitialisation = function() { }

formValidator.prototype.extendedValidate = function() {
	var valor=true;
	if (this.localitat){
		var formu=document.getElementById(this.formid);
		if (formu.localitat.value!=""){
			if ((formu.localitat.value.indexOf("Municipi")==-1)&&(formu.localitat.value.indexOf("Comarca")==-1)&&(formu.localitat.value.indexOf("Provincia")==-1)){
				var index=0;
				index=buscarCodi(myP,formu.localitat.value,false);
				alert(myP.length+' != '+index)
				if (myP.length!=index){
					formu.cod_muni.value=myP[index].id;
					formu.cod_prov.value=myP[index].pro;
					formu.cod_com.value=myP[index].com;
					}
				else{
					index=buscarCodi(myV,formu.localitat.value,false);
					if (myC.length!=index){
						formu.cod_prov.value=myC[index].pro;
						formu.cod_com.value=myC[index].id;
						formu.cod_muni.value="";
						}
					else{
						index=buscarCodi(myV,formu.localitat.value,false);
						if (myV.length!=index){
							formu.cod_prov.value=myV[index].id;
							formu.cod_muni.value="";
							formu.cod_com.value="";						
							}
						}
					}
				}
			else{
				if (formu.localitat.value.indexOf("Municipi")!=-1){
					valor=formu.localitat.value.replace(" (Municipi)","")
					var index=0;
					index=buscarCodi(myP,valor,false);
					if (myP.length!=index){
						formu.cod_muni.value=myP[index].id;
						formu.cod_prov.value=myP[index].pro;
						formu.cod_com.value=myP[index].com;
						}
					}
				else if (formu.localitat.value.indexOf("Comarca")!=-1){
					valor=formu.localitat.value.replace(" (Comarca)","")
					var index=0;
					index=buscarCodi(myC,valor,false);
					if (myC.length!=index){
						formu.cod_prov.value=myC[index].pro;
						formu.cod_com.value=myC[index].id;
						formu.cod_muni.value="";
						}
					}
				else if (formu.localitat.value.indexOf("Provincia")!=-1){
					valor=formu.localitat.value.replace(" (Provincia)","")
					var index=0;
					index=buscarCodi(myV,valor,false);
					if (myV.length!=index){
						formu.cod_prov.value=myV[index].id;
						formu.cod_muni.value="";
						formu.cod_com.value="";						
						}
					}
				}
		}
		if (formu.localitat.value==""){
			formu.cod_prov.value="";
		 	formu.cod_com.value="";
		 	formu.cod_muni.value="";
			}
		}
		if (typeof objAutocompleter!="undefined"){
			if (objAutocompleter.element.value!=""){
				var municipiCorrecte=buscarCodi(myP,objAutocompleter.element.value,true);
				if (myP.length!=municipiCorrecte){
					if (document.getElementById(objAutocompleter.options.codiPostal).value=="") {
						objAutocompleter.buscarCodiPostal(myP[municipiCorrecte].id,objAutocompleter.options.codiPostal);		
						if (document.getElementById(objAutocompleter.options.codiPostal).type!="INPUT") return false;
						}
					else{
						municipiCorrecte=this.comprovaCodiPostal(myP[municipiCorrecte].id,document.getElementById(objAutocompleter.options.codiPostal).value);
						}
					if (!municipiCorrecte){
						numRule=objAutocompleter.buscarRulesValidator(objAutocompleter.element.id,this);
						this.posarInvalidCamp(numRule);
						numRule=objAutocompleter.buscarRulesValidator(objAutocompleter.options.codiPostal,this);
						this.posarInvalidCamp(numRule);
						valor=false;
						}
					else {
						valor=true;
						}
					}
				else    {
					numRule=objAutocompleter.buscarRulesValidator(objAutocompleter.element.id,this);
					numRuleCP=objAutocompleter.buscarRulesValidator(objAutocompleter.options.codiPostal,this);
					this.posarInvalidCamp(numRule);
					this.posarMissatgeMunicipi(numRule,numRuleCP);
					if (document.getElementById(objAutocompleter.options.codiPostal).type!="INPUT") {
						objAutocompleter.posarInput("",objAutocompleter.options.codiPostal);
						}
					this.posarInvalidCamp(numRuleCP);
					valor=false;					
					}
				}
			}
	return valor;
}

formValidator.prototype.extendedValidateSingleRule = function(id, rule) {
	if(typeof(postValidacio)=='function'){
		postValidacio(id, rule,this.rules);
	}
}

formValidator.prototype.postSubmitValidation = function() { 
	
}
formValidator.prototype.postSingleRuleValidation = function() { 
	
}

formValidator.validatorCollection = new Array();

function initiateFormValidation() {
   // Bail out if the browser can't handle the script
   if(!document.getElementById  || !document.getElementsByTagName) return;

   var validator;
   var formCollection = document.getElementsByTagName('form');
   
   // Iterate over the forms
   for(var i = 0; i < formCollection.length; i++) {
      // If the current form has an assigned id
      if(typeof formCollection[i].id != 'undefined' && formCollection[i].id != "") {
         // Create new validator object
         validator = new formValidator(formCollection[i].id);

         // Initialise the rule parsing
         validator.init();
         formValidator.validatorCollection.push(validator);
      }
   }

  if (document.getElementById("formOTG") || document.getElementById("formFitxes") || document.getElementById("formOtgsHome") || document.getElementById("formCentresFormacio") || document.getElementById("formOfertesOcupRapid") || document.getElementById("formOfertesOcup") || document.getElementById("formFormacio")) controlaFocus();
  cargado=true;
}

// Helper function: Retuns the validator object corresponding to the form id
function getValidatorObject(formid) {
   for(i = 0; i < formValidator.validatorCollection.length; i++) {
      if(formValidator.validatorCollection[i].formid == formid) {
         return formValidator.validatorCollection[i];
      }
   }
   return null;
}

function controlaFocus(){

	// funcio IoS
	// aquesta funcio ha d'existir (implementada a la pagina a importada des de una altre js)
	// d'aquesta forma treiem la complexitat del validator.js
	if(typeof(controlFocusPagina)=='function'){
		controlFocusPagina();
	}

	if (document.getElementById("formOTG") || document.getElementById("formOtgsHome") || document.getElementById("formCentresFormacio")) {
		if (document.getElementById('cpostal') && (document.getElementById('localitat') || document.getElementById('localitat_ofe'))) {			
			objCp = document.getElementById('cpostal');
			objMun = document.getElementById('localitat') || document.getElementById('localitat_ofe');
			objCp.onkeyup= function() { if ((objCp.value!='') && (objMun.value!='')) objMun.value=''; }
			objMun.onkeyup= function() { if ((objCp.value!='') && (objMun.value!='')) objCp.value=''; }
		}
	}
	
	if (document.getElementById("formFitxes")) {
		if (document.getElementById('palabra') && document.getElementById('codiSectorAct')) {
			objPal = document.getElementById('palabra');
			objCsa = document.getElementById('codiSectorAct');
			objPal.onkeyup= function() { if ((objPal.value!='') && (objCsa.value!='')) objCsa.value=''; }
			objPal.onchange= function() { if ((objPal.value!='') && (objCsa.value!='')) objCsa.value=''; }
			objCsa.onchange= function() { if ((objPal.value!='') && (objCsa.value!='')) objPal.value=''; }
		}
	}
	
	if (document.getElementById("formOfertesHome")) {
		if (document.getElementById('palabra') && document.getElementById('localitat_ofe') && document.getElementById('identificador_oferta')) {
			objPal = document.getElementById('palabra');
			objLoc = document.getElementById('localitat_ofe');
			objOfId = document.getElementById('identificador_oferta');
			
			objPal.onkeyup= function() { if ((objPal.value!='') || (objLoc.value!='')) objOfId.value=''; }
			objPal.onchange= function() { if ((objPal.value!='') || (objLoc.value!='')) objOfId.value=''; }

			objLoc.onkeyup= function() { if ((objPal.value!='') || (objLoc.value!='')) objOfId.value=''; }
			objLoc.onchange= function() { if ((objPal.value!='') || (objLoc.value!='')) objOfId.value=''; }

			objOfId.onkeyup= function() { if ((objOfId.value!='')){ objPal.value=''; objLoc.value='';}}
			objOfId.onchange= function() { if ((objOfId.value!='')){ objPal.value=''; objLoc.value='';}}
		}
	}
	
	if (document.getElementById("formOfertesOcupRapid")) {
		if (document.getElementById('identificador_oferta')) {

			objOfId = document.getElementById('identificador_oferta');
			objCodSec = document.getElementById('cod_sector');
			objCodOcu = document.getElementById('cod_ocupacio');
			objLoc = document.getElementById('localitat');
			
			if(objOfId!=null && objCodSec!=null && objCodOcu!=null && objLoc!=null){
				
				
				objOfId.onkeyup= function() { 
					if ((objOfId.value!='')){
						 objCodSec.selectedIndex=0;
						 objCodOcu.selectedIndex=0;
						 objLoc.value='';
					}
				}

				objOfId.onchange= function() { 
					if ((objOfId.value!='')){
						 objCodSec.selectedIndex=0;
						 objCodOcu.selectedIndex=0;
						 objLoc.value='';
					}
				}

				
				objCodSec.onchange=function(){
					objOfId.value='';
				}
				
				objCodOcu.onchange=function(){
					objOfId.value='';
				}	
				
				objLoc.onkeyup=function(){ 
					if ((objLoc.value!='')){ 
						objOfId.value=''; 
					}
				}
				objLoc.onchange=function(){ 
					if ((objLoc.value!='')){ 
						objOfId.value=''; 
					}
				}

			}
		}
	}
	
	if (document.getElementById("formOfertesOcup")) {
		if (document.getElementById('identificador_oferta')) {
			
			objOfId = document.getElementById('identificador_oferta');
			objPal = document.getElementById('palabra');
			objCodJor = document.getElementById('cod_jornada');
			objLoc = document.getElementById('localitat');
			objIdEx = document.getElementById('id_experiencia');
			objflgEtt = document.getElementById('flag_ett');
			objCodSec = document.getElementById('cod_sector');
			objDis = document.getElementById('discapacitats');
			objflgAv = document.getElementById('flag_avui');
			
			if(objOfId!=null && objPal!=null && objCodJor!=null && objLoc!=null && objIdEx!=null && objflgEtt!=null && objCodSec!=null && objDis!=null && objflgAv!=null){
				
				objOfId.onkeyup= function() { 
					if ((objOfId.value!='')){
						 objPal.value='';
						 objCodJor.selectedIndex=0;
						 objLoc.value='';
						 objIdEx.selectedIndex=0;
						 objflgEtt.selectedIndex=0;
						 objCodSec.selectedIndex=0;
						 objDis.checked=false;
						 objflgAv.checked=false;
					}
				}

				objOfId.onchange= function() { 
					if ((objOfId.value!='')){
						 objPal.value='';
						 objCodJor.selectedIndex=0;
						 objLoc.value='';
						 objIdEx.selectedIndex=0;
						 objflgEtt.selectedIndex=0;
						 objCodSec.selectedIndex=0;
						 objDis.checked=false;
						 objflgAv.checked=false;
					}
				}
				
				objPal.onkeyup=function(){ 
					if ((objPal.value!='')){ 
						objOfId.value=''; 
					}
				}

				objPal.onchange=function(){ 
					if ((objPal.value!='')){ 
						objOfId.value=''; 
					}
				}

				
				objCodJor.onchange=function(){
					objOfId.value='';
				}
				
				objLoc.onkeyup=function(){ 
					if ((objLoc.value!='')){ 
						objOfId.value=''; 
					}
				}

				objLoc.onchange=function(){ 
					if ((objLoc.value!='')){ 
						objOfId.value=''; 
					}
				}
				
				objIdEx.onchange=function(){
					objOfId.value='';
				}
				
				objflgEtt.onchange=function(){
					objOfId.value='';
				}
				
				objCodSec.onchange=function(){
					objOfId.value='';
				}
				
				objDis.onclick=function(){
					objOfId.value='';
				}
				
				objflgAv.onclick=function(){
					objOfId.value='';
				}
			}
		}
		
	}
}
