//**************  Interactive Services Architecture (ISA)  *****************
//
// CVS File Id :  $Id: isajslib.js,v 1.4 2007/06/25 14:32:50 tbeasley Exp $
//
// File: js/isajslib.js
//
// Summary:       ISA Javascript Library
//
// Usage:
//                Included by the site template.
//
// Persistence:
//                None
//
// Copyright: 
//                Copyright 2005 American Tire Distributors, Inc.
//
// Author(s):
//                Bryan Martin - brmartin@atd-us.com
//
//                American Tire Distributors
//                12200 Herbert Wayne Ct.
//                Huntersville, NC 28078
//
// History:
// (code)  
//                $Log: isajslib.js,v $
//                Revision 1.4  2007/06/25 14:32:50  tbeasley
//                Development update
//
//                Revision 1.3  2007/05/22 18:29:33  disaac
//                Added code for sortable tables
//
//                Revision 1.2  2007/05/15 17:18:42  bryanm
//                development updates
//
//                Revision 1.1  2007/04/27 13:27:57  bryanm
//                Initial upload
//
//**************************************************************************

//  +-----------------------------------------------------------+
//  | findDOM code, to determine if the client if MSIE or       |
//  | Netscape/Firefox.                                         |
//  +-----------------------------------------------------------+ 

var isID = 0;
var isDHTML = 0;
var isAll = 0;
var isLayers = 0; 

if (document.getElementById) { 
    isID = 1; 
    isDHTML = 1; 
} else { 
    if (document.all) {
    isAll = 1; 
    isDHTML = 1; 
    } else { 
        browserVersion = parseInt(navigator.appVersion);
        if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {
            isLayers = 1; 
            isDHTML = 1; 
        }
    } 
} 

// Function: findDOM
//
// Utility function used to look-up an element or object
// based on it's id attribute, in a cross-browser way.
// withStyle is just a flag (0/1) to request the object's
// style instead of the object itself.
//
function findDOM(objectID,withStyle) {
    // If caller requested the style attribute of the object, return it.
    //
    if (withStyle == 1) {
        if (isID) { 
            return (document.getElementById(objectID).style); 
        } else {
            if (isAll) { 
                return (document.all[objectID].style); 
            } else {
                if (isLayers) { 
                    return (document.layers[objectID]); 
                }
            }; 
        }
    } else {
        // Otherwise, just return the object.
        //
        if (isID) { 
            return (document.getElementById(objectID)); 
        } else {
            if (isAll) { 
                return (document.all[objectID]); 
            } else {
                if (isLayers) {
                    return (document.layers[objectID]); 
                }
            }; 
        }
    }
}

// Function: setfocus
//
// Set the focus of an element, such as an entry.  This can be called where
// needed, as in:
// (code)
// if (empty($_POST['f_custnum']))
//    $out .= "<script language='JavaScript'>setfocus('f_custnum');</script>";
// (end)
//
function setfocus(id) {
    obj = findDOM(id);

    obj.focus();
}

// Set focus to the first form item
function focusFirstItem()
{
    // This will only work IF we have
    // an element to focus on
    if ( document.forms[0] )
    document.forms[0].elements[0].focus();

}

// Function: visiblityToggle
//
// Toggle the visiblity of an element, such as an entry.  This can be called as:
//
// (code)
// <a href='' onClick="visibilityToggle('leftmenuitems'); return false;">Hide</a>
// (end)
//
function visibilityToggle(id) {

    objStyle = findDOM(id, 1);

    if(objStyle.display == "") {
        objStyle.display = "block";
    } else {
        objStyle.display = "";
    }
}

// Function: visiblityToggleInline
//
// Toggle the visiblity of the help panels.  This differs from visibilityToggle
// in that it doesn't set visibility to "block".
// (code)
// <a href='' onClick="visibilityToggleInline('panelname'); return false;">Hide</a>
// (end)
//
function visibilityToggleInline(id) {

    objStyle = findDOM(id, 1);

    if(objStyle.display == "none") {
        objStyle.display = "inline";
    } else {
        objStyle.display = "none";
    }
}

// Function: submitenter
//
// Since we don't use typical Submit buttons, forms won't automatically get
// submitted when the user presses Return (on the login page, for example).  So
// we use this in conjunction with an onKeyPress handler for form fields that
// we want to submit on Return:
// (code)
// <input name=foo type=PASSWORD onKeyPress='return submitenter(this,event)'>
// (end)
//
function submitenter(myfield,e)
{
    var keycode;
    if (window.event) 
        keycode = window.event.keyCode;
    else if (e) 
        keycode = e.which;
    else return true;

    if (keycode == 13) {
        myfield.form.submit();
        return false;
    } else
    return true;
}

// Function: openWindow
//
// This is the function to open popups as needed, for exampel:
// (code)
// <a href="javascript://" onClick="openWindow('gbb.asp?carcode=$carcode','','')">
// (end)
//
function openWindow(theURL,winName,features)
{ 
    window.open(theURL,"","height=720,width=850,scrollbars=yes");
}

// Function: copyCheckedToAllCheckboxes
//
// This function allows the easy implementation of a "select all" checkbox that
// in turn controls the checked state of all checkboxes in the form.
//
function copyCheckedToAllCheckboxes(controller, children) {
    var theForm = controller.form
    var z = 0;

    for(z=0; z < theForm.length; z++) {
        if(theForm[z].type == 'checkbox' && theForm[z].name == children) {
            theForm[z].checked = controller.checked;
        }
    }
}

// Function: uncheckAllExcept
//
// This function unchecks all checkboxes except one with a specified value.  It works
// on a group of checkboxes.
//
function uncheckAllExcept(theForm, name, exception) {
    var z = 0;

    for(z=0; z < theForm.length; z++) {
        if(theForm[z].type == 'checkbox' && theForm[z].name == name) {
            if (theForm[z].value == exception)
                theForm[z].checked = true;
            else
                theForm[z].checked = false;
        }
    }
}

/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
function nextFieldOnReturn(field, event) {

    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

    if (keyCode == 13) {
        var i;
        for (i = 0; i < field.form.elements.length; i++)
            if (field == field.form.elements[i])
                break;
        // Mod causes us to wrap around if at the last form element.  Neat trick.
        i = (i + 1) % field.form.elements.length;
        field.form.elements[i].focus();
        return false;
    } 
    else
        return true;
}      



// These functions support sortable resultset tables.  Snarfed from
// http://kryogenix.org/code/browser/sorttable/ 
// and modified to work with both single-line tables and our dual-line search 
// result table format used with tires/wheels/merchandise.
//
// This code is under the MIT License, allowing us to use it:
// http://www.kryogenix.org/code/browser/licence.html
//
addEvent(window, "load", sortables_init);

var SORT_COLUMN_INDEX;

function sortables_init() {
    double_row_sortables_init();
    single_row_sortables_init();
}

function double_row_sortables_init() {
    // Find all tables with class sortable and make them sortable
    if (!document.getElementsByTagName) return;
    tbls = document.getElementsByTagName("table");
    for (ti=0;ti<tbls.length;ti++) {
        thisTbl = tbls[ti];
        if (((' '+thisTbl.className+' ').indexOf("double_row_sortable") != -1) && (thisTbl.id)) {
            //initTable(thisTbl.id);
            ts_doubleRowMakeSortable(thisTbl);
        }
    }
}

function ts_doubleRowMakeSortable(table) {

    if (table.rows && table.rows.length > 0) {
          // Result sets are multiple-row (since it would be to wide to show all
          // the fields in one row), so they are built as a table of tables.  Throughout
          // this code you'll see odd references that take this nesting into account.
          // Also, the first row in the first sub-table is a title row.
          var firstRow = table.rows[0].cells[0].firstChild.rows[1];
          var secondRow = table.rows[0].cells[0].firstChild.rows[2];
    }
    if (!firstRow) return;
    if (!secondRow) return;

    // We have a first row: assume it's the header, and make its contents clickable links
    for (var i=0;i<firstRow.cells.length;i++) {
        var cell = firstRow.cells[i];
        var txt = ts_getInnerText(cell);

        // If a cell has an image in it, we don't want to alter the contents.  Handle this by
        // setting nosort in the td tag, as in <td nosort=true>
        //
        if (cell.getAttribute("nosort") != 'true')
            cell.innerHTML = '<a href="#" class="sortheader" onclick="ts_doubleRowResortTable(this);return false;">'+txt+'<span class=sortarrow></span></a>';
    }

    for (var i=0;i<secondRow.cells.length;i++) {
        var cell = secondRow.cells[i];
        var txt = ts_getInnerText(cell);

        if (cell.getAttribute("nosort") != 'true')
            cell.innerHTML = '<a href="#" class="sortheader" onclick="ts_doubleRowResortTable(this);return false;">'+txt+'<span class=sortarrow></span></a>';
    }

}

function ts_doubleRowResortTable(lnk) {
    // get the span
    var span;
    for (var ci=0;ci<lnk.childNodes.length;ci++) {
        if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci];
    }
    var spantext = ts_getInnerText(span);
    var td = lnk.parentNode;
    var tr = td.parentNode;
    var column = td.cellIndex;

    // Calculate the row in a normal data row (row zero or one) based on the row in the table column
    // headers.  It's minus one because of the table titlerow, which is part of the top TR.
    //
    var row = tr.rowIndex - 1; 
    var subtable = getParent(td,'TABLE');
    var table = getParent(subtable.parentNode,'TABLE');

    // Work out a type for the column
    if (table.rows.length <= 1) return;

    // For some reason ts_getInnerText seems to return some whitespace after the
    // string.  We trim it before determining datatype.
    //
    var itm = TrimString(ts_getInnerText(table.rows[1].cells[0].firstChild.rows[row].cells[column]));

    sortfn = ts_double_row_sort_caseinsensitive;

    if (IsNumeric(itm)) sortfn = ts_double_row_sort_numeric;

    SORT_COLUMN_INDEX = column;
    SORT_ROW_INDEX = row;
    var firstRow = new Array();
    var newRows = new Array();
    for (i=0;i<table.rows[0].length;i++) { firstRow[i] = table.rows[0][i]; }
    for (j=1;j<table.rows.length;j++) { newRows[j-1] = table.rows[j]; }

    newRows.sort(sortfn);

    if (span.getAttribute("sortdir") == 'down') {
        ARROW = '&nbsp;&nbsp;&uarr;';
        newRows.reverse();
        span.setAttribute('sortdir','up');
    } else {
        ARROW = '&nbsp;&nbsp;&darr;';
        span.setAttribute('sortdir','down');
    }
    
    // Alternate rows get style 'shaded'
    //
    for (i=0;i<newRows.length;i++) { 
        if (i % 2 == 0)
            newRows[i].cells[0].firstChild.className="noshade"; 
        else
            newRows[i].cells[0].firstChild.className="shaded"; 
    }

    // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
    // don't do sortbottom rows
    for (i=0;i<newRows.length;i++) { 
        if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) 
            table.tBodies[0].appendChild(newRows[i]);
    }

    // do sortbottom rows only
    for (i=0;i<newRows.length;i++) { 
        if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1)) 
        table.tBodies[0].appendChild(newRows[i]);
    }
    
    // Delete any other arrows there may be showing
    var allspans = document.getElementsByTagName("span");
    for (var ci=0;ci<allspans.length;ci++) {
        if (allspans[ci].className == 'sortarrow') {
            if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us?
                allspans[ci].innerHTML = '&nbsp;&nbsp;&nbsp;';
            }
        }
    }
        
//    span.innerHTML = ARROW;
}

function ts_double_row_sort_numeric(a,b) { 
    aa = parseFloat(ts_getInnerText(a.cells[0].firstChild.rows[SORT_ROW_INDEX].cells[SORT_COLUMN_INDEX]));
    if (isNaN(aa)) aa = 0;

    bb = parseFloat(ts_getInnerText(b.cells[0].firstChild.rows[SORT_ROW_INDEX].cells[SORT_COLUMN_INDEX]));
    if (isNaN(bb)) bb = 0;

    return aa-bb;
}

function ts_double_row_sort_caseinsensitive(a,b) {
    aa = ts_getInnerText(a.cells[0].firstChild.rows[SORT_ROW_INDEX].cells[SORT_COLUMN_INDEX]).toLowerCase();
    bb = ts_getInnerText(b.cells[0].firstChild.rows[SORT_ROW_INDEX].cells[SORT_COLUMN_INDEX]).toLowerCase();
    if (aa==bb) return 0;
    if (aa<bb) return -1;

    return 1;
}

function single_row_sortables_init() {

    // Find all tables with class single_row_sortable and make them sortable
    if (!document.getElementsByTagName) return;
    tbls = document.getElementsByTagName("table");
    for (ti=0;ti<tbls.length;ti++) {
        thisTbl = tbls[ti];
        if (((' '+thisTbl.className+' ').indexOf("single_row_sortable") != -1) && (thisTbl.id)) {
            //initTable(thisTbl.id);
            ts_singleRowMakeSortable(thisTbl);
        }
    }
}

function ts_singleRowMakeSortable(table) {

    // First row is a title row, ignore that one (row 0).
    //
    if (table.rows && table.rows.length > 1) {
        var firstRow = table.rows[1];
    }

    if (!firstRow) return;

    // We have a first row: assume it's the header, and make its contents clickable links
    for (var i=0;i<firstRow.cells.length;i++) {
        var cell = firstRow.cells[i];
        var txt = ts_getInnerText(cell);

        // If a cell has an image in it, we don't want to alter the contents.  Handle this by
        // setting nosort in the td tag, as in <td nosort=true>
        //
        if (cell.getAttribute("nosort") != 'true')
            cell.innerHTML = '<a href="#" class="sortheader" onclick="ts_singleRowResortTable(this);return false;">'+txt+'<span class=sortarrow></span></a>';
    }
}

function ts_singleRowResortTable(lnk) {
    // get the span
    var span;
    for (var ci=0;ci<lnk.childNodes.length;ci++) {
        if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci];
    }
    var spantext = ts_getInnerText(span);
    var td = lnk.parentNode;
    var tr = td.parentNode;
    var column = td.cellIndex;

    var table = getParent(td,'TABLE');

    // Work out a type for the column
    if (table.rows.length <= 1) return;

    // For some reason ts_getInnerText seems to return some whitespace after the
    // string.  We trim it before determining datatype.
    //
    var itm = TrimString(ts_getInnerText(table.rows[2].cells[column]));

    sortfn = ts_single_row_sort_caseinsensitive;

    if (IsNumeric(itm)) sortfn = ts_single_row_sort_numeric;

    SORT_COLUMN_INDEX = column;
    var newRows = new Array();
    for (j=2;j<table.rows.length;j++) { newRows[j-2] = table.rows[j]; }

    newRows.sort(sortfn);

    if (span.getAttribute("sortdir") == 'down') {
        ARROW = '&nbsp;&nbsp;&uarr;';
        newRows.reverse();
        span.setAttribute('sortdir','up');
    } else {
        ARROW = '&nbsp;&nbsp;&darr;';
        span.setAttribute('sortdir','down');
    }
    
    // Alternate rows get style 'shaded'
    //
    for (i=0;i<newRows.length;i++) { 
        if (i % 2 == 0)
            newRows[i].className="noshade"; 
        else
            newRows[i].className="shaded"; 
    }

    // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
    // don't do sortbottom rows
    for (i=0;i<newRows.length;i++) { 
        if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) 
            table.tBodies[0].appendChild(newRows[i]);
    }

    // do sortbottom rows only
    for (i=0;i<newRows.length;i++) { 
        if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1)) 
        table.tBodies[0].appendChild(newRows[i]);
    }
    
    // Delete any other arrows there may be showing
    var allspans = document.getElementsByTagName("span");
    for (var ci=0;ci<allspans.length;ci++) {
        if (allspans[ci].className == 'sortarrow') {
            if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us?
                allspans[ci].innerHTML = '&nbsp;&nbsp;&nbsp;';
            }
        }
    }
        
//    span.innerHTML = ARROW;
}

function ts_single_row_sort_numeric(a,b) { 

    aa = parseFloat(ts_getInnerText(a.cells[SORT_COLUMN_INDEX]));

    if (isNaN(aa)) aa = 0;
    bb = parseFloat(ts_getInnerText(b.cells[SORT_COLUMN_INDEX])); 

    if (isNaN(bb)) bb = 0;
    return aa-bb;
}

function ts_single_row_sort_caseinsensitive(a,b) {

    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase();
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase();

    if (aa==bb) return 0;
    if (aa<bb) return -1;
    return 1;
}

function ts_getInnerText(el) {
	if (typeof el == "string") return el;
	if (typeof el == "undefined") { return el };
	if (el.innerText) return el.innerText;	//Not needed but it is faster
	var str = "";
	
	var cs = el.childNodes;
	var l = cs.length;
	for (var i = 0; i < l; i++) {
		switch (cs[i].nodeType) {
			case 1: //ELEMENT_NODE
				str += ts_getInnerText(cs[i]);
				break;
			case 3:	//TEXT_NODE
				str += cs[i].nodeValue;
				break;
		}
	}
	return str;
}

function getParent(el, pTagName) {
	if (el == null) return null;
	else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())	// Gecko bug, supposed to be uppercase
		return el;
	else
		return getParent(el.parentNode, pTagName);
}




function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}




function getSelectedItem(selectbox) {
    obj = findDOM(selectbox, false );

    i = obj.selectedIndex;

    return obj[i].value;
}

// Form validation function, courtesy Dreamweaver
//
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v3.0

  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=args[i+1]; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following fields need your attention:\n'+errors);
  document.MM_returnValue = (errors == '');
}

// Form Validation function with more options than above function
function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){s+='* '+a[i+3]+'\n'; err=false}
  }
  if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
  
document.MM_returnValue = (s=='');
}

function check_checkbox(theform,errmsg) {
    document.checkedIt = 0;
    if (document.all||document.getElementById) {
	    for (i=0;i<document.theform.length;i++){
    		var tempobj=document.theform.elements[i];
    		//alert(tempobj.value);
    		
    		if(tempobj.type.toLowerCase()=="checkbox") {
    		    if(tempobj.value.length>1) {		        
    			    if(document.theform.elements[i].checked) {			     
    			        document.checkedIt = 1;
    			    }
    			}
    		}
    	}
    	if(document.checkedIt == 0) {
    	    alert(errmsg);
    	   
    	}
    }
}

function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
	for (i=0;i<theform.length;i++){
		var tempobj=theform.elements[i]
		if(tempobj.type.toLowerCase()=="submit")
			//disable submit button
			tempobj.disabled=true
		}
	}
	tempobj.value="Synchronizing Data . . . .";
}

function IsNumeric(strString)
   //  check for valid numeric strings  
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

function TrimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}


function MM_changeProp(objName,x,theProp,theValue) {
    var obj = MM_findObj(objName);
  
    if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
        if (theValue == true || theValue == false)
            eval("obj."+theProp+"="+theValue);
        else 
	        eval("obj."+theProp+"='"+theValue+"'");
    }
}

//CheckUncheck all checkboxes
var checkflag = "false";
function SelectAll(field) {
	//alert(field);
		if (checkflag == "false") {
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;}
			checkflag = "true";
			return "Uncheck All"; 
		}else {
			for (i = 0; i < field.length; i++) {
				field[i].checked = false; 
			}
			checkflag = "false";
			return " Check All "; 
		}
}

// Autotab to next phone/fax field
// example: 
//<input name="Phone1" type="text" id="Phone1" size="3" maxlength="3" onKeyDown="TabNext(this,'down',3)" onKeyUp="TabNext(this,'up',3,formname.Phone2)">
//<input type="text" name="Phone2" id="Phone2" size="3" maxlength="3" onKeyDown="TabNext(this,'down',3)" onKeyUp="TabNext(this,'up',3,formname.Phone3)">
//<input type="text" name="Phone3" id="Phone3" size="4" maxlength="4">
var phone_field_length=0;
function TabNext(obj,event,len,next_field) {
	if (event == "down") {
		phone_field_length=obj.value.length;
		}
	else if (event == "up") {
		if (obj.value.length != phone_field_length) {
			phone_field_length=obj.value.length;
			if (phone_field_length == len) {
				next_field.focus();
			}
		}
	}
}

// Locate all sortable tables and toggle visiblity to none for all except
// the requested one.
//    
function activateResultSet(link_node, to_activate) {

    // Find all tables with class sortable and make them invisible, then change
    // the requested on to visible.
    //
    if (!document.getElementsByTagName) return;

    tbls = document.getElementsByTagName("div");

    for (ti=0;ti<tbls.length;ti++) {
        thisTbl = tbls[ti];
        if (((' '+thisTbl.className+' ').indexOf("resultset") != -1) && (thisTbl.id)) {
            thisTbl.style.display = "none";
        }
    }

    // Raise the requested panel
    //
    visibilityToggle(to_activate);

    // In order to highlight the clicked-on tab, we set all the tabs to style
    // "nothing" and the clicked one to "selected".  These styles are in isa.css.
    //
    var li = link_node.parentNode;
    var ul = li.parentNode;

    // In order to highlight the clicked-on tab, we set all the tabs to style
    // "nothing" and the clicked one to "selected".  These styles are in isa.css.
    //
    var li = link_node.parentNode;
    var ul = li.parentNode;

    for (var i=0;i<ul.childNodes.length;i++) {
        var item = ul.childNodes[i];
        if (item!=null && item.nodeName == "LI")
            item.className = "";
    }

    link_node.parentNode.className = "TabMenuCurrent";

}    
