/* Log Window Function */
/** Replace with:
		function log(message) { } // I.e. a null function
	when deploying. */
var logCount = 0;
function log(message) {
	var useExisting = true;
    if (!log.window_ || log.window_.closed) {
		var win;
		if (useExisting == true) {
			win = window.open("", "DebugLog", "width=400,height=200," +
								  "scrollbars=yes,resizable=yes,status=no," +
								  "location=no,menubar=no,toolbar=no");
		} else {
			win = window.open("", null, "width=400,height=200," +
								  "scrollbars=yes,resizable=yes,status=no," +
								  "location=no,menubar=no,toolbar=no");
		}
        if (!win) {
			return;
		}
		var doc = win.document;
		doc.write("<html><head><title>Debug Log</title><style>body { background: #333333; color: #dddddd; font-family: Courier New, Courier; font-size: 75%; }</style></head>" +
				  "<body></body></html>");
		doc.close();
		log.window_ = win;
    }
    var logLine = log.window_.document.createElement("div");
    logLine.appendChild(log.window_.document.createTextNode((logCount++) + "> " + message));
    log.window_.document.body.appendChild(logLine);
	log.window_.scrollBy(0,50);
}

function FormatCurrency(t) {
	var amount = t.value;
	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;
	t.value = s;
	//return "$" + s;
}

function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
	} else {
		expires = "";
	}
	document.cookie = name+"="+value+expires+";path=/";
}

function setCookieWithArray(name,arr,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
	} else {
		expires = "";
	}
	var cookieString = '';
	for (var k in arr) {
		cookieString += arr[k] + '|';
	}
	document.cookie = name+"="+cookieString+expires+";path=/";
}

/*
function testArrayCode() {
    var a = new Array();
    a['arg1'] = 123;
    a['arg2'] = 345;
    a['arg3'] = 567;
    a['arg4'] = 789;
    setCookieWithArray('cookieArray',a,1);
}
*/

function killCookie(name) {
	setCookie(name,"",-1);
}
