
//var g_hostName = "factors-chain.com.dev";


// Hide all layers
function hideAllLayers() {
	
	closeAllSubMenus();
}


// Logon on enter
function submitOnEnter(event, formname) {

	if (navigator.appName == "Netscape") {
		var code = event.which;
	} else {
		var code = event.keyCode;
	}

	if (code == 13) {
		document.forms[formname].submit();
		return false;
	}
	
	return true;

}

function nav_main_click(id) {
	if (getCookie('cur_active_tab')!="") {
		setCookie('previous_tab', getCookie('cur_active_tab'), false, '/', '.' + g_hostName);
	}
	setCookie('cur_active_tab', id, false, '/', '.' + g_hostName);
}

function clear_main_nav_cookie() {
	delCookie('cur_active_tab');
}

// The specification for cookies says that browsers need support no more than 300 different cookies.
// Of those, no more than 20 should be associated with any particular server. 
// For each cookie, the data stored is not expected to exceed 4 kilobytes.
function setCookie(cookieName, cookieValue, expires, path, domain, secure) {
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; EXPIRES=' + expires.toGMTString() : '')
		+ (path ? '; PATH=' + path : '')
		+ (domain ? '; DOMAIN=' + domain : '')
		+ (secure ? '; SECURE' : '');
}

// A complementary function to unwrap a cookie.
function getCookie(cookieName) {
	
	var cookieValue = null;
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	
	if (posName != -1) {

		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);

		if (endPos != -1) {
			cookieValue = unescape(document.cookie.substring(posValue, endPos));
		} else {
			cookieValue = unescape(document.cookie.substring(posValue));
		}
	}
	return cookieValue;
}

function delCookie(cookieName,path, domain) {
	d = new Date();
	document.cookie = escape(cookieName) 
	+ '=; expires=' + getexpirydate(-1)
	+ (path ? '; PATH=' + path : '')
	+ (domain ? '; DOMAIN=' + domain : '');
} 


// Returns a date in UTC format which can be used to set an expiration date for a cookie
function getexpirydate(nodays){
	var UTCstring;
	Today = new Date();
	nomilli = Date.parse(Today);
	Today.setTime (nomilli + nodays * 24 * 60 * 60 * 1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}


function doBack() {
	delCookie('cur_active_tab', '/', '.' + g_hostName);
	//history.go(-1);
	history.back();
}

function printPreview(varid,tab,type) {
	window.open('/print_preview.php?varid='+varid+'&type='+type+'&tab='+tab,'Print','width=520,height=500,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no,top=40,left=50');
}