﻿/*
    Autor: Karlos E. Collazo 
    Date: May 2011
    Description:
                This function dynamically populates the sections inside MyAccount.aspx
*/

function createAccInfoDivs(index,Address,AddressCont,Address2,AccNum,hasHSD,hasVideo,hasTelephpony,AccAmount,hasDirectDebit) {

//    console.log('Function Accessed!');
//    console.log('HSD', hasHSD);
//    console.log('TEL', hasTelephpony);
//    console.log('VIDEO', hasVideo);

    //------------------------------------------------ My Profile ---------------------------------------------

    //DIVs Declaration  
    var curDiv = document.getElementById('CustProfile');
    var newDivAccData = document.createElement('div');
    var newDivHouseData = document.createElement('div');
    var newDivCardData = document.createElement('div');//NOT IN USE 
    var newDivTheCardImage = document.createElement('div');//NOT IN USE
    var newDivPackages = document.createElement('div');
    var newDivClear = document.createElement('div');
    var newDivTelevision = document.createElement('div');
    var newDivComputer = document.createElement('div');
    var newDivTelephony = document.createElement('div');

    //Append account-data to the-content
    curDiv.appendChild(newDivAccData);

    //Append fl to account-data
    newDivAccData.setAttribute('class','account-data');
    newDivAccData.appendChild(newDivHouseData);

    //Place address info inside fl
    newDivHouseData.setAttribute('class', 'fl');
    newDivHouseData.innerHTML = '<p>' + Address + '</p>' +
                                '<p>' + AddressCont + '</p>' +
                                '<p>' + Address2 + '</p>' +
                                '<p><strong>Acc #</strong>' + AccNum + '</p>';

    //Append card-data to account-data
    newDivAccData.appendChild(newDivCardData);
    newDivCardData.setAttribute('class','card-data');

        //Append the-card to card-data
        newDivCardData.appendChild(newDivTheCardImage);
        if (hasDirectDebit == 'True') {
            newDivTheCardImage.setAttribute('class', 'the-card');
        }
        else {
            newDivTheCardImage.setAttribute('class', 'the-card disable');
        }   
        //newDivTheCardImage.innerHTML = '<img src="../images/costumer-center/card-01.png" />';

        //Append the-packages to card-data
        newDivCardData.appendChild(newDivPackages);
        newDivPackages.setAttribute('class', 'the-packages');

        //Append img-items to the-packages
        newDivPackages.appendChild(newDivTelevision);
        newDivPackages.appendChild(newDivComputer);
        newDivPackages.appendChild(newDivTelephony);
    

        //Update Status
        if (hasVideo == 'True') {

            newDivTelevision.setAttribute('class', 'img-television');
        }
        else {

            newDivTelevision.setAttribute('class', 'img-television disable');
        }
        if (hasHSD == 'True') {

            newDivComputer.setAttribute('class', 'img-computer');
    
        }
        else {

            newDivComputer.setAttribute('class', 'img-computer disable');

        }
        if (hasTelephpony == 'True') {

            newDivTelephony.setAttribute('class', 'img-telephony');
        }
        else {

            newDivTelephony.setAttribute('class', 'img-telephony disable');
        }

    //Append clr to account-data
    newDivAccData.appendChild(newDivClear);
    newDivClear.setAttribute('class', 'clr');


    //--------------------------------------------- Manage your accounts -------------------------------------
    //Div Declaration
    var manageMasterDiv = document.getElementById('CustAccManagement');
    var accountDataDiv = document.createElement('div');
    var dataDiv = document.createElement('div');
    var clearDiv = document.createElement('div');
    var removeLinkDiv = document.createElement('div');

    console.log('Starting manage your accounts')

    //Append acount-data to the-content
    manageMasterDiv.appendChild(accountDataDiv);
    accountDataDiv.setAttribute('class', 'account-data');

    //Append the-data to account-data
    accountDataDiv.appendChild(dataDiv);
    dataDiv.setAttribute('class', 'the-data');

    //Insert information on the-data
    dataDiv.innerHTML = '<p>' + Address + '</p>' +
                        '<p>' + AddressCont + '</p>' +
                        '<p>' + Address2 + '</p>' +
                        '<p><strong>Acc #</strong>' + AccNum + '</p>';

    //Insert Remove btn to account if more than one account
    if (AccAmount > 1) {
        accountDataDiv.appendChild(removeLinkDiv);
        removeLinkDiv.setAttribute('id', index);
        removeLinkDiv.setAttribute('name','unlink')
        removeLinkDiv.setAttribute('class','removeLink');
        removeLinkDiv.innerHTML = '<a class="remove-account">Remove</a>';
    }   

    //Append Clear Division to account-data
    accountDataDiv.appendChild(clearDiv);
    clearDiv.setAttribute('class', 'clr');

    console.log('Finished manage your accounts');
}
