
function IsNumeric(input){
   return (input - 0) == input && input.length > 0;
}

function getJulian(myday, mymonth, myyear) {
    MM=eval(mymonth)
    DD=eval(myday)
    YY=eval(myyear)
    with (Math) {  
      GGG = 1;
      if (YY <= 1585) GGG = 0;
      JD = -1 * floor(7 * (floor((MM + 9) / 12) + YY) / 4);
      S = 1;
      if ((MM - 9)<0) S=-1;
      A = abs(MM - 9);
      J1 = floor(YY + S * floor(A / 7));
      J1 = -1 * floor((floor(J1 / 100) + 1) * 3 / 4);
      JD = JD + floor(275 * MM / 9) + DD + (GGG * J1);
      JD = JD + 1721027 + 2 * GGG + 367 * YY;
    }
	return JD;
}

function getJulianFulldate(date){
	var mySplit = date.split("/");
	return getJulian(mySplit[1], mySplit[0], mySplit[2]);
}

/*  MOD  --  Modulus function which works for non-integers.  */
function mod(a, b)
{
    return a - (b * Math.floor(a / b));
}

var GREGORIAN_EPOCH = 1721425.5;


function gregorian_to_jd(year, month, day)
{
    return (GREGORIAN_EPOCH - 1) +
           (365 * (year - 1)) +
           Math.floor((year - 1) / 4) +
           (-Math.floor((year - 1) / 100)) +
           Math.floor((year - 1) / 400) +
           Math.floor((((367 * month) - 362) / 12) +
           ((month <= 2) ? 0 :
                               (leap_gregorian(year) ? -1 : -2)
           ) +
           day);
}

//  LEAP_GREGORIAN  --  Is a given year in the Gregorian calendar a leap year ?
function leap_gregorian(year)
{
    return ((year % 4) == 0) &&
            (!(((year % 100) == 0) && ((year % 400) != 0)));
}

function jd_to_cal( jd ){
//alert("in jd_to_cal " + jd);
    var wjd, depoch, quadricent, dqc, cent, dcent, quad, dquad,
        yindex, dyindex, year, yearday, leapadj;

    wjd = Math.floor(jd - 0.5) + 0.5;
    depoch = wjd - GREGORIAN_EPOCH;
//    depoch = wjd - 1721425.5;
//alert("made it this far");
    quadricent = Math.floor(depoch / 146097);
    dqc = mod(depoch, 146097);
    cent = Math.floor(dqc / 36524);
    dcent = mod(dqc, 36524);
    quad = Math.floor(dcent / 1461);
    dquad = mod(dcent, 1461);
    yindex = Math.floor(dquad / 365);
    year = (quadricent * 400) + (cent * 100) + (quad * 4) + yindex;
    if (!((cent == 4) || (yindex == 4))) {
        year++;
    }
    yearday = wjd - gregorian_to_jd(year, 1, 1);
    leapadj = ((wjd < gregorian_to_jd(year, 3, 1)) ? 0
                                                  :
                  (leap_gregorian(year) ? 1 : 2)
              );
    month = Math.floor((((yearday + leapadj) * 12) + 373) / 367);
    day = (wjd - gregorian_to_jd(year, month, 1)) + 1;

//    return new Array(year, month, day);
	var retval = month + "/" + day + "/" + year;
//alert("leaving with " + retval);
	return retval;
}

function getdata(what,where) { // get data from source (what)
//alert("in getdata");
	// set the where window to the loading image
	var tempTable = '<table class="data_table" border="1" bordercolor="#dedede" width="640" align="center">';
	tempTable = tempTable + '<tr>';
	tempTable = tempTable + '<td>';
	tempTable = tempTable + '<img src="images/ajax-loader.gif">';
	tempTable = tempTable + '</td>';
	tempTable = tempTable + '</tr>';
	tempTable = tempTable + '<tr>';
	tempTable = tempTable + '<td>';
	tempTable = tempTable + 'Loading...';
	tempTable = tempTable + '</td>';
	tempTable = tempTable + '</tr>';
	tempTable = tempTable + '</table>';

//alert("we are here");
	 try {
   xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
  		new ActiveXObject("Microsoft.XMLHTTP");
	 }
	 catch (e) { /* do nothing */ }
//alert("made it this far");
	document.getElementById(where).innerHTML = tempTable;
// 		document.getElementById(where).innerHTML ="put load image here";
// we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
//alert("made it that far");
	 ajaxdestination=where;

	 
//alert("destination set");
 	xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
//alert("about to get");
 	xmlhttp.open("GET", what);
//alert("got, about to send");
 	xmlhttp.send(null);
//alert("about to return");
  return false;
}

function triggered() { // put data returned by requested URL to selected DIV
//alert("in triggered - destination = " + ajaxdestination);
  if (xmlhttp.readyState == 4) if (xmlhttp.status == 200) {
//alert("response = " + xmlhttp.responseText);
//alert("ajaxdestination is " + ajaxdestination);
    document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
  }
}

function topicSelectRedirect(foo){
//alert("in topicSelectRedirect");
	var myindex  = foo.selectedIndex;
    var SelValue = foo.options[myindex].value;
	window.location = SelValue;
}

// functions used for js_table
function jsTableSetPage(whatPage){
	jstCurrPage = whatPage;
	replaceDiv();
}

//jstAliasList = new Array();
// all the vars we need for the jstTable stuff
jstAliasList = null;
jstDispNames = null;
		// set initial variables
jstCurrPage = 0;
jstFirstSort = 0;
jstCurrSort = -99;
jstCurrSortType = "";
jstOldSort = -99;
jstMaxPerPage = 50;
jstFilter = -99;
jstFilterValue = "";

function jsTableReplaceDiv(dispArray, tableName, targetID, aliasList){
	if (dispArray == null){
//alert("in jsTableReplaceDiv with null");
		newTable = "";
		newTable = newTable + '<table border="0" class="jstMainTable">';
		newTable = newTable + '<tr>';
		newTable = newTable + '<td class="jstTableData">';
		newTable = newTable + 'The database is currently empty';
		newTable = newTable + '</td>';
		newTable = newTable + '</tr>';
		newTable = newTable + '</table>';
//		alert("null tableset");
	} else {
//alert("in jsTableReplaceDiv");
		newArray = null;
		newArray = new Array;
		for (loop = 0; loop < dispArray.length; loop++){
			newArray[loop] = new Array;
			newArray[loop] = dispArray[loop];
		}
	
		// add filter
		if (jstFilter != -99){
	//alert("filtering");		
			// we have a filter
			tempArray = null;
			tempArray = new Array;
			tempArrayCount = 0;
			for (loop = 0; loop < newArray.length; loop++){
				if (jstFilterValue == newArray[loop][jstFilter]){
	//alert("we have a match");				
					tempArray[tempArrayCount] = new Array;
					tempArray[tempArrayCount] = newArray[loop];
					tempArrayCount += 1;
				}
			}
			
			// copy the array back to newArray;
			newArray = tempArray;
		}
		
		// add sorting
		if (jstCurrSort != -99){
			if (jstCurrSortType == "desc"){
	//alert("desc");		
				newArray.sort(jstSortBy2);
	//			if (jstOldSort != -99){
	//				jstCurrPage = 0;
	//			}
				jstOldSort = -99;
			} else {
	//alert("asc");		
				newArray.sort(jstSortBy);	
				jstOldSort = jstCurrSort;
			}
		}
		
	//alert("Creating Table");
		// create the new table
		var newTable = "";
	//alert("displaying size = " + newArray.length);
		newTable = newTable + '<table border="0" class="jstMainTable">';
		// tell the user what the hell they are searching for
	//	if (currSearch != ""){
	//		newTable = newTable + '<tr>';
	//		newTable = newTable + '<td>';
	//		newTable = newTable + '<span class="date">Current Search is: ' + currSearch + '</span>';
				
	//		newTable = newTable + '</td>';
	//		newTable = newTable + '</tr>';
	//	}
/* - REmoved from the top per pathik 
		if (newArray.length > jstMaxPerPage){
	//alert("multipage");
			newTable = newTable + '<tr>';
			newTable = newTable + '<td>';
	
			newTable = newTable + '<table border="0" class="jstTable2">';
			newTable = newTable + '<tr align="right">';
			newTable = newTable + '<td class="jstPageRow"><span class="jstPage">Page</span>  ';
			pageCounter = 1;
			for (loop = 0; loop < newArray.length; loop = loop + jstMaxPerPage){
	//alert("page " + pageCounter);
						newTable = newTable + '<span class="hand jstPage" onClick="jstSetPage(' + (pageCounter - 1) + ')">' + pageCounter + '</span> ';
						pageCounter = pageCounter + 1;
			}
			newTable = newTable + '</td>';
			newTable = newTable + '</tr>';
			newTable = newTable + '</table>';
	
			newTable = newTable + '</td>';
			newTable = newTable + '</tr>';
		}
	//	for (loop = 0; loop < newArray.length; loop++){
*/		
		if (((jstCurrPage * jstMaxPerPage) + jstMaxPerPage) > newArray.length){
			maxOut = newArray.length;
		} else {
			maxOut = (jstCurrPage * jstMaxPerPage) + jstMaxPerPage;
		}
		
		// start the element table
		newTable = newTable + '<tr>';
		newTable = newTable + '<td>';
	
		// check for filters
		if (aliasList != null){
	//alert("aliasList exists - disp names");		
			// aliaslist exists
			for (loop = 0; loop < aliasList.length; loop++){
				newTable = newTable + '<table  border="0" class="jstFilterTable">';
				if ((jstAliasVar("filter", aliasList[loop][2]) != -1) || (jstAliasVar("filteralias", aliasList[loop][2]) != -1)){
					// create a filter for this element
					newTable = newTable + '<tr>';
					newTable = newTable + '<td class="jstTableFilterLabel">';
					newTable = newTable + 'Filter by ' + aliasList[loop][1];
					newTable = newTable + '</td>';
					newTable = newTable + '<td class="jstTableFilterSpace">&nbsp;</td>';
					newTable = newTable + '<td>';
					newTable = newTable + '<select name="filter" onchange="jstSetFilter(this.options[this.selectedIndex].value, ' + aliasList[loop][0] + ')" class="jstFilterSelect">';
					// create a "blank" option
					newTable = newTable + '<option value="-99"></option>';
					// populate with all the values from dispArray
					filterArray = null;
					filterArray = new Array;
					for (filterLoop = 0; filterLoop < dispArray.length; filterLoop++){
						filterArray[filterLoop] = new Array;
						filterArray[filterLoop] = dispArray[filterLoop];
					}
					// sort the filterArray to get that column in order
	//				filterArray.sort(jstSortBy);
					
					var oldFilterVar = "";
					for (filterLoop = 0; filterLoop < filterArray.length; filterLoop++){
	//alert("filterloop = " + filterLoop + " looking at column " + aliasList[loop][0] + " value " + filterArray[filterLoop][aliasList[loop][0]]);
						if (filterArray[filterLoop][aliasList[loop][0]] != oldFilterVar){
							// we should have a new option
							newTable = newTable + '<option value="' + filterArray[filterLoop][aliasList[loop][0]] + '"';
							// check to see if this is already selected
							if ((jstFilter == aliasList[loop][0]) && (jstFilterValue == filterArray[filterLoop][aliasList[loop][0]])){
	//alert("selected");							
								newTable = newTable + " SELECTED";
							}
							newTable = newTable + '>';
							// see if it is aliased or not
							if (jstAliasVar("filteralias", aliasList[loop][2]) != -1){
								newTable = newTable + get_string_from_array(jstAliasVar("dbtable", aliasList[loop][2]), jstAliasVar("dbindex", aliasList[loop][2]), jstAliasVar("dbalias", aliasList[loop][2]), filterArray[filterLoop][aliasList[loop][0]]);
								//newTable = newTable + "foo";
							} else {
								newTable = newTable + filterArray[filterLoop][aliasList[loop][0]];
							}
							newTable = newTable + '</option>';
							oldFilterVar = filterArray[filterLoop][aliasList[loop][0]];
						}
					}
	
					newTable = newTable + '</select>';
					newTable = newTable + '</td>';
					newTable = newTable + '</tr>';
				}
				
				// check for an aliased filter
				newTable = newTable + '</table>';
			}
		}
	
		// create the main data table
		newTable = newTable + '<table  border="0" class="jstTable">';
	
		// display the titles
		newTable = newTable + '<tr>';
	//alert("checking aliasList");
	//alert("aliasList length " + aliasList.length);
		if (aliasList != null){
	//alert("aliasList exists - disp names");		
			// aliaslist exists
			for (loop = 0; loop < aliasList.length; loop++){
				newTable = newTable + '<td class="jstTableHeader"';
				if (jstAliasVar("width", aliasList[loop][2]) != -1){
	//alert("loop - " + loop + " our of a max " + aliasList.length + " width var found to be " + jstAliasVar("width", aliasList[loop][3]));
					newTable = newTable + ' width="' + jstAliasVar("width", aliasList[loop][2]) + '%"'
				}
				if (jstAliasVar("widthpx", aliasList[loop][2]) != -1){
//alert("loop - " + loop + " our of a max " + aliasList.length + " pixel width var found to be " + jstAliasVar("widthpx", aliasList[loop][2]));
					newTable = newTable + ' width="' + jstAliasVar("width", aliasList[loop][2]) + '"'
				}
				newTable = newTable + '>';
				if (aliasList[loop][1] == "Options"){
					newTable = newTable + '<div class="jstTableHeader">';
					newTable = newTable + aliasList[loop][1];
					newTable = newTable + '</div></td>';
				} else {
					newTable = newTable + '<div class="hand" onClick="jstSetSort(' + loop + ');">';
					newTable = newTable + aliasList[loop][1];
					newTable = newTable + '</div></td>';
				}
	}
		} else {
	//alert("aliasList does not exist");		
			// an alias list does NOT exist, run every element
			for (loop = 0; loop < tableName.length; loop++){
				newTable = newTable + '<td><div class="hand" onClick="jstSetSort(' + loop + ');">' + tableName[loop] + '</div></td>';
			}
		}
	
		newTable = newTable + '</tr>';
		
		thisRow = 0;
		
		// loop for each element
	//alert("adding elements");
		for (loop = (jstCurrPage * jstMaxPerPage); loop < maxOut; loop++){
	//alert("line " + loop);
			if (aliasList != null){
				newTable = newTable + '<tr>';
				for (loop2 = 0; loop2 < aliasList.length; loop2++){
	//alert("element " + loop2);				
					newTable = newTable + '<td';
					thisJSTVar = jstAliasVar("align", aliasList[loop2][2]);
					if (thisJSTVar != -1){
						newTable = newTable + ' align="' + thisJSTVar + '"';
					}
					if (thisRow % 2){
						newTable = newTable + ' class="jstTableData">';
					} else {
						newTable = newTable + ' class="jstTableData1">';
					}
	
	//alert("header built");
					// see if there is a link
					if (jstAliasVar("link", aliasList[loop2][2]) != -1){
	//alert("we have a link on field " + loop2);
						newTable = newTable + '<a href="' + jstAliasVar("link", aliasList[loop2][2]);
						if (jstAliasVar("linkadfield", aliasList[loop2][2]) != -1){
							newTable = newTable + "=" + newArray[loop][jstAliasVar("linkadfield", aliasList[loop2][2])];
						}
						newTable = newTable + '" class="jstTableLink">';
					}
					
					if (aliasList[loop2][0] != -99){
						thisDispVar = newArray[loop][aliasList[loop2][0]];
						if (jstAliasVar("dbtable", aliasList[loop2][2]) != -1){
//alert("dbTable = " + jstAliasVar("dbtable", aliasList[loop2][2]));
//alert("dbindex = " + jstAliasVar("dbindex", aliasList[loop2][2]));
//alert("dbalias = " + jstAliasVar("dbalias", aliasList[loop2][2]));
							thisDispVar = get_string_from_array(jstAliasVar("dbtable", aliasList[loop2][2]), jstAliasVar("dbindex", aliasList[loop2][2]), jstAliasVar("dbalias", aliasList[loop2][2]), thisDispVar);
						}
						if (jstAliasVar("stripHTML", aliasList[loop2][2]) != -1){
							thisDispVar = thisDispVar.stripHTML();
						}
						if (jstAliasVar("julianToDate", aliasList[loop2][2]) != -1){
							thisDispVar = jd_to_cal(thisDispVar);
						}
						if (jstAliasVar("length", aliasList[loop2][2]) != -1){
		//alert("setting the length to " + thisLength + " for row " + loop + " column " + loop2);
							if (thisDispVar.length > jstAliasVar("length", aliasList[loop2][2])){
		//alert("trimming");						
								thisDispVar = thisDispVar.slice(0,jstAliasVar("length", aliasList[loop2][2])) + "...";
							}
						}
						if (jstAliasVar("format", aliasList[loop2][2]) != -1){
							switch (jstAliasVar("format", aliasList[loop2][2])){
								case "money": 
									thisDispVar = "$" + CurrencyFormatted(thisDispVar);
									break;
								case "percent": 
									thisDispVar = thisDispVar + "%";
									break;
							}
						}
					} else {
						thisDispVar = "";
						// get value of extra
						switch (jstAliasVar("extra", aliasList[loop2][2])){
							case "button":
								// get the text, and convert _ to space
								thisDispText = jstAliasVar("btnText", aliasList[loop2][2]);
								thisDispText = thisDispText.replace(/_/g, " ");
								// create the "edit" button
								thisDispVar = thisDispVar + '<INPUT type="button" value="' + thisDispText + '" class="jstButton" onClick="location.href=\'' + jstAliasVar("editlink", aliasList[loop2][2]);
								if (jstAliasVar("editadfield", aliasList[loop2][2]) != -1){
									thisDispVar = thisDispVar + '=' + newArray[loop][jstAliasVar("editadfield", aliasList[loop2][2])];
								}
								thisDispVar = thisDispVar + '\'">';
//alert("this button = " + thisDispVar);
								break;
							case "edit/del":
								// create the "edit" button
								thisDispVar = thisDispVar + '<INPUT type="button" value="Edit" class="jstButton" onClick="location.href=\'' + jstAliasVar("editlink", aliasList[loop2][2]);
								if (jstAliasVar("editadfield", aliasList[loop2][2]) != -1){
									thisDispVar = thisDispVar + '=' + newArray[loop][jstAliasVar("editadfield", aliasList[loop2][2])];
								}
								thisDispVar = thisDispVar + '\'">';
	
								// create the "del" button
								thisDispVar = thisDispVar + '<INPUT type="button" value="Delete" class="jstButton" onClick="if (confirm(\'Do you really want to delete this listing?\')) {window.location.href=\'' + jstAliasVar("dellink", aliasList[loop2][2]);
								if (jstAliasVar("deladfield", aliasList[loop2][2]) != -1){
									thisDispVar = thisDispVar + '=' + newArray[loop][jstAliasVar("deladfield", aliasList[loop2][2])];
								}
								thisDispVar = thisDispVar + "\'} else {void(\'\')};";
								thisDispVar = thisDispVar + '">';
								
								break;
							case "edit":
								// create the "edit" button
								thisDispVar = thisDispVar + '<INPUT type="button" value="Edit" class="jstButton" onClick="location.href=\'' + jstAliasVar("editlink", aliasList[loop2][2]);
								if (jstAliasVar("editadfield", aliasList[loop2][2]) != -1){
									thisDispVar = thisDispVar + '=' + newArray[loop][jstAliasVar("editadfield", aliasList[loop2][2])];
								}
								thisDispVar = thisDispVar + '\'">';
	
								break;
							case "del":
								// create the "del" button
								thisDispVar = thisDispVar + '<INPUT type="button" value="Delete" class="jstButton" onClick="if (confirm(\'Do you really want to delete this listing?\')) {window.location.href=\'' + jstAliasVar("dellink", aliasList[loop2][2]);
								if (jstAliasVar("deladfield", aliasList[loop2][2]) != -1){
									thisDispVar = thisDispVar + '=' + newArray[loop][jstAliasVar("deladfield", aliasList[loop2][2])];
								}
								thisDispVar = thisDispVar + "\'} else {void(\'\')};";
								thisDispVar = thisDispVar + '">';
								
								break;
						}
					}
	//alert("adding element");
					// show the var, at last
					newTable = newTable + thisDispVar;
					
					// see if we need to CLOSE a link
					if (jstAliasVar("link", aliasList[loop2][2]) != -1){
						newTable = newTable + '</a>';
					}
					
	//alert("closing element");
					newTable = newTable + '</td >';
				}
				newTable = newTable + '<tr>';
				thisRow = thisRow + 1;
	
			} else {
				// an alias list does NOT exist, run every element
				newTable = newTable + '<tr>';
				for (loop2 = 0; loop2 < jstDispArrayMaxArrayFields; loop2++){
					newTable = newTable + '<td >' + newArray[loop][loop2] + '</td>';
				}
				newTable = newTable + '<tr>';
			}
		}
		
		
		// finished with all elements, close the element table
		newTable = newTable + '</td>';
		newTable = newTable + '</tr>';
		newTable = newTable + '</table>';
	
		newTable = newTable + '</td>';
		newTable = newTable + '</tr>';
	
		// display the end of the table
	//alert("adding end of table");	
		if (newArray.length > jstMaxPerPage){
	//alert("multipage");
			newTable = newTable + '<tr>';
			newTable = newTable + '<td>';
	
			newTable = newTable + '<table border="0" class="jstTable2">';
			newTable = newTable + '<tr align="right">';
			newTable = newTable + '<td class="jstPageRow2"><span class="jstPage">Page</span>  ';
			pageCounter = 1;
			for (loop = 0; loop < newArray.length; loop = loop + jstMaxPerPage){
	//alert("page " + pageCounter);
						newTable = newTable + '<span class="hand jstPage" onClick="jstSetPage(' + (pageCounter - 1) + ')">' + pageCounter + '</span> ';
						pageCounter = pageCounter + 1;
			}
			newTable = newTable + '</td>';
			newTable = newTable + '</tr>';
			newTable = newTable + '</table>';
	
			newTable = newTable + '</td>';
			newTable = newTable + '</tr>';
		}
			newTable = newTable + '<tr>';
			newTable = newTable + '<td>';
			newTable = newTable + '<table>';
			newTable = newTable + '</table>';
			newTable = newTable + '</td>';
			newTable = newTable + '</tr>';
		
		newTable = newTable + '</table>';
//alert("replacing");
	}
	
	document.getElementById(targetID).innerHTML = newTable; 
}

function jstSetFilter(foo, thisColumn){
	if (foo != -99){
//alert("fooval is [" + foo + "]");		
		jstFilter = thisColumn;
		jstFilterValue = foo;
	} else {
		jstFilter = -99;
		jstFilterValue = "";
	}
	jsTableReplaceDiv(jstDispArray, jstDispNames, "dataplace", jstAliasList);
}

// this will need to be rewritten for each one
function get_string_from_array(thisDbTable, thisDbIndex, thisDbAlias, thisValue){
//alert("table=" + thisDbTable + " index=" + thisDbIndex + " alias=" + thisDbAlias + " value=" + thisValue);
	// get the database
	switch (thisDbTable){
		case "jstCategory":
			thisDb = jstCategory;
			break;
		case "jstCat":
			thisDb = jstCat;
			break;
		case "jstCust":
			thisDb = jstCust;
			break;
		case "jstItems":
			thisDb = jstItems;
			break;
		case "userNameCheck":
			thisDb = userNameCheck;
			break;
	}

//alert("entering loop - length = " + thisDb.length);
	for (thisLoop = 0; thisLoop < thisDb.length; thisLoop++){
//alert("looking at item = " + thisLoop + " comparing " + thisDb[thisLoop][thisDbIndex] + " and " + thisValue);
		if (thisDb[thisLoop][thisDbIndex] == thisValue){
			return(thisDb[thisLoop][thisDbAlias]);
		}
	}
	return "";
}

function jstSetSort(foo){
	if (foo == jstCurrSort){
		// hit column again, toggle jstCurrSortType
		if (jstCurrSortType == "asc"){
			jstCurrSortType = "desc";
		} else {
			jstCurrSortType = "asc";
		}
	} else {
		// new column
		jstCurrSort = foo;
	}
	jstCurrPage = 0;
	jsTableReplaceDiv(jstDispArray, jstDispNames, "dataplace", jstAliasList);
}

function jstSetPage(whatPage){
	jstCurrPage = whatPage;
	jstSortPageadv = 1;
//alert("setting current page to " + whatPage);
	jsTableReplaceDiv(jstDispArray, jstDispNames, "dataplace", jstAliasList);
//	jsTableReplaceDiv(jstDispArray, jstDispNames, "dataplace", null);

//	replaceDiv();
}

function jstAliasVar(whatVar, whatList){
//alert("jstAliasVar is looking for " + whatVar + " in " + whatList);
	stringList = whatList.split(' ').join('');
	stringList = stringList.split(",");
	for (jstLoop = 0; jstLoop < stringList.length; jstLoop++){
		thisElement = stringList[jstLoop];
		thisVar = thisElement.split("=");
		if (thisVar[0] == whatVar){
			// put the rest back together
			var retval = "";
			var isFirst = 0;
			for (jstLoop2 = 1; jstLoop2 < thisVar.length; jstLoop2++){
				if (isFirst == 0){
					isFirst = 1;
				} else {
					retval = retval + "=";
				}
				retval = retval + thisVar[jstLoop2];
			}
			return(retval);
		}
	}
	return(-1);
}

function jstFilterSort(a,b){
	// what is the REAL currSort
	realCurrSort = jstCurrSort;
	if (jstAliasList != null){
		realCurrSort = jstAliasList[jstCurrSort][0];
	}
//alert("real sort column is " + 	realCurrSort);
	
	if (IsNumeric(a[realCurrSort])){
		return a[realCurrSort] - b[realCurrSort];
	} else {
		if (jstCurrSort == 0){
			var first = a[realCurrSort];
			var second = b[realCurrSort];
			first = first.toLowerCase();
			second = second.toLowerCase();
			if (first<second) return -1;
			if (first>second) return 1;
		} else {
			if (a[jstCurrSort]<b[jstCurrSort]) return -1;
			if (a[jstCurrSort]>b[jstCurrSort]) return 1;
		}
	}
return 0;
}

function jstSortBy(a,b) {
	// what is the REAL currSort
	realCurrSort = jstCurrSort;
	if (jstAliasList != null){
		realCurrSort = jstAliasList[jstCurrSort][0];
	}
//alert("real sort column is " + 	realCurrSort);
	
	if (IsNumeric(a[realCurrSort])){
		return a[realCurrSort] - b[realCurrSort];
	} else {
		if (jstCurrSort == 0){
			var first = a[realCurrSort];
			var second = b[realCurrSort];
			first = first.toLowerCase();
			second = second.toLowerCase();
			if (first<second) return -1;
			if (first>second) return 1;
		} else {
			if (a[jstCurrSort]<b[jstCurrSort]) return -1;
			if (a[jstCurrSort]>b[jstCurrSort]) return 1;
		}
	}
return 0;
}

function jstSortBy2(a,b) {
	// what is the REAL currSort
	realCurrSort = jstCurrSort;
	if (jstAliasList != null){
		realCurrSort = jstAliasList[jstCurrSort][0];
	}
//alert("real sort column is " + 	realCurrSort);

	if (IsNumeric(a[realCurrSort])){
		return b[realCurrSort] - a[realCurrSort];
	} else {
		if (jstCurrSort == 0){
			var first = a[realCurrSort];
			var second = b[realCurrSort];
			first = first.toLowerCase();
			second = second.toLowerCase();
			if (first>second) return -1;
			if (first<second) return 1;
		} else {
			if (a[jstCurrSort]>b[jstCurrSort]) return -1;
			if (a[jstCurrSort]<b[jstCurrSort]) return 1;
		}
	}
return 0;
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
// end of function CurrencyFormatted()

String.prototype.stripHTML = function(){
        // What a tag looks like
        var matchTag = /<(?:.|\s)*?>/g;
        // Replace the tag
        return this.replace(matchTag, "");
};