
function roundNumber(num, dec) 
{
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function add_zeros(num, zeros) 
{
	// It will add trailing zeros
	if(zeros == undefined || zeros == null)
		zeros = 2;
		
	var result = num.toFixed(zeros); // result will equal 10.00
	return result;
}

/* checks max character length for textarea */
function textCounter(field, maxlimit) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
	{
		alert("You can not enter more than "+maxlimit+" characters");
		field.value = field.value.substring(0, maxlimit);
	}
}

function URLEncode(objSource)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = objSource.value;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
		if (ch == " ") {
			encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
			encoded += ch;
		} else {
			var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				alert( "Unicode Character '" 
						+ ch 
						+ "' cannot be encoded using standard URL encoding.\n" +
						  "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	//objDest.value = encoded;
	return encoded;
}

var zzz=0;
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
	if(zzz==1) { opacStart=30; opacEnd=100; }

	var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
	zzz++;	if(zzz==2) zzz=0;
	//alert(zzz);
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	if( document.getElementById(id) )
	{
		var object = document.getElementById(id).style;
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
	    object.filter = "alpha(opacity=" + opacity + ")";
	}
}

function formatPrice(price)
{
	var price = price;
	var price = new Number(price);
	var price = (price.toFixed(2));
	return price;
}
