//format as us currency
Number.prototype.formatMoney = function(c, d, t){
    var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "." : d, t = t == undefined ? "," : t, s = n < 0 ? "-" : "",
    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t)
    + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};

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 convertCurrency(number, currency){
	
	var ret = "";

	switch(currency){
		
		case 'MYPOINTS':
			
			number = Math.ceil(number*100);
			
			number = addCommas(number);

			return number + " Points";
		
		default: //USD
			
			return "$" + number;
	}
};

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

var IE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
		
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
//document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var mouseX = 0;
var mouseY = 0;


function getWindowHeight() {

	var height = 0;

	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		height = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		height = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		height = document.body.clientHeight;
	}
	
	return height;
}

function getWindowWidth() {

	var width = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		width = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		width = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		width = document.body.clientWidth;
	}
	
	return width;
}

function getScrollTop(){
	
	var scrollTop = document.body.scrollTop;
	
	if (document.documentElement && document.documentElement.scrollTop){
		scrollTop = document.documentElement.scrollTop;	
	}
	
	return scrollTop;
}

function getScrollLeft(){
	
	var scrollLeft = document.body.scrollLeft;
	
	if (document.documentElement && document.documentElement.scrollLeft){
		scrollLeft = document.documentElement.scrollLeft;	
	}
	
	return scrollLeft;
}

function getMouseXY(e){
	
	if (IE) { // grab the x-y pos.s if browser is IE
		
		var scrollTop = getScrollTop();
		var scrollLeft = getScrollLeft();
		
		mouseX = event.clientX + scrollLeft;
		mouseY = event.clientY + scrollTop;
		
	} else {  // grab the x-y pos.s if browser is NS
		mouseX = e.pageX;
		mouseY = e.pageY;
	}  
	
	// catch possible negative values in NS4
	if (mouseX < 0){mouseX = 0}
	if (mouseY < 0){mouseY = 0}  
 
	return true
}

function unset_default_text(field, text){
	if(field.value == text){
		field.value = '';
	}
}

function set_default_text(field, text){
	if(field.value == ''){
		field.value = text;
	}
}

function hide(in_id)
{
	document.getElementById(in_id).style.visibility = "hidden";
}

function show(in_id)
{
	document.getElementById(in_id).style.visibility = "visible";
}

function get_event(e){
	
	if (!e) var e = window.event;

	return e;
	
}

function get_target(e){
	
	var targ;
	
	var e = get_event(e);
	
	if (e.target){
		
		targ = e.target;
		
	}else if (e.srcElement){
		
		targ = e.srcElement;
	
	}
	
	// defeat Safari bug
	if (targ.nodeType == 3) {
	
		targ = targ.parentNode;
	}
	
	return targ;
}

function get_key_code(e){
	
	var e = get_event(e);
	
	var key_code;
	
	if (e.keyCode){
		
		 key_code = e.keyCode;
		 
	}else if (e.which){
		
		key_code = e.which;
		
	}
	
	return key_code;
	
}

function getNextNode(node, name){

	parent = node.parentNode;
	
	children = parent.childNodes;
	
	var look = false;
	
	for(var i = 0; i < children.length; i++){
		
		if(look){
			
			if(children[i].nodeName == name){
			
				return children[i];
			
			}
		}
			
		if(children[i].id == node.id){
			
			look = true;
			
		}	
	}	
}

function getObj(name)
{
	if (document.getElementById && document.getElementById(name)){
		
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	
	}else if (document.all){

		this.obj = document.all[name];
		this.style = document.all[name].style;
	
	}else if (document.layers){
		
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}

function getFrameObj(name, frame_name)
{
	
	frame_doc = getFrame(frame_name).document;
		
	if (frame_doc.getElementById){
			
		this.obj = frame_doc.getElementById(name);
		this.style = frame_doc.getElementById(name).style;
		
	}else if (frame_doc.all){

		this.obj = frame_doc.all[name];
		this.style = frame_doc.all[name].style;
	
	}else if (frame_doc.layers){
		
		this.obj = frame_doc.layers[name];
		this.style = frame_doc.layers[name];
	}
}

function getFrame(frame_name){
	
	if(window.frames){
		
		return window.frames[frame_name];
	
	}else if(document.frames){
		
		return document.frames(frame_name);
		
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function loadXMLDoc(url, processChange) {
	// Internet Explorer


	try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) {
		try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch(oc) { req = null; }
	}
	
	// Mozailla/Safari
	if (req == null && typeof XMLHttpRequest != "undefined") {
		req = new XMLHttpRequest();
	}
	
	// Call the processChange() function when the page has loaded
	if (req != null) {
		
		//alert(url);
		
		req.onreadystatechange = processChange;
		req.open("GET", url, true);
		req.send(null);
	}
}

