/*
$Date: 2010-07-30 12:46:10 -0700 (Fri, 30 Jul 2010) $
$Author: doug $
*/

browserName = navigator.appName;
browserVer  = parseInt(navigator.appVersion);

// may return an array of elements if there are several with the same NAME in a form
function domElement(id) {
    var el;
    if (document.getElementById) {
        // this will not ever return an array... just don't name two things with the same id
        el = document.getElementById(id);
    } else if (document.all) {
        el = document.all[id];
    }
    if (el && el.id == id) {
        return el;
    }

    // attempt to look through forms for fields where element NAME = id
    var els = new Array();
    for (var i = 0; i < document.forms.length; i++) {
        if (document.forms[i][id]) {
            if (document.forms[i][id].length) {
                for (var j = 0; j < document.forms[i][id].length; j++) {
                    els.push(document.forms[i][id][j]);
                }
            } else {
                els.push(document.forms[i][id]);
            }
        }
    }
    if (els.length == 1) {
        return els[0];
    } else if (els.length) {
        return els;
    }

    return undefined;
}

// Use this instead of window.onload = ...
function addOnload(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function() {
            if (oldonload)
              oldonload();
            return func();
        }
    }
}

function addOnBeforeUnload(func) {
    var oldOnBeforeUnload = window.onbeforeunload;
    if (typeof window.onbeforeunload != 'function') {
        window.onbeforeunload = func;
    }
    else {
        window.onbeforeunload = function() {
            if (oldOnBeforeUnload) {
                var result = oldOnBeforeUnload();
                if (result) return result;
            }
            return func();
        }
    }
}

function sortList (ul) {

    var clone = ul.cloneNode(0);

    var lis = ul.getElementsByTagName('li');
    var max = lis.length;
    var items = [];

    for ( var i = 0; i < max; i++ ) {
        items.push( lis[i] );
    }

    items.sort(
        function ( a, b ) { 
            var a_lc = a.innerHTML.toLowerCase();
            var b_lc = b.innerHTML.toLowerCase();
            if ( a_lc < b_lc ) return -1;
            if ( a_lc > b_lc ) return 1;
            return 0;
        }
    );

    for ( i = 0; i < max; i++ ) {
        clone.appendChild( items[i] );
    }

    ul.parentNode.replaceChild( clone, ul );
}

// for alternate navigation in side bar
function toggleNav(el) {

    var mytds = '';
    //var myexpand = document.getElementById(el + "-expand");

    mytds = document.getElementById("alt_" + el);
    //if( !mytds.style.display || mytds.style.display == "none" ) {
    if(mytds) {
        if(document.all && !window.opera) {
            mytds.style.display = "block";
        }
        else {
            mytds.style.display = "table-cell";
        }
    }
    //myexpand.innerHTML= "^";
    //} else {
        //mytds.style.display = "none";
        //myexpand.innerHTML= "+";
    //}
}

function swapClass(element, newClass)
{
    element.className = newClass;
}

function populateDatetimeDefaults(type)
{
    if (!type) return;

    var days;
    if ( type == 'star' ) {
        days = new Array( 0, 1, 2, 3, 4, 5, 6 );

    }
    else if ( type == 'm_f' ) {
        days = new Array( 1, 2, 3, 4, 5 );

    }
    else if ( type == 'weekend' ) {
        days = new Array( 0, 6 );

    }
    else {
        return;
    }

    var i;
    var time_attribs = new Array( 'hour', 'min' );
    var new_start_time_selections = new Array(time_attribs.length);
    var new_end_time_selections   = new Array(time_attribs.length);
    
    for ( i = 0; i < time_attribs.length; i++ ) {
        var tmp_start_time = domElement(type + '_start_time_' + time_attribs[i]);
        var tmp_end_time   = domElement(type + '_end_time_' + time_attribs[i]);

        new_start_time_selections[i] = tmp_start_time.selectedIndex;
        new_end_time_selections[i]   = tmp_end_time.selectedIndex;
    }

    for ( i = 0; i < days.length; i++ ) {
        var check_element = domElement( 'check_' + days[i] + '_on' );
        check_element.checked = true;
        var j;
        for ( j = 0; j < time_attribs.length; j++ ) {
            // set start time time attributes
            var start_time_element = domElement( 'start_time_' + days[i] + '_' + time_attribs[j] );
            start_time_element.selectedIndex = new_start_time_selections[j];

            // set end time time attributes
            var end_time_element = domElement( 'end_time_' + days[i] + '_' + time_attribs[j] );
            end_time_element.selectedIndex = new_end_time_selections[j];
        }
    }
    return;
}

function contactToggleRequired(name)
{
    var disp = 'none';
    var country = domElement(name + "_country");
    if (!country)
        return;

    if (country.options[country.selectedIndex].value == 'US')
        disp = 'inline';

    var element = domElement(name + "_state_star");
    if (element)
        element.style.display = disp;
    element = domElement(name + "_zip_star");
    if (element)
        element.style.display = disp;

}

function datetimeToggleInputs(name)
{
    var type = domElement(name + "_type");
    if (!(type && type.length == 2 && type[0].type == 'radio' && type[1].type == 'radio'))
        return;

    var selectArray = new Array("month", "day", "year", "hour", "minute", "ampm");
    var disabled = false;
    var element;

    if ((type[0].checked && type[0].value == "datetime_select") || (type[1].checked && type[1].value == "datetime_select"))
        disabled = true;

    for(i=0; i<selectArray.length; i++) {
        element = domElement(name + "_" + selectArray[i]);
        if (element) {
            if (element.length) {
                element[0].parentNode.disabled = !disabled;
            } else {
                element.disabled = !disabled;
            }
        }
    }

    element = domElement(name + "_enter_date");
    if (element) element.disabled = disabled;
}

function clickclear(thisfield, defaulttext, color) {
    if (thisfield.value == defaulttext) {
        thisfield.value = "";
        //if (!color) {
        //  color = "000000";
        //}
        //thisfield.style.color = "#" + color;
    }
}

function clickrecall(thisfield, defaulttext, color) {
    if (thisfield.value == "") {
        thisfield.value = defaulttext;
        //if (!color) {
        //  color = "cccccc";
        //}
        //thisfield.style.color = "#" + color;
    }
}

////////////////////////////////////////////////////////////////////
// Chooser functions
////////////////////////////////////////////////////////////////////
function chooserMove(id, src, dst)
{
    _chooserMove(id, src, dst);
    _chooserUpdateHidden(id);
}

function chooserMove2(myname, id, src, dst)
{
    _chooserMove(id, src, dst);
    _chooserUpdateHidden2(myname, id);
}

function _chooserMove(id, src, dst)
{
    var srcEl = domElement(id + src);
    var dstEl = domElement(id + dst);

    for (i = 0; i < srcEl.options.length; i++) {
        var opt = srcEl.options[i];
        if (opt.selected && !opt.disabled) {
            dstEl.disabled = '';

            var temp = new Option;
            temp.text = opt.text;
            temp.value = opt.value;

            if (dstEl.options.length == 1 && dstEl.options[0].text == '-none-') {
                dstEl.options[0] = temp;
            } else {
                dstEl.options[dstEl.options.length] = temp;
            }

            srcEl.options[i] = null;
            i--;
        }
    }
    if (srcEl.options.length == 0) {
        var temp = new Option;
        temp.text = '-none-';
        temp.disabled = 'disabled';
        temp.value = '';
        srcEl.options[0] = temp;
        srcEl.disabled = 'disabled';
    }
}

function _chooserUpdateHidden(id) {
    var hidEl = domElement(id);
    var retEl = domElement(id + '_dst');
    hidEl.value = "";

    for (i = 0; i < retEl.options.length - 1; i++) {
        hidEl.value += '"' + retEl.options[i].value + '",';
    }
    if (retEl.options.length && !retEl.options[retEl.options.length-1].disabled) {
        hidEl.value += '"' + retEl.options[retEl.options.length-1].value + '"';
    }
}

function _chooserUpdateHidden2(myname, id) {
    var container = domElement(id + '_chosen');
    var dest = domElement(id + '_dst');
    container.innerHTML = '';

    for (i = 0; i < dest.options.length; i++) {
        if (!dest.options[i].disabled) {
            container.innerHTML += '<input type="hidden" name="' + myname + '" value="' + dest.options[i].value + '" />';
            //var inp = document.createElement('INPUT');
            //inp.type = 'hidden';
            //inp.value = dest.options[i].value;
            //inp.name = myname;
            //container.appendChild(inp);
        }
    }
}

function chooserMoveUp(id, dst)
{
    _chooserMoveUp(id, dst);
    _chooserUpdateHidden(id);
}

function chooserMoveUp2(myname, id, dst)
{
    _chooserMoveUp(id, dst);
    _chooserUpdateHidden2(myname, id);
}

function _chooserMoveUp(id, dst)
{
    var dstEl = domElement(id + dst);

    for (i = 1; i < dstEl.options.length; i++) {
        var opt1 = dstEl.options[i-1];
        var opt2 = dstEl.options[i];
        if (opt2.selected && !opt1.selected) {
            var temp_text = opt2.text;
            var temp_value = opt2.value;
            opt2.text = opt1.text;
            opt2.value = opt1.value;
            opt2.selected = opt1.selected;
            opt1.text = temp_text;
            opt1.value = temp_value;
            opt1.selected = true;
        }
    }
}

function chooserMoveDown(id, dst)
{
    _chooserMoveDown(id, dst);
    _chooserUpdateHidden(id);
}

function chooserMoveDown2(myname, id, dst)
{
    _chooserMoveDown(id, dst);
    _chooserUpdateHidden2(myname, id);
}

function _chooserMoveDown(id, dst)
{
    var dstEl = domElement(id + dst);

    for (i = dstEl.options.length - 2; i >= 0; i--) {
        var opt1 = dstEl.options[i+1];
        var opt2 = dstEl.options[i];
        if (opt2.selected && !opt1.selected) {
            var temp_text = opt2.text;
            var temp_value = opt2.value;
            opt2.text = opt1.text;
            opt2.value = opt1.value;
            opt2.selected = opt1.selected;
            opt1.text = temp_text;
            opt1.value = temp_value;
            opt1.selected = true;
        }
    }
}

////////////////////////////////////////////////////////////////////
// Popups
////////////////////////////////////////////////////////////////////
function click_to_call(phone_number, extension)
{
    if(confirm("Do you wish to make a connection to " + phone_number + " from extension " + extension + "?")) {
        var myWindow = null;
        myWindow = window.open("","",'toolbar=no, width=400, height=300');
        myWindow.location.replace("/hr/click_to_call?phone_number=" + phone_number + "&extension=" + extension);
    }
}

function open_help_window(url)
{
    helpwindow = window.open(url,'helpwindow','height=500,width=550,scrollbars=no,menubar=no,resizable=yes');
}

function info_popup(mytext,scroll,sid,width,height)
{
    var extra = '';
    if (scroll == 1)
        extra = ",scrollbars=yes";

    var myWindow = null;
    myWindow = window.open("", "", 'toolbar=0,status=0,resizable=1,width='+width+',height='+height+extra);
    myWindow.document.open();
    myWindow.document.writeln('<html><head>');
    myWindow.document.writeln(' <link rel="stylesheet" href="/themes/base.css" type="text/css" />');
    myWindow.document.writeln(' <link rel="stylesheet" href="/themes/blueyellow/base.css" type="text/css" />');
    myWindow.document.writeln(' <link rel="stylesheet" href="/themes/small.css" type="text/css" />');
    myWindow.document.writeln(' <script language="javascript" type="text/javascript" /><!--');
    myWindow.document.writeln(' var sid = "' + sid + '";');
    myWindow.document.writeln(' // --></script>');
    myWindow.document.writeln('</head>');
    myWindow.document.writeln('<body class="info' + '_popup">');
    myWindow.document.writeln('<table><tr><td>');
    mytext = mytext.replace(/<br \/>/gi, '<br />\n');
    myWindow.document.writeln(mytext);
    myWindow.document.writeln('</td></tr>');
    //myWindow.document.writeln('<tr><td><a href="javascript:window.close()">Close this window</a></td></tr>');
    myWindow.document.writeln('</table>');
    myWindow.document.writeln('</body></html>');
    myWindow.document.close();
}

function launch_chat_support(brand,loginname,loginemail) {
    var branding = 
        brand == '1'   ? '&websiteid=126&departmentid=4816' : //tn 
        brand == '2'   ? '&websiteid=125&departmentid=4819' : //dd 
        brand == '4'   ? '&websiteid=125&departmentid=4819' : //dd 
        brand == '586' ? '&websiteid=124&departmentid=4815' : //phone.com
                         '&websiteid=127&departmentid=4822';  //domainsupport
    
    if (typeof(loginname) == 'undefined')
        loginname = '';

    if (typeof(loginemail) == 'undefined')
        loginemail = '';

    var request_url = 'https://www.websitealive5.com/4245/rRouter.asp?groupid=4245'
        + branding
        + '&loginname=' + loginname
        + '&loginemail=' + loginemail
        + '&dl=' + escape(document.location.href);

    newwin = window.open(request_url, 'unique', 'scrollbars=no,menubar=no,resizable=0,location=no,screenX=50,screenY=100,width=450,height=350');
    newwin.focus();
}

function launch_chat_support_phplive(brand) {

    var deptid = 
        brand == '1' ? 1 :   //tn 
        brand == '2' ? 2 :   //dd 
        brand == '4' ? 2 :   //dd 
        brand == '586' ? 3 : //phone.com
        4;                   //domainsupport

    var theme = 
        brand == '1' ? 'tierranet' :
        brand == '2' ? 'domaindiscover' :
        brand == '4' ? 'domaindiscover' :
        brand == '586' ? 'phonecom' :
        'default';
    
    var url = "https://www.serverchat.com";
    var request_url = url + "/request.php?l=administrator&x=1&theme=" + theme + "&deptid= " + deptid + "&pagex=";

    newwin = window.open(request_url, 'unique', 'scrollbars=no,menubar=no,resizable=0,location=no,screenX=50,screenY=100,width=450,height=350');
    newwin.focus();
}

function copy_clip(mytext)
{
    if (window.clipboardData)
        // IE
        window.clipboardData.setData("Text", mytext);
    else// if (window.netscape)
    {
        window.open('x-clipboard:' + mytext);
        return;
        var copyDom = domElement('_copy_dom');
        //if (! copyDom) {
        //    window.document.writeln('<textarea name="_copy_dom" id="_copy_dom" disabled="disabled" style="display: none;"></textarea>');
        //    copyDom = domElement('_copy_dom');
        //}
        alert(mytext);
        if (copyDom) {
            copyDom.style.display = 'block'
            copyDom.disabled = false;
            copyDom.innerHTML = mytext;
            copyDom.select();
            copyDom.focus();
            //alert('Wahoo??');
            //copyDom.style.display = 'none'
        } else {
            alert('doh??');
        }
        //netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
        //var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        //if (!clip) return;
        //var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        //if (!trans) return;
        //trans.addDataFlavor('text/unicode');
        //var str = new Object();
        //var len = new Object();
        //var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
        //var copytext=mytext;
        //str.data=copytext;
        //trans.setTransferData("text/unicode",str,copytext.length*2);
        //var clipid=Components.interfaces.nsIClipboard;
        //if (!clip) return false;
        //clip.setData(trans,null,clipid.kGlobalClipboard);
    }
    //alert("Following info was copied to your clipboard:\n\n" + mytext);
    //return false;
}


////////////////////////////////////////////////////////////////////
// better alt text (and better than overdiv too!)
// original code by DDM
//
// to use, do this:

// <span onmouseover="alt(event, 'alt text');" onmouseout="noalt();">this should have alt text!</span>
////////////////////////////////////////////////////////////////////
function alt(evt, text) {
    clearto();
    if (window.event) {evt = window.event}
    var xpos = evt.clientX + getBody().scrollLeft;
    var ypos = evt.clientY + getBody().scrollTop;

    getBody().appendChild(getAltSpan(xpos, ypos, text));
}
function noalt() {
    to = setTimeout(closeAlt, 500);
}

var altspan;
var body;
var to;
function getBody() {
    if (!body) {body = document.getElementsByTagName('BODY')[0];}
    return body;
}
function getAltSpan(x, y, text) {
    if (!altspan) {
        altspan = document.createElement('SPAN');
        altspan.className = 'alt_text';
        altspan.style.position = 'absolute';
        altspan.style.background = '#f7f7f7';
        altspan.onmouseover = clearto;
        altspan.onmouseout = noalt;
    }
    altspan.style.left = x + 'px';
    altspan.style.top = y + 'px';
    altspan.innerHTML = text;
    return altspan;
}
function clearto() {
    if (to) {clearTimeout(to); to = '';}
}
function closeAlt() {
    if (altspan) {getBody().removeChild(altspan)}
}

function textAlt(spanObj, evt, text)
{
    spanObj.oldColor              = spanObj.style.color;
    spanObj.oldBackgroundColor    = spanObj.style.backgroundColor;
    spanObj.style.color           = '#000000';
    spanObj.style.backgroundColor = '#a0dceb';
    alt(evt, text);
}

function textNoalt(spanObj)
{
    spanObj.style.color           = spanObj.oldColor;
    spanObj.style.backgroundColor = spanObj.oldBackgroundColor;
    noalt();
}

function setActiveColorScheme(title)
{
    if (title && document.getElementsByTagName) {
        var index, style;
        for(var index=0; (style = document.getElementsByTagName('link')[index]); index++) {
            if(style.getAttribute('rel').indexOf('style') != -1 && style.getAttribute('title')) {
                if (style.getAttribute('title') == title)
                    style.disabled = false;
                else
                    style.disabled = true;
            }
        }
    }
}

function setActiveFontSize(title)
{
    if (title && document.getElementsByTagName) {
        var index, style;
        for(var index=0; (style = document.getElementsByTagName('link')[index]); index++) {
            if(style.getAttribute('rel').indexOf('style') != -1 && style.getAttribute('title')) {
                if (style.getAttribute('title') == title)
                    style.disabled = false;
                else
                    style.disabled = true;
            }
        }
    }
}

function showLastTab(showthis)
{
    var lasttab = getCookie("lasttab");
    if(showthis) { lasttab = showthis; }
    if(lasttab && typeof(is_admin) != 'undefined') {
        toggleActiveTab(lasttab);
    } else {
        toggleActiveTab('general_tab');
    }
}

function showLastTab_flipped(showthis)
{
    var lasttab = getCookie("lasttab");
    if(showthis) { lasttab = showthis; }
    if(lasttab && typeof(is_admin) != 'undefined') {
        toggleActiveTab_flipped(lasttab);
    } else {
        toggleActiveTab_flipped('general_tab');
    }
}

// shows the requested tab (obj) e.g. general_tab, admin_tab
function toggleActiveTab(obj) {
    // list of all the tabs. Needs to set all of them to none
    if(domElement('general_tab')) { domElement('general_tab').style.display = 'none'; }
    if(domElement('admin_tab')) { domElement('admin_tab').style.display = 'none'; }
    if(domElement('domains_tab')) { domElement('domains_tab').style.display = 'none'; }

    // change image of selected tab to selected image, and set all others to non-selected images
    if(obj == 'admin_tab') {
        if(domElement('admin_tab_img')) { domElement('admin_tab_img').src = '/images/tabs/admin_tab_selected.gif'; }
        if(domElement('general_tab_img')) { domElement('general_tab_img').src = '/images/tabs/general_tab.gif'; }
        if(domElement('domains_tab_img')) { domElement('domains_tab_img').src = '/images/tabs/domains_tab.gif'; }
    }
    else if(obj == 'general_tab') {
        if(domElement('general_tab_img')) { domElement('general_tab_img').src = '/images/tabs/general_tab_selected.gif'; }
        if(domElement('admin_tab_img')) { domElement('admin_tab_img').src = '/images/tabs/admin_tab.gif'; }
        if(domElement('domains_tab_img')) { domElement('domains_tab_img').src = '/images/tabs/domains_tab.gif'; }
    }
    else if(obj == 'domains_tab') {
        if(domElement('domains_tab_img')) { domElement('domains_tab_img').src = '/images/tabs/domains_tab_selected.gif'; }
        if(domElement('general_tab_img')) { domElement('general_tab_img').src = '/images/tabs/general_tab.gif'; }
        if(domElement('admin_tab_img')) { domElement('admin_tab_img').src = '/images/tabs/admin_tab.gif'; }
    }

    // show the tab you want to show
    var element = domElement(obj)
    if (element) {
        if (typeof(is_admin) != 'undefined') {
            setCookie("lasttab", obj,'' ,"/");
        }
        element.style.display = 'block'
    }
}
// shows the requested tab (obj) e.g. general_tab, admin_tab when side_bar is on left
function toggleActiveTab_flipped(obj) {
    // list of all the tabs. Needs to set all of them to none
    if(domElement('general_tab')) { domElement('general_tab').style.display = 'none'; }
    if(domElement('admin_tab')) { domElement('admin_tab').style.display = 'none'; }
    if(domElement('domains_tab')) { domElement('domains_tab').style.display = 'none'; }

    // change image of selected tab to selected image, and set all others to non-selected images
    if(obj == 'admin_tab') {
        if(domElement('admin_tab_img')) { domElement('admin_tab_img').src = '/images/tabs/admin_tab_selected_flipped.gif'; }
        if(domElement('general_tab_img')) { domElement('general_tab_img').src = '/images/tabs/general_tab_flipped.gif'; }
        if(domElement('domains_tab_img')) { domElement('domains_tab_img').src = '/images/tabs/domains_tab_flipped.gif'; }
    }
    else if(obj == 'general_tab') {
        if(domElement('general_tab_img')) { domElement('general_tab_img').src = '/images/tabs/general_tab_selected_flipped.gif'; }
        if(domElement('admin_tab_img')) { domElement('admin_tab_img').src = '/images/tabs/admin_tab_flipped.gif'; }
        if(domElement('domains_tab_img')) { domElement('domains_tab_img').src = '/images/tabs/domains_tab_flipped.gif'; }
    }
    else if(obj == 'domains_tab') {
        if(domElement('domains_tab_img')) { domElement('domains_tab_img').src = '/images/tabs/domains_tab_selected_flipped.gif'; }
        if(domElement('admin_tab_img')) { domElement('admin_tab_img').src = '/images/tabs/admin_tab_flipped.gif'; }
        if(domElement('general_tab_img')) { domElement('general_tab_img').src = '/images/tabs/general_tab_flipped.gif'; }
    }

    // show the tab you want to show
    var element = domElement(obj)
    if (element) {
        if (typeof(is_admin) != 'undefined') {
            setCookie("lasttab", obj,'' ,"/");
        }
        element.style.display = 'block'
    }
}

// * Sets a Cookie with the given name and value.
// *
// * name       Name of the cookie
// * value      Value of the cookie
// * [expires]  Expiration date of the cookie (default: end of current session)
// * [path]     Path where the cookie is valid (default: path of calling document)
// * [domain]   Domain where the cookie is valid
// *              (default: domain of calling document)
// * [secure]   Boolean value indicating if the cookie transmission requires a
// *              secure transmission

function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

// * Gets the value of the specified cookie.
// *
// * name  Name of the desired cookie.
// *
// * Returns a string containing value of specified cookie,
// *   or null if cookie does not exist.

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function wizardStep(step)
{
    domElement('_jump_step').value = step;
    document.forms['_wizard'].submit();
}

function toggleDiv (divID, display)
{
    var dom = domElement(divID);
    if (! dom) {
        //alert(divID+"\\n"+display+"\\nError: no dom!");
        return;
    } else if (dom.tagName != 'DIV') {
        //alert(divID+"\\n"+display+"\\nError: not div! ("+dom.tagName+")");
        return;
    }

    if (! display) {
        if (dom.style.display == 'none')
            display = 'block';
        else
            display = 'none';
    }

    var disabled = 0;
    if (display == 'none')
        disabled = 1;

    dom.style.display = display;
    dom.disabled = disabled;

    var sub;
    for (var i=0; i < dom.childNodes.length; i++) {
        sub = dom.childNodes[i];
        if (sub.nodeName == 'INPUT' || sub.nodeName == 'SELECT' || sub.nodeName == 'TEXTAREA')
            sub.disabled = disabled;
    }
}

function toggleTr (trID)
{
    var row_counter = 1;
    var myelement;
    var myimg = domElement(trID + '_img');
    var myrow = domElement(trID);
    // if src has plus in it
    if(/plus/.test(myimg.src)) {
        myimg.src= '/images/domains/minus.gif';
        myrow.style.borderTopColor = '#cccccc';
        myrow.style.borderTopWidth = '1px';
        myrow.style.borderTopStyle = 'solid';
    } else {
        myimg.src= '/images/domains/plus.gif';
    }

    while(myelement = domElement(trID + '_' + row_counter)) {
        //var nameelement = domElement(trID + '-featurename');
        var child;
        if(!myelement.style.display || myelement.style.display != 'none' ) {
            myelement.style.display = 'none';
        } else {
            if(document.all && !window.opera) {
                myelement.style.display = 'inline';
            } else {
                myelement.style.display = 'table-row';
            }
        }

        // why is this here?
        // for (var i=0; i < myelement.childNodes.length; i++) {
        //     child = myelement.childNodes[i];
        //     if(child.nodeType == 1) {
        //         if( !child.style.display || child.style.display != 'none' ) {
        //             child.style.display = 'none'
        //             //nameelement.style.fontWeight = 'bold';
        //         } else {
        //             if(document.all) {
        //                 child.style.display = 'inline';
        //             } else {
        //                 child.style.display = 'table-cell';
        //                 //nameelement.style.fontWeight = 'normal';
        //             }
        //         }
        //     }
        // }
        row_counter++;
    }
}

function toggleOptions ()
{
    var row_counter = 1;
    var myelement;
    var myimg = domElement('options_img');
    // if src has plus in it
    if(/down/.test(myimg.src)) {
        myimg.src= "/images/lang/group_up.gif";
    } else {
        myimg.src= "/images/lang/group_down.gif";
    }
    //for (var j=1; j<5; j++) {
        //var myelement = domElement('options_' + j);
    while(myelement = domElement("options_" + row_counter)) {
        if(!myelement.style.display || myelement.style.display != 'none' ) {
            myelement.style.display = 'none';
        } else {
            if(document.all && !window.opera) {
                myelement.style.display = 'inline';
            } else {
                myelement.style.display = 'table-row';
            }
        }
        for (var i=0; i < myelement.childNodes.length; i++) {
            var child = myelement.childNodes[i];
            if(child.nodeType == 1) {
                if( !child.style.display || child.style.display != "none" ) {
                    child.style.display = "none"
                } else {
                    if(document.all && !window.opera) {
                        child.style.display = 'inline';
                    } else {
                        child.style.display = "table-cell";
                    }
                }
            }
        }
        row_counter++;
    }
}

function pause(numberMillis) {
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    while (true) {
    now = new Date();
    if (now.getTime() > exitTime)
        return;
    }
}

////////////////////////////////////////////////////////////////////
// payment functions
////////////////////////////////////////////////////////////////////

function paymentImageSwap(ccNumber)
{
    if (browserVer >= 3) {
        if (! ccNumber)
            ccNumber = "4";
        switch(parseInt(ccNumber.match(/^[3456]/))) {
        case 3:
            popup_image = "amex";
            popup_text  = "For an American Express card, enter the 4 digits which are printed to the right of the imprinted card number on the front of your credit card.";
            break;
        case 4:
            popup_image = "visa";
            popup_text  = "For a Visa card, enter the last 3 digits of the number printed on the back of your credit card in the signature strip.";
            break;
        case 5:
            popup_image = "mc";
            popup_text  = "For a MasterCard, enter the last 3 digits of the number printed on the back of your credit card in the signature strip.";
            break;
        case 6:
            popup_image = "discover";
            popup_text  = "For a Discover card, enter the last 3 digits of the number printed on the back of your credit card in the signature strip.";
            break;
        }
    }
}

function paymentOnLoad (name)
{
    toggleDiv(name + '_custom_amount_div', 'none');

    toggleDiv(name + '_receive_check_div', 'none');
    toggleDiv(name + '_wire_transfer_div', 'none');
    toggleDiv(name + '_miscellaneous_div', 'none');
    toggleDiv(name + '_cc_div', 'none');
    toggleDiv(name + '_ec_div', 'none');

    toggleDiv(name + '_admin_cc_contact_div', 'none');
    toggleDiv(name + '_billing_cc_contact_div', 'none');
    toggleDiv(name + '_existing_cc_contact_div', 'none');
    toggleDiv(name + '_custom_cc_contact_div', 'none');

    toggleDiv(name + '_admin_ec_contact_div', 'none');
    toggleDiv(name + '_billing_ec_contact_div', 'none');
    toggleDiv(name + '_existing_ec_contact_div', 'none');
    toggleDiv(name + '_custom_ec_contact_div', 'none');

    paymentToggleAmount(name);
    paymentToggleMethod(name);
}

var paymentSelectedAmount = new Array();
function paymentToggleAmount (name, value)
{
    if (! value) {
        var dom = domElement(name + '_amount');
        if (! dom)
            return;

        if (! dom.length) {
            value = dom.value
        } else {
            for (i = 0; i < dom.length; i++) {
                if (dom[i].checked) {
                    value = dom[i].value;
                    break;
                }
            }
        }
    }

    if (paymentSelectedAmount[name])
        toggleDiv(name + '_' + paymentSelectedAmount[name] + '_amount_div');

    paymentSelectedAmount[name] = value;
    toggleDiv(name + '_' + paymentSelectedAmount[name] + '_amount_div');
}

var paymentSelectedMethod = new Array();
function paymentToggleMethod (name, value)
{
    if (! value) {
        var dom = domElement(name + '_method');
        if (! dom)
            return;

        if (! dom.length) {
            value = dom.value
        } else {
            for (i = 0; i < dom.length; i++) {
                if (dom[i].checked) {
                    value = dom[i].value;
                    break;
                }
            }
        }
    }

    if (paymentSelectedMethod[name])
        toggleDiv(name + '_' + paymentSelectedMethod[name] + '_div');

    paymentSelectedMethod[name] = value;
    toggleDiv(name + '_' + paymentSelectedMethod[name] + '_div');

    switch (value) {
    case 'cc':
        paymentPopupImageSwap(name);
        paymentToggleCCContact(name);
        break;
    case 'ec':
        paymentToggleECType(name);
        paymentToggleECContact(name);
        break;
    }
}

var paymentSelectedECType = new Array();
function paymentToggleECType (name, value)
{
    if (! value) {
        var dom = domElement(name + '_ec_type');
        if (! dom)
            return;
        value = dom.options[dom.selectedIndex].value;
    }

    if (paymentSelectedECType[name])
        toggleDiv(name + '_' + paymentSelectedECType[name] + '_div');
    paymentSelectedECType[name] = value;

    toggleDiv(name + '_' + paymentSelectedECType[name] + '_div');
}

var paymentSelectedCCContact = new Array();
function paymentToggleCCContact (name, value)
{
    if (! value) {
        var dom = domElement(name + '_cc_contact');
        if (! dom)
            return;
        value = dom.options[dom.selectedIndex].value;
    }

    if (paymentSelectedCCContact[name])
        toggleDiv(name + '_' + paymentSelectedCCContact[name] + '_cc_contact_div');
    paymentSelectedCCContact[name] = value;

    toggleDiv(name + '_' + paymentSelectedCCContact[name] + '_cc_contact_div');
}

var paymentSelectedECContact = new Array();
function paymentToggleECContact (name, value)
{
    if (! value) {
        var dom = domElement(name + '_ec_contact');
        if (! dom)
            return;
        value = dom.options[dom.selectedIndex].value;
    }

    if (paymentSelectedECContact[name])
        toggleDiv(name + '_' + paymentSelectedECContact[name] + '_ec_contact_div');
    paymentSelectedECContact[name] = value;

    toggleDiv(name + '_' + paymentSelectedECContact[name] + '_ec_contact_div');
}

var paymentPopupImage = new Array();
var paymentPopupText  = new Array();
function paymentPopupImageSwap (name, value)
{
    if (browserVer >= 3) {
        if (! value) {
            var dom = domElement(name + '_card_type');
            if (! dom)
                return;
            value = dom.options[dom.selectedIndex].value;
        }

        switch(parseInt(value.match(/^[3456]/))) {
        case 3:
            paymentPopupImage[name] = "amex";
            paymentPopupText[name]  = "For an American Express card, enter the 4 digits which are printed to the right of the imprinted card number on the front of your credit card.";
            break;
        case 4:
            paymentPopupImage[name] = "visa";
            paymentPopupText[name]  = "For a Visa card, enter the last 3 digits of the number printed on the back of your credit card in the signature strip.";
            break;
        case 5:
            paymentPopupImage[name] = "mc";
            paymentPopupText[name]  = "For a MasterCard, enter the last 3 digits of the number printed on the back of your credit card in the signature strip.";
            break;
        case 6:
            paymentPopupImage[name] = "discover";
            paymentPopupText[name]  = "For a Discover card, enter the last 3 digits of the number printed on the back of your credit card in the signature strip.";
            break;
        }
    }
}

////////////////////////////////////////////////////////////////////

function whoisValidationOnLoad (name)
{
    toggleDiv(name + '_phone_div', 'none');

    if (name == 'claim_type')
        toggleDiv(name + '_email_div', 'none');
    else if (name == 'final_attempt')
        toggleDiv(name + '_reason_div', 'none');

    whoisToggleAction(name);
}

function vasOnLoad (name)
{
    toggleDiv(name + '_http_div', 'none');
    toggleDiv(name + '_frame_div', 'none');
    toggleDiv(name + '_A_div', 'none');
    toggleDiv(name + '_one_page_div', 'none');

    vasToggleService(name);
}

function noticeOnLoad (name)
{
    toggleDiv(name + '_notice_id_div', 'none');
    toggleDiv(name + '_account_id_div', 'none');
    toggleDiv(name + '_account_username_div', 'none');
    toggleDiv(name + '_domain_div', 'none');

    noticeToggleSearch(name);
}

var whoisSelectedAction = new Array();
function whoisToggleAction (name, value)
{
    if (! value) {
        var dom = domElement(name);

        if (! dom)
            return;

        if (! dom.length) {
            value = dom.value
        } else {
            for (i = 0; i < dom.length; i++) {
                if (dom[i].checked) {
                    value = dom[i].value;
                    break;
                }
            }
        }
    }
    if (whoisSelectedAction[name])
        toggleDiv(name + '_' + whoisSelectedAction[name] + '_div');

    whoisSelectedAction[name] = value;
    toggleDiv(name + '_' + whoisSelectedAction[name] + '_div');
}

var noticeSelectedSearch = new Array();
function noticeToggleSearch (name, value) 
{
    if (! value) {
        var dom = domElement(name);

        if (! dom)
            return;

        if (! dom.length) {
            value = dom.value
        } else {
            for (i = 0; i < dom.length; i++) {
                if (dom[i].checked) {
                    value = dom[i].value;
                    break;
                }
            }
        }
    }
    if (noticeSelectedSearch[name]) 
        toggleDiv(name + '_' + noticeSelectedSearch[name] + '_div');

    noticeSelectedSearch[name] = value;
    toggleDiv(name + '_' + noticeSelectedSearch[name] + '_div');
}


function vasToggleContact (name, value)
{

    if (! value) {
        var dom = domElement(name);
        if (! dom)
            return;
        if (! dom.length) {
            value = dom.checked;
        } else {
            for (i = 0; i < dom.length; i++) {
                if (dom[i].checked) {
                    value = dom[i].checked;
                    break;
                }
            }
        }
    }

    if (value)
        toggleDiv(name + '_div', 'block');
    else
        toggleDiv(name + '_div', 'none');
}

var vasSelectedService = new Array();
function vasToggleService (name, value)
{
    if (! value) {
        var dom = domElement(name);

        if (! dom)
            return;

        if (! dom.length) {
            value = dom.value
        } else {
            for (i = 0; i < dom.length; i++) {
                if (dom[i].checked) {
                    value = dom[i].value;
                    break;
                }
            }
        }
    }

    if (vasSelectedService[name])
        toggleDiv(name + '_' + vasSelectedService[name] + '_div');
    vasSelectedService[name] = value;

    toggleDiv(name + '_' + vasSelectedService[name] + '_div');

    vasToggleContact('use_contact');
}

function swapOnePageLogo (name, imgname) {
    var dom = domElement(name);
    if (! dom)
        return;

    var img_dom = domElement(imgname);
    if (! img_dom)
        return;

    var imgpath = new Array(
        '/images/domains/disabled_template.gif',
        '/images/domains/layout_1_template.gif',
        '/images/domains/layout_2_template.gif',
        '/images/domains/no_layout_template.gif'
    );

    if (! dom.length) {
        img_dom.src = imgpath[0];
    } else {
        for (i = 0; i < dom.length; i++) {
            if (dom[i].checked) {
                img_dom.src = imgpath[i];
                break;
            }
        }
    }
}

function toggleCheckboxes (id, targetInput) {
    var checkall = domElement(id);
    if (!checkall)
        return;  

    if (!targetInput.length)
        return;

    for (i = 0; i < targetInput.length; i++)  {
        if ((checkall.checked  && !targetInput[i].checked) ||
            (!checkall.checked && targetInput[i].checked)) 
            targetInput[i].click();            
    }
    return;  
}

////////////////////////////////////////////////////////////////////
// javascript http get function!
////////////////////////////////////////////////////////////////////
//var xmlhttp = false;
//var xmlhttp_dest = '';

function getXmlHttpRequest() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        // Based on http://jibbering.com/2002/4/httprequest.html
        /*@cc_on @*/
        /*@if (@_jscript_version >= 5)
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                return new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                return null;
            }
        }
        @end @*/
    } else {
        return null;
    }
}

function ajax (url, func, method) {
    if ( typeof(method) != 'undefined' && method.toUpperCase() == 'POST' )
        return ajax_post(url, func);

    return ajax_get(url, func);
}

function ajax_post (url, func) {    

    var xmlhttp = getXmlHttpRequest();
    if (!xmlhttp) return;

    var url_n_qstr = url.split( '?' );
    url = url_n_qstr[0];
    var content = url_n_qstr.length > 1 ? url_n_qstr[1] : null;
    
    xmlhttp.open('POST', url, true);

    xmlhttp.setRequestHeader(
        'Content-Type',
        'application/x-www-form-urlencoded'
    );

    xmlhttp.onreadystatechange = function() {
        var rs = xmlhttp.readyState; 
        func(xmlhttp); 
        if (rs == 4) xmlhttp = null;
    };

    xmlhttp.send( content );

    return true;
}

function ajax_get (url, func) {    

    var xmlhttp = getXmlHttpRequest();
    if (!xmlhttp) return;

    xmlhttp.open('GET', url, true);

    xmlhttp.onreadystatechange = function() {
        var rs = xmlhttp.readyState; 
        func(xmlhttp); 
        if (rs == 4) xmlhttp = null;
    };

    xmlhttp.send(null);

    return true;
}

function http_get (url, obj) {
    var xmlhttp_dest = (typeof(obj) == 'string')
       ? domElement(obj)
       : obj;

    if (typeof(xmlhttp_dest) != 'object') return false;
    xmlhttp_dest.innerHTML = '<' + 'img src="/images/lang/icon_ajax_thinking.gif" height="16" width="16" alt="" />';

    ajax_get(url, function(req) {
        if (req.readyState == 4) {
            // 2xx: Successful
            if (req.status > 199 && req.status < 300) xmlhttp_dest.innerHTML = req.responseText;
            // 502: Proxied Resource Error (probably transient)
            else if (req.status == 502) return http_get(url, xmlhttp_dest);
            // Other abnormal condition
            else {
                xmlhttp_dest.innerHTML = '<' + 'div class="error">Server returned a non-okay response: ' + req.status + '<' + '/div>';
            }
        }
    });

    return true;
}

function http_update_children(parent, children) {
    var value = '';
    if (parent.value) {
        value = parent.value;
    } else if (parent.options) {
        value = parent.options[parent.selectedIndex].value;
    } else {
        return false;
    }

    var index = '';
    if (parent.name && parent.name.lastIndexOf(':') > -1) {
        index = '_' + parent.name.substring(parent.name.lastIndexOf(':') + 1);
    }

    for (var i = 0; i < children.length; i++) {
        var id = children[i];
        var url = window.location.pathname;
        url += sid + 'action=' + id + ';' + parent.name + '=' + value;
        http_get(url, id + index);
    }
}

// returns field1=value1;field2=value2;field3=value3;etc
function form_getify(formElement) {
    var url = '';

    var children = formElement.getElementsByTagName('INPUT');
    for (var i = 0; i < children.length; i++) {

        var type = children[i].type;

        if ( /submit|reset|image|button/.test(type) ) 
            continue;
        
        var value = '';
        if ( type == 'radio' || type == 'checkbox' ) {
            if (children[i].checked)
                value = children[i].value;
        }
        else {
            value = children[i].value;
        }

        if (value != '') {
            url += ';' + encodeURIComponent( children[i].name ) + '=' + encodeURIComponent(value);
        }
    }

    children = formElement.getElementsByTagName('SELECT');
    for (var i = 0; i < children.length; i++) {
        value = children[i].selectedIndex == -1 ? '' : children[i].options[children[i].selectedIndex].value;
        if (value != '') {
            url += ';' + encodeURIComponent( children[i].name ) + '=' + encodeURIComponent(value);
        }
    }

    children = formElement.getElementsByTagName('TEXTAREA');
    for ( var i = 0; i < children.length; i++ ) {
        if ( children[i].value ) 
            url += ';' + encodeURIComponent( children[i].name ) + '=' + encodeURIComponent( children[i].value );
    }

    return url.length > 0 ? url.substring(1) : '';
}

function http_submit(el, container) {
    // find form
    var formElement = el;
    while (formElement && formElement.tagName != 'FORM') {
        formElement = formElement.parentNode;
    }
    if (!formElement || formElement.tagName != 'FORM') {
        return false;
    }
    var url = formElement.action + ';ajax=1;' + el.name
        + '.x=1;' + el.name + '.y=1;' + form_getify(formElement);

    http_get(url, container);
}

function toggle_background_inputs(value) {

    // find value if value is not given by looping thru radio button and
    // finding checked input
    if ( !value ) {
        var entity_radio_array = domElement('action');
        for ( index in entity_radio_array ) {
            var entity_input_el = entity_radio_array[index];

            if ( entity_input_el.checked ) {
                value = entity_input_el.value;
                break;
            }
        }
    }

    var table_el = domElement('background_table');
    //var seen     = new Array();

    var container_id = new Array( 'tierranet1', 'tierranet2' );
    for ( index in container_id ) {
        var id = container_id[index];
        var container_el = domElement(id);

        if (container_el) {
            if ( value != id 
                && ( container_el.style.display == 'block' 
                    || !container_el.style.display 
                )
            ) {
                container_el.style.display = 'none';    

                //if ( container_el.style.display == 'block' ) {
                //    seen.push(container_el);
                //}
            }
            else if ( value == id 
                && ( container_el.style.display == 'none' 
                    || !container_el.style.display 
                )
            ) {
                container_el.style.display    = 'block';
                container_el.style.marginLeft = '25px';
                container_el.style.marginTop  = '10px';
                container_el.appendChild(table_el);
            }
        }
    }

    //if ( seen.length == 2 ) {
    //    var local_container_el = seen.pop();
    //    local_container_el.removeChild(table_el);        
    //}
    return;
}

////////////////////////////////////////////////////////////////////
// flash detection (do they have at least flash v6?)
////////////////////////////////////////////////////////////////////
function has_flash() {
    if (navigator.plugins && navigator.mimeTypes.length) {
        var x = navigator.plugins["Shockwave Flash"];
        if (x && x.description) {
            var fullversion = x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".");
            var majorversion = fullversion.split(".")[0];
            if (majorversion >= 6)
                return majorversion;
        }
    }
    else {
        // do minor version lookup in IE, but avoid fp6 crashing issues
        // see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
        try {
            var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.9");
            return 9;
        } catch(e) {}

        try {
            var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.8");
            return 8;
        } catch(e) {}

        try {
            var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
            return 7;
        } catch(e) {}

        try {
            var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
            return 6;
        } catch(e) {}
    }
    return 0;
}

function write_listen_link(url, obj) {
    if (typeof(obj) == 'string')
       obj = domElement(obj);

    if (!obj) {
        document.write(get_flash_listen_html(url));
    }
    else if (typeof(obj) == 'object') {
        obj.innerHTML = get_flash_listen_html(url);
    }
}

function get_flash_listen_html(url) {
    var html = '';
    var flash = has_flash();
    url = url.replace(/\?/, sid);
    if (flash) {
        html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="115" height="21" align="middle">';
        html += '<param name="allowScriptAccess" value="sameDomain" />';
        html += '<param name="movie" value="/html/flash/mp3_preview.swf" />';
        html += '<param name="quality" value="high" />';
        html += '<param name="bgcolor" value="#ffffff" />';
        html += '<param name="wmode" value="transparent" />';
        html += '<param name="flashvars" value="file=' + url + '">';
        html += '<embed src="/html/flash/mp3_preview.swf" quality="high" bgcolor="#ffffff" width="115" height="21" flashvars="file=' + url + '" align="top" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" />';
        html += '</object>';
    }
    else {
        html += '<table style="display:inline;"><tr><td><img alt="" src="/images/lang/icon_speaker.gif" width="16" height="22" /></td><td><a href="' + url + '">listen</a></td></tr></table>';
    }
    return html;
}

function get_domain_donkey_list() {
    var query_string = '';

    var page = domElement('page_selection');
    if (page) {
        var index = page.selectedIndex;
        query_string = 'page=' + page.options[index].value;
    }
    var sort = domElement('sort_method_selection');
    if (sort) {
        var index = sort.selectedIndex;
        if (query_string) {
            query_string += ';';
        }
        query_string += 'sort_method=' + sort.options[index].value;
    }
    var tld = domElement('tld_selection');
    if (tld) {
        var index = tld.selectedIndex;
        if (query_string) {
            query_string += ';';
        }
        query_string += 'tld=' + tld.options[index].value;
    }
    
    if ( ! query_string ) {
        query_string = 'page=1;tld=com;sort_method=domain';
    }

    http_fill_container( 'domain_container', query_string );
}

function refine_hourtracker_list() {
    var query_string = ''; 

    var status = document.getElementsByName('status');
    if (status) {
        var selected_status = new Array();
        for ( var i = 0; i < status.length; i++ ) {
            if ( status[i].checked )
                selected_status.push( status[i].value );
        }
        if ( selected_status.length ) 
            query_string += "status=" + selected_status.join(',');
    }
    
    var view = document.getElementsByName('view');
    if (view) {
        for ( var i = 0; i < view.length; i++ ) {
            if (view[i].checked) {
                if (query_string.length)
                    query_string += '&';

                query_string += 'view=' + view[i].value;
                break;
            }
        }
    }

    http_fill_hourtracker_list('month_link_container', 'rows_container', query_string);

    return false;
}

function http_fill_hourtracker_list(month_container_id, row_container_id, query_string) {
    if ( !query_string || !month_container_id || !row_container_id )
        return false;

    var month_container = domElement(month_container_id);
    if (   query_string.match(/month/) 
        || query_string.match(/my/) 
        || query_string.match(/everyone/) 
    ) {
        month_container.style.display = 'block';

        http_fill_container(row_container_id, query_string);
        http_fill_container(month_container_id, query_string);

    } else {
        month_container.style.display = 'none';

        http_fill_container(row_container_id, query_string);
    }
}

function http_fill_domain_list(account_id, container_id) {
    if ( !account_id || !container_id ) 
        return false;

    var query_string = 'id=' + account_id;
    http_fill_container( container_id, query_string );
}

function http_fill_container ( container_id, query_string ) {
    if ( !query_string || !container_id ) 
        return false;

    var url = window.location.pathname;
    url += sid + 'action=' + container_id + '&' + query_string;
    http_get(url, container_id);
}

function toggle_whois_data(linkElement,id) {
    if ( !id )
        return;
    
    var obj = domElement(id);
    if (obj) {
        obj.style.display = obj.style.display == 'none' 
            ?  'block' : 'none';
    
        linkElement.innerHTML = obj.style.display == 'none'
            ? '+expand'
            : '-collapse';

        http_fill_whois_data(id);
    }
    return;
}

function refresh_whois(id) {
    if ( !id )
        return;

    var obj = domElement(id);
    if (obj) {
        if ( obj.style.display == 'none' )
            obj.style.display = 'block';
    }
    http_fill_whois_data(id, 'refresh_flag=1');
    return; 
}

function http_fill_whois_data(id,additional_query_str) {
    if ( !id )
        return;

    var url = window.location.pathname;
    url += sid + 'action=whois_data&' + 'id=' + id;

    if ( additional_query_str ) 
        url += '&' + additional_query_str;

    http_get(url, id);

    return;
}

function toggle_legal_owner_inputs(parent_id,parent_form) {
    if ( !parent_id )
        return;

    var parentElement = domElement(parent_id);

    if ( !parentElement )
        return;

    for (i = 0; i < parent_form.elements.length; i++) {
        if (parent_form.elements[i].id == parent_id)
            continue;

        if ( !parentElement.value ) {
            parent_form.elements[i].disabled = true;
        } else {
            parent_form.elements[i].disabled = false;
        }
    }

    var update_button = domElement('process_update_legal_owner_button');
    if ( update_button ) {
        if ( !parentElement.value ) {
            update_button.disabled = true;
        } else {
            update_button.disabled = false;
        }
    }
}

////////////////////////////////////////////////////////////////////
// Language Management
////////////////////////////////////////////////////////////////////
function createImageUploadUI(prefix) {
    if (prefix) prefix += '_';
    var image_upload_row = document.getElementById(prefix + 'image_upload_row');
    var image_src_row = document.getElementById(prefix + 'image_src_row');
    if (image_upload_row && image_src_row) {
        image_upload_row.style.visibility = 'visible';
        image_upload_row.style.position = 'static';
        image_src_row.style.visibility = 'hidden';
        image_src_row.style.position = 'absolute';
    }
    var image_overwr_expl = document.getElementById('overwrite_explain');
    if (image_overwr_expl) {
        image_overwr_expl.style.visibility = 'visible';
        image_overwr_expl.style.position = 'static';
    }
    return false;
}

////////////////////////////////////////////////////////////////////
// Annoying "you've made changes" warning
////////////////////////////////////////////////////////////////////

function detectFormUpdatesAndWarn(formid) {
    var initialstate; // nice closure!
    var needtoconfirm = true;

    addOnload(function() {
        initialstate = form_getify(domElement(formid));
        domElement(formid).onsubmit = function() { needtoconfirm = false; };
    });

    addOnBeforeUnload(function() {
        if (!needtoconfirm)
            return;

        if (initialstate == form_getify(domElement(formid)))
            return;

        return 'Your unsaved changes will be lost if you continue.';
    });
}

/////////////////////////////////////
// For choosing your login question.
/////////////////////////////////////
function change_login_question() {
    var canned_question_input = domElement( 'canned_login_questions' );
    var question_input        = domElement( 'login_question' );
    var canned_question       = canned_question_input[canned_question_input.selectedIndex].innerHTML;
    var number_of_options;

    // The user selected 'choose from' (assumed to be the first item).
    if ( canned_question_input.selectedIndex == 0 ) {
        // Restore the original value and return.
        if ( window.cachedQuestion ) question_input.value = cachedQuestion;
        return;
    }
    else {
        // Preserve the current value in case the user wants to go back.
        if ( !window.cachedQuestion ) window.cachedQuestion = question_input.value;

        var options = canned_question_input.getElementsByTagName( 'OPTION' );
        number_of_options = options.length;
    }

    // The last option indicates the user wishes to define a custom question.
    if ( canned_question_input.selectedIndex == ( number_of_options - 1 ) ) {
        canned_question = '';
    }
    question_input.value = canned_question;
    return;
}

function insertAtCursor ( elt, value ) {

    // inserts "value" at the position of the cursor in textarea "elt"

    if ( document.selection ) {
        elt.focus();
        var sel = document.selection.createRange();
        sel.text = value;
        elt.focus();
    }
    else if ( elt.selectionStart || ( elt.selectionStart == 0 ) ) {
        var startPos = elt.selectionStart;
        var endPos = elt.selectionEnd;
        var scrollTop = elt.scrollTop;
        
        elt.value = elt.value.substring( 0, startPos ) + value + elt.value.substring( endPos, elt.value.length );
        elt.focus();

        elt.selectionStart = startPos + value.length;
        elt.selectionEnd = startPos + value.length;
        elt.scrollTop = scrollTop;
    }
    else {
        elt.value += value;
        elt.focus();
    }
}

function getMouseEventCoords (event) {

    // based on www.quirksmode.org example

    var coords = { x: 0, y: 0 };

    if ( event.pageX || event.pageY ) {
        coords.x = event.pageX;
        coords.y = event.pageY;
    }
    else if ( event.clientX || event.clientY ) {
        coords.x = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        coords.y = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }

    return coords;
}

function setTextAreaMaxLength() {
    /*  
     *  from http://www.quirksmode.org/dom/maxlength.html
     *  Looks for textareas with maxlength attribute and sets
     *  handler to let user know when they have gone over limit.
     *  Does not actually *impose* the limit so as not to annoy.
     *
    */
    var x = document.getElementsByTagName('textarea');
    var counter = document.createElement('div');
    counter.className = 'counter';
    for (var i=0;i<x.length;i++) {
        if (x[i].getAttribute('maxlength')) {
            var counterClone = counter.cloneNode(true);
            counterClone.relatedElement = x[i];
            counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
            x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
            x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

            x[i].onkeyup = x[i].onchange = checkTextAreaMaxLength;
            x[i].onkeyup();
        }
    }
}

function checkTextAreaMaxLength() {
    var maxLength = this.getAttribute('maxlength');
    var currentLength = this.value.length;
    if (currentLength > maxLength)
        this.relatedElement.className = 'error';
    else
        this.relatedElement.className = '';
    this.relatedElement.firstChild.nodeValue = currentLength;
}

//////////////////////////
// Express service code
//////////////////////////

function expressServiceCode(sid) {
    var el = domElement('express_service_code_div');
    if (el.style.display == 'block') {
        el.style.display = 'none';
    }
    else {
        el.style.display = 'block';
        var code = domElement('express_service_code');
        code.innerHTML = '..<blink>.</blink>';
        ajax_get('/special/express_service_code' + sid, function(req) {
            if (req.readyState == 4) {
                if (req.status > 199 && req.status < 300) {
                    eval('var response = ' + req.responseText);
                    code.innerHTML = response.code;
                }
                else {
                    code.innerHTML = 'error';
                }
            }
        });
    }
}

///////////////////////////////////////////////////////////////
// This function should run on every page load. Keep it simple
///////////////////////////////////////////////////////////////

function onPageLoad() {
    $('.javascript-warning').hide();

    $("a[href^=/voip/send_sms]").click(function() {
        var href = $(this).attr("href").replace(/["']/gi,"");
        href += ";action=ajax#TB_iframe?height=200&width=300";
        tb_show("Send SMS", href);
        return false;
    });

    $("a[href^=/voip/call_out]").click(function() {
        var href = $(this).attr("href").replace(/["']/gi,"");
        href += ";popup=1#TB_iframe?height=240&width=300";
        tb_show("Place a Call", href);
        return false;
    });

    $("form.oneclick").submit(function() {
        var me = $(this);
        if (me.attr("submitted")) return false;
        $(window).unload(function() {
            me.removeAttr("submitted");
        });
        me.attr("submitted", 1);
    });

    $("select.payment").change(function() {
        var duration = 200;
        var me = $(this);
        var id = me.attr("id");
        var current = $(me.attr("current"));
        if (current != null) 
            current.hide();
        var selector = "#" + id + "_" + me.val();
        current = $(selector);
        if (current != null) {
            current.show();
            me.attr("current", selector);
        }
        else {
            me.removeAttr("current");
        }
    });
    $("select.payment").change();
}
