function JSObj_show_form()
{
	this.posId = 1;
	this.compId = 1;
	this.lngId = 'es';
	this.contentTypeId = 0;
	this.varName = '';
	this.uploadingFilesIds = new Array();
	this.uploadingFileDone = new Array();
	this.relationshipContentId;
	this.useEvent = "cms_content_save_form";
	this.to = '';
	this.controlUpload = false;
	this.controlUploadLength = 81920; //sromero tamaño máximo de control de subida de archivo (por defecto 80Mb)
	this.videoField;
	this.heightFrame;
	this.newRelations = false;
	this.subject = '';
	
	this.time_to_save = 0;
	
	// sbadal 25.10.2007 añadimos esta linea
	this.FormValidator = new WBEFormValidator();

	this.getParams = function (oAjax) {
		var asParams = new Array();
		var oIdsElem = eval('document.WBForm.att_ids_' + this.posId);
		var sId;
		var tempElem;
		
		oAjax.clear();

		if (oIdsElem.length) {
			for (var i = 0; i < oIdsElem.length; i++) {
				sId = oIdsElem[i].value;
				oAjax.addPostParameter('att_input_' + sId, this.getValue(sId));
			}
		} else {
			var aIdsElem = oIdsElem.value.split(',');
			for (var i = 0; i < aIdsElem.length; i++) {
				sId = aIdsElem[i];
				oAjax.addPostParameter('att_input_' + sId, this.getValue(sId));
			}
			//sId = oIdsElem.value;
			//oAjax.addPostParameter('att_input_' + sId, this.getValue(sId));
		}
		oAjax.addPostParameter('att_ids', oIdsElem.value);
		oAjax.addPostParameter('content_ct_id', this.contentTypeId);
		oAjax.addPostParameter('lng_id', this.lngId);
		oAjax.addPostParameter('pos_id', this.posId);
		oAjax.addPostParameter('comp_id', this.compId);
		
		// Categorías, si las hay las coge del constructor de formularios
		var oFormBuilder = new InmediaFormBuilder(this.posId);
		var sValues;
		sValues = '';
		sValues = oFormBuilder.getFieldMultipleValues("category_" + this.posId);
		oAjax.addPostParameter("category_ids", sValues);

		// Establece los contenidos padre
		this.setContentParents(oFormBuilder, oAjax);
		
		// El destino del correo, si lo hemos especificado
		if (this.to != '') {
			oAjax.addPostParameter('__msg_system_input_to', this.to);
		}
		//dgrande
		if (this.subject != '') {
			oAjax.addPostParameter('__msg_system_input_subject', this.subject);
		}		
		
		// El valor del CAPTCHA, si está
		var oElemCaptcha = eval('document.WBForm.txt_captcha_' + this.posId);
		if (oElemCaptcha) oAjax.addPostParameter('captcha', oElemCaptcha.value);
		
		var tags = this.getValue('tag');		
		oAjax.addPostParameter('__tag__', tags);		
	};
	
	// Contenidos Padre, si los hay
	this.setContentParents = function(oFormBuilder, oAjax) {
		//var oFormRelation = eval('document.WBForm.cnt_parent_relship_' + this.posId);
		var sField = (this.newRelations) ? 'relation_ids' : 'cnt_parent_relship' ;
		if (this.relationshipContentId && this.relationshipContentId!='')
			oAjax.addPostParameter(sField, this.relationshipContentId);

		//var sValue = this.getValue('cnt_parent_relship', false);
		var sValues = oFormBuilder.getFieldMultipleValues("content_parent_" + this.posId);
		if (sValues!=null && sValues!='') oAjax.addPostParameter(sField, sValues);
	}

	// Recupera los valores	
	this.getValue = function (sElemId) {
		var oElem = eval('document.forms[0].att_input_' + sElemId + '_' + this.posId);
   		var sValue = '';
   		if (oElem==null) return '';
		if (oElem.length) { // n campos con el mismo nombre o un select
			for (var i = 0; i < oElem.length; i++) {
				if (oElem[i].checked) {
					if (sValue != '') sValue += ',';
					sValue += oElem[i].value;
				} else {
					if (oElem[i].selected) {
						if (sValue != '') sValue += ',';
						sValue += oElem[i].value;
					}
				}
			}
		} else {  // un solo campo
        if (oElem.type == "checkbox" || oElem.type == "radio") sValue = (oElem.checked) ? oElem.value : "";
				else sValue = oElem.value;
		}
		return sValue;

	};

	// Guarda el formulario
	this.save = function() {

	    this.uploadFiles();

	    if (this.isAllUploaded()) {

	        //	 sromero 14-11-2007. Selecion de tipo de idioma en las alertas
	        this.FormValidator.sLng = this.lngId;
	        if (!this.FormValidator.validateForm(document.WBForm, this.posId) || !this.checkCaptcha()) return false;


	        this.savePre();

	        setTimeout(this.varName + ".do_save();", this.time_to_save);

	    } else {
	        setTimeout(this.varName + '.save();', 1000);
	    }
	};

    // Lanza el evento!
	this.do_save = function() {
	    var oAjax = new WBE_AjaxClass();
	    
	    this.getParams(oAjax);
	    this.addParameters(oAjax);
	    
	    xmlObj = oAjax.throwEventXML(this.useEvent);

	    this.savePost(xmlObj);
    }
	

	// Acciones antes de llamar al evento
	this.savePre = function() {
		if (document.getElementById('form_loading_' + this.posId)) {
			window.scroll(0, this.getOffsetTop('form_loading_' + this.posId));
			document.getElementById('form_loading_' + this.posId).style.display = '';
			document.getElementById('form_' + this.posId).style.display = 'none';
			document.getElementById('form_ok_' + this.posId).style.display = 'none';
		}
    }

    // Acciones antes de llamar al evento
    this.addParameters = function(oAjax) {  }
	
	this.getOffsetTop = function(elemId) {
		var elem = document.getElementById(elemId);
		if (elem==null) return 0;
		var ot = (elem.offsetTop != null) ? elem.offsetTop : 0 ;
		while ( ( elem = elem.offsetParent ) != null ) {
			ot += elem.offsetTop;
		}
		return ot;
	}

	// Acciones a realizar después de guardar
	this.savePost = function(xmlObj) { 
		window.scroll(0, this.getOffsetTop('form_ok_' + this.posId));
		if (document.getElementById('form_loading_' + this.posId)) document.getElementById('form_loading_' + this.posId).style.display = 'none';
		document.getElementById('form_' + this.posId).style.display = 'none';
		document.getElementById('form_ok_' + this.posId).style.display = '';
	}

	// Guarda y redirige
	this.saveAndGo = function(url, req_var) {
		window.scroll(0, this.getOffsetTop('form_' + this.posId));
			
		this.uploadFiles();
		if (this.isAllUploaded()) {
	
			var oAjax = new WBE_AjaxClass();
			this.getParams(oAjax);

			//	 sromero 14-11-2007. Selecion de tipo de idioma en las alertas
			this.FormValidator.sLng=this.lngId;

			// sbadal 25.10.2007
			//var oValidator = new WBEFormValidator();
			if(!this.FormValidator.validateForm(document.WBForm, this.posId) || !this.checkCaptcha()) return false;
			
			this.saveAndGoPre();
			xmlObj = oAjax.throwEventXML(this.useEvent);
			this.saveAndGoPost(xmlObj, url, req_var);
			
		} else {
			setTimeout(this.varName + '.saveAndGo("' + url + '", "' + req_var + '");', 1000);
		}
	}; 

	// Acciones antes de llamar al evento
	this.saveAndGoPre = function() {
		if (document.getElementById('form_loading_' + this.posId)) {
			window.scroll(0, this.getOffsetTop('form_loading_' + this.posId));
			document.getElementById('form_loading_' + this.posId).style.display = '';
			document.getElementById('form_' + this.posId).style.display = 'none';
		}
	}

	// Acciones a realizar después de guardar y redirigir
	this.saveAndGoPost = function(xmlObj, url, req_var) {
		if (req_var) {
			var oAjax = new WBE_AjaxClass();
			var iContentID = oAjax.getXMLNodeValue(xmlObj, "id");
			document.location.href = url + '?' +  req_var + '=' + iContentID;
		} else {
			document.location.href = url;
		}
	}

	this.saveAndExecute = function(func_name) {
		window.scroll(0, this.getOffsetTop('form_' + this.posId));
		this.uploadFiles();
	
		if (this.isAllUploaded()) {
	
			var oAjax = new WBE_AjaxClass();
			this.getParams(oAjax);

			this.FormValidator.sLng=this.lngId;
			
			// sbadal 25.10.2007
			//var oValidator = new WBEFormValidator();
			if(!this.FormValidator.validateForm(document.WBForm, this.posId) || !this.checkCaptcha())return false;

			xmlObj = oAjax.throwEventXML(this.useEvent);
			
			eval(func_name);
		} else {
			setTimeout(this.varName + '.saveAndExecute("' + func_name + '");', 1000);
		}
	}; 

	this.saveSubscription = function(sSalePrice, sParams) {
	
		window.scroll(0, this.getOffsetTop('form_' + this.posId));
		this.uploadFiles();
	
		if (this.isAllUploaded()) {
	
			var oAjax = new WBE_AjaxClass();
			this.getParams(oAjax);
			
			oAjax.addPostParameter('sale_price', sSalePrice);

			//	 sromero 14-11-2007. Selecion de tipo de idioma en las alertas
			this.FormValidator.sLng=this.lngId;
			
			// sbadal 25.10.2007
			//var oValidator = new WBEFormValidator();
			if(!this.FormValidator.validateForm(document.WBForm, this.posId) || !this.checkCaptcha())return false;

			xmlObj = oAjax.throwEventXML(this.useEvent);
			this.saveSubscriptionPost(xmlObj, sParams);

/*			document.getElementById('form_' + this.posId).style.display = 'none';
			document.getElementById('form_ok_' + this.posId).style.display = '';*/
		} else {
			setTimeout(this.varName + '.saveSubscription(' + sSalePrice + ');', 1000);
		}
	}; 
	
	// tarea después de suscripción
	this.saveSubscriptionPost = function(xmlObj, sParams) {
	    if (!xmlObj) return;
	    var oAjax = new WBE_AjaxClass();
	    var sUrl = oAjax.getXMLNodeValue(xmlObj, 'tpv_url');
	    //alert(sUrl);
	    if (sParams) {
	        if (sUrl.indexOf('?') > 1) sUrl += '&' + sParams;
	        else sUrl += '?' + sParams;
	    }
	    document.location.href = sUrl;
	}
			
	this.isAllUploaded = function () {
		var bOK = true;
		//alert('isAllUploaded: ' + this.uploadingFileDone.length);
		for (var i = 0; i < this.uploadingFileDone.length; i++) {
			//alert(i + ' - ' + bOK + ' - ' + this.uploadingFileDone[i]);
			bOK = bOK && this.uploadingFileDone[i]; 
		}
		return bOK;
	}
	
	this.uploadFiles = function () {
		var elem = eval('document.WBForm.file_atts_' + this.posId);
		if (elem) {
			if (elem.value) {
				this.uploadFile(elem.value);
			} else {
				for (var i = 0; i < elem.length; i++) {
					this.uploadFile(elem[i].value);
				}
			}
		}
	};
	
	this.pause = function (millis) {
		var date = new Date();
		var curDate = null;
		do { 
			curDate = new Date(); 
		} while(curDate - date < millis);
	};
	
	this.uploadFile = function (att_id) {
		var bIsUploading = false;
		for (var i = 0; i < this.uploadingFilesIds.length; i++) {
			if (this.uploadingFilesIds[i] == att_id) {
				bIsUploading = true;
				break;
			}
		}
		if (!bIsUploading) {
			var iframe_doc = this.getIFrameDocument('iframe_' + att_id + '_' + this.posId);
			this.uploadingFilesIds[this.uploadingFilesIds.length] = att_id;
			this.uploadingFileDone[this.uploadingFileDone.length] = false;
			//var elem = this.getFileElem(iframe_doc.WBForm);
			//alert(elem.value);
			iframe_doc.WBForm.submit();
		}
	};

	this.getFileElem = function (oForm) {
		for (var i = 0; i < oForm.elements.length; i++) {
			if (oForm.elements[i].type == 'file') {
				return oForm.elements[i].type;
			}
		}
	};

	this.getIFrameDocument = function (aID) {
	  // if contentDocument exists, W3C compliant (Mozilla)
	  if (document.getElementById(aID).contentDocument){
			return document.getElementById(aID).contentDocument;
	  } else {
			// IE
			return document.frames[aID].document;
	  }
	};
	
	this.fileUploaded = function (att_id, file_name) {
		eval('document.WBForm.att_input_' + att_id + '_' + this.posId).value = file_name;
		this.uploadingFileDone[this.getArrayAttIndex(att_id)] = true;
	};
	
	this.getArrayAttIndex = function (att_id) {
		for (var i = 0; i < this.uploadingFilesIds.length; i++) {
			if (this.uploadingFilesIds[i] == att_id) {
				return i;
			}
		}
	};
	
	this.increaseFieldSize = function (sId, mode) {
		if (mode=="html") {
			var oFrame = document.getElementById(sId + "___Frame");
			oFrame.height = parseInt(oFrame.height) + 50; 
		} else {
			var elem = eval('document.forms[0].' + sId);
			elem.rows += 5;
		}
	};

	this.decreaseFieldSize = function (sId, mode) {
		if (mode=="html") {
			var oFrame = document.getElementById(sId + "___Frame");
			var i = parseInt(oFrame.height);
			if (i>100) oFrame.height = i - 50; 
		} else {
			var elem = eval('document.forms[0].' + sId);
			if (elem.rows>5) elem.rows -= 5;
		}
	};
	
	this.showFileUpload = function (sAttId) {
		document.getElementById('file_upload_' + sAttId + '_' + this.posId).style.display = '';
		if (document.getElementById('file_upload_msg_' + sAttId + '_' + this.posId)) {
			document.getElementById('file_upload_msg_' + sAttId + '_' + this.posId).style.display = '';
		}
		document.getElementById('file_upload_' + sAttId + '_' + this.posId).height=30;
	};
	
	this.controlFileUpload = function (sAttId) {	
		this.heightFrame = document.getElementById('file_upload_' + sAttId + '_' + this.posId).height;
		if (document.getElementById('upload_loading_' + sAttId + '_' + this.posId)) {
			document.getElementById('file_upload_' + sAttId + '_' + this.posId).height='0';
			document.getElementById('upload_loading_' + sAttId + '_' + this.posId).style.display = '';
		}
		if (this.controlUpload) {
			window.open('ADMIN_PAGE.wbe?cmp_code=CMS_FILE_UPLOAD_CONTROL&guid='+sAttId+'&pObj='+this.varName,'','toolbar=0,scrollbars=0,location=0,status=0,menubar=0,resizable=0,height=170,width=320,top=70,left=100');
		}
	};
	
	this.hideFileTypeUpload = function (sAttId, sImgName) {
		document.getElementById('file_upload_' + sAttId + '_' + this.posId).height='0';
		
		if (document.getElementById('upload_link_' + sAttId + '_' + this.posId)) {
			document.getElementById('upload_link_' + sAttId + '_' + this.posId).style.display = 'none';
		}
		if (document.getElementById('file_upload_msg_' + sAttId + '_' + this.posId)) {
			document.getElementById('file_upload_msg_' + sAttId + '_' + this.posId).style.display = 'none';
		}
		if (document.getElementById('upload_loading_' + sAttId + '_' + this.posId)) {
		document.getElementById('upload_loading_' + sAttId + '_' + this.posId).style.display = 'none';
		}
		document.getElementById('file_show_' + sAttId + '_' + this.posId).style.display = '';
		document.getElementById('file_' + sAttId + '_' + this.posId).href = 'resources/image/' + sImgName;
		eval('document.forms[0].att_input_' + sAttId + '_' + this.posId).value = sImgName;
		
	};
	
	// Elemento del formulario modificado, hace comprobaciones del valor.
	this.itemModified = function (elem, att_id, editorType) {
		//this.HasModifications = true;
		var bReturn = true;
		if (elem==null || att_id==null || editorType==null) return;
		if (editorType == 'TEXT_UNIQUE_VALUES') {
			bReturn = this.checkFieldValue(elem, att_id);
		}
		return bReturn;
	};

	// Comprueba el valor Ãºnico de un atributo.
	this.checkFieldValue = function (elem, att_id) {
		var oAjax = new WBE_AjaxClass();
		oAjax.clear();
		oAjax.addPostParameter("ct_id", this.contentTypeId);
		oAjax.addPostParameter("cv_id", this.contentId);
		oAjax.addPostParameter("att_id", att_id);
		oAjax.addPostParameter("value", elem.value);
		var xmlObj = oAjax.throwEventXML("count_version_by_att_value");
		if (xmlObj){
			var iCount = oAjax.getXMLNodeValue(xmlObj, 'c');
			if (iCount!=0) {
				alert('Existe un contenido con este valor');
				elem.select();
				elem.focus();
				return false;
			}
		}
		return true;
	}
	
	this.hideImgUpload = function (sAttId, sImgName) {
		//document.getElementById('file_upload_' + sAttId + '_' + this.posId).style.display = 'none';
		document.getElementById('file_upload_' + sAttId + '_' + this.posId).height='0';
		if (document.getElementById('upload_loading_' + sAttId + '_' + this.posId)) {
			document.getElementById('upload_loading_' + sAttId + '_' + this.posId).style.display = 'none';
		}
		if (document.getElementById('upload_link_' + sAttId + '_' + this.posId)) {
			document.getElementById('upload_link_' + sAttId + '_' + this.posId).style.display = 'none';
		}
		if (document.getElementById('file_upload_msg_' + sAttId + '_' + this.posId)) {
			document.getElementById('file_upload_msg_' + sAttId + '_' + this.posId).style.display = 'none';
		}
		document.getElementById('file_show_' + sAttId + '_' + this.posId).style.display = '';
		document.getElementById('img_' + sAttId + '_' + this.posId).src = 'resources/image/s_' + sImgName;
		eval('document.forms[0].att_input_' + sAttId + '_' + this.posId).value =
			's_' + sImgName + '||' + sImgName + '|';
		this.itemModified();
	};
	
	this.hideImgUploadFailed = function (sAttId) {		
		
		if (document.getElementById('upload_loading_' + sAttId + '_' + this.posId)) {
			document.getElementById('upload_loading_' + sAttId + '_' + this.posId).style.display = 'none';
		}
		if (document.getElementById('upload_link_' + sAttId + '_' + this.posId)) {
			document.getElementById('upload_link_' + sAttId + '_' + this.posId).style.display = 'none';
		}
		if (document.getElementById('file_upload_msg_' + sAttId + '_' + this.posId)) {
			document.getElementById('file_upload_msg_' + sAttId + '_' + this.posId).style.display = 'none';
		}
		if (document.getElementById('file_show_' + sAttId + '_' + this.posId)) {
			document.getElementById('file_show_' + sAttId + '_' + this.posId).style.display = 'none';
		}
		document.getElementById('file_upload_' + sAttId + '_' + this.posId).height=this.heightFrame;
	};

	this.toggleWindowDates = function (sId) {
		var elem = eval('document.forms[0].trv_shop_window_pub_' + sId + '_' + this.posId);
		if (elem.options[elem.selectedIndex].value == '1') {
			document.getElementById('show_window_dates_' + sId + '_' + this.posId).style.display = '';
		} else {
			document.getElementById('show_window_dates_' + sId + '_' + this.posId).style.display = 'none';
		}
	};

	this.showImgs = function (id, max_width, att_id) {
		var i = 1;
		var oElem = document.getElementById('server_images_div_' + i + '_' + att_id + '_' + this.posId);
		while (oElem) {
			oElem.style.display = 'none';
			i++;
			oElem = document.getElementById('server_images_div_' + i + '_' + att_id + '_' + this.posId);
		}

		oElem = document.getElementById('server_images_div_' + id + '_' + att_id + '_' + this.posId);
		oElem.style.display = '';

		i = 1;
		var oElem = document.getElementById('server_images_img_' + id + '_' + i + '_' + att_id + '_' + this.posId);
		while (oElem) {
			this.redimImg(oElem, max_width);
			i++;
			oElem = document.getElementById('server_images_img_' + id + '_' + i + '_' + att_id + '_' + this.posId);
		}

	}

	this.createContent = function (id_content_type, attIds, attValues) {
		
		if ( (id_content_type == undefined) || (id_content_type == '')
			|| (attIds == undefined) || (attIds == '')
			|| (attValues == undefined) || (attValues == '') ) 	return -1;
		
		// Añade el nuevo contenido
		var oAjax = new WBE_AjaxClass();
		oAjax.clear();
		
		oAjax.addPostParameter('content_ct_id', id_content_type);
		oAjax.addPostParameter('lng_id', this.lngId);
		oAjax.addPostParameter('pos_id', this.posId);
		oAjax.addPostParameter('comp_id', this.compId);
		
		var a_attId = attIds.split(',');
		var a_attValue = attValues.split(',');
		
		for (var i=0; i < a_attId.length; i++) {
			oAjax.addPostParameter('att_input_' + a_attId[i] , a_attValue[i]);
		}
		
		xmlObj = oAjax.throwEventXML("cms_save_struc_content");
		var iCVId;
		if (xmlObj){
			iCVId = oAjax.getXMLNodeValue(xmlObj, 'id');
			return (iCVId!=undefined) ? iCVId : -1;
		}
		
		return -1;
	}
	
	this.checkCaptcha = function() {
		var oElemCaptcha = eval('document.WBForm.txt_captcha_' + this.posId);
		if (oElemCaptcha) {
			var oAjax = new WBE_AjaxClass();
			oAjax.clear();
			oAjax.addPostParameter('captcha', oElemCaptcha.value);
			xmlObj = oAjax.throwEventXML("check_captcha");
			if (xmlObj) return true;
			else {
				alert('Error comprobando campo de seguridad');
				oElemCaptcha.focus();
				return false;
			}

		} else {
			return true;
		}
	}
};  