/*************************************************
** JAVASCRIPT FILE				**
**						**
** Author:  Adam Butler				**
** Contact: [webmaster@pacex.com]		**
** Description: This file includes all the main **
** 		javascripts for the PACEX	**
**		website.			**
** Created: Nov. 29, 2006			**
** Last Modified: Nov. 29, 2006			**
**						**
** ©2006 PACEX Package Express Inc.		**
**************************************************/


//************************************************
//*** Opens a new window that displays our
//*** certificates
//************************************************
function ShowISO()
{
	new_window = window.open("cert_iso.html","","screenx=0,screeny=0,width=710,height=580,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,resizable=no,status=no"); 		
}
function ShowFAST()
{
	new_window = window.open("cert_fast.html","","screenx=0,screeny=0,width=620,height=510,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,resizable=no,status=no");
}
function ShowCSA()
{
	new_window = window.open("cert_csa.html","","screenx=0,screeny=0,width=600,height=510,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,resizable=no,status=no");
}
function ShowCBSA()
{
	new_window = window.open("cert_cbsa.html","","screenx=0,screeny=0,width=645,height=500,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,resizable=no,status=no");
}
function ShowCTPAT()
{
	new_window = window.open("cert_ctpat.html","","screenx=0,screeny=0,width=410,height=645,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,resizable=no,status=no");
}


//************************************************
//*** Expands/Collapses the Certificate links on
//*** the left menu (ISO, FAST, CT-PAST, etc.)
//************************************************
function collapsethis(elem) {
	if (document.getElementById(elem).style.display=="none") {
		document.getElementById(elem).style.display="block";
	}
	else {	
		(document.getElementById(elem).style.display="none");
	}
}



//************************************************
//*** Changes the message in the status bar.
//*** Used for MouseOver on buttons.
//*** NOTE: Must be used with "return true".
//***
//*** MSG - The message to be displayed
//************************************************
function Status(MSG)
{
	window.status = MSG;
}


//************************************************
//*** Validates and submits "Client Login" form
//*** for CCWeb
//************************************************
function SubmitLogin()
{
	var sAccNo = document.forms.frmLogin.AccNo.value;
	var sUserID = document.forms.frmLogin.UserID.value;
	var sPasswd = document.forms.frmLogin.Passwd.value;

	var sMsg = "CLIENT LOGIN\n\nYou must fill in the following fields:\n";
	var errs = 0;

	var bGPSLogin = 0;

	sAccNo = sAccNo.replace(/^\s*|\s*$/g,"");
	sUserID = sUserID.replace(/^\s*|\s*$/g,"");
	sPasswd = sPasswd.replace(/^\s*|\s*$/g,"");

	if(sAccNo == '')
	{
		sMsg = sMsg + "\n     • Account Number";
		errs++;
	}
	if(sUserID == '')
	{
		sMsg = sMsg + "\n     • Login";
		errs++;
	}
	if(sPasswd == '')
	{
		sMsg = sMsg + "\n     • Password";
		errs++;
	}
	
	if(errs == 3)		window.open("http://www.pacex.com/ccWeb/login.aspx", "ccWeb");
	else if(errs > 0)	alert(sMsg);
	else {
		if(document.getElementById("RememberMe").checked)
		{
			createCookie("RememberLogin", "yes", 1825);
			createCookie("ccWebAccNo", sAccNo, 1825);
			createCookie("ccWebUserID", sUserID, 1825);
		}
		else
		{
			createCookie("RememberLogin", "no", -1);
			createCookie("ccWebAccNo", "", -1);
			createCookie("ccWebUserID", "", -1);
		}

		document.frmLogin.submit();
	}
}


//************************************************
//*** Load the website's cookie and fill in the
//*** ccWeb login fields (if applicable)
//************************************************
function RememberLogin() {
	var rem = readCookie("RememberLogin");
	if(rem == "yes")
	{
		document.forms.frmLogin.AccNo.value = readCookie("ccWebAccNo");
		document.forms.frmLogin.UserID.value = readCookie("ccWebUserID");
		document.getElementById("RememberMe").checked = true;
	}
}


//************************************************
//*** CREATECOOKIE()     //     READCOOKIE()
//***
//*** Creates/reads a coookie (for the 'Remember Me'
//*** checkbox on the ccWeb login)
//************************************************
function createCookie(name,value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";

	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


//************************************************
//*** EXCHLOGIN()
//***
//*** Displays security warning message for
//*** Exchange 'LOGIN' link.
//************************************************
function ExchLogin()
{
	alert('! AUTHORIZED ACCESS ONLY !\n\nUnauthorized persons who access this system will be reported to the authorities.\nOnly exployees of PACEX Transportation Solutions may log in to this system.');
	//window.location.href = "https://mail2.pacex.com/Exchange";
}
