


function addSkey(link)
{
    var URL;  
    var skey;
    
    skey=getValue('ctl00_txtSkey');
    
    URL=link;
    if (skey != '')
    {
        URL = URL + '?SKey=' + skey;
    }
    window.open(URL, '_blank'); //,'menubar=yes, toolbar=yes, resizable=yes, scrollbars=yes');    
}


function addSkeySelf(link)
{
    var URL;  
    var skey;
    
    skey=getValue('ctl00_txtSkey');
    
    URL=link;
    if (skey != '')
    {
        URL = URL + '?SKey=' + skey;
    }
    //alert(URL);
    window.open(URL, '_self');    
}





function sendEmail(email)
{     
  var link = "mailto:" + trim(email);

  window.location.href = link;  

/*
function sendEmail() {     var link = "mailto:me@example.com"              + "?cc=myCCaddress@example.com"              + "&subject=" + escape("This is my subject")              + "&body=" + escape(document.getElementById('myText').value)     ;      window.location.href = link; } 
*/
}



function capitalize(txt)
{
    var warray = new Array;
    var i;
    var s = "";
    var w = "";
    var c = ""
    
    warray = txt.split(" ");
    for (i=0; i < warray.length; i++)
    {
        w = warray[i].toString().toLowerCase(); 
        c = w.charAt(0).toUpperCase();
        w = c + w.substr(1);
        s += w + ' ';
    }
    
    return trim(s);
}





function removeHTML(txt)
{
    var note = txt.toString();
    note = nCaseReplace(note, "http", "ht p");
    note = nCaseReplace(note, "<", " ");
    note = nCaseReplace(note, ">", " ");
    return note;
}




function radioGroupValue(radioGroupId )
{
    var list;
    var i;
    list = document.getElementById(radioGroupId).getElementsByTagName("input");
    for ( i = 0 ; i < list.length; i ++)
    {  
      if (list[i].checked)
      {
	    return list[i].value;
      }  
    }
    return '';
}


/* for radio groups defined like the following
 
<div id='radioGroupId'> 
<input type='radio'  checked='checked' name='sex' value='male' /> Male
<br />
<input type='radio'  name='sex' value='female' /> Female
</div>

*/



function BR2CR(txt)
{
    var x;
    x = nCaseReplace(txt,"<br>","\r\n");
    x = nCaseReplace(x,"<br >","\r\n");
    x = nCaseReplace(x,"<br/>","\r\n");
    x = nCaseReplace(x,"<br />","\r\n");
    return x;
}

function CR2BR(txt)
{
    var x;
    x = nCaseReplace(txt,"\n","<br/>");
    x = nCaseReplace(x,"\r","");
    return x;
}



function removeHidden(obj)
{
    var hiddenKey = 'Copyright 2011 by Crystal Beach Software, All Rights Reserved.';
	var txt;
	var i;
    if (hiddenRemoved == true) return;
	txt = obj.innerHTML;
	//alert(txt)
	txt =  nCaseReplace(txt, "\n", ""); // apple and firefox add leading new line when getting from div
	txt=trim(txt);
    i = txt.indexOf(hiddenKey);
    if (i >= 0)
    {
        txt = txt.substr(0, i)
        obj.innerHTML = txt;
    }
    hiddenRemoved = true;
}


////////////////////////////////////////
//
// Core Javascript functions
//

  //      <input id="Text1" type="text" />
  //  <textarea id="TextArea1" cols="20" rows="2"></textarea>


        var CTRL = false;       
        var SHIFT = false;      
        var ALT = false;
        var CHAR_CODE = -1;



 function testKeys()
 {
    if (CTRL == true) 
    {
        alert('Ctrl down');
        clearKeys();
    }
 }
 

function clearKeys()
{
    CTRL = false;       
    SHIFT = false;      
    ALT = false;
    CHAR_CODE = -1;
}        

function KeyDownHandler(e)
{
//dalert('KEYDOWN mouse=' + mouse_Y + ' ' + winMouse_Y);  
    var x = '';
    if (document.all)
    {
        var evnt = window.event;
        x = evnt.keyCode;
    }
    else
    {
        x = e.keyCode;
    }
    DetectKeys(x, true);
    return true;
}



function KeyUpHandler(e)

{
//dalert('KEYUP');            
    var x = '';
    if (document.all)
    {
        var evnt = window.event;
        x = evnt.keyCode;
    }
    else
    {
        x = e.keyCode;
    }
    DetectKeys(x, false);
    return true;
}



function DetectKeys(KeyCode, IsKeyDown)
{
//dalert('key code=' + KeyCode + ', down=' + IsKeyDown);            
    if (KeyCode == '16')
    {
        SHIFT = IsKeyDown;
    }
    else if (KeyCode == '17')
    {
        CTRL = IsKeyDown;
    }
    else if (KeyCode == '18')
    {
        ALT = IsKeyDown;
    }
    else
    {
        if(IsKeyDown)
        {
            CHAR_CODE = KeyCode;
        }
        else
        {
            CHAR_CODE = -1;
        }
    }
}




 
// Handy JavaScript to meature the size taken to render the supplied text; 
// you can supply additional style information too if you have it to hand. 
 
function measureText(pText, pFontSize, pwidth, pStyle) { 
  var lDiv = document.createElement('lDiv'); 
 
  document.body.appendChild(lDiv); 
 
  if (pStyle != null) 
  { 
    lDiv.style = pStyle; 
  } 
  
  lDiv.style.fontSize = "" + pFontSize + "px"; 
  lDiv.style.position = "absolute"; 

  //lDiv.style.left = -1000; 
  //lDiv.style.top = -1000; 
 
    position: absolute; 
    visibility: hidden;
     
    lDiv.style.height = auto;
    lDiv.style.width = pwidth; 
 
 
  lDiv.innerHTML = pText; 
 
  var lResult = { 
   width: lDiv.clientWidth, 
   height: lDiv.clienHeight 
  }; 
 
  document.body.removeChild(lDiv); 
  lDiv = null; 
 
  return lResult; 
} 


function fix1()
{
}

//getpos    
////////obj.parentNode.scrollTop
function getPos(obj) 
{
    var coord = new Object();

    if (typeof obj == 'string')
    {
        o = document.getElementById(obj);
    }
    else
    {
        o = obj;
    }
    coord.left = o.offsetLeft;
    coord.top = o.offsetTop;
    while(o.offsetParent != null) 
    {
        oParent = o.offsetParent;
        coord.left += oParent.offsetLeft;
        coord.top += oParent.offsetTop;
        if (oParent.tagName.toLowerCase() == 'div')  // 7/25/10 adjust for scrolling
        {
        
                coord.left -= o.parentNode.scrollLeft
                coord.top -= o.parentNode.scrollTop
       
        
        
        
 //           coord.left -= oParent.scrollLeft
  //          coord.top -= oParent.scrollTop
        }
        o = oParent;
    }
    coord.x = coord.left;
    coord.y = coord.top;
    return coord;
}




function isRightButton(e)
{
	var rightclick;
	if (!e) var e = window.event;
	if (e.which) rightclick = (e.which == 3);
	else if (e.button) rightclick = (e.button == 2);
	return rightclick; // true or false
}



function stopBubble(e)
{
    if (!e)
    {
    var e=window.event;
    }
    e.cancelBubble=true;
    if (e.stopPropagation) 
    {
       e.stopPropagation();
    }
}


function getEventTarget(e)
{
var targ;
if (!e)
  {
  var e=window.event;
  }
if (e.target)
  {
  targ=e.target;
  }
else if (e.srcElement)
  {
  targ=e.srcElement;
  }
if (targ.nodeType==3) // defeat Safari bug
  {
  targ = targ.parentNode;
  }
  
  return targ;
  }



function whichElement(e)
{
var targ;
if (!e)
  {
  var e=window.event;
  }
if (e.target)
  {
  targ=e.target;
  }
else if (e.srcElement)
  {
  targ=e.srcElement;
  }
if (targ.nodeType==3) // defeat Safari bug
  {
  targ = targ.parentNode;
  }
var tname;
tname=targ.tagName;
alert("You clicked on a " + tname + " element.");
}


var ndalert = 0;
function dalert(txt)
{
    var obj;
 
    obj = document.getElementById('debug');
    if (obj)
    {
        ndalert = ndalert + 1;
        obj.innerHTML =  ndalert + ' ' + txt + '<br/>' + obj.innerHTML;
    }
}


 
function htmlEncode(x)
{
    var xdata;
    xdata = nCaseReplace(x, '&' , '&amp;' );
    xdata = nCaseReplace(xdata, "'" , '&apos;' );
    xdata = nCaseReplace(xdata, '<' , '&lt;' );
    xdata = nCaseReplace(xdata, '>' , '&gt;' );
    return xdata;
}

 
function htmlDecode(x)
{
    var xdata;
    xdata = nCaseReplace(x, '&apos;' , "'" );
    xdata = nCaseReplace(xdata, '&lt;', '<'  );
    xdata = nCaseReplace(xdata, '&gt;', '>'  );
    xdata = nCaseReplace(xdata, '&amp;', '&'  );
    return xdata;
}



function evalReturnedAjaxValue(xobj)
{
    var xdata;
    xdata=xobj.value.toString();
    if (xdata > '') 
    {
    //alert(xdata);
        eval(xdata);
    }
}



/*
    Public Shared Function encodeIllegalAjax(ByVal txt As String) As String
        Dim c As Char
        Dim s As String = ""

        For Each c In txt
            If AscW(c) > 127 Or AscW(c) < 32 Then
                s += "&#" & Right("0000" & (AscW(c) Mod 256), 4) & ";"
            Else
                s += c
            End If
        Next

        Return s
    End Function
    
    &#8704;
    
*/

/*
<html>
<body>

<script type="text/javascript">

var str="Visit  &#1234; &#1234; &#1234;!";
var pat = "&#[0-9]+;"
document.write(str.search(pat));

</script>

</body>
</html>
*/



function hookOnClose()
{
    if (doesFnExist('onWindowClose'))
    {
        onWindowClose();    
    }
    try
    {
        if (window.opener)
        {
           if (window.opener.doesFnExist('onChildClose') == true)
           {
                window.opener.onChildClose();
           }
        }
    }
    catch (err)
    {
    }
}




function decodeIllegalAjax(txt)
{
    var pat = "&#[0-9]+;"
    var s = new String(txt);
    var o = new String('');
    var semi;
    var nxt;
    var charVal;
    
    nxt = s.search(pat)
    while (nxt >= 0)
    {
        if (nxt > 0)
        {
            o = o + s.substr(0, nxt);
        }
        s = s.substr(nxt+2);
        semi = s.search(";");
        charVal = Number(s.substr(0, semi));
        o = o + String.fromCharCode(charVal);
        s = s.substr(semi + 1)
        nxt = s.search(pat)
    }
    
    o = o + s;    
    return o;
}


function xbug(txt)
{
    setValue('xbug', txt); // xbug is an input element somewhere
}

// get value from string like "name1=value1;name2=value2;....."
function getNamedValue(src, name, tobool)
{
    var sbeg;
    var send;
    var retval = '';
    if (src != null && src != '')
    {
        sbeg = src.indexOf(name + '=');
        if (sbeg >= 0)
        {
            sbeg = src.indexOf('=', sbeg);
            sbeg += 1;
            send = src.indexOf(';', sbeg);
            if (send > sbeg)
            {
                retval=src.substring(sbeg, send);
            }
        }
    }
    if (tobool != null && tobool == true)
    {
        if (retval == 'true')
        {
            retval = true;   
        }
        else
        {
            retval = false;
        }
    }
    return retval;
}

function type1Children(obj)
{
    var i;
    var n = 0;
    for (i = 0; i < obj.childNodes.length; i++)
    {
        if (obj.childNodes[i].nodeType == 1)
        {
            n += 1;
        }
    }
    return n;   
}

function objChild(obj, vN)
{
    var i;
    var n = -1;
    for (i = 0; i < obj.childNodes.length; i++)
    {
        if (obj.childNodes[i].nodeType == 1)
        {
            n += 1;
            if (n == vN)
            {
                return obj.childNodes[i];
            }
        }
    }
    return null;   
}

function objParent(obj)
{
    var p;
    var B = new cBrowser();
    p = B.ns6 ? obj.parentNode : obj.parentElement;
    return p;
}

function parentObj(obj)
{
    var p;
    var B = new cBrowser();
    p = B.ns6 ? obj.parentNode : obj.parentElement;
    return p;
}


function getParentType(el, xtag)
{
    var p;
    //p = el.parentNode;
    p = objParent(el);
    while (p)
    {
        if (p.tagName.toLowerCase() == xtag)
        {
            return p;
        }
        //p = p.parentNode;
        p = objParent(p);
    }
    return null;
}



function MenuGoTo(url)
{
    var xurl;
    var Obj;
    if (url != '')
    {
        Obj = document.getElementById('xmasterMenuDiv'); //OTG
        if (Obj == null)
        {
            Obj = document.getElementById('masterMenuDiv'); //WebSite1
        }
        Obj.disabled = true;
        xurl = nCaseReplace(url,'~/',getBaseURL());
        window.open(xurl,'_self');
    }
}
 

function date2String(vDate)
{
    var xDate = new Date(vDate)
    var dd = new String();
    dd = dd.concat((1 + xDate.getMonth()).toString(), '/',   xDate.getDate().toString(),   '/',  xDate.getFullYear().toString());
    return dd;
}


function date2YYMMDD(vDate)
{
    var xDate = new Date(vDate)
    var dd = new String();
    dd = dd.concat( nChr(xDate.getFullYear(), 2), nChr(1 + xDate.getMonth(),2), nChr( xDate.getDate(),2) );
    return dd;
}


function nChr(xval, nChrs)
{
    s = new String('00000000000000000000000' + xval.toString());
    s = s.substr(s.length - nChrs)
    return s
}



//if function exists defined
function doesFnExist(funcName)
{
    try 
    {
        if (typeof(eval(funcName)) === 'function' )
        {
           return true;
        }
        else
        {
           return false;
        }
    }
    catch(err)
    {
        return false;
    }
}


function stripFmt(txt)
{
    var x;
    var y;
    x=txt.toString();
    x = x.replace(new RegExp(',',"gi"), '');
    y = x.replace(new RegExp('[^+-12345.67890]',"gi"), '');
    return y;  
}
function stripFmtSign(txt)
{
    var x;
    var y;
    x=txt.toString();
    x = x.replace(new RegExp(',',"gi"), '');
    y = x.replace(new RegExp('[^12345.67890]',"gi"), '');
    return y;  
}

function stripHtml(tx)
{
    var x = '';
    var txt = tx.toString();
    var inHtml = 0;
    
    for (i=0; i < txt.length; i ++)
    {
        if (txt.charAt(i) == '<') inHtml +=1;
        if (inHtml <= 0)
        {
            x += txt.charAt(i);
        }
        if (txt.charAt(i) == '>') inHtml -=1;
    }
    return x
}



// deativate a textbox
function deactivate(aBool, id)
{
    var obj;
    if (typeof id == "string")
    {
        obj = document.getElementById(id);
    }
    else
    {
        obj = id;
    }
    
    obj.disabled=aBool;
    if (aBool)
    {
        obj.style.borderWidth='0px';
        obj.style.backgroundColor=parentBackgroundColor(obj); //'#fffff0';
    }
    else
    {
        obj.style.borderWidth='2px 2px 2px 2px';
        obj.style.backgroundColor='white';
    }
}

function parentBackgroundColor(vobj)
{
    var obj;
    var color;
    obj = vobj;
    while (obj.parentElement)
    {
        obj = obj.parentElement;
        color = obj.style.backgroundColor;
        if (color != '')
        {
            return color;
        }
    }
    return 'white';
}

function findName(vtag, vclass, vname)
{
    var xtag;
    var xclass
    var x;
    var i;
    var xobj;
    var txt;
    
    x = document.getElementsByName(vname);

    for (i=x.length-1; i >= 0; i--)
    {
        xobj = x[i];
        xtag = xobj.tagName.toLowerCase();
        xclass = xobj.className.toLowerCase();
        if (xtag == vtag && xclass == vclass)
        {
            return xobj;
        }
    }
    return null;
}


 function removeButtons()
 {
    var x;
    var i;
    var xobj;
    var txt;
    
    //return;
    
    x=document.getElementsByTagName("input");
    for (i=x.length-1; i >= 0; i--)
    {
        x[i].setAttribute('onclick', 'return false;');
        x[i].setAttribute('ondblclick', 'return false;');
        x[i].setAttribute('onmousedown', 'return false;');
        x[i].setAttribute('onmouseup', 'return false;');
        x[i].setAttribute('onchange', 'return false;'); 
        x[i].setAttribute('onblur', null);
        x[i].setAttribute('onfocus', 'this.blur();');
        
        if ( x[i].type == 'button')
        {
            x[i].parentNode.removeChild(x[i]);  
        }
        else
        {
            xobj = x[i];
            deactivate(true, xobj);
            
 // alert(xobj.style.width);
 
            if (xobj.style.width == '1px' )
            {
                xobj.parentNode.removeChild(xobj);   //
            }
            else
            {
                if (xobj.className)
                {
                    if (xobj.className == 'noShowYellow')
                    {
                         xobj.parentNode.removeChild(xobj);   
                    
                    }
                }
                else
                {
                    
                
                }
            }
        }
    }


    x=document.getElementsByTagName("select");
    for (i=x.length-1; i >= 0; i--)
    {
        xobj = x[i];
        x[i].setAttribute('onclick', 'return false;');
        x[i].setAttribute('ondblclick', 'return false;');
        x[i].setAttribute('onmousedown', 'return false;');
        x[i].setAttribute('onmouseup', 'return false;');
        x[i].setAttribute('onchange', 'return false;');
        x[i].setAttribute('onmouseover', 'this.disabled = true;');
        x[i].setAttribute('onfocus', 'this.blur();');
        
        
        while (xobj.length > 0)
        {
            xobj.remove(xobj.length-1);
        }
          var y=document.createElement('option');
          y.text=xobj.getAttribute('text');    //'Inventory';
            y.value=xobj.getAttribute('text');  //'Inventory';
          try
            {
            xobj.add(y,null); // standards compliant
            }
          catch(ex)
            {
            xobj.add(y); // IE only
            }
    }
    
    
    x=document.getElementsByTagName("textarea");
    for (i=x.length-1; i >= 0; i--)
    {
        x[i].setAttribute('onclick', 'return false;');
        x[i].setAttribute('ondblclick', 'return false;');
        x[i].setAttribute('onmousedown', 'return false;');
        x[i].setAttribute('onmouseup', 'return false;');
        x[i].setAttribute('onchange', 'return false;');
        
    }



    x=document.getElementsByTagName("img");
    for (i=x.length-1; i >= 0; i--)
    {
        xobj = x[i];
        xobj.disabled = true;
        if (xobj.id.search(/saveIcon/i) == 0)
        {
             xobj.parentNode.removeChild(xobj);   
        }
        else if (xobj.id.search(/undoIcon/i) == 0)
        {
             xobj.parentNode.removeChild(xobj);   
        }
        else if(xobj.id.search(/printIcon/i) == 0)
        {
             xobj.parentNode.removeChild(xobj);   
        }
    }


/*
    x=document.getElementsByTagName("th");
    for (i=x.length-1; i >= 0; i--)
    {
        xobj = x[i];
        xobj.onclick = null;
        xobj.disabled = true;
    }



    x=document.getElementsByTagName("a");
    for (i=x.length-1; i >= 0; i--)
    {
        xobj = x[i];
        xobj.onclick = null;
        xobj.disabled = true;
        txt= getObjInnerText(xobj);
     }

*/



    
    xobj=document.getElementById("listPrintButton")
    if (xobj)
    {
         xobj.parentNode.removeChild(xobj);  
    }
    
    xobj=document.getElementById("detailPrintButton")
    if (xobj)
    {
         xobj.parentNode.removeChild(xobj);  
    }
    
 }





    function setInnerHTML(ID, text)
    {
  	var xx;
	    var txtObj;
        txtObj = document.getElementById(ID);
        txtObj.innerHTML= text;
 	   // xx.txt='xx';
   }

    function getInnerHTML(ID)
    {
  	var xx;
	    var txtObj;
        txtObj = document.getElementById(ID);
        return txtObj.innerHTML;
 	   // xx.txt='xx';
   }



function nullevent(e)
{

return false;
}



function cancelEvent(e)
{
 
    try
    {
        void(0);
    }
    catch(err)
    {
        alert('CbsCore.cancelEvent err: ' + err.message.toString());
    }
   
    return false;
}



    function pipe2Selections( aListBox , pipe)
    {
        var i;
        var j;
        var retval  = "";
        var selections;
        
        selections = pipe.split('|');

        for (j=0; j < selections.length; j++)
        {
            for (i=0; i < aListBox.options.length; i++)
            {
                if (aListBox.options[i].value == selections[j])
                {
                    aListBox.options[i].selected = true;
                }
            }
        }
        return retval
    }
    

    function selections2Pipe( aListBox )
    {
        var i;
        var retval  = "";
 

        for (i=0; i < aListBox.options.length; i++)
        {
            if (aListBox.options[i].selected)
            {
                retval +=   aListBox.options[i].value.replace(/\|/g,'&pipe;') + "|"
            }
        }
        return retval
    }
    




    function commaSelections(aListBox, vquoteit)
    {  
        var i;
        var retval = "";
        var comma = "";
        var quote = "'";
        var hitNAN = new Boolean(false);
        var quoteit  = new Boolean(false);
        
        if (vquoteit) quoteit = true;
        
        for (i=0; i < aListBox.options.length; i++)
        {
            if (aListBox.options[i].selected)
            {
                retval +=  comma + quote + nCaseReplace(aListBox.options[i].value,"'","''") + quote
                comma = ', '
                if (isNaN(aListBox.options[i].value) || quoteit)
                {
                    hitNAN = true;
                }
            }
        }
        if ((hitNAN == false) && (quoteit == false))
        {
            retval = nCaseReplace(retval,"'", '');
        }
        return retval
    }
    






function setCookie(c_name,value,vExpiredays)
{
/*    var exdate=new Date();
    var expiredays;
    if (vExpiredays)
    {
        expiredays=vExpiredays;   
    }
    else
    {
        expiredays=365;
    }
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
*/
}


function getCookie(c_name)
{
/*    xval = getCookieOrNull(c_name);
    if (xval != null)
    {
        return xval;
    }
    else
    */
        {
        return '';
    }

}



function getCookieOrNull(c_name)
{
/*    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start != -1)
        { 
            c_start=c_start + c_name.length+1; 
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) 
            {
                c_end=document.cookie.length;
            }
            return unescape(document.cookie.substring(c_start,c_end));
        } 
    }
    */
    return "";
}
 
function remNonNum(xstr)
{
    var nstr = xstr.toString();
    nstr = nstr.replace(/[^-+.1234567890]/g,'');
    return nstr;
}
 

function hidePU()
{
    xObj=$find('ctl00_ContentPlaceHolder1_ModalPopupExtender1'); //.hide();
  //  $find('ModalPopupExtender1').hide();
   xObj.hide();
    
//document.getElementById('ctl00_ContentPlaceHolder1_PickListPopup').hide();    
    
} 


function hidePopupID(id)
{
    xObj=$find('ctl00_ContentPlaceHolder1_' + id); //.hide();
  //  $find('ModalPopupExtender1').hide();
   xObj.hide();
    
//document.getElementById('ctl00_ContentPlaceHolder1_PickListPopup').hide();    
    
} 


function i2s2t(iUrl, iKey,  sP1, sP2)
{
    var url;
    var xval;
    
    //alert('1');
    switch (iUrl)
    {
        case 100:   // SJP LeadsPopup from Leads
        
            xval = sp1A.getValue('dd_WebLeads_origin');
            //alert( xval );
         //  url = 'Reports/LeadsPopup.aspx?dealer=' + iKey + '&start=' + sP1 + '&origin=' + escape(xval) + '&olist=' + escape(nCaseReplace(xval, "'", ''));
            url = 'Reports/LeadsPopup.aspx?dealer=' + iKey + '&start=' + sP1 + '&origin=' + escape(xval) + '&olist=' + escape(nCaseReplace(xval, "'", ''));
            break;
    }
    //alert('3');

    popupB800(url);
}

var curPopupWindow;

function focusPopupWindow()
{
    var xwin;
    var retval = true;
    xwin = window;
    while (xwin.curPopupWindow.document)
    {
        retval = false;
        try
        { 
            xwin.focus
            if (xwin.curPopupWindow.document)
            {
                xwin.curPopupWindow.focus();
                if (xwin.curPopupWindow.document)
                {
                    xwin = xwin.curPopupWindow;
                }
                else
                {
                    xwin.focus();
                    return false;
                }
            }
            else
            {
               xwin.focus();
                return false;
            }
        }
        catch(err)
        {
            xwin.curPopupWindow = null;
            return false;
        }
    }
    return retval;
}


function popupB800(url, vWidth, vHeight)
{
    var width = 800;
    var height = 600;
    var xurl='' 
    if (vWidth)
    {
        width = Number(vWidth);
    }

    if (vHeight)
    {
        height = Number(vHeight);
    }
   xurl=getBaseURL() + encodeURI(url)
    //curPopupWindow = window.open(xurl ,  '_blank' , 'toolbar=yes, location=yes, menubar=yes,scrollbars=yes, resizable=yes, width = ' + width + ', height= ' + height )
    curPopupWindow = window.open(xurl ,  '_blank' , 'toolbar=no, location=no, menubar=no,scrollbars=yes, resizable=yes, width = ' + width + ', height= ' + height );

}

function openChatModerator()
{
    popupB800('chat/moderator.aspx', 300, 400);
    curPopupWindow = null;
}

function openChatClient()
{
    popupB800('chat/client.aspx', 300, 400);
    curPopupWindow = null;
}



function popupEx(url, vWidth, vHeight)
{
    var width = 800;
    var height = 600; 
    if (vWidth)
    {
        width = Number(vWidth);
    }

    if (vHeight)
    {
        height = Number(vHeight);
    }
   
    //curPopupWindow = window.open(getBaseURL() + encodeURI(url)  ,  '_blank' , 'toolbar=yes, location=yes, menubar=yes,scrollbars=yes, resizable=yes, width = ' + width + ', height= ' + height )
    window.open(getBaseURL() + encodeURI(url)   ,  '_blank' , 'toolbar=no, location=no, menubar=no,scrollbars=yes, resizable=yes, width = ' + width + ', height= ' + height );
}

function mapDealerPkey(pkey)
{
    popupB800('ops/map.aspx?dealerpkey=' + pkey, 800, 700);
}

function windowOpen(url)
{
    var xurl;
    var x;
    var h;
    
    xurl = nCaseReplace(url, '@baseurl', getBaseURL());
    window.open(xurl, '_self');
}

function windowOpenBlank(url)
{
    var xurl;
    var x;
    var h;
    //url example = @baseurlOtgHome.aspx
    xurl = nCaseReplace(url, '@baseurl', getBaseURL());
    window.open(xurl,  '_blank' , 'toolbar=no, location=no, menubar=no,scrollbars=yes, resizable=yes ' );
}


function windowOpenNew(url)
{
    var xurl;
    var x;
    var h;
    //url example = @baseurlOtgHome.aspx
    xurl = nCaseReplace(url, '@baseurl', getBaseURL());
    window.open(xurl,  '_blank'  );
}





/*
function popup(vUrl, vWidth, vHeight)
{
    var width = 800;
    var height = 600; 
    var url = vUrl;
    var lurl = url.toLowerCase();
    
    if (vWidth)
    {
        width = Number(vWidth);
    }

    if (vHeight)
    {
        height = Number(vHeight);
    }
   
    if ( (lurl.indexOf('http:')  < 0)  )
    {
        url = 'http://' + url;
    }
    url = nCaseReplace(url,'%20','')
    url = nCaseReplace(url,' ','')
    
    window.open(url,  '_blank' , 'toolbar=yes, location=yes, menubar=yes,scrollbars=yes, resizable=yes, width = ' + width + ', height= ' + height )
}
*/
 



function computeDiscount(amt, discountRule, vfmt)
{
     var discount = 0;
    var result;

    if (discountRule > '')
    {
        discount = Number(stripFmt(discountRule)) * .01;
        if (discountRule.indexOf('$') > -1)
        {
            discount = 0.0;
        }
    }

    result = Number(stripFmt(amt)) * (1 - discount);
    
    if (vfmt != '')
    {
        result = format(result, vfmt);
    }

    return result;

}




////////////////////////////////////////
//
// tax rule format:
// 7.0 to $50,000.00 then 5.0%
// or
// 7% to 5000
// or
// 6.375
// 


function taxComputation(amt, vTaxRule)
{
    var formula;
    var result;
    var taxRule = trim(vTaxRule.toString());
    var steps;
    var nlen;
    var olen =9999999;
    var taxAmt = 0;
    var i = 0;
    var limit = 0;
    var rate = 0;
    var taxable;
    var taxableRemaining = amt;
    var lastLimit = 0;
    
    taxRule = taxRule.replace (/to/ig,'');
    taxRule = taxRule.replace (/then/ig,'');
     
    nlen = taxRule.length;
    while (olen != nlen && nlen > 0)
    {
        olen = nlen;
        taxRule = taxRule.replace(/  /g, ' '); // replace double space with single space
        nlen = taxRule.length;
    }
    taxRule = taxRule.replace(/,/g, '');
    taxRule = taxRule.replace(/[^+-12345 67890]/g, '');
    
    steps = taxRule.split(" ");
    i = 0;
    while (i < steps.length)
    {
        rate = steps[i];
        limit = 99999999;
        if ((i + 1) < steps.length)
        {
            limit = steps[i + 1];
        }
        if (isNaN(rate) || isNaN(limit))
        {
            alert('"' + vTaxRule + '"\nIs an invalid tax rule.\nShould be formatted as:\nRate [to Limit then Rate]...\nExample: 7.5% to $5000 then 6.0');
            return 0;
        }

        limit -= lastLimit;
        lastLimit = limit;
        
        if (taxableRemaining > limit )
        {
            taxable = limit;
        }
        else
        {
            taxable = taxableRemaining;
        }
        taxAmt += taxable * rate * .01;
        taxableRemaining -= taxable;
        i += 2;
    } 
    return taxAmt;
}

function flipRowStyle(CurRowStyle, RowStyle, AltRowStyle)
{            
    if (CurRowStyle == RowStyle)
    {
        CurRowStyle = AltRowStyle;
    }
    else
    {
        CurRowStyle = RowStyle;
    }
    return CurRowStyle;
}


function recordactiveToBool(x)
{
    var tf = new Boolean;
    var tfs;
    tfs = x.toString().toLowerCase();
    tf = (tfs == 'true' || tfs == '1' || tfs == 'a' );
    return tf;
}
function fBool(x)
{
    return forceToBool(x);
}

function forceToBool(x)
{
    var tf = new Boolean;
    var tfs;
    tfs = x.toString().toLowerCase();
    tf = (tfs == 'true' || tfs == '1' );
    return tf;
}




function addCommas(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 aNop()
{
}

function ckErr(xObj, name)
{
	var xdata;
	var evalstr;
	if (xObj)
	{
		xdata = xObj.value.toString();
		if (xdata.indexOf('err=') == 0)
		{
		    if (doesFnExist('showWaitScreen') == true)
		    {
		        showWaitScreen(false); //  added 6/09/09
		    }
			if (name)
			{
				alert(name + ": " + xdata)
			}
			else
			{
				alert(xdata);
			}
			return true;
		}
		else
		{
			if (xdata.indexOf('eval=') == 0)
			{
			    evalstr  = nCaseReplace(xdata.substr(5, xdata.length - 5), '@baseurl', getBaseURL());
			    eval(evalstr);
			}
			return false;
		}
	}
	else
	{
		return false;
	}
}
 





function findObj(partID)
{
    var i;
    var xObj;
    var j;
    
    i = 1;
    xObj = document.all(i);
    while (xObj)
    {
        if (xObj.id)
        {
            j= xObj.id.toString().search(new RegExp(partID,"gi"));
            if (j >= 0)
            {
                alert(xObj.id.toString());
            }   
        }
        i = i + 1;
        xObj = document.all(i);
    } 
}

/*
function findPos(obj) //  
{
var curleft = curtop = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        }
    }
    return [curleft,curtop];
}
*/


function deleteRow(trNode)
{
    var i;
    i = getMyRow(trNode)
    trNode.parentElement.deleteRow(i)
}


function getMyRow ( aTRNode )
{
    var pNode;
    var trNode;
    var iRow;
    
    iRow=0;
    pNode = aTRNode.parentElement;
    trNode=pNode.firstChild;
    while ((trNode != aTRNode) && (trNode != undefined))
    {
        iRow += 1;
        trNode=trNode.nextSibling;
    }
    return iRow;
}


 
function getRowCount(tblName)
{
    var tableNode;
    var tbodyNode;
    var trNode;
    var tdNode;
    var i=0;
    tableNode=document.getElementById(tblName);
    tbodyNode=tableNode.firstChild;
    trNode=tbodyNode.firstChild;
    while (trNode != undefined)
    {
        i += 1;
        trNode=trNode.nextSibling;
    }
    return i;
} 

function getTableCell(tbl, row, col)
{
        var tableNode;
        var tbodyNode;
        var trNode;
        var tdNode;
        var i;
        tableNode=document.getElementById(tbl);
        tbodyNode=tableNode.firstChild;
        trNode=tbodyNode.firstChild;
        for (i = 0; i < row; i ++)
        {
            trNode=trNode.nextSibling;
        }
        tdNode=trNode.firstChild;
        for (i = 0; i < col; i ++)
        {
            tdNode=tdNode.nextSibling;
        }
        return tdNode; 
}



function tableInputValue(tbl,row,col)
{
    var tdNode;
    var inputNode;
    var retVal;
    tdNode=getTableCell(tbl,row,col);
    inputNode=tdNode.firstChild;
    retVal = inputNode.value;
    return retVal;
}

function setVisible(ID, tf)
{
    var txtObj;
    txtObj = document.getElementById(ID);
    if (txtObj)
    {
        if (tf)
        {
            txtObj.style.visibility='visible';
        }
        else
        {
            txtObj.style.visibility='hidden';
        }
    }
}

function setText(ID,txt)
{
    setInnerText(ID,txt);
}


function setButtonText(id,txt)
{
    var obj;
    if (typeof id == "string")
    {
        obj = document.getElementById(id);
    }
    else
    {
        obj = id;
    }
    if (obj)
    {
        obj.value = txt;
    }
}


function setInnerText(ID, text)
{
    var txtObj;
    txtObj = document.getElementById(ID);
    setObjInnerText(txtObj, text);
}


function setObjInnerText(xobj, text)
{    
   var b = new cBrowser;
   
   if (b.moz)
   {
        xobj.textContent= text;
   }
   else
   {
        xobj.innerText= text;
   }
    return (0);
}



function getInnerText(ID)
{
    var txtObj;
    txtObj = document.getElementById(ID);
    return getObjInnerText(txtObj);
}

function getObjInnerText(xobj)
{
    var b = new cBrowser;
    if (b.moz)
    {
        return xobj.textContent;  //firefox
    }
    else
    {
        return xobj.innerText;
    }
}


function getChecked(ID)
{
 	    var txtObj;
        var xx;
        txtObj = document.getElementById(ID);
        return txtObj.checked;
}

function checkBoxUnclick(objx)
{
	if (objx.checked)
	{
		objx.checked = false;
	}
	else
	{
		objx.checked = true;
	}
}



function setObjUnEncodedValue(vObj, xdata)
{
    var xtag;
    var xtype;
    var xObj;
    var currentValue;
    var armOnChange;

    try
    {
        if (typeof vObj == 'string')
        {
            xObj= document.getElementById(vObj);
            if  (xObj == null)
            {
                return;
            }
        }
        else
        {
            xObj = vObj;
        }


        currentValue = getObjValue(xObj);


        xtag = xObj.tagName.toLowerCase();
        switch (xtag)
        {
            case 'span':
            case 'td':
                xObj.innerHTML = xdata;
                break;
            case 'select':
                break;
            case 'div':
                xObj.innerHTML = xdata;
                break;
            case 'input':
                xtype = xObj.type.toLowerCase();
                switch (xtype)
                {
                    case 'radio':
                    case 'checkbox':
                        xObj.checked = (xdata.toString().toLowerCase() == 'true');
                        break;
                    default:
                        xObj.value = xdata;
                }
                break;
            default:
                xObj.value = xdata;
        }


        fireOnChange(xObj, currentValue);
    }
    catch(ex)
    {
        alert("CbsCore.prototype.setObjUnEncodedValue() err=" + ex.message.toString());
    }
}

    
function fireOnChange(obj,  curVal, force)
{
    var xcode;
    var newf;
    var i;
    
    if ( (curVal != getObjValue(obj))  || force)
    {
        armOnChange = obj.getAttribute('armonchange');
        if (armOnChange)
        {
            if (armOnChange.toString() > '')
            {
                //lert('armonchange=' + armOnChange.toString());
                //eval(armOnChange.toString());
                xcode = armOnChange.toString();
                i = xcode.indexOf('function');
                if (i >= 0)
                {
                    i = xcode.indexOf('{');
                    xcode = xcode.substr(i+1);
                    i = xcode.lastIndexOf('}');   
                    xcode = xcode.substr(0,i);
                }
                newf = new Function("thisobj", xcode)
                newf(obj);
            }
        }
    }
}

 
function setObjValue(vObj, xdata)
{
    var xtag;
    var xtype;
    var xObj;
    
    var currentValue;
    var armOnChange;

    if (typeof vObj == 'string')
    {
        xObj= document.getElementById(vObj);
        if  (xObj == null)
        {
            return;
        }
    }
    else
    {
        xObj = vObj;
    }
    
    currentValue = getObjValue(xObj);

    xtag = xObj.tagName.toLowerCase();

    switch (xtag)
    {
        case 'span':
        case 'td':
            setObjInnerText(xObj, xdata);
            break;
        case 'select':
            break;
        case 'div':
            setObjInnerText(xObj, xdata);
            break;
        case 'input':
            xtype = xObj.type.toLowerCase();
            switch (xtype)
            {
                case 'radio':
                case 'checkbox':
                    xObj.checked = (xdata.toString().toLowerCase() == 'true');
                    break;
                default:
              
                    xObj.value = xdata;
            }
            break;
        default:
            xObj.value = xdata;
    }
    
    fireOnChange(xObj, currentValue);

}








function formatAndSet(xObj, vdata, JSONcol)
{
    var xdata = vdata;
    if (JSONcol.fmt > '')
    {
        xdata = format(vdata, JSONcol.fmt);
    }
    if (JSONcol.htmlencode == 'true')
    {
        setObjValue(xObj, xdata);
    }
    else
    {
        setObjUnEncodedValue(xObj, xdata);    
    }
}




function setObjValueByID(ID, xdata)
{
    var xObj;
    xObj= document.getElementById(ID);
    
    if (xObj)
    {
        setObjValue(xObj, xdata);
    }
}








function radioClick(xObj)
{
    var xval;
    var aColl;
    xval = getObjValue(xObj);
    aColl = document.getElementsByName(xObj.name);
    if (xval.toString().toLowerCase() == 'true')
    {
        for (i=0; i < aColl.length; i++)
        {
            setObjValue(aColl[i], 'false')
        }
        setObjValue(xObj, 'true')
    } 
}



function getObjValue(xObj)
{
    var xtag;
    var xtype;
    var i;
    var xvalue;
    xtag = xObj.tagName.toLowerCase();
    switch (xtag)
    {
        case 'input':
            xtype = xObj.type.toLowerCase();
            if (xtype)
            {
                switch (xtype)
                {
                    case 'radio':
                    case 'checkbox':
                        return xObj.checked.toString();
                    default:
                        return xObj.value;
                }
            }
            return xObj.value;
        case 'div':
            return getObjInnerText(xObj);
        case 'td':
            return getObjInnerText(xObj);
        case 'select':
            if (xObj.multiple)
            {
                xvalue = commaSelections(xObj , true);
                if (xvalue.toString() == '')
                {
                    xvalue = "''";
                }
                return xvalue
            }
            else
            {
                return xObj.value;
            }   
            
        default:
            return xObj.value;
    }



}

function getValue(ID)
{
    var xObj;
    var xx;
    xObj = document.getElementById(ID);
    return getObjValue(xObj);
}


function getValueX(ID)
{
    var xObj;
    var xx;
    xObj = document.getElementById(ID);
    return getObjValue(xObj);
}



function setValue(ID, text)
{
var xx;
    var txtObj;
    txtObj = document.getElementById(ID);
    txtObj.value= text;
   // xx.txt='xx';
}

function setMaxLength(ID, maxLength)
{
    var xx;
    var txtObj;
    txtObj = document.getElementById(ID);
    txtObj.maxLength= maxLength;
//     xx.text='';
}


function highlightRowN(tblID, N, hiColor, stdColor)
{
    var tblNode;
    var tbodyNode;
    var rowNode;
    var colNode;
    var i;
    i=0
    tblNode = document.getElementById(tblID);
    tbodyNode = tblNode.firstChild;
    rowNode = tbodyNode.firstChild;
    while (rowNode != undefined)
    {
        if (i == N)
        {
            rowNode.style.backgroundColor=hiColor;
        }
        else
        {
            rowNode.style.backgroundColor=stdColor;
        }
        rowNode=rowNode.nextSibling;
        i+=1;
    }

}


function highlightRow(highLiteRow, hiColor, stdColor)
{
    var tbl;
    var firstRow;
    var aRow;
    
    tbl = highLiteRow.parentElement;
    firstRow=tbl.firstChild;
    aRow= firstRow;
    while (aRow != undefined)
    {
        if (aRow == highLiteRow)
        {
            aRow.style.backgroundColor=hiColor;
        }
        else
        {
            aRow.style.backgroundColor=stdColor;
        }
        aRow=aRow.nextSibling;
    }   
}





    function highlightRow1stTD(TableID,SelectedTDNode)
    {
 	    var tableNode;
 	    var xx;
 	    var tbodyNode;
 	    var trNode;
 	    var tdNode;
        tableNode = document.getElementById(TableID);
        tbodyNode=tableNode.firstChild;
        trNode=tbodyNode.firstChild;
        while (trNode != undefined)
        {
            tdNode=trNode.firstChild;
    //        //alert(tdNode.innerText);
            if (tdNode == SelectedTDNode)
            {
            tdNode.style.backgroundColor='#dcdcdc';
            }
            else
            {
            tdNode.style.backgroundColor='White';
            }
            trNode=trNode.nextSibling;
        }
       //   xx.text='';   
    }


    function highlightMatchingRow(TableID, txt)
    {
 	    var tableNode;
 	    var xx;
 	    var tbodyNode;
 	    var trNode;
 	    var tdNode;
        tableNode = document.getElementById(TableID);
        tbodyNode=tableNode.firstChild;
        trNode=tbodyNode.firstChild;
        while (trNode != undefined)
        {
            tdNode=trNode.firstChild;
    //alert(tdNode.innerText);
            if (getObjInnerText(tdNode).toUpperCase() == txt.toUpperCase())
            {
            tdNode.style.backgroundColor='#dcdcdc';
            }
            else
            {
            tdNode.style.backgroundColor='White';
            }
            trNode=trNode.nextSibling;
        }
       //   xx.text='';   
    }


    function findMatch(TableID,txt)
    {
 	    var tableNode;
 	    var xx;
 	    var tbodyNode;
 	    var trNode;
 	    var tdNode;
        tableNode = document.getElementById(TableID);
        tbodyNode=tableNode.firstChild;
        trNode=tbodyNode.firstChild;
        while (trNode != undefined)
        {
            tdNode=trNode.firstChild;
            if (getObjInnerText(tdNode).toUpperCase() == txt.toUpperCase())
            {
                return true;
            }
            trNode=trNode.nextSibling;
        }
       return false;   
    }


function click(buttonID)
{
    var txtObj;
    txtObj = document.getElementById(buttonID);
    txtObj.click();
}

function trimCRs(x)
{
    while ((x.length > 0) && ((x.substring(0,1) == '\n') || (x.substring(0,1) == '\r')))
    {
            x=x.substring(1)
    }
    while ((x.length > 0) && ((x.substring(x.length-1) == '\n') || (x.substring(x.length-1) == '\r')))
    {
            x=x.substring(0,x.length-1)
    }
    return x;
}


/////////////////////////////////////////////////////////////
function trimC(xx, c)
{
    var x=xx;
    while ((x.length > 0) && (x.substring(0,1) == c))
    {
            x=x.substring(1,x.length)
    }

    while ((x.length > 0) && (x.substring(x.length-1,x.length) == c))
    {
            x=x.substring(0,x.length-1)
    }
    return x;
}


function trim(xx)
{
    var x=xx;
    while ((x.length > 0) && (x.substring(0,1) == ' '))
    {
            x=x.substring(1,x.length)
    }

    while ((x.length > 0) && (x.substring(x.length-1,x.length) == ' '))
    {
            x=x.substring(0,x.length-1)
    }
    return x;
}

    
function enable(xID, tf)
{
    var yy;
    yy=document.getElementById(xID);
    if (tf)
    {
        yy.disabled= false;
        
    }
    else
    {
        yy.disabled= true;
    }
}

function nCaseReplace(txt, find, replace)
{
    var x;
    var y;
    
    x = txt.toString();
    y = x.replace(new RegExp(find,"gi"), replace);
    return y;  
}


function trimZeros(x, maxZs)
{
    var y;
    y = Number(x);
    y = y.toFixed(maxZs);
    y = y.toString();

    while (y.length > 1)
    {
        if (y.charAt(y.length -1) == '0')  
        {
            y = y.substr(0, y.length -1);
        }
        else if (y.charAt(y.length -1) == '.')
        {
            y = y.substr(0, y.length -1);
            return y;
        }
        else
        {
            return y;
        }
    }
    return y;
}    
    
    

function format(x, fmt)
{
    var data = x.toString();
    var retval = data;
    var aDate = new Date();
    var filter;
    var nonZeros;
    
    filter = /[^0]/;
    nonZeros = filter.test(fmt);
    
    if (nonZeros == false)
    {
        retval =  ('000000000000000000000000' + stripFmt(retval)).toString();
        retval = retval.substr(retval.length - fmt.length);
        return retval;
    }

    switch(fmt.toLowerCase())
    {
         case "##":
            retval = Number(stripFmt(retval));
            if (retval.toString().length < 2) 
            {
                retval = ('0' + retval.toString()); 
            }
            break;
        case "binteger":
            retval = Number(stripFmt(retval));
            retval = retval.toFixed(0); 
            break;
        case "integer":
            retval = Number(stripFmt(retval));
            retval = retval.toFixed(0); 
            break;
        case ".##":
            retval = Number(stripFmt(retval));
            retval = retval.toFixed(2); 
            break;
        case  "#.##":
            retval = Number(stripFmt(retval));
            retval = retval.toFixed(2); 
            break;
        case  ".00":
            retval = Number(stripFmt(retval));
            retval = retval.toFixed(2); 
            break;
        case  "0.00":
            retval = Number(stripFmt(retval));
            retval = retval.toFixed(2); 
            break;
        case  "currency":
            retval = Number(stripFmtSign(retval));
            retval = retval.toFixed(2);
            retval = '$' + addCommas(retval);
            if (Number(data) < 0)
            { 
                retval = '-' + retval;
            }
            break;
        case  "bcurrency":
            retval = Number(stripFmtSign(retval));
            retval = retval.toFixed(2);
            if (retval == 0.00)
            {
                retval = ''
                break;
            }
            retval = '$' + addCommas(retval);
            if (Number(data) < 0)
            { 
                retval = '-' + retval;
            }
            break;
        case  "%":
            retval = Number(stripFmt(retval));
            retval = retval.toFixed(2);
            retval =  retval + '%';
            break;
        case  "b%":
            retval = Number(stripFmt(retval));
            retval = retval.toFixed(2);
            if (retval == 0.00)
            {
                retval = ''
                break;
            }
            retval =  retval + '%';
            break;
        case  "fixed":
            break;
        case  "standard":
            break;
        case  "scientific":
            break;
        case  "yes/no":
            break;
        case  "true/false":
            break;
        case  "on/off":
            break;
        case  "general date":
            retval = formatDate(data, fmt);
            break;
        case  "long late":
             retval = formatDate(data, fmt);
            break;
        case  "medium date":
            retval = formatDate(data, fmt);
            break;
        case  "m/d/yy h:mm tt":
            retval = formatDate(data, fmt);
        case  "m/d/yy":
            retval = formatDate(data, fmt);
        case  "m/d/yyyy":
            retval = formatDate(data, fmt);
        case  "long time":
             retval = formatDate(data, fmt);
            break;
        case  "medium time":
            retval = formatDate(data, fmt);
            break;
        case  "short time":
            retval = formatDate(data, fmt);
            break;
        case  "h:mm tt":
            retval = formatDate(data, fmt);
            break;
        default:
            alert("CbsCore.js.Format().. invalid format = (" + fmt + ")");   
    
    }
    
    return retval;
}

function formatDate(strDateTime, fmt)
{
    var delim = '/';
    
    var m= new Number(-1);
    var d= new Number(-1);
    var y= new Number(-1);
    
    var h= new Number(0);
    var min= new Number(0);
    var s= new Number(0);
    
    var i;
    var j;
    var x;
    
    var strDate  = "";
    var strTime = "";
    var ampm = "";
    var dateTime;
  
    
    if (strDateTime.indexOf('1/1/2099') >= 0 || strDateTime == '')
    {
        return '';
    }
    
    dateTime = new Date(strDateTime);
    
   
    if (strDateTime.indexOf('-') >= 0 )
    {
        delim = '-';
    }
    if (strDateTime.indexOf('.') >= 0 && strDate.indexOf('.') < 4)
    {
        delim = '.';
    }
    
    i = strDateTime.indexOf(' ');
    if (i >= 0)
    {
        strDate = strDateTime.substr(0, i);
        strTime = strDateTime.substr(i+1);
    }
    else
    {
        strDate = strDateTime;
    }
    
////////////////// get month day year 
    j = 0;
    i =  strDate.indexOf(delim);    // get the first field
    if (i >= 0)
    {
        x = strDate.substring(j, i);
        if (! isNaN(x))
        {
            m = Number(x)
            j = i + 1;
            i =  strDate.indexOf(delim, j); // get the second field
            if (i >= 0)
            {
                x = strDate.substring(j, i);
                if (! isNaN(x))
                {
                    d = Number(x)
                    j = i + 1;
                    i =  strDate.indexOf(' ', j); // and the third
                    if (i >= 0)
                    {
                        x = strDate.substring(j, i);
                        if (! isNaN(x))
                        {
                            y = Number(x)
                            j = i + 1;
                            
                        }        
                    }
                    else
                    {
                        x = strDate.substr(j);
                        if (! isNaN(x))
                        {
                            y = Number(x)
                            j = j + x.length;
                        }        
                    }
                }        
            }
        }        
    }

    // should have m, d and y by now


    

////////////////// get hour minute second 
    j = 0;
    i =  strTime.indexOf(':');    // get the first field
    if (i >= 0)
    {
        x = strTime.substring(j, i);
        if (! isNaN(x))
        {
            h = Number(x)
            j = i + 1;
            i =  strTime.indexOf(':', j); // get the second field
            if (i >= 0)
            {
                x = strTime.substring(j, i);
                if (! isNaN(x))
                {
                    min = Number(x)
                    j = i + 1;
                    i =  strTime.indexOf(' ', j); // and the third
                    if (i >= 0)
                    {
                        x = strTime.substring(j, i);
                        if (! isNaN(x))
                        {
                            s = Number(x)
                            j = i + 1;
                            ampm = strTime.substring(j);
                        }        
                    }
                    else
                    {
                        x = strTime.substr(j);
                        if (! isNaN(x))
                        {
                            s = Number(x)
                            j = j + x.length;
                            ampm = strTime.substring(j);
                        }        
                    }
                }        
            }
        }        
    }

    // should have h , min and s by now




    
    switch(fmt.toLowerCase())
    {

        case  "m/d/yy":
            return m.toString() + delim + d.toString() + delim + y.toString().substr(y.toString().length - 2);
            break
        case  "m/d/yyyy":
        case "short date":
            return m.toString() + delim + d.toString() + delim + y.toString();
            break;
/*        case  "long time":
            return m.toString() + delim + d.toString() + delim + y.toString();
            break;
        case  "medium time":
            return m.toString() + delim + d.toString() + delim + y.toString();
            break;
        case  "short time":
            return m.toString() + delim + d.toString() + delim + y.toString();
            break;
*/

case "m/d/yy h:mm tt":

ampm = 'PM';
if (h < 12) 
{
    ampm = 'AM';
    if (h==0) h = 12;    
}
if (h > 12) h = h - 12;


return m.toString() + delim + d.toString() + delim + y.toString().substr(y.toString().length - 2) + ' ' + h.toString() + ':' + format(min, "##") + ' ' + ampm ;
break;

        case  "h:mm tt":
            return h.toString() + ':' + format(min, "##") + ' ' + ampm ;
            break;
        case  "h:mm:ss":
ampm = 'pm';
if (h < 12) 
{
    ampm = 'am';
    if (h==0) h = 12;    
}
if (h > 12) h = h - 12;

            return h.toString() + ':' + format(min, "##") + ':' + format(s, "##");
            break;
        default:
            alert("CbsCore.js.FormatDate().. invalid format = " + fmt);
            return m.toString() + delim + d.toString() + delim + y.toString();

    }
}

 
    
var month=new Array(12)
    month[0]="January"
    month[1]="February"
    month[2]="March"
    month[3]="April"
    month[4]="May"
    month[5]="June"
    month[6]="July"
    month[7]="August"
    month[8]="September"
    month[9]="October"
    month[10]="November"
    month[11]="December"

    
function MMM(i)
{
    return month[i].substr(0,3);
}




function keyFilterNone()
{
    return false; 
}


function keyFilterHTML(e )
{
    var keynum;
    var keychar;
    var filter;
    if(window.event) // IE
      {
      keynum = e.keyCode;
      }
    else if(e.which) // Netscape/Firefox/Opera
      {
      keynum = e.which;
      }
      
    keychar = String.fromCharCode(keynum);
    filter = /[<>]/;

    return !filter.test(keychar);
}


function keyFilterFilename(e )
{
    var keynum;
    var keychar;
    var filter;
    if(window.event) // IE
      {
      keynum = e.keyCode;
      }
    else if(e.which) // Netscape/Firefox/Opera
      {
      keynum = e.which;
      }
      
    keychar = String.fromCharCode(keynum);
    filter = /\d/;
    filter = /[+(=)`^;'<->,|]/;
    //+(=)`^;'<->,

    return !filter.test(keychar);
}


function keyFilterNoNumbers(e)
{
var keynum;
var keychar;
var numcheck;if(window.event) // IE
  {
  keynum = e.keyCode;
  }
else if(e.which) // Netscape/Firefox/Opera
  {
  keynum = e.which;
  }
keychar = String.fromCharCode(keynum);
numcheck = /\d/;

return  !numcheck.test(keychar);
}




function keyFilterDecimal(e)
{
    
    var keynum;
    var keychar;
    var filter;

try
{
    if (window.event) // IE
	{
	    keynum = e.keyCode;
	}
    else if(e.which) // Netscape/Firefox/Opera
	{
	    keynum = e.which;
	}
    keychar = String.fromCharCode(keynum);
    
    filter = /[-+.1234567890]/;
    
}    
    catch(err)
    {
        alert('keyFilterDecimal err:' + err.message.toString());
    }
    return filter.test(keychar); 
}


function keyFilterEmail(e)
{
    
    var keynum;
    var keychar;
    var filter;

try
{
    if (window.event) // IE
	{
	    keynum = e.keyCode;
	}
    else if(e.which) // Netscape/Firefox/Opera
	{
	    keynum = e.which;
	}
    keychar = String.fromCharCode(keynum);
    
    filter = /[@_A-Za-z0-9.%+\-]/;
    
}    
    catch(err)
    {
        alert('keyFilterEmail err:' + err.message.toString());
    }
    return filter.test(keychar); 
}

    
     
function keyFilterNumeric(e)
{
    var keynum;
    var keychar;
    var filter;

try
{
    if (window.event) // IE
	{
	    keynum = e.keyCode;
	}
    else if(e.which) // Netscape/Firefox/Opera
	{
	    keynum = e.which;
	}
    keychar = String.fromCharCode(keynum);
    
    filter = /[-+1234567890]/;
    
}    
    catch(err)
    {
        alert('keyFilterNumeric err:' + err.message.toString());
    }
    return filter.test(keychar); 
}


 
  function countInStr(astr, srcStr)
  {
    var i;
    var j;
    var n;
    
    i=0;
    j=0;
    n=0;
      
    while (astr.indexOf(srcStr,j) > -1)
    {
        i = astr.indexOf(srcStr, j);
        j = i + 1
        n = n + 1
    }   
    return n;
  }
  

function stdHistoryLen()
{
    //alert ('ie=' +  browser.ie);
    //alert ('firefox=' + browser.moz);

    var browser = new cBrowser();
    
    if (!browser.ie)
    {
            return window.history.length -1;
    }
    else 
    {
            return window.history.length
    }
}




function backupOrClose( )
{

    if (stdHistoryLen() > 0)
    {
        window.history.back();
    }
    else
    {
        try
        {
            window.opener.focus();
            window.blur();
        }
        catch(err)
        {
            alert('backupOrClose() - ' + err.message.toString());
        }
        window.close();
        return true;
    }
}



function setSelectChoice(selectName, vValue) 
{
    var obj;
    var index;
    var curValue;
    obj=document.getElementById(selectName);
    curValue = obj.value;
    curValue = obj.value;
    
    obj.selectedIndex = 0;
    for(index = 0; index < obj.length; index++)
    {
        if(obj[index].value == vValue)
        {
            obj.selectedIndex = index;
            obj.text = obj[index].text;
        }
    }
    if (curValue.toString() != vValue.toString())
    {
        //obj.onchange();
    }
}




//http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function getWindowSize() 
{
  var myWidth = 0, myHeight = 0;
  var xy = new Object();
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
   //window.alert( 'Width = ' + myWidth );
   //window.alert( 'Height = ' + myHeight );
  xy.x=myWidth;
  xy.y=myHeight;
  return xy;
}

//http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
 
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  var xy = new Object();
   
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  xy.x = scrOfX;
  xy.y = scrOfY;
  
  //xy.x = f_scrollLeft();
  //xy.y = f_scrollTop();
  return xy;
}





//http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html


function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}




// Temporary variables to hold mouse x-y pos.s
var mouse_X = 0
var mouse_Y = 0

var winMouse_X = 0
var winMouse_Y = 0



// Main function to retrieve mouse x-y pos.s

function masterGetMouseXY(e) // called on document.onmousemove in OtgMasterPage
{
  scrollxy=getScrollXY();


  if (document.all?true:false) { // grab the x-y pos.s if browser is IE
    //scrollxy=getScrollXY();
    winMouse_X = event.clientX;
    winMouse_Y = event.clientY;
    mouse_X = event.clientX + scrollxy.x //document.body.scrollLeft
    mouse_Y = event.clientY + scrollxy.y //document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    winMouse_X = e.pageX - scrollxy.x;
    winMouse_Y = e.pageY - scrollxy.y
    mouse_X = e.pageX
    mouse_Y = e.pageY
    
  }  
  // catch possible negative values in NS4
  if (mouse_X < 0){mouse_X = 0}
  if (mouse_Y < 0){mouse_Y = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  
  
  // dalert('masterGetMouseXY() x=' + mouse_X + ', y=' + mouse_Y);
  
  return true
}



function iJSONcolByName (xname,  JSONcols)
{
     
    for (i = 0; i < JSONcols.length ; i++)
    {
        if(JSONcols[i].name == xname)
        {
            return i;
        }
    }
    return -1;
}

            
function dataToRowCell(rowButton, cellIndex, data, encode, cr2br) // returns false if unsuccessful
{
    var p1;
    var index;
    var b = new cBrowser;
    var last = 0;
   
    try
    { 
        index  = cellIndex;
        if ( (! b.ie) || b.ie9) index += 1;
        //if ( ! b.ie   ) index += 1;
        //index += 1;
        p1=rowButton;
        
        if (p1)
        {  
            p1 = getParentType(p1,'tr');
            p1 = getParentType(p1,'tr');
            
            if (index < p1.childNodes.length)
            {
                p1 = p1.childNodes[index];
            }
            else
            {
                return false;
            }
            
            p2 = p1;
            while (p1.childNodes.length > 0 && p1.tagName != 'SPAN' && p1.tagName != 'A'  && p1.tagName != 'B'  && p1.tagName != 'LARGER' )
            {
                p2 = p1;
                p1 = p1.childNodes[0];    
            }
            if (!p1.tagName)
            {
                p1 = p2;
            }
            else
            {
                if (p1.tagName == 'SPAN' || p1.tagName == 'A' || p1.tagName == 'B' || p1.tagName == 'LARGER')
                {
                    p1 = p2;
                }
            }
            
            if (cr2br.toString() == 'true' && encode.toString() == 'true')
            {
                data = htmlEncode(data)
                data = nCaseReplace(data, '\n', '<br/>');
                setObjUnEncodedValue(p1, data);
            }
            else  
            {
                if (encode.toString() == 'true')
                {
                    // set .text
                    setObjValue(p1, data);
                }
                else
                {   // set .innerHTML
                   if (cr2br.toString() == 'true' )
                    {
                        data = nCaseReplace(data, '\n', '<br/>');
                    }
                    setObjUnEncodedValue(p1, data);
                }
            }
            return p1;
        }
    }
    catch(ex)
    {
        alert("CbsCore.prototype.dataToRowCell() err=" + ex.message.toString());

    }
    return p1;
}


function clearTR(tr, data)
{
    var p1 = tr;
    var p2;
    var index;
    index  = 0;
    
    while (index < p1.childNodes.length)
    {
        p2 = p1.childNodes[index];
        p2.innerHTML = data;
        index ++;
    }
    return true;
}




            
function clearRow(rowButton, data) // returns false if unsuccessful
{
    var p1;
    var p2;
    var index;
    var b = new cBrowser;
    var html;
    
    p1=rowButton;
    
    if (p1)
    {       
        p1 = getParentType(p1,'tr');
        p1 = getParentType(p1,'tr');
        clearTR(p1, data);
 
 /*       
        index  = 0;
        
        while (index < p1.childNodes.length)
        {
            p2 = p1.childNodes[index];
            p2.innerHTML = data;
            index ++;
        }
 */       
        
        return true;
    }
    return false;
}




function hilightTD(e, obj)
{
    try
    {
        if (lastHilightTD) 
        {
            lastHilightTD.style.borderColor = '';
        }
    }
    catch(err)
    {} 
    obj.style.borderColor = 'red';
    lastHilightTD = obj;    
}

var lastHilightTD;

function getHilightedTD(table)
{
    var tbody;
    var tr;
    var td;

    tbody = objChild(table,0);
    tr = objChild(tbody,0);
    td = objChild(tr,0);
    i = 0;
    while (td)
    {
        if (td.style.borderColor.toString().indexOf('red') == 0)
        {
            return i;
        }
        i += 1;
        td = objChild(tr,i); 
    }
    return -1;
}


function isMouseOver(obj, xclose, yclose)
{
    var coord;
    var tdw;
    var tdh;
    
    coord= getPos(obj);
    tdw = parseInt(lastHilightTD.offsetWidth);
    tdh = parseInt(lastHilightTD.offsetHeight);
    if (mouse_X >= (coord.x - xclose) &&  mouse_X <= (coord.x + tdw + xclose) &&
        mouse_Y >= (coord.y - yclose) &&  mouse_Y <= (coord.y + tdh + yclose))
    {
        return true;
    }
    else
    {
        return false;
    }
}








function ctest()
{
 var listColumns = [{"name":"FirstName", 
                     "fmt": "", 
                     "htmlencode":"false"},
                    {"name":"LastName", 
                     "fmt": "le\"ft", 
                     "htmlencode":"true"}
                   ];
                   
  alert(listColumns.length);

}

function valfile()
{

var tf = validateFileType('ctl00_ContentPlaceHolder1_FileUpload1', ['bmp', 'jpg', 'jpeg', 'jpe', 'jfif', 'gif','tif','tiff','png'] );
if (tf)
{
    tf=true;
    return true;
}
return false;
}

function validateFileType(id, typeArray)
{
    var obj;
    var pathfile;
    var ext;
    var i;
    var msg = "Only the following file types may be uploaded here: \n" 
    
    obj = document.getElementById(id);
    pathfile=obj.value;
    if (trim(pathfile)=='')
    {
        alert('Please enter a filename to upload.');
        return false;
    }
    ext = getFileExtension(pathfile).toLowerCase();
    for (i = 0; i < typeArray.length; i ++)
    {
        if (i != 0) msg = msg + ', ';
        msg = msg + '.' + typeArray[i]
        if (ext == '.' + typeArray[i])
        {
            return true;
        }    
    }
    alert (msg);
    return false;
}

function getFileExtension(pathFileName)
{
    var i;
    i = pathFileName.lastIndexOf(".");
    if (i < 0)
    {
        return '';
    }
    return pathFileName.substr(i);
}






