/*+***********************************************************************************
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 *************************************************************************************/
/* Henry 06:57 p.m. 11/04/2017  */
Vtiger_Edit_Js("Potentials_Edit_Js",{
   
},{


	initForm : function(){
		$("#Potentials_editView_fieldName_cf_905").attr("readonly", true);
		/*$("#Accounts_editView_fieldName_bill_pobox").attr("readonly", true);
		$("#Accounts_editView_fieldName_bill_state").attr("readonly", true);
		$("#Accounts_editView_fieldName_bill_city").attr("readonly", true);*/
	},
	changeFaseVenta : function() {
		var this_ = this;
		$("select[name='sales_stage']").change(function(){
			this_.requireFieldsChangeFaseVenta( $(this).val() );
		});
		$("select[name='sales_stage']").trigger("change");
	},

	setRequire : function( instance , required ){ 
		var required = (required=='undefined' || required == null)? true : required;
		if ( required ) {
			instance.attr("data-validation-engine","validate[required,funcCall[Vtiger_Base_Validator_Js.invokeValidation]]");
		} else {
			instance.attr("data-validation-engine","validate[funcCall[Vtiger_Base_Validator_Js.invokeValidation]]");
		}
	},

	requireFieldsChangeFaseVenta : function( option ) {
		if ( option == 'Home: Interes' || option == 'Base 1: Approach' ) {
			var required = true;
			this.setRequire( $("#Potentials_editView_fieldName_potentialname") , required );
			this.setRequire( $("select[name='opportunity_type']") , required );
			this.setRequire( $("#contact_id_display") , required );
			this.setRequire( $("#related_to_display") , required );
			this.setRequire( $("select[name='leadsource']") , required );
			this.setRequire( $("select[name='cf_863']") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_859") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_767") , required );
		}else{
			//------------ Else Home
			var required = false;
			//this.setRequire( $("#Potentials_editView_fieldName_potentialname") , required ); //Es requerido por configuración
			this.setRequire( $("select[name='opportunity_type']") , required );
			this.setRequire( $("#contact_id_display") , required );
			this.setRequire( $("#related_to_display") , required );
			this.setRequire( $("select[name='leadsource']") , required );
			this.setRequire( $("select[name='cf_863']") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_859") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_767") , required );
		}
		if ( option == 'Base 1: Approach' ) {
			var required = true;
			this.setRequire( $("#Potentials_editView_fieldName_closingdate") , required );
			this.setRequire( $("select[name='cf_803']") , required );
			this.setRequire( $("#Potentials_editView_fieldName_amount") , required );
			this.setRequire( $("select[name='cf_753']") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_755") , required );
			this.setRequire( $("#Potentials_Edit_fieldName_cf_757") , required );
			this.setRequire( $("#Potentials_Edit_fieldName_cf_805") , required );
			// todo necesidad
			this.setRequire( $("#Potentials_editView_fieldName_description") , required );
			this.setRequire( $("select[name='cf_783']") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_769") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_771") , required );
			this.setRequire( $("#Potentials_editView_fieldName_nextstep") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_773") , required );
			//todo informacion enviada por el cliente
			this.setRequire( $("select[name='cf_865']") , required );
			this.setRequire( $("select[name='cf_867']") , required );
			this.setRequire( $("select[name='cf_869']") , required );
			this.setRequire( $("select[name='cf_871']") , required );
			this.setRequire( $("select[name='cf_873']") , required );
			//informacion para la cotizacion
			this.setRequire( $("#Potentials_editView_fieldName_cf_785") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_787") , required );
			this.setRequire( $("select[name='cf_789']") , required );
			this.setRequire( $("select[name='cf_791']") , required );
			this.setRequire( $("select[name='cf_793']") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_767") , required );
				
		}else {
			var required = false;
			//------------ Else Base 1
			//this.setRequire( $("#Potentials_editView_fieldName_closingdate") , required ); // Es requerido por configuración
			this.setRequire( $("select[name='cf_803']") , required );
			this.setRequire( $("#Potentials_editView_fieldName_amount") , required );
			//this.setRequire( $("select[name='cf_753']") , required ); // Es requerido por configuración
			this.setRequire( $("#Potentials_editView_fieldName_cf_755") , required );
			$("#Potentials_Edit_fieldName_cf_757").removeAttr("data-validation-engine");
			$("#Potentials_Edit_fieldName_cf_805").removeAttr("data-validation-engine");
			// todo necesidad
			this.setRequire( $("#Potentials_editView_fieldName_description") , required );
			this.setRequire( $("select[name='cf_783']") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_769") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_771") , required );
			this.setRequire( $("#Potentials_editView_fieldName_nextstep") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_773") , required );
			//todo informacion enviada por el cliente
			this.setRequire( $("select[name='cf_865']") , required );
			this.setRequire( $("select[name='cf_867']") , required );
			this.setRequire( $("select[name='cf_869']") , required );
			this.setRequire( $("select[name='cf_871']") , required );
			this.setRequire( $("select[name='cf_873']") , required );
			//informacion para la cotizacion
			this.setRequire( $("#Potentials_editView_fieldName_cf_785") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_787") , required );
			this.setRequire( $("select[name='cf_789']") , required );
			this.setRequire( $("select[name='cf_791']") , required );
			this.setRequire( $("select[name='cf_793']") , required );
			this.setRequire( $("#Potentials_editView_fieldName_cf_767") , required );
		}
	},
	
	/**
	 * Function which will register basic events which will be used in quick create as well
	 *
	 */
	registerBasicEvents : function(container) {
		this._super(container);
		this.requireFieldsChangeFaseVenta();
		this.changeFaseVenta();
		this.initForm();
			//container.trigger(Vtiger_Edit_Js.recordPreSave, {'value': 'edit'});
	}

});