// ++=========================================================================++
// || DTO Core v2.0.1 - 213
// || Copyright © 2008-2010 Drive Thru Online, Inc. All Rights Reserved.
// || This file may not be redistributed in whole or significant part, or
// || used on web site without licensing of the enclosed code,
// || and software features.
// || http://www.drivethruonline.com | info@drivethruonline.com
// || Downloaded 15:34, Sun Jul 18th 2010
// || 623790213_604952770317
// ++ ========================================================================++

function showDebug(enable)
{
    if(enable == 1 || enable == 'true' || enable == 'yes' || enable == 'on' || enable == '1')
    {
        window.top.debugWindow =
              window.open("",   "Debug",
              "left=0,top=0,width=300,height=300,scrollbars=yes,"
              +"status=yes,resizable=yes");

        window.top.debugWindow.opener = self;
        window.top.debugWindow.document.open();
        window.top.debugWindow.document.write(
          "<HTML><HEAD><TITLE>Debug Window</TITLE></HEAD><BODY><PRE>\n");
    }
}

function debug(text)
{
    if (window.top.debugWindow && ! window.top.debugWindow.closed)
        window.top.debugWindow.document.write(text+"\n");
}

function debugObject(obj, name) 
{
    if (obj && typeof obj == "object") 
    {
        var child = null;

        debug('debugObject() named '+name);
        for (var item in obj)
        {
            try {child = obj[item];} 
            catch (e) {child = "<Unable to Evaluate>";}

            if (typeof child == "object") 
                debug(item + ' not recursed');
            else
                debug(item + ' --> ' + child);
        }            
    }
    else
    {
        if(obj)
            debug('attempt to debugObject() on null object named '+name);
        else
            debug('attempt to debugObject(' + typeof obj + ') on non-object named '+name);
    }
}


function clearChildNodes(elem)
{
    if(elem && elem.childNodes)
        while (elem.childNodes.length > 0)
            elem.removeChild(elem.firstChild);
}

function clearChildNodesNamed(elemID)
{
    var elem = document.getElementById(elemID);
    if(elem)
        clearChildNodes(elem);
}

/*--------------------------------------------------------------*/

function DTO_AjaxCall()                         {}

function DTO_AjaxCall_new(target, tag)
{
    var obj = new DTO_AjaxCall();
    DTO_AjaxCall_init(obj, target, tag);
    return obj;
}

function DTO_AjaxCall_init(obj, target, tag)
{
    obj.target = target;
    obj.tag = tag;
    
    if (window.XMLHttpRequest)
        obj.request = new XMLHttpRequest();                             //IE 7 and everything else
    else if (window.ActiveXObject)
    {
        obj.request = new ActiveXObject("Msxml2.XMLHTTP");              //new IE
        if(!obj.request)
            obj.request = new ActiveXObject("Microsoft.XMLHTTP");       //older IE
    }   
    
    obj.callback = function()
    {
        if(this.request.readyState==4 )
            this.target.ajaxCallback(this.tag, this.request.responseText);
    }
     
    obj.call = function(url)
    {
        var cb = function() 
        {
            var self = obj;
            self.callback();
        }
        this.request.open('GET', url, true);
        //req.setRequestHeader("content-type","application/x-www-form-urlencoded");
        this.request.onreadystatechange = cb;
        this.request.send(null);
    }
}

/*--------------------------------------------------------------*/

function formatCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

/*--------------------------------------------------------------*/

function Array_clear(array)
{
    while(array.length)
        array.pop();
}

/*
function drawRow2ColString(frag, varname, prompt, value)
{
    tr_u = document.createElement("tr");
    td_u1 = document.createElement("td");
    td_u2 = document.createElement("td");

    txt = document.createTextNode(prompt);
    td_u1.appendChild(txt);
    tr_u.appendChild(td_u1)
        
    input_u = document.createElement("input");
    input_u.setAttribute("type", "text");
    input_u.setAttribute("name", varname);
    input_u.setAttribute("value", value);
    td_u2.appendChild(input_u);

    tr_u.appendChild(td_u2);
    frag.appendChild(tr_u)
}

function drawRow2ColCheckbox(frag, varname, prompt, value)
{
}

function drawRow2ColPopup(frag, varname, prompt, selected, optionArray)
{
}

function drawRow2ColSubmit(frag, varname, prompt)
{
    tr_submit = document.createElement("tr");
    td_submit = document.createElement("td");
    td_submit.colSpan = 2;
    td_submit.setAttribute("align", "center");

    input_submit = document.createElement("input");
    input_submit.setAttribute("type", "submit");
    input_submit.setAttribute("name", varname);
    input_submit.setAttribute("value", prompt);
    td_submit.appendChild(input_submit);

    tr_submit.appendChild(td_submit);
    frag.appendChild(tr_submit)
}
*/

/*--------------------------------------------------------------*/

function DTO_Phrase()                           {}

function DTO_Phrase_new(id, phrase)
{
    var obj = new DTO_Phrase();
    DTO_Phrase_init(obj, id, phrase);
    return obj;
}

function DTO_Phrase_init(obj, id, phrase)
{
    obj.id = id;
    obj.phrase = phrase;
}

DTO_Phrase_cache = {};
 
function DTO_Phrase_buildLookup(array)  
{
    var count = array.length;
    for (var i=0; i<count; i++) 
    {
        var obj = array[i];   
        DTO_Phrase_cache[obj.id] = obj;
    }
}

function DTO_Phrase_cachedWithID(id)             
{
    phrase = DTO_Phrase_cache[id];
    return (phrase ? phrase : id + '_NOT_FOUND');
}

/*--------------------------------------------------------------*/

