function highlightOnNav(tabName)
{
	getById('tab' + tabName).className = 'navtabon';
	getById('lnk' + tabName).className = 'navon';
}
function highlightOnListingNav(tabName)
{
	getById('tab' + tabName).className = 'subtabon';
	getById('lnk' + tabName).className = 'tabon';
}
function highlightOnSubNav(linkName)
{
	getById(linkName).className = 'subnavon';
}
function ResizeWindowLimitedToScreenSize(width, height)
{
	var windowWidth = width > screen.availWidth ? screen.availWidth : width;	
	var windowHeight = height > screen.availHeight ? screen.availHeight : height;
	
	window.resizeTo(windowWidth, windowHeight);
}
function UnderlineItem(itemName)
{
	getById(itemName).style['textDecoration'] = 'underline';
}
function ListingNav(tabName, itemName)
{
	getById('tab' + tabName).className = 'subtabon';
	getById(itemName).className = 'tabon';
	
}
function IsNumeric(sender, args) {
   //  check for valid numeric strings
	var strString = args.Value;
	var strValidChars = ",0123456789.-";
	var strChar;
	var blnResult = true;
	if (strString.length == 0) 
	{
		args.IsValid = false;
		return;
	}

	//  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;
		}
	}
	args.IsValid = blnResult;
	return;
}   
function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))	num = "0";
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	num = Math.floor(num/100).toString();
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
	
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num);
}
/********* UTILITY   *****************************************************************************************************/
function getTwoDigitDecimal(n)
{
    var s = "" + Math.round(n * 100)/100;
    var i = s.indexOf('.');
    if(i < 0)
    {
        return s + ".00";
    }
    var d = s.substring(0, i+1) + s.substring(i+1, i+3);
    if(i+2 == s.length)
    {
        d += "0";
    }
    return d;
}
function getFourDigitDecimal(n)
{
    var s = "" + Math.round(n * 10000)/10000;
    var i = s.indexOf('.');
    if(i < 0)
    {
        return s + ".00";
    }
    var d = s.substring(0, i+1) + s.substring(i+1, i+5);
    if(i+2 == s.length)
    {
        d += "0";
    }
    return d;
}
function getInteger(n)
{
    var s = "" + Math.round(n * 100)/100;
    var i = s.indexOf('.');
    if(i < 0)
    {
        return s;
    }
    var d = s.substring(0, i+1);
    if(i+2 == s.length)
    {
        d += "0";
    }
    return d;
}
function toIntPercent(elmID)
{
    elm = getById(elmID);
    n = getInteger(elm.value)+"%";
    elm.value = n;
}
function toDecimalPercent(elmID)
{
    elm = getById(elmID);
    n = getTwoDigitDecimal(elm.value)+"%";
    elm.value = n;
}
function toInt(elmID)
{
    elm = getById(elmID);
    n = elm.value.replace("%", "");
    elm.value = getInteger(n);
}
function toDecimal(elmID)
{
    elm = getById(elmID);
    n = elm.value.replace("%", "");
    elm.value = getTwoDigitDecimal(n);
}
function toDollarsAndCents(n) 
{
	var s= "" + Math.round(n * 100)/100;
	var i = s.indexOf('.');
	if (i < 0) { return s + ".00"; }
	var t = s.substring(0, i+1) + s.substring(i + 1, i + 3);
	if (i + 2 == s.length) { t += "0"; }
    return t;
}
function getById(id) 
{
    if (document.getElementById) 
    {
		return document.getElementById(id);
    } 
    else if (document.all) 
    {
		return document.all[id];
    }
    return null;
}
function ChkBox(cBoxName, CheckIt)
{
	getById(cBoxName).checked = CheckIt;
}
function ChkBoxNew(allCBoxName, cBoxName, CheckIt)
{
	getById(cBoxName).checked = getById(allCBoxName).checked;	
}
function isDigit(num) 
{
    if (num.length > 1) { return false; }
    var string = "1234567890";
    if (string.indexOf(num) != -1) { return true; }
    return false;
}
function isInteger(s)
{
    var i;
    if (s == null || s.length == 0) { return false; }
    else 
    {
        for (i = 0; i < s.length; i++)
        {
            var c = s.charAt(i);
            if (!isDigit(c)) { return false; }
        }
    }
    return true;
}
function isDecimal(s)
{
    var i;
    var dp = 0;
    if (s == null || s.length == 0) { return false; }
    else 
    {
        for (i = 0; i < s.length; i++)
        {
            var c = s.charAt(i);
            if(i > 0 && i < s.length-1)
            {
                if(dp == 0)
                {
                    if(c == ".") { dp = 1; }
                    else if (!isDigit(c)) { return false; }
                }
                else if (!isDigit(c)) { return false; }
            }
            else
            {
                if (!isDigit(c)) { return false; }
            }
        }
    }
    return true;
}
function isInteger2(s)
{
    var i;
    if (s == null || s.length == 0)
    {
        if (isInteger.arguments.length == 1) { return 0; }
    }
    else { return (isInteger.arguments[1] == true); }
    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (!isDigit(c)) { return false; }
    }
    return true;
}
function isValidEmail(email, required) 
{
    if (required==undefined) { required = true; }
    if (email==null) 
    {
        if (required) { return false; }
        return true;
    }
    if (email.length==0) 
    {  
        if (required) { return false; }
        return true;
    }
    if (!allValidChars(email)) { return false; }
    if (email.indexOf("@") < 1) { return false; } 
    else if (email.lastIndexOf(".") <= email.indexOf("@")) { return false; } 
    else if (email.indexOf("@") == email.length) { return false; } 
    else if (email.indexOf("..") >=0) { return false; } 
    else if (email.indexOf(".") == email.length) { return false; }
    return true;
}
function isDate(sDate) 
{
    var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/
    if (re.test(sDate)) 
    {
        var dArr = sDate.split("/");
        var d = new Date(sDate);
        return d.getMonth() + 1 == dArr[0] && d.getDate() == dArr[1] && d.getFullYear() == dArr[2];
    }
    else { return false; }
}
function allValidChars(email) 
{
    var parsed = true;
    var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
    for (var i=0; i < email.length; i++) 
    {
        var letter = email.charAt(i).toLowerCase();
        if (validchars.indexOf(letter) != -1) { continue; }
        parsed = false;
        break;
    }
    return parsed;
}
function getFormattedDate(dt) 
{
    if (!dt) { return ''; }
    return (dt.getMonth() + 1) + '/' + dt.getDate() + '/' + dt.getFullYear()
}
function getFormattedTime(dateValue) 
{
    var hours = dateValue.getHours();
    var minutes = dateValue.getMinutes();
    var timeValue = "" + ((hours >12) ? hours -12 :hours)
    if (timeValue == "0") { timeValue = 12; }
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes
    timeValue += (hours >= 12) ? " PM" : " AM"
    return timeValue;
}
function getElementPosition(obj) 
{
    var curleft = curtop = 0;
    if (obj.offsetParent) 
    {
	    curleft = obj.offsetLeft
	    curtop = obj.offsetTop
	    while (obj = obj.offsetParent)
	    {
		    curleft += obj.offsetLeft
		    curtop += obj.offsetTop
	    }
    }
    return [curleft, curtop];
}

/*Added By Andrew Below*/
// This function formats numbers by adding commas
function numberFormat(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;}

// This function removes non-numeric characters
function stripNonNumeric( str ){  str += '';  var rgx = /^\d|\.|-$/;  var out = '';  for( var i = 0; i < str.length; i++ ){    if( rgx.test( str.charAt(i) ) ){      if( !( ( str.charAt(i) == '.' && out.indexOf( '.' ) != -1 ) ||             ( str.charAt(i) == '-' && out.length != 0 ) ) ){        out += str.charAt(i);      }    }  }  return out;}

// This function formats numbers by adding commas and dollar sign
function currencyFormat(nStr){ nStr = roundNumber(nStr,2);  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'); var ret = x1 + x2; if(ret.indexOf('NaN')>-1)return '$0';  return '$' + x1 + x2;}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}/**********************************************************************************************************************************/
