﻿/// <reference path="GlobalJS/jquery/jquery-1.4.1.js" />


RegMgr._instance = null;
RegMgr.GetInstance = function() 
{
    if (this._instance == null) 
    {
        this._instance = new RegMgr();
    }
    return this._instance;
}
function RegMgr()
{
    this._Form = undefined;
    this._ServerPage = undefined;
    this._RegDivTag = undefined;
    this._IPLocation = undefined;

    this._FormControl = new Object();
    this._RegType = undefined;
    this._Culture = undefined;
    
    this._utmsource = undefined;
    this._utmmedium = undefined;
    this._utmkwd = undefined;
    this._utmterm = undefined;
     
    
    if (RegMgr.caller != RegMgr.GetInstance)
    {
        throw new Error("There is no public constructor for RegMgr.");
    }
    RegMgr.prototype.BindFormAndPage = function(FormName,ServerPage,RegDivTag)
    {
        var junk ="me";
        this._Form = document.forms[FormName];
        this._ServerPage = ServerPage;
        this._RegDivTag = RegDivTag ;   
    }
    RegMgr.prototype.EmailUpdate = function(EID, CID)
    {
        try{
            //var junk = this._RegType;
            this.RegEvent('EMAIL:' + $('#'+EID).val() + '~COUNTRY:' + $('#'+CID).val() + '~RegType:' + this._RegType);
        }
        catch (ex) { IDESJSUtil.LogErr("EmailUpdate", ex.message); }
    }

    RegMgr.prototype.UpdateCountry = function(EID, CID) {
        try{
       // var junk = $('#'+ID);
            this.RegEvent('EMAIL:' + $('#'+EID).val() + '~COUNTRY:' + $('#'+CID).val() + '~RegType:' + this._RegType);
        }
        catch (ex) { IDESJSUtil.LogErr("UpdateCountry", ex.message); }
    }

    RegMgr.prototype.SubmitClick = function (CID, EID, FNID, LNID, JTID, JFID, PID, CPID, CTID, MTID, A1ID, A2ID, CTYID, STID, PCID, PW1ID) {
        //var junk = $('#'+CID);
        var re = /^[\w\s@\-.\u00A9\u00AE\u0026\u0027\u0028\u0029\u002B\u002C\u002D\u00A9\u00AE]+/;
        var ProcessOK = true;
        try {
            if ($('#Country').is(':visible') && $('#Country').val() == '-1') {
                ProcessOK = false;
                $('#CountryREQCell').html('Required');
            }
            else
                $('#CountryREQCell').html('');

            if ($('#EmailAddress').is(':visible') && $('#EmailAddress').val() == '') {
                ProcessOK = false;
                $('#EmailREQCell').html('Required');
            }
            else
                $('#EmailREQCell').html('');

            if ($('#Password1').is(':visible') && $('#Password1').val() == '') {
                ProcessOK = false;
                $('#Password1REQCell').html('Required');
            }
            else if ($('#Password1').is(':visible') && !re.test($('#Password1').val())) {
                ProcessOK = false;
                $('#Password1REQCell').html('Invalid');
            }
            else
                $('#Password1REQCell').html('');

            if ($('#FirstName').is(':visible') && $('#FirstName').val() == '') {
                ProcessOK = false;
                $('#FirstNameREQCell').html('Required');
            }
            else if ($('#FirstName').is(':visible') && !re.test($('#FirstName').val())) {
                ProcessOK = false;
                $('#FirstNameREQCell').html('Invalid');
            }
            else
                $('#FirstNameREQCell').html('');

            if ($('#LastName').is(':visible') && $('#LastName').val() == '') {
                ProcessOK = false;
                $('#LastNameREQCell').html('Required');
            }
            else if ($('#LastName').is(':visible') && !re.test($('#LastName').val())) {
                ProcessOK = false;
                $('#LastNameREQCell').html('Invalid');
            }
            else
                $('#LastNameREQCell').html('');

            if ($('#JobTitle').is(':visible') && $('#JobTitle').val() == '') {
                ProcessOK = false;
                $('#JobTitleREQCell').html('Required');
            }
            else if ($('#JobTitle').is(':visible') && !re.test($('#JobTitle').val())) {
                ProcessOK = false;
                $('#JobTitleREQCell').html('Invalid');
            }
            else
                $('#JobTitleREQCell').html('');

            if ($('#Phone').is(':visible') && $('#Phone').val() == '') {
                ProcessOK = false;
                $('#PhoneREQCell').html('Required');
            }
            else if ($('#Phone').is(':visible') && !re.test($('#Phone').val())) {
                ProcessOK = false;
                $('#PhoneREQCell').html('Invalid');
            }
            else
                $('#PhoneREQCell').html('');

            if ($('#Company').is(':visible') && $('#Company').val() == '') {
                ProcessOK = false;
                $('#CompanyREQCell').html('Required');
            }
            else if ($('#Company').is(':visible') && !re.test($('#Company').val())) {
                ProcessOK = false;
                $('#CompanyREQCell').html('Invalid');
            }
            else
                $('#CompanyREQCell').html('');

            if ($('#CompanyType').is(':visible') && $('#CompanyType').val() == '-1') {
                ProcessOK = false;
                $('#CompanyTypeREQCell').html('Required');
            }
            else
                $('#CompanyTypeREQCell').html('');

            if ($('#MarketType').is(':visible') && $('#MarketType').val() == '-1') {
                ProcessOK = false;
                $('#MarketTypeREQCell').html('Required');
            }
            else
                $('#MarketTypeREQCell').html('');

            if ($('#JobFunction').is(':visible') && $('#JobFunction').val() == '-1') {
                ProcessOK = false;
                $('#JobFunctionREQCell').html('Required');
            }
            else
                $('#JobFunctionREQCell').html('');

            if ($('#Address1').is(':visible') && $('#Address1').val() == '') {
                ProcessOK = false;
                $('#Address1REQCell').html('Required');
            }
            else if ($('#Address1').is(':visible') && !re.test($('#Address1').val())) {
                ProcessOK = false;
                $('#Address1REQCell').html('Invalid');
            }
            else
                $('#Address1REQCell').html('');

            if ($('#Address2').is(':visible') && $('#Address2').val() == '') {
                ProcessOK = false;
                $('#Address2REQCell').html('Required');
            }
            else if ($('#Address2').is(':visible') && !re.test($('#Address2').val())) {
                ProcessOK = false;
                $('#Address2REQCell').html('Invalid');
            }
            else
                $('#Address2REQCell').html('');

            if ($('#City').is(':visible') && $('#City').val() == '') {
                ProcessOK = false;
                $('#CityREQCell').html('Required');
            }
            else if ($('#City').is(':visible') && !re.test($('#City').val())) {
                ProcessOK = false;
                $('#CityREQCell').html('Invalid');
            }
            else
                $('#CityREQCell').html('');

            if ($('#States').is(':visible') && $('#States').val() == '') {
                ProcessOK = false;
                $('#StatesREQCell').html('Required');
            }
            else
                $('#StatesREQCell').html('');

            if (($('#PostalCode').is(':visible') && $('#PostalCode').val() == '') || ($('#PostalCode').is(':visible') && !re.test($('#PostalCode').val()))) {
                ProcessOK = false;
                $('#PostalCodeREQCell').html('Required');
            }
            else
                $('#PostalCodeREQCell').html('');

            if (ProcessOK)
                this.SubmitEvent('COUNTRY:' + $('#' + CID).val() + '~EMAIL:' + $('#' + EID).val() + '~FirstName:' + $('#' + FNID).val() + '~LastName:' + $('#' + LNID).val() + '~JobTitle:' + $('#' + JTID).val() + '~JobFunction:' + $('#' + JFID).val() + '~Phone:' + $('#' + PID).val() + '~Company:' + $('#' + CPID).val() + '~CompanyType:' + $('#' + CTID).val() + '~MarketType:' + $('#' + MTID).val() + '~Address1:' + $('#' + A1ID).val() + '~Address2:' + $('#' + A2ID).val() + '~City:' + $('#' + CTYID).val() + '~State:' + $('#' + STID).val() + '~PostalCode:' + $('#' + PCID).val() + '~Password1:' + $('#' + PW1ID).val() + '~RegType:' + this._RegType + '~UtmSource:' + this._utmsource + '~UtmMedium:' + this._utmmedium + '~UtmKWD:' + this._utmkwd + '~UtmTerm:' + this._utmterm);
        }
        catch (ex) { IDESJSUtil.LogErr("SubmitClick", ex.message); }
    }
    
    RegMgr.prototype.RegEvent = function(APRAM) {
    
        try{
            if (APRAM==undefined){APRAM = '';}
            this._Form.elements['APARAM'].value='RegEvent~'+APRAM;
            this.AJAXRequest(this.RegEventPostBack);
        }
        catch (ex) { IDESJSUtil.LogErr("RegEvent", ex.message); }
           
    }

    RegMgr.prototype.SubmitEvent = function(APRAM) {
        try{
            if (APRAM == undefined) { APRAM = ''; }
            this._Form.elements['APARAM'].value = 'SubmitEvent~' + APRAM;
            this.AJAXRequest(this.SubmitEventPostBack);
        }
        catch (ex) { IDESJSUtil.LogErr("SubmitEvent", ex.message); }
    }
    
    RegMgr.prototype.AJAXRequest = function(CallBackFunction)
    {
      //  new Ajax.Request(this._ServerPage, { method: 'post',  onSuccess: CallBackFunction, parameters: Form.serialize(this._Form) });
          $.post(this._ServerPage, $(this._Form).serialize(), CallBackFunction, 'json');
    }
    RegMgr.prototype.SubmitEventPostBack = function (AJAXResp) {
        var RTResp;
        //var junk = "me";

        try {
            //   eval('AJAXResp = ' + transport.responseText); // } catch (ex) { alert(ex.message); }

            if (AJAXResp.RegContent != undefined) {
                //            RegMgr._instance.CheckForCRMAccount(AJAXResp.RegContent);
                //alert(AJAXResp.RegContent.IsSuccess);
                if (AJAXResp.RegContent.Email != 'Error') {

                    if (AJAXResp.RegContent.IsSuccess == "True") {
                        // transfer to final Page

                        // Need to determin What Site
                        var RegSite = "PL";
                        if (RegMgr._instance._RegType == 'FH')
                            RegSite = 'FH';

                        if (AJAXResp.RegContent.Verify == "True") {
                            top.location.href = "thankyou.aspx?site=" + RegSite + "&LNG=" + RegMgr._instance._Culture + "&Verify=True"; //"confirmation.aspx?COMPLETE=True&LNG=" + RegMgr._instance._Culture;
                        }
                        else
                            top.location.href = "thankyou.aspx?site=" + RegSite + "&LNG=" + RegMgr._instance._Culture; //+ "&uid=" + $('#'+'EmailAddress') + "&pwd=" + $('#'+'Password1');

                        //                    if (RegMgr._instance._RegType != 'FH')
                        //                        top.location.href = "http://prospector.ides.com/loginpage.aspx?uid=" + $('#'+'EmailAddress') + "&pwd=" + $('#'+'Password1') + "&A=DOLOGIN";
                        //                    else if (RegMgr._instance._RegType == 'FH')
                        //                        top.location.href = "http://composites.ides.com/loginpage.aspx?uid=" + $('#'+'EmailAddress') + "&pwd=" + $('#'+'Password1') + "&A=DOLOGIN"; // Change to Firehole once Live
                        return void (0);
                    }
                    else {
                        if (AJAXResp.RegContent.IsSuccess == "False") {
                            if (AJAXResp.RegContent.IsBL == "True" || AJAXResp.RegContent.IsGL == "True" || AJAXResp.RegContent.BLDomain == "True" || AJAXResp.RegContent.ISGENERAL == "True") {
                                location.href = "unable.aspx";
                                return void (0);
                            }
                            else if (AJAXResp.RegContent.Corporate == 'True') {
                                location.href = "Corporate.aspx";
                                return void (0)
                            }
                            else if (AJAXResp.RegContent.HasAccount == 'True') {
                                location.href = "CurrentUser.aspx";
                                return void (0)
                            }
                            else {
                                location.href = "regerror.aspx";
                                return void (0);
                            }
                        }
                    }
                }
                else {
                    if (AJAXResp.RegContent.ISGENERAL == 'True') {
                        $('#EmailREQCell').html('Use Company Email Address');
                    }
                    else {
                        $('#EmailREQCell').html('Incorrect Email Format');
                    }
                }
            }
        }
        catch (ex) { IDESJSUtil.LogErr("SubmitEventPostback", ex.message); }
    }
    RegMgr.prototype.RegEventPostBack = function(AJAXResp) {
        var RTResp;
        //var junk = "me";
       // try { eval('AJAXResp = ' + transport.responseText); //} catch (ex) { alert(ex.message); }
        try{
            if (AJAXResp.RegContent != undefined) {
                if (AJAXResp.RegContent.Email != 'Error') {
                    RegMgr._instance.UpdateRegContent(AJAXResp.RegContent, RegMgr.GetInstance()._Culture);
                    RegMgr._instance.CheckForUserAccount(AJAXResp.RegContent);
                    RegMgr._instance.CheckForCRMAccount(AJAXResp.RegContent, RegMgr.GetInstance()._Culture);
                    RegMgr._instance.CheckForCorporateAccount(AJAXResp.RegContent);
                    
                    $('#EmailREQCell').html( '');
                }
                else {
                    $('#EmailREQCell').html( 'Incorrect Email Format');
                
                }
            }
        }
        catch (ex) { IDESJSUtil.LogErr("RegEventPostBack", ex.message); }
    }
    RegMgr.prototype.RegInitLoadPostBack = function(AJAXResp) {
        var RTResp;
        //  var junk= "me";
        try {
            //eval('AJAXResp = ' + transport.responseText); //} catch (ex) { alert(ex.message); }
            IDESJSUtil.PopulateList('JobFunction', AJAXResp.JobFunction.Options);
            IDESJSUtil.PopulateList('MarketType', AJAXResp.MarketType.Options);
            IDESJSUtil.PopulateList('CompanyType', AJAXResp.CompanyType.Options);
            IDESJSUtil.PopulateList('States', AJAXResp.States.Options);
            IDESJSUtil.PopulateList('Country', AJAXResp.Country.Options);
            RegMgr.GetInstance()._IPLocation = AJAXResp.IPLoc;
            RegMgr.GetInstance()._RegType = AJAXResp.regType;
            RegMgr.GetInstance()._FormControl = AJAXResp.PageControl;
            RegMgr.GetInstance()._utmkwd = AJAXResp.UTMKWD;
            RegMgr.GetInstance()._utmmedium = AJAXResp.UTMMEDIUM;
            RegMgr.GetInstance()._utmsource = AJAXResp.UTMSOURCE;
            RegMgr.GetInstance()._utmterm = AJAXResp.UTMTERM;
            RegMgr.GetInstance()._Culture = AJAXResp.Culture;


            RegMgr._instance.SetInitDisplay(AJAXResp.Culture);
        }
        catch (ex) { IDESJSUtil.LogErr("RegInitLoadPostBack", ex.message); }
    }

    RegMgr.prototype.CheckForCRMAccount = function(RegContent,lang) {

        var page_type;
        var password;
        try{
            password = RegContent.Password;

            if (RegContent.Company == undefined || RegContent.Company == "") {// do heavy registration
                page_type = 'heavy';
            }
            else if (RegContent.Company != "") {// Light Registration
                page_type = 'light';
            }
            else
                page_type = 'heavy';

            if (RegContent.HasCRMAccount == 'true') {

                if (password != undefined && password != '')
                    this.ControlOnOffNew('Password1', 'hide', 'light', page_type, password, this._FormControl.Password1[0][lang]);
                    this.ControlOnOffNew('FirstName', 'hide', this._FormControl.FirstName[0].type, page_type, '', this._FormControl.FirstName[0][lang]);
                    this.ControlOnOffNew('LastName', 'hide', this._FormControl.LastName[0].type, page_type, '', this._FormControl.LastName[0][lang]);
                    this.ControlOnOffNew('Company', 'hide', this._FormControl.Company[0].type, page_type, RegContent.Company, this._FormControl.Company[0][lang]);
                    this.ControlOnOffNew('JobTitle', 'hide', this._FormControl.JobTitle[0].type, page_type, '', this._FormControl.JobTitle[0][lang]);
                    this.ControlOnOffNew('Phone', 'hide', this._FormControl.Phone[0].type, page_type, '', this._FormControl.Phone[0][lang]);
                    this.ControlOnOffNew('CompanyType', 'hide', this._FormControl.CompanyType[0].type, page_type, RegContent.CompanyType, this._FormControl.CompanyType[0][lang]);
                    this.ControlOnOffNew('MarketType', 'hide', this._FormControl.MarketType[0].type, page_type, RegContent.MarketType, this._FormControl.MarketType[0][lang]);
                    this.ControlOnOffNew('JobFunction', 'hide', this._FormControl.JobFunction[0].type, page_type, null, this._FormControl.JobFunction[0][lang]);
                    this.ControlOnOffNew('Address1', 'hide', this._FormControl.Address1[0].type, page_type, '', this._FormControl.Address1[0][lang]);
                    this.ControlOnOffNew('Address2', 'hide', this._FormControl.Address2[0].type, page_type, '', this._FormControl.Address2[0][lang]);
                    this.ControlOnOffNew('City', 'hide', this._FormControl.City[0].type, page_type, '', this._FormControl.City[0][lang]);
                    this.ControlOnOffNew('States', 'hide', this._FormControl.States[0].type, page_type, null, this._FormControl.States[0][lang]);
                    this.ControlOnOffNew('PostalCode', 'hide', this._FormControl.PostalCode[0].type, page_type, '', this._FormControl.PostalCode[0][lang]);
                    this.ControlOnOffNew('Country', 'hide', 'light', page_type, null, this._FormControl.Country[0][lang]);
                
            }
        }
        catch (ex) { IDESJSUtil.LogErr("CheckForCRMAccount", ex.message); }
    }
    RegMgr.prototype.CheckForUserAccount = function(RegContent) {

        try{
            if (RegContent.HasAccount == 'true') {
                location.href = "CurrentUser.aspx";
                return void (0);
            }
        }
        catch (ex) { IDESJSUtil.LogErr("CheckForUserAccount", ex.message); }        
    }
    
    RegMgr.prototype.CheckForCorporateAccount = function(RegContent) {
        try{
             if (RegContent.Corporate == 'true' ) 
             {    
                location.href = "Corporate.aspx";
                return void (0);
             }
             if (RegContent.BLDomain == 'true' ) 
             {
                location.href = "unable.aspx";
                return void (0);
             }
             if (RegContent.ISGENERAL == 'true') {
                location.href = "unable.aspx";
                return void (0);
             }

           }
        
        catch (ex) { IDESJSUtil.LogErr("CheckforCorporateAccount", ex.message); }
    }

    RegMgr.prototype.UpdateRegContent = function(RegContent, lang) {

        var page_type;
        // Do Heavy/Light form adjustment here
        try{
            if (RegContent.Company == undefined || RegContent.Company == "") {// do heavy registration
                page_type = 'heavy';
            }
            else if (RegContent.Company != "") {// Light Registration
                page_type = 'light';
            }
            else
                page_type = 'heavy';
            
            this.ControlOnOffNew('EmailAddress', 'show', 'light', page_type, null, this._FormControl.EmailAddress[0][lang]);
            this.ControlOnOffNew('FirstName', this._FormControl.FirstName[0].visible, this._FormControl.FirstName[0].type, page_type, '', this._FormControl.FirstName[0][lang]);
            this.ControlOnOffNew('LastName', this._FormControl.LastName[0].visible, this._FormControl.LastName[0].type, page_type, '', this._FormControl.LastName[0][lang]);
            this.ControlOnOffNew('Company', this._FormControl.Company[0].visible, this._FormControl.Company[0].type, page_type, RegContent.Company, this._FormControl.Company[0][lang]);
            this.ControlOnOffNew('JobTitle', this._FormControl.JobTitle[0].visible, this._FormControl.JobTitle[0].type, page_type, '', this._FormControl.JobTitle[0][lang]);
            this.ControlOnOffNew('Phone', this._FormControl.Phone[0].visible, this._FormControl.Phone[0].type, page_type, '', this._FormControl.Phone[0][lang]);
            this.ControlOnOffNew('CompanyType', this._FormControl.CompanyType[0].visible, this._FormControl.CompanyType[0].type, page_type, RegContent.CompanyType, this._FormControl.CompanyType[0][lang]);
            this.ControlOnOffNew('MarketType', this._FormControl.MarketType[0].visible, this._FormControl.MarketType[0].type, page_type, RegContent.MarketType, this._FormControl.MarketType[0][lang]);
            this.ControlOnOffNew('JobFunction', this._FormControl.JobFunction[0].visible, this._FormControl.JobFunction[0].type, page_type, null, this._FormControl.JobFunction[0][lang]);
            this.ControlOnOffNew('Address1', this._FormControl.Address1[0].visible, this._FormControl.Address1[0].type, page_type, '', this._FormControl.Address1[0][lang]);
            this.ControlOnOffNew('Address2', this._FormControl.Address2[0].visible, this._FormControl.Address2[0].type, page_type, '', this._FormControl.Address2[0][lang]);
            this.ControlOnOffNew('City', this._FormControl.City[0].visible, this._FormControl.City[0].type, page_type, '', this._FormControl.City[0][lang]);
            this.ControlOnOffNew('States', this._FormControl.States[0].visible, this._FormControl.States[0].type, page_type, null, this._FormControl.States[0][lang]);
            this.ControlOnOffNew('PostalCode', this._FormControl.PostalCode[0].visible, this._FormControl.PostalCode[0].type, page_type, '', this._FormControl.PostalCode[0][lang]);
            this.ControlOnOffNew('Country', 'show', 'light', page_type, (RegContent.Country != null) ? RegContent.Country : this._IPLocation, this._FormControl.Country[0][lang]);
            this.ControlOnOffNew('Password1', 'show', 'light', page_type, '', this._FormControl.Password1[0][lang]);

        }
        catch (ex) { IDESJSUtil.LogErr("UpdateRegContent", ex.message); }
    }
    
    RegMgr.prototype.InitLoad = function() {   
    
       
         this._Form.elements['APARAM'].value='InitLoad';
        this.AJAXRequest(this.RegInitLoadPostBack);        
    }



    RegMgr.prototype.ControlOnOffNew = function(control, visibility, type, page_type, value, display_text) {
        try{
            if (visibility == 'show' && (type == page_type || page_type == 'heavy' || page_type == null)) {

                $('#'+control).show();
                $('#' + control + 'Cell').html(display_text);
                if (value != null) {
                    if ($('#'+control).get(0).type == 'text')
                        $('#'+control).get(0).value = value;
                    else if ($('#'+control).get(0).type == 'select-one')
                        SelectItem($('#'+control), value);
                }
            }
            else {
                $('#'+control).hide();
                $('#'+control + 'Cell').html( "");
                $('#'+control + 'REQCell').html( "");
                if (value != null) {
                    if ($('#'+control).get(0).type == 'text')
                        $('#'+control).get(0).value = value;
                    else if ($('#'+control).get(0).type == 'select-one')
                        SelectItem($('#'+control), value);
                }
                else if ($('#'+control).get(0).type == 'select-one')
                    SelectItem($('#'+control), 'Other');
            }
        }
        catch (ex) { IDESJSUtil.LogErr("ContronOnOffNew", ex.message); }
    }


    RegMgr.prototype.SetInitDisplay = function(lang) {
        var page_type = null;
        try{
            this.ControlOnOffNew('EmailAddress', 'show', 'light', page_type, null, this._FormControl.EmailAddress[0][lang]);
            this.ControlOnOffNew('FirstName', this._FormControl.FirstName[0].visible, this._FormControl.FirstName[0].type, page_type, '', this._FormControl.FirstName[0][lang]);
            this.ControlOnOffNew('LastName', this._FormControl.LastName[0].visible, this._FormControl.LastName[0].type, page_type, '', this._FormControl.LastName[0][lang]);
            this.ControlOnOffNew('Company', this._FormControl.Company[0].visible, this._FormControl.Company[0].type, page_type, '', this._FormControl.Company[0][lang]);
            this.ControlOnOffNew('JobTitle', this._FormControl.JobTitle[0].visible, this._FormControl.JobTitle[0].type, page_type, '', this._FormControl.JobTitle[0][lang]);
            this.ControlOnOffNew('Phone', this._FormControl.Phone[0].visible, this._FormControl.Phone[0].type, page_type, '', this._FormControl.Phone[0][lang]);
            this.ControlOnOffNew('CompanyType', this._FormControl.CompanyType[0].visible, this._FormControl.CompanyType[0].type, page_type, null, this._FormControl.CompanyType[0][lang]);
            this.ControlOnOffNew('MarketType', this._FormControl.MarketType[0].visible, this._FormControl.MarketType[0].type, page_type, null, this._FormControl.MarketType[0][lang]);
            this.ControlOnOffNew('JobFunction', this._FormControl.JobFunction[0].visible, this._FormControl.JobFunction[0].type, page_type, null, this._FormControl.JobFunction[0][lang]);
            this.ControlOnOffNew('Address1', this._FormControl.Address1[0].visible, this._FormControl.Address1[0].type, page_type, '', this._FormControl.Address1[0][lang]);
            this.ControlOnOffNew('Address2', this._FormControl.Address2[0].visible, this._FormControl.Address2[0].type, page_type, '', this._FormControl.Address2[0][lang]);
            this.ControlOnOffNew('City', this._FormControl.City[0].visible, this._FormControl.City[0].type, page_type, '', this._FormControl.City[0][lang]);
            this.ControlOnOffNew('States', this._FormControl.States[0].visible, this._FormControl.States[0].type, page_type, null, this._FormControl.States[0][lang]);
            this.ControlOnOffNew('PostalCode', this._FormControl.PostalCode[0].visible, this._FormControl.PostalCode[0].type, page_type, '', this._FormControl.PostalCode[0][lang]);
            this.ControlOnOffNew('Country', 'show', 'light', page_type, this._IPLocation, this._FormControl.Country[0][lang]);
            this.ControlOnOffNew('Password1', 'show', 'light', page_type, '', this._FormControl.Password1[0][lang]);
        
            $('#RegSubmit').get(0).value= this._FormControl.RegSubmit[0][lang];
        }
        catch (ex) { IDESJSUtil.LogErr("SetInitDisplay", ex.message); }
    }
}
function SelectItem(ListBoxID, ItemName)
{
    var ListBoxElem = $(ListBoxID);
    try {
            for (var i = 0; i < ListBoxElem[0].length; i++) {
                var ID = ListBoxElem[0][i].value;
                var Display = trim(ListBoxElem[0][i].text,' '); 
                if (Display == ItemName)
                { ListBoxElem[0].options[i].selected = true; break; }
            }

    }
    catch (ex) { IDESJSUtil.LogErr("SelectItem", ex.message); }
}
function SetBoxValue(ListBoxID, Value) {
    var ListBoxElem = $(ListBoxID);
    try {
        ListBoxElem
        
    }
    catch (ex) { IDESJSUtil.LogErr("SetBoxValue", ex.message); }
    
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}




