﻿var strStepNumber="";
var strHCompInitial="";
var strLanguageKey ="";
var IsEPS=false;
var IsBusiness=false;
//Load proper registration step page, based on URL passed    
function LoadRegistrationStepPage() {

try 
{
        strStepNumber = getQSValue("step");
        strHCompInitial = getQSValue("HCompInitial");
        strLanguageKey = getQSValue("Lang");
        IntRID=getQSValue("RID");
        IsEPS = getQSValue("IsEPS");        
        IsBusiness = getQSValue("Isbusiness");
        
        if (strStepNumber == "") {
            var lmPleaseWait = bb.document.getElementById('lmPleaseWait');
            lmPleaseWait.show()
            bb.command.load('Registration.aspx?HCompInitial=' + strHCompInitial + '&Lang=' + strLanguageKey + '&RID=' + IntRID, 'GET', null, null, null, null, onSuccessRegistrationPage);
        }
        else if (strStepNumber == 2) {
            if (gIsRegister=='False') {
                bb.command.load('RegistrationStep2.aspx?HCompInitial=' + strHCompInitial + '&Lang=' + strLanguageKey, 'GET', null, null, null, null, onSuccessRegistrationPage);
            }
        }
        else if (strStepNumber == 3)
            bb.command.load('RegistrationStep3.aspx', 'GET', null, null, null, null, onSuccessRegistrationPage);
 }
 catch (exception) {
     showTopMsg(exception, 7000, '1', true);
 }   
 
};

function onSuccessRegistrationPage(Response)
{       
    try
    {                             
        if(Response) 
        {      
                   var xmlRegistration=Response.responseText;
                        parseBTL(xmlRegistration, 'divDetails', 'replaceChildren');
                        if (strStepNumber == "")
                         {
                            if (strHCompInitial != "MMPHAND") {
                                if (bb.browser.ie)
                                    document.getElementById('trlanguaguge').style.display = 'block';                                    
                                else
                                    document.getElementById('trlanguaguge').style.display = 'table-row';

                                FillLanguage();
                            }
                            else
                            { document.getElementById('trlanguaguge').style.display = 'none'; }
                        }
                        if (strStepNumber==2)
                        {    
                            getContactDetails();
                        }            
                        var lmPleaseWait = bb.document.getElementById('lmPleaseWait');
                        lmPleaseWait.hide()
                    }
         }
        catch (exception) {
                showTopMsg(exception, 7000, '1', true);
        }      
};
//to get query string parameter's value
function getQSValue(key) 
{
    try {
        var url = window.location.search.substring(1);
        var keyValues = url.split("&");
        for (i = 0; i < keyValues.length; i++) {
            var val = keyValues[i].split("=");
            if (val[0] == key)
                return val[1];
        }
        return "";
    }
    catch (exception) {
        showTopMsg(exception, 7000, '1', true);
    }   
};  

function clearErrorMsg(spanId)
{
    document.getElementById(spanId).innerHTML="";
    document.getElementById(spanId).innerText="";
};

function onRegistrationCancel() {

try {
            if (strHCompInitial == "MMPHAND")
                location.href = "../MMPLOGIN.aspx";
            else if (strHCompInitial == "PCBSHOPHAND")
                location.href = "../ThePCBShopLOGIN.aspx";
            else
                location.href = "../ECLOGIN.aspx";
   }
   catch (exception) {
       showTopMsg(exception, 7000, '1', true);
   }
};

function FillLanguage() {
    try 
    {
        strLanguageCode = getQSValue("Lang");
        EC09WebApp.EC09WebService.EC09WebService.GetCodeTableDataByCode('LANGUAGES', strLanguageCode, OnSuccessLANGUAGES);
    }
    catch (exception) {
        showTopMsg(exception, 7000, '1', true);
    }
};
function OnSuccessLANGUAGES(arrResponse) {
    IsEPS = getQSValue("IsEPS");
    if (IsEPS == "false")
        IsEPS = false; 
    if (IsEPS == "") {
        IsEPS = false;
    }
    
    var cboLanguage = bb.evaluateSmart("id('cboLanguage')");
    if (IsEPS == false) {
    
        for (var intCount = 1; intCount < arrResponse.length; intCount++) {
            if (arrResponse[intCount].Code != "EN-US") {
                if (arrResponse[intCount].Code != "LANGUAGES") {
                    if (strLanguageKey == arrResponse[intCount].Code)
                        addOption(cboLanguage, arrResponse[intCount].ShortDescription, arrResponse[intCount].Code, true);
                    else
                        addOption(cboLanguage, arrResponse[intCount].ShortDescription, arrResponse[intCount].Code, false);
                }
            }
        } 
    }
    else {
        for (var intCount = 1; intCount < arrResponse.length; intCount++) {
            if (arrResponse[intCount].Code != "EN-US") {
                if (arrResponse[intCount].Code != "LANGUAGES") {
                    if (arrResponse[intCount].Code == "de" || arrResponse[intCount].Code == "fr" || arrResponse[intCount].Code == "en" || arrResponse[intCount].Code == "nl") {
                        if (strLanguageKey == arrResponse[intCount].Code)
                            addOption(cboLanguage, arrResponse[intCount].ShortDescription, arrResponse[intCount].Code, true);
                        else
                            addOption(cboLanguage, arrResponse[intCount].ShortDescription, arrResponse[intCount].Code, false);
                    }
                }
            }
        } 
    }
};
function setUrlForLanguage() {
try
{
    if (strStepNumber == "") {
        strLanguageKey = bb.evaluateSmart("id('cboLanguage')").getProperty("value");
        
        if (IsEPS == "")
            IsEPS = false;
        if (IsBusiness == "")
            IsBusiness = false;    
        //http: //beta.eurocircuits.com/Registration/RegContainer.aspx?RID=947&Lang=en&HCompInitial=EPHAND&IsEPS=true&Isbusiness=false
        location.href = "RegContainer.aspx?RID=" + IntRID + "&Lang=" + strLanguageKey + "&HCompInitial="+strHCompInitial + "&IsEPS="+IsEPS+"&Isbusiness="+IsBusiness;
        
    }    
}
catch (exception) {
    showTopMsg(exception, 7000, '1', true);
}  
};

function GetLoginpage() {

    try {
        var UID = getQSValue("UID");
        var RID = getQSValue("RID");
        location.href = "../TempLoginPage.aspx?UserName=" + UID + "&RootId=" + RID;
    }
    catch (exception) {
        showTopMsg(exception, 7000, '1', true);
    }    
};
