﻿function ShowSubTab(divId) {

    if (document.getElementById(divId)) {

        if (document.getElementById(divId).style.display == 'block') {

            document.getElementById(divId).style.display = 'none';
        }
        else {
            document.getElementById(divId).style.display = 'block';
        }
    }
}

function ShowAgentDiv(tabId, divId, tabStorage, divStorage) {
    HideAgentDivs();
    if (document.getElementById(divId))
        document.getElementById(divId).style.display = 'block';

    //reset all tabs to inactive
    SetTabClass('tabBasicInfo', 'agentInActiveTab');
    SetTabClass('tabPhone', 'agentInActiveTab');
    SetTabClass('tabTestimonial', 'agentInActiveTab');
    SetTabClass('tabURL', 'agentInActiveTab');

    //set current tab to active
    SetTabClass(tabId, 'agentActiveTab');

    if (document.getElementById(tabStorage))
        document.getElementById(tabStorage).innerText = tabId;

    if (document.getElementById(divStorage))
        document.getElementById(divStorage).innerText = divId;

}

function HideAgentDivs() {
    if (document.getElementById('divBasicInfo'))
        document.getElementById('divBasicInfo').style.display = 'none';

    if (document.getElementById('divPhone'))
        document.getElementById('divPhone').style.display = 'none';

    if (document.getElementById('divTestimonial'))
        document.getElementById('divTestimonial').style.display = 'none';

    if (document.getElementById('divURL'))
        document.getElementById('divURL').style.display = 'none';

}


function SetTabClass(tabId, className) {
    var tab = document.getElementById(tabId);
    if (tab) {
        var attributeNode = tab.getAttributeNode('class');
        if (attributeNode) {
            attributeNode.value = className;
        }
        else {
            tab.setAttribute("class", className);
        }
    }
}

function HideAgentPicture(elementId) {
    if (document.getElementById(elementId)) {
        document.getElementById(elementId).style.visibility = 'hidden';
    }
}

function ShowAgentPicture(event, elementId, detail) {
    popup(event, elementId, detail);
}

function HideControl(controlId) {
    if (document.getElementById(controlId)) {
        document.getElementById(controlId).style.visibility = 'hidden';
    }
}


function AddDestinationAddress(address, chkboxID) {

    var chkBx = document.getElementById(chkboxID);
    var txtAdd = document.getElementById('txtAddresses');

    if (txtAdd && chkBx) {

        if (chkBx.checked) {
            if (txtAdd.value != '') {
                txtAdd.value = txtAdd.value + ' to:' + address;
            }
            else {
                txtAdd.value = address;
            }
        }
        else {
            txtAdd.value = txtAdd.value.replace(' to:' + address, '');
            txtAdd.value = txtAdd.value.replace('to:' + address, '');
            txtAdd.value = txtAdd.value.replace(address + ' to:', '');
            txtAdd.value = txtAdd.value.replace(address, '');
        }
    }
}

function MapDirections() {
    var txtAdd = document.getElementById('txtAddresses');
    if (txtAdd && txtAdd.value!='') {
        var url = "http://maps.google.com/maps?hl=en&z=15&saddr=WI" + "&daddr=" + txtAdd.value;
        window.open(url, 'Directions');//, 'height=800px, width=850px;resizable=1;scrollbars=1;location=1');
    }

}
