﻿// JavaScript File
Entegris.ProductCatalog.TSupportContactUs= function(SiteId, IsBlueBox,Type, ConfiirmationPage)
{
    this.errorMsg = Entegris.Translations.get('lblFormErrorMessage', "Please enter all required fields marked in red.");
    this.siteId = SiteId;
    this.IsBlueBox = IsBlueBox;
    this.type = Type;
  //  this.LanguageId = LanguageId;
    this.ConfiirmationPage = ConfiirmationPage;
 
    Ext.apply(Ext.form.VTypes, {
     'emailAddress': function(){
         var re = /^(([^<>()[\]\\.,;:\s@""]+(\.[^<>()[\]\\.,;:\s@""]+)*)|("".+""))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
         return function(v){
             return re.test(v);
         }
     }()
    });
    
    if( this.type == "TechnicalSupport" )
    {
       this.data = eval(Entegris.API.TechSupport.GetTechnicalSupportCommentTypes().value);
       
    }
    else
    {
        this.data = eval(Entegris.API.TechSupport.GetCommentTypes().value);
    }
    
    this.dataStore = new Ext.data.SimpleStore({'id': 0,fields: ['value', 'text', 'class', 'type'],data : this.data});
    
    
   this.ddlProducts = new Ext.form.ComboBox({
        typeAhead: false,
        transform: "ddTSProductServices",
        store:this.dataStore,
        width:300,
        forceSelection:true,
        editable: false, 
        mode: 'local',
        valueField: 'value',
        displayField: 'text', 
        tpl: '<div class="x-combo-list-item"><div class="{class}">{text}</div></div>',
        allowBlank:false
    });
    
   this.ddlProducts.on('beforequery', this.onBeforeQuery, this);
   
   this.TSquestion = new Ext.form.TextArea({
                                            allowBlank:true,
                                            selectOnFocus : true,
                                            width:418,
                                            name:"TSquestion"
                                        }); 
   this.TSquestion.applyTo(Ext.get("TSquestion"));
   Ext.get("TSquestion").setHeight(100, false);
   
   this.txtTSFName= new Ext.form.TextField({
                fieldLabel: '',
	            name: 'txtTSFName',
	            width:200,
	            allowBlank:false
                });
       
   this.txtTSFName.applyTo(Ext.get("txtTSFName"));
   
    this.txtTSLName= new Ext.form.TextField({
                fieldLabel: '',
	            name: 'txtTSLName',
	            width:200,
	            allowBlank:false
                });
       
    this.txtTSLName.applyTo(Ext.get("txtTSLName"));

    this.txtTSCompany= new Ext.form.TextField({
            fieldLabel: '',
            name: 'txtTSCompany',
            width:200,
            allowBlank:true 
            });
       
    this.txtTSCompany.applyTo(Ext.get("txtTSCompany"));
    
    this.txtTSTitle= new Ext.form.TextField({
        fieldLabel: '',
        name: 'txtTSTitle',
        width:200,
        allowBlank:true 
        });
       
    this.txtTSTitle.applyTo(Ext.get("txtTSTitle"));
    
    this.txtTSAddress= new Ext.form.TextField({
        fieldLabel: '',
        name: 'txtTSAddress',
        width:200,
        allowBlank:false 
        });
       
    this.txtTSAddress.applyTo(Ext.get("txtTSAddress"));
    
    this.txtTSAptNo= new Ext.form.TextField({
        fieldLabel: '',
        name: 'txtTSAptNo',
        width:200,
        allowBlank:true 
        });
       
    this.txtTSAptNo.applyTo(Ext.get("txtTSAptNo"));
    
    this.txtTSMailStation= new Ext.form.TextField({
    fieldLabel: '',
    name: 'txtTSMailStation',
    width:200,
    allowBlank:true 
    });
       
    this.txtTSMailStation.applyTo(Ext.get("txtTSMailStation"));
    
    this.txtTSCity= new Ext.form.TextField({
    fieldLabel: '',
    name: 'txtTSCity',
    width:200,
    allowBlank:false 
    });
       
    this.txtTSCity.applyTo(Ext.get("txtTSCity"));
    
    this.txtTSState= new Ext.form.TextField({
    fieldLabel: '',
    name: 'txtTSState',
    width:200,
    allowBlank:false 
    });
       
    this.txtTSState.applyTo(Ext.get("txtTSState"));
    
    this.txtTSZip= new Ext.form.TextField({
    fieldLabel: '',
    name: 'txtTSZip',
    width:200,
    allowBlank:false 
    });
       
    this.txtTSZip.applyTo(Ext.get("txtTSZip"));   
        
    this.txtTSZip= new Ext.form.TextField({
    fieldLabel: '',
    name: 'txtTSZip',
    width:200,
    allowBlank:false 
    });
       
    this.txtTSZip.applyTo(Ext.get("txtTSZip"));   
        
    this.txtTSCountry= new Ext.form.TextField({
    fieldLabel: '',
    name: 'txtTSCountry',
    width:200,
    allowBlank:false 
    });
       
    this.txtTSCountry.applyTo(Ext.get("txtTSCountry"));   
        
    this.txtTSReason= new Ext.form.TextField({
    fieldLabel: '',
    name: 'txtTSReason',
    width:200,
    allowBlank:false 
    });
       
    this.txtTSReason.applyTo(Ext.get("txtTSReason"));   
        
    this.txtTSPhone= new Ext.form.TextField({
    fieldLabel: '',
    name: 'txtTSPhone',
    width:200,
    allowBlank:false 
    });
       
    this.txtTSPhone.applyTo(Ext.get("txtTSPhone"));   
        
    this.txtTSFax= new Ext.form.TextField({
    fieldLabel: '',
    name: 'txtTSFax',
    width:200,
    allowBlank:false 
    });
       
    this.txtTSFax.applyTo(Ext.get("txtTSFax"));   
            
    this.txtTSEmailAddress= new Ext.form.TextField({
    fieldLabel: '',
    name: 'txtTSEmailAddress',
    width:200,
    allowBlank:false ,
    vtype: 'emailAddress'
    });
       
    this.txtTSEmailAddress.applyTo(Ext.get("txtTSEmailAddress"));  
    
    this.byPhone = new Ext.form.Radio({boxLabel:Entegris.Translations.get('lblFormContactPreferencePhone', "Phone"), name:"byPhone"});
    this.byPhone.applyTo(Ext.get("byPhone"));
    
    this.byFax = new Ext.form.Radio({boxLabel:Entegris.Translations.get('lblFormContactPreferenceFax', "Fax"), name:"byFax"});
    this.byFax.applyTo(Ext.get("byFax"));
    
    this.byEmail = new Ext.form.Radio({boxLabel:Entegris.Translations.get('lblFormContactPreferenceEmail', "Email"), name:"byEmail"});
    this.byEmail.applyTo(Ext.get("byEmail"));
    
    this.btnSend= new Ext.Button(Ext.get("TSsend"),{text: Entegris.Translations.get('lblFormSend', "Send"), scope:this,tooltip:"Send",type:"button", cls:"ProductSearchButton"});
    this.btnSend.on('click',this.onSendClick,this,{});
};

 Ext.extend(Entegris.ProductCatalog.TSupportContactUs, Ext.util.Observable, {
     onBeforeQuery: function(combo, e)
       {
        combo.forceAll = true;
        combo.query="";
       }, 
     onSendClick:function()
    {
        var errorMessage = Ext.get("errMsg");
        this.ddlProducts.focus();
        this.txtTSFName.focus();
        this.txtTSLName.focus();
        this.txtTSAddress.focus();
        this.txtTSCity.focus();
        this.txtTSState.focus();
        this.txtTSZip.focus();
        this.txtTSCountry.focus();
        this.txtTSReason.focus();
        this.txtTSPhone.focus();
        this.txtTSFax.focus();
        this.txtTSEmailAddress.focus();
        this.btnSend.focus();
        
        if( this.ddlProducts.validate() &&
            this.txtTSFName.validate() && 
            this.txtTSLName.validate() &&
            this.txtTSAddress.validate() &&
            this.txtTSCity.validate() &&
            this.txtTSState.validate() &&
            this.txtTSZip.validate() &&
            this.txtTSCountry.validate() &&
            this.txtTSReason.validate() &&
            this.txtTSPhone.validate() &&
            this.txtTSFax.validate() &&
            this.txtTSEmailAddress.validate()
            )
        {
            Ext.get('TechnicalSupportContactUsCtrl').mask(Entegris.Translations.get('lblFormSendingRequest', "Sending Request..."));
           errorMessage.dom.innerHTML = "" ;
           var techSupportContent = Entegris.API.TechSupport.GetTechSupportContentInstance().value;
           techSupportContent.CommentType = this.ddlProducts.getValue();
           techSupportContent.Questions = this.TSquestion.getValue();
           techSupportContent.FirstName = this.txtTSFName.getValue();
           techSupportContent.LastName = this.txtTSLName.getValue();
           techSupportContent.Company = this.txtTSCompany.getValue();
           techSupportContent.JobTitle = this.txtTSTitle.getValue();
           techSupportContent.Address = this.txtTSAddress.getValue();
           techSupportContent.Suite = this.txtTSAptNo.getValue();
           techSupportContent.MailStation = this.txtTSMailStation.getValue();
           techSupportContent.City = this.txtTSCity.getValue();
           techSupportContent.State = this.txtTSState.getValue();
           techSupportContent.Zip = this.txtTSZip.getValue();
           techSupportContent.Country = this.txtTSCountry.getValue();
           techSupportContent.Reason = this.txtTSReason.getValue();
           techSupportContent.Phone = this.txtTSPhone.getValue();
           techSupportContent.Fax = this.txtTSFax.getValue();
           techSupportContent.EmailAddress = this.txtTSEmailAddress.getValue();
 
           techSupportContent.ContactType = Ext.get(Ext.DomQuery.selectNode("input[name=contactBy]:checked")).getValue();

           /* var contactUsType = Entegris.API.TechSupport.GetContactUsType().value;  */ 
           techSupportContent.Type = 0; /* contactUsType.TechnicalSupport; */
           var sendMail = Entegris.API.TechSupport.SendTechSupportContactUsEmail(techSupportContent);
           
           if (sendMail.value == true) {
                location.href = this.ConfiirmationPage;
           } else {
                Ext.get('TechnicalSupportContactUsCtrl').unmask();
                errorMessage.dom.innerHTML = Entegris.Translations.get('lblFormTechnicalError', 'There was an error during the submission. Please try again later.');
           }
        }
        else
        {
            Ext.get('tblTechSupportContactUs').addClass('allow-invalids');
            errorMessage.dom.innerHTML = this.errorMsg ;
            if (!this.txtTSEmailAddress.validate()) {
                errorMessage.dom.innerHTML = this.errorMsg + '<br/>' + Entegris.Translations.get('lblFormErrorInvalidEmailAddress', 'Please enter a valid email address.');
            }
        }
       
    }
});