﻿var exp_alphanumeric = /[\s0-9a-z]+/i ;
var exp_noSpace = /[^\s]/ ;
var exp_Space_head = /^(\s+)(\S?.*)$/ ;
var exp_Space_tail = /^(.*\S+)(\s+)$/ ;
var exp_Space_mid  = /^(\S+)(\s+)(\S?.*)$/ ;
var theElements    = document.forms[0].elements ;
var currentFormName = document.forms[0].name;
var curfocus = "";

var abackstroke = 47
//var last_mod_date_tou = ""
var last_mod_date_pss = "."
var last_mod_date_tou_format = "31 August 2004"
var last_mod_date_pss_format = "31 August 2004"
var last_mod_date_csda_format = "31 August 2004"
var csda_ver = "2.0"
var legal_year = "2000 - 2006"
var numOfCustomer = "30,000"
var last_mod_date_tou = " "
//var last_mod_date_pss = " (last updated October 2004)."
var screen_ht = screen.availHeight;
var screen_wd = screen.availWidth;
var screen_left = 0;
var screen_top = 10;
var monthsDesc = new Array();
var monthsNum = new Array();
var now	= "";
var sec	= "";
var min	= "";
var hr	= "";
var day	= "";
var month = "";
var year = "";
var nowutc = "";
var then = "";

//bdadmin/123456
FULL= CargoSmartConfig.FULL;
NONE= CargoSmartConfig.NONE;
MENUONLY= CargoSmartConfig.MENUONLY;
ALL = CargoSmartConfig.ALL;
waiturl = CargoSmartConfig.waiturl;
//waiturl = "http://hksudv54.oocl.com:7778/admin/login/ul_sign_in.jsf?action=doSignIn&ENTRY=MCC&ENTRY_TYPE=OOCL";
//alert(encodeURIComponent(waiturl));
serverurl = CargoSmartConfig.serverurl;
appSSLservlet = CargoSmartConfig.appSSLservlet;
//appSSLservlet = "http://hksudv54.oocl.com:7778/admin/login/ul_sign_in.jsf?action=doSignIn&ENTRY=MCC&ENTRY_TYPE=OOCL";

appdomain = CargoSmartConfig.appdomain;

TOUURL = serverurl.substring(0,serverurl.length-11)+"about/terms_of_use.htm";
COPYURL = serverurl.substring(0,serverurl.length-11)+"about/terms_of_use.htm#Section5";
PSSURL = serverurl.substring(0,serverurl.length-11)+"about/privacy_policy.htm"; 
EXITURL = serverurl.substring(0,serverurl.length-11)+"exit.htm";

var_submit_win = "navigation.submit_win"
var_ssl = "navigation.ssl"
var_proceed = true
function clearFocus(){
curfocus = "" ;
}
function onEnter(e)	{
    if (document.all) e = window.event;
    if (navigator.appName == 'Microsoft Internet Explorer')
        Key = window.event.keyCode;
    else
        Key = e.which;
	if (Key == 13)	{
		if (curfocus == "" || curfocus == "USER_NAME" || curfocus == "PASSWORD") { return false; }
	   
	}
	return true;
}


var jsversion = 1.2;
//var supported_browsers = {"IE":{"name":"IE", "min":6.0, "max": 9.99}, "firefox":{"name":"firefox", "min":2.0, "max": 5.99}};
var agt = navigator.userAgent.toLowerCase();
var debug = false;

function checkBrowser(){
    var errorCode = "";
    if (!navigator.cookieEnabled) {
        errorCode = "invalid_cookies_setting";
    }
    if (errorCode == "") {
        if (jsversion < 1.2) {
            errorCode = "invalid_js_version";
        }
    }
    return errorCode;
}
 
function clearSearchHidden(){
    curfocus = "";   
}

function setSearchFocus(what) {
	curfocus = what.name;	
}

function setEnterFocus(what) {   
	if (what.type == "password") { what.select(); }
	curfocus = what.name;
	
}

if (navigator.appName == 'Netscape') document.captureEvents(Event.KEYPRESS);
document.onkeypress = onEnter;

function setFocus() {
  theElements['USER_NAME'].focus();
}
function validate(){
  theElements['USER_NAME'].value =  theElements['USER_NAME'].value.replace(exp_Space_head, "$2");
  theElements['USER_NAME'].value =  theElements['USER_NAME'].value.replace(exp_Space_tail, "$1");
  theElements['PASSWORD'].value =  theElements['PASSWORD'].value.replace(exp_Space_head, "$2");
  theElements['PASSWORD'].value =  theElements['PASSWORD'].value.replace(exp_Space_tail, "$1");
  if ( ( theElements['USER_NAME'].value == "") ) {
    alert('Please type your User ID.');
    theElements['USER_NAME'].focus();
    return false;
  } else if ( ( theElements['PASSWORD'].value == "") ) {
    alert('Please type your Password.');
    theElements['PASSWORD'].focus();
    return false;
  } else {
     return true;
  }
}
function validateInput(){
  theElements['USER_NAME'].value =  theElements['USER_NAME'].value.replace(exp_Space_head, "$2");
  theElements['USER_NAME'].value =  theElements['USER_NAME'].value.replace(exp_Space_tail, "$1");
  theElements['PASSWORD'].value =  theElements['PASSWORD'].value.replace(exp_Space_head, "$2");
  theElements['PASSWORD'].value =  theElements['PASSWORD'].value.replace(exp_Space_tail, "$1");
  if ( ( theElements['USER_NAME'].value == "") ) {
    alert('Please type your User ID.');
    theElements['USER_NAME'].focus();
    return false;
  } else if ( ( theElements['PASSWORD'].value == "") ) {
    alert('Please type your Password.');
    theElements['PASSWORD'].focus();
    return false;
  } else {
     doSignIn();
  }
}

function popupSearchResult(strUrl)
{
    window.open(strUrl,'popup','left=160,top=110,width=800,height=600,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,status=yes');
}

function popupFullScreen(strUrl)
{
    var client_width = screen.width;
    var client_height = screen.height;
    window.open(strUrl,'popup','left=0,top=0,width='+client_width+',height='+client_height+',toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,status=yes');
}


function setValues(aAction,aBtn,aPage,aID) {
  document.forms[0].action = aAction;
  theElements['clicked_btn'].value = aBtn;
  theElements['fromPage'].value = aPage;
  theElements['navigation.cacheId'].value = aID;
}
function func1()
{
	theElements['navigation.taskId'].value = "LoginTask";
	theElements['navigation.workId'].value = "LoginWork";
	theElements['navigation.action'].value = "forward";
	theElements['navigation.newTask'].value = true;
	return true;
}
function func2()
{
	theElements['navigation.flow'].value = "btn_public_signin";
	theElements['navigation.workId'].value = "LoginWork";
	theElements['navigation.action'].value = "forward";
	theElements['navigation.taskId'].value = "LoginTask";
	theElements['navigation.newTask'].value = true;
	return true;
}

function func8()
{ 
    theElements['navigation.workId'].value = "LoginUserTypeWork";
    theElements['navigation.action'].value = "forward";
    theElements['navigation.taskId'].value = "LoginUserTypeTask";
    theElements['navigation.newTask'].value = true;
    return true;
}

function doSignIn(){
    document.getElementById('ERROR_CODE').value = checkBrowser();
    dcsMultiTrack('DCS.dcssip',' moc.oocl.com','DCS.dcsuri',' admin/login/ul_sign_in.jsf','DCSext.exapp','MOC');
    //end
    if (document.getElementById("chkRememberMOCUserID").checked)
    {
        setCSUIDCookie("USER_NAME", currentFormName);
    }
    else
    {
        deleteCookie(csuid_cookie, "/");
    }
	
    //************
    //doSignInCS2()
    //************
    setValues(appSSLservlet,"sign_in","CS2_WINDOW","hp_usertype");
    submitClickSignIn(true, "mycscenter",NONE,appSSLservlet,document.forms[0],"post",func8());
	//end
	    
}

function submitClickSignIn(newWin, windowName, windowType, url, form, method, para)
{if (var_proceed) {
        var_proceed = false;
        windownames = getWindowName(windowName);
	var w_ht = screen_ht - 60;
	var w_wd = screen_wd - 20;
	windowType += "left=10,top=10,screenX=10,screenY=10,";
	windowType += "height=" + w_ht + ",width=" + w_wd;
	form.method = method
	if (form.elements[var_submit_win] != null)
		form.elements[var_submit_win].value = escape(windownames);
	if (form.elements[var_ssl] != null)
		form.elements[var_ssl].value = isSSL(form.action);  
	var_proceed = true;
	if (checkWindowNum())
	{
		var_proceed = false
		form.target = windowName
		if (window.loginWindow) {
			if (!loginWindow.closed) { alert("You may have already signed in.\n\nPlease make sure you sign off the previous session or refresh this page before attempting to sign in again.") }
			else {
				loginWindow = window.open(waiturl, windowName, windowType)
				loginWindow.window.focus()
				form.submit();
			}
		}	
		else {
			loginWindow = window.open(waiturl, windowName, windowType)
			loginWindow.window.focus()
			form.submit();
		}
		var_proceed = true
		if (!(document.getElementById("chkRememberMOCUserID").checked))
		{
		    form.elements['USER_NAME'].value ="";
		}
		form.elements['PASSWORD'].value ="";
	}
} else 
        { alert('Please wait while processing...')} 
}

//function doResetPwdIDCS2()
//{
//    popupCenter('https://cs2ver.cargosmart.com/admin/login/ul_reset.jsf?action=doReset');
//    return false;
//}
function doResetPwdID() {
    aNum= 15; isOn = modDT[aNum].value;
    if (isOn) { return true; }
    else {
      popupCenter('http://www.cargosmart.com/help/help_cs_service_resume_by_module.htm?' + aNum);return false;
    }
}
function goRegisterNow()
{
	popupFullScreen(serverurl.substring(0,serverurl.length-11)+"register/default.htm");
}



function turnOn(imageName) {
  if (document.images) {
    document[imageName].src = eval(imageName + "on.src");
  }
}
function turnOff(imageName) {
  if (document.images) {
    document[imageName].src = eval(imageName + "off.src");
  }
}
function popup(url) {
  popupWin = window.open(url + '?getPage=popup.jsp', 'popup', 'width=400,height=240,left=300,top=300') 
}
function popupPage(url,winsize,winname,winparms) {
	if (winsize == "S") scalar = 0.33;
	 else if (winsize == "M") scalar = 0.50;
	  else if (winsize == "L") scalar = 0.75;
	   else scalar = 0.9;
	w_ht = Math.round(scalar * screen_ht);
	w_wd = Math.round(scalar * screen_wd);
	left = (screen_wd - w_wd) - 20;
	winparms += "left=" + left + ",top=" + screen_top + ",screenX=" + left + ",screenY=" + screen_top + ",";
	winparms += "height=" + w_ht + ",width=" + w_wd;
	if (window.noncsWin) {
	if (!noncsWin.closed) noncsWin.close();
	}
	noncsWin = window.open(url,winname,winparms);
	return;
}
function popupTOU(){
	popupPage(TOUURL,"L","cslegal",NONE);
}
function popupCopyRight(){
	popupPage(COPYURL,"L","cslegal",NONE);
}
function popupPSS(){
	popupPage(PSSURL,"L","cslegal",NONE);
}
function popupCenter(url) {
	var top = Math.round((screen_ht-300)*0.5);
	var left= Math.round((screen_wd-460)*0.5);
	var winparms = "width=460,height=360,";
	winparms += "left=" + left + ",top=" + top;
	ctrtWin = window.open(url, 'popup', winparms)		
	ctrtWin.focus();
}
function getSelection (radio_button) {
  if(radio_button) {
    for (i=0; i<radio_button.length; i++) {
      if (radio_button[i].checked) {
        selection=radio_button[i].value
         return selection
      }
    }
    return ""
  }
  return ""
}
function popupExit(url) {
	var top = Math.round((screen_ht-300)*0.5);
	var left= Math.round((screen_wd-460)*0.5);
	var winparms = "width=460,height=200,";
	winparms += "left=" + left + ",top=" + top;
	exitWin = window.open(EXITURL, 'popup', winparms)		
	popupPage(url,"X","noncs",FULL);	
	exitWin.focus();
}
function addCookie(id,value) {
  var todays_date = new Date();
  var expires_date = new Date(todays_date.getTime() + 20000); // 20 sec from now	
  document.cookie= id + "=" + escape(value) + "; expires=" + expires_date.toGMTString() + appdomain;
}
function isSSL(url)
{
	if (url.indexOf("http") == -1 )
	{ return isSSL(location.protocol) }
	if (url.indexOf("https") == -1 ) 
	{ return false }
	else 
	{ return true }
}
function submitClick(newWin, windowName, windowType, url, form, method, para)
{if (var_proceed) {
        var_proceed = false;
        windownames = getWindowName(windowName);
	var w_ht = screen_ht - 60;
	var w_wd = screen_wd - 20;
	windowType += "left=10,top=10,screenX=10,screenY=10,";
	windowType += "height=" + w_ht + ",width=" + w_wd;
        if (method == "get")
        {
		para = var_submit_win + '=' + escape(windownames) + '&' + para + '&' + var_ssl + '=' + isSSL(url)
                if (newWin == true)
                {	var_proceed = true;
                        if (checkWindowNum())
                        {
                                var_proceed = false
                                newWindow = window.open(url + '?' + para, windowName)
                                newWindow.window.focus()
                                var_proceed = true
                        }
                }
                else
                {
                        window.location.href = url + "?" + para;
                }
        }
        else if (method == "post")
        {
                form.method = method
                if (form.elements[var_submit_win] != null)
                	form.elements[var_submit_win].value = escape(windownames);
		if (form.elements[var_ssl] != null)
                	form.elements[var_ssl].value = isSSL(form.action);                    
                if (newWin == true)
                {	var_proceed = true;
                        if (checkWindowNum())
                        {
                                var_proceed = false
                                form.target = windowName
                                newWindow = window.open(waiturl, windowName)
                                newWindow.window.focus()
		                form.submit()
		                var_proceed = true                                
                        }
                }
                else
                {
                        form.target = "_self"
                	form.submit()
                }
        }
        else 
        { return }
} else 
        { alert('Please wait while processing...')}        
}

function getWindowName(aWinName)
{
	if (aWinName == "")
		return escape("win" + self.name);
	else
		return escape("win" + aWinName);
}
function setMyCookie(){
        var winnames = "win" + self.name;
        addCookie(winnames,winnames)
}
function closeSelf()
{
}
function checkWindowNum(){
if (document.cookie.split(";").length<16){
        return true
        }
else {
        alert("Maximum allowable opened windows has been reached. Please close unused CargoSmart windows before proceeding further.")
        return false
        }       
}
function resetCookies()
{
        if (document.cookie!="")
        {
                thisCookie = document.cookie.split(";")
                expireDate = new Date
                expireDate.setYear(expireDate.getYear() - 1)
                for (i=0; i < thisCookie.length; i++) 
                {
                        cookieName= thisCookie[i].split("=")[0]
                        cookieValue = thisCookie[i].split("=")[1]
                        if (cookieName.substring(0,1)==" ") { aWin = (cookieName.substring(1,4)=="win")}
                        else  {aWin = (cookieName.substring(0,3)=="win")}
                        if (aWin) {
                        if ((cookieValue.substring(3) != self.name) && (cookieValue.substring(3) != "cargosmart")) 
                        {
                                document.cookie = cookieName + "=;expires=" + expireDate.toGMTString() + appdomain ;
                        }}      
                }                               
        }
}
function w(astring) {
        document.writeln(astring);
}
function spacer(w,imagepath) {
	document.writeln("<img src='" + imagepath + "spacer.gif' width='" + w + "' HEIGHT='1'>")
}
function today() {
	return calcday(0);
	}
function calcday(delta)	{
	now	= new Date();
	sec	= now.getSeconds();
	min	= now.getMinutes();
	hr	= now.getHours();
	day	= now.getDate();
	month	= now.getMonth();
	year	= now.getYear();
	if (year < 1000) year += 1900;
	nowutc	= Date.UTC(year,month,day,hr,min,sec);
	then	= new Date(nowutc + (delta * 24 * 60 * 60 * 1000));
	day	= then.getDate();
	month	= then.getMonth();
	year	= then.getYear();
	if (year < 1000) year += 1900;
	if (day<10) day = "0" + day;
	monthsDesc[0] = "Jan";
	monthsDesc[1] = "Feb";
	monthsDesc[2] = "Mar";
	monthsDesc[3] = "Apr";
	monthsDesc[4] = "May";
	monthsDesc[5] = "Jun";
	monthsDesc[6] = "Jul";
	monthsDesc[7] = "Aug";
	monthsDesc[8] = "Sep";
	monthsDesc[9] = "Oct";
	monthsDesc[10] = "Nov";
	monthsDesc[11] = "Dec"; 
	monthsNum[0] = "01";
	monthsNum[1] = "02";
	monthsNum[2] = "03";
	monthsNum[3] = "04";
	monthsNum[4] = "05";
	monthsNum[5] = "06";
	monthsNum[6] = "07";
	monthsNum[7] = "08";
	monthsNum[8] = "09";
	monthsNum[9] = "10";
	monthsNum[10] = "11";
	monthsNum[11] = "12"; 
	}
function calcdayOnline(delta)	{
	calcday(delta);
	then = day + " " + monthsDesc[month] + " " + year;
	return then;
	}
function calcdayEmail(delta)	{
	calcday(delta);
	then = monthsDesc[month] + " " + day + " " + year;
	return then;
	}	
function calcdayRpt(delta)	{
	calcday(delta);	
	then =  monthsNum[month] + "/" + day + "/" + year;
	return then;
	}	
function calctime()	{
	var now	= new Date();
	var sec	= now.getSeconds();
	var min	= now.getMinutes();
	var hr	= now.getHours();
	min = min.toString();
	if (hr.length == 1) hr = '0' + hr;
	if (min.length == 1) min = '0' + min;
	return hr + ':' + min;
	}
function trim(str) { 
   //str.replace(/^\s*/, '').replace(/\s*$/, ''); 
   str = str.replace(/^\s*/, "");
   str = str.replace(/\s*$/, "");
   return str;
	} 
function format_datetime(thisdate,thistime,thistimezone)	{
	if (trim(thistime) == "") {
	return thisdate + "" + thistime + thistimezone ;}
	else {
	return thisdate + ", " + thistime + thistimezone ;}	
	}
function emaildata()	{
	f_destination = "CHI01 Chicago, Cook, USA";
	f_origin = "SHA01 Shanghai, China";
	destination = "Chicago, Cook, Illinois, United States";
	origin = "Shanghai, China";
	o_origin = "Shanghai, China";
	o_destination = "Chicago, USA";
	o_pod = "Long Beach, USA";
	shipper_co = "ABC Company";
	forwarder_co = "DDD Company";
	consignee_co = "ACME Company";
	booking_office = "CHI - Chicago";
	clearance_location = "Chicago Facility";
	full_destination = "Chicago, Illinois, USA";
	crefnum = "00112233";
	cntrnum = "ABCU1234567-1";
	cntrnum2 = "ABCU1234568-1";
	cntrnum3 = "ABCU1234569-1";
	vessel = "OJP";
	vessel_new = "OHK";
	voyage = "SSX-OJP-036-W";
	voyage_1 = "OJP-036-W";
}
function wbutton()	{
	w('<table width="100%">');
	w('	<tr><form>');
	w('	<td width="100%" align="right">');
	if (window.history.length > 1) w('<input type="button" name="button_serv" onClick="history.back(-1);" value="&nbsp;&nbsp;OK&nbsp;&nbsp;">');
	 else w('<input type="button" name="button_serv" onClick="window.close();" value="Close">');
	w('</td></tr></table>');
	document.close();
}

// write navigation bar in all pages with this function 
// para "level" is the page location in which level folder
// para "num" is the call page's menu order
function  writeNavigation(level,num) {
	var imgState = new Array();
	var  path = "";
	var length = 11;
	for(i=0;i<length;i++) 
	{
		imgState[i] = "off";
		if (i == num) imgState[i] = "on";
	}
	if (level == 1) path = "../";
	if (level == 0) path = "";
	w('<table border="0" cellpadding="0" cellspacing="0">');
    w('<tr><td><IMG border=0 height=20 name=image1 src="' + path + 'images/2nd_tier/2nd_tier_nav_' + imgState[1] + '_01.gif" useMap=#image1Map width=206></td></tr>');
	w('<tr><td><IMG border=0 height=22 name=image2 src="' + path + 'images/2nd_tier/2nd_tier_nav_' + imgState[2] + '_02.gif" useMap=#image2Map width=206></td></tr>');
	w('<tr><td><IMG border=0 height=21 name=image3 src="' + path + 'images/2nd_tier/2nd_tier_nav_' + imgState[3] + '_03.gif" useMap=#image3Map width=206></td></tr>');
	w('<tr><td><IMG border=0 height=22 name=image4 src="' + path + 'images/2nd_tier/2nd_tier_nav_' + imgState[4] + '_04.gif" useMap=#image4Map width=206></td></tr>');
	w('<tr><td><IMG border=0 height=21 name=image5 src="' + path + 'images/2nd_tier/2nd_tier_nav_' + imgState[5]+ '_05.gif" useMap=#image5Map width=206></td></tr>');
	w('<tr><td><IMG border=0 height=22 name=image6 src="' + path + 'images/2nd_tier/2nd_tier_nav_' + imgState[6] + '_06.gif" useMap=#image6Map width=206></td></tr>');
	w('<tr><td><IMG border=0 height=21 name=image7 src="' + path + 'images/2nd_tier/2nd_tier_nav_' + imgState[7] + '_07.gif" useMap=#image7Map width=206></td></tr>');
	w('<tr><td><IMG border=0 height=22 name=image8 src="' + path + 'images/2nd_tier/2nd_tier_nav_' + imgState[8] + '_08.gif" useMap=#image8Map width=206 ></td></tr>');
	w('<tr><td><IMG border=0 height=21 name=image9 src="' + path + 'images/2nd_tier/2nd_tier_nav_'+ imgState[9] + '_09.gif" useMap=#image9Map  width=206 ></td></tr>');
	w('<tr><td><IMG border=0 height=22 name=image10 src="' + path + 'images/2nd_tier/2nd_tier_nav_' + imgState[10] + '_10.gif" width=206 ></td></tr>');
    w(' <tr><td height="21"><IMG border=0 height=22 name=image11 src="' + path + 'images/2nd_tier/2T_nav_home_off.gif" useMap=#image11Map width=206></td></tr>');
    w('</table>');
}

function pubOptObject(url, title, imagemap, loc ){
this.url = url ;
this.title = title ;
this.imagemap = imagemap ;
this.loc = loc;
}	

var pubOpt = new Array();
pubOpt[0] = new pubOptObject("about/default.htm",     "About CargoSmart", "image1Map", "0,0,189,21");
pubOpt[1] = new pubOptObject("sol/default.htm",       "Solutions",        "image2Map", "0,0,172,21");
pubOpt[2] = new pubOptObject("services/default.htm", "Services",        "image3Map", "0,0,163,20");
pubOpt[3] = new pubOptObject("carriers/default.htm",  "Carriers",         "image4Map", "0,0,158,23");
pubOpt[4] = new pubOptObject("cust/default.htm",       "Customers",     "image5Map", "0,0,157,21");
pubOpt[5] = new pubOptObject("alliances/default.htm", "Alliances",        "image6Map", "0,0,157,20");
pubOpt[6] = new pubOptObject("news/default.htm",      "News",             "image7Map", "0,0,157,20");
pubOpt[7] = new pubOptObject("contact_us.htm",        "Contact Us",       "image8Map", "0,0,157,20");
pubOpt[8] = new pubOptObject("register/default.htm",  "Register",         "image9Map", "0,0,157,21");
pubOpt[9] = new pubOptObject("default.htm",           "CargoSmart Home",  "image11Map","0,0,157,21");

function writePubLinks() {
  i=0;
  while ( i <pubOpt.length ) 
  {	
	w('<map name="' + pubOpt[i].imagemap + '"><area shape="RECT" coords="' + pubOpt[i].loc + '" href="' + serverurl.substring(0,serverurl.length-11) + pubOpt[i].url + '" alt="' + pubOpt[i].title + '" title="' + pubOpt[i].title + '"></map>');
	i++
  }
}

//below for cargosmart cookie setting
// CargoSmart Cookie Management JScript

// Variable to hold CargoSmart domain name

var cargosmart_domain = "www.cargosmart.com";

// Variable to hold Terms & Condition Version number

var tc_ver = "5.0";

// Variable to hold Terms & Condition url

var tc_url = "http://www.cargosmart.com/about/terms_of_use_v1.htm";

// Variable to hold Terms & Condition cookie name

var tc_cookie = "cstc";

// Variable to hold Terms & Condition cookie's expiration days

var tc_expire_day = 1500;

// Variable to hold cookie usage url

var cookie_url = "http://www.cargosmart.com/about/cookieu.htm";

// Variable to hold the last User ID cookie name

var csuid_cookie = "csuid";

// Variable to hold the last Product News language version

var cspsl_cookie = "cspsl";

//  Function to correct for 2.x Mac date bug

function fixCookieDate (date) 

{

	var base = new Date(0);

	var skew = base.getTime(); // dawn of (Unix) time - should be 0

	if (skew > 0)  // Except on the Mac - ahead of its time

	date.setTime (date.getTime() - skew);

}

// Function to open the cookie usage page

function showCookieUsage()

{

	window.location.href = cookie_url;

}

// Function to open Terms & Conditions page

function navigate_openTC(url,windowname,winsize) {

	winsize = winsize.toUpperCase();

	var ht = screen.availHeight;

	var wd = screen.availWidth;

	var left = 0;

	var top = 10;

	if (winsize == "S") scalar = 0.33;

	 else if (winsize == "M") scalar = 0.50;

	  else scalar = 0.75;

	w_ht = Math.round(scalar * ht);

	w_wd = Math.round(scalar * wd);

	left = (wd - w_wd) - 20;

	var windowparms = "resizable=yes,status=yes,scrollbars=yes,";

	windowparms += "left=" + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top + ",";

	windowparms += "height=" + w_ht + ",width=" + w_wd;

	if (window.NewWindow) {

		if (!NewWindow.closed) NewWindow.close();

		}

	NewWindow = window.open(url,windowname,windowparms);

	NewWindow.window.focus();

	return;

}

function showTermsAndConditions()

{

	

	if (!isCookieEnabled())

	{

		showCookieUsage();

	}

	if (isTermsAndConditionsRead() == false)

	{

		var w_ht = screen.availHeight/2;

		var w_wd = screen.availWidth/2;

		var windowType = "left=" + w_ht/2 + ",top=" + w_wd/2 + ",screenX=10,screenY=10,";

		windowType += "height=" + w_ht + ",width=" + w_wd;

		windowType +=  ",scrollbars=yes," ;

		//newWindow = window.open(tc_url, "termsNcond", windowType);

		//newWindow.window.focus();

		navigate_openTC(tc_url,"termsNcond","l");

		

	}



}

function checkTermsAndConditions(toPage)

{

	proceed = "t";

	if (!isCookieEnabled())

	{

		showCookieUsage();

		proceed = "f";

			

	}

	if (isTermsAndConditionsRead() == false)

	{

		var w_ht = screen.availHeight/2;

		var w_wd = screen.availWidth/2;

		var windowType = "left=" + w_ht/2 + ",top=" + w_wd/2 + ",screenX=10,screenY=10,";

		windowType += "height=" + w_ht + ",width=" + w_wd;

		windowType +=  ",scrollbars=yes," ;

		//newWindow = window.open(tc_url, "termsNcond", windowType);

		//newWindow.window.focus();

		navigate_openTC(tc_url+'?'+toPage, "termsNcond","l");

		proceed = "f";

	}

	return proceed;

}

// Function to check if CargoSmart's cookie on T&C holds the right version or not

function isTermsAndConditionsRead()

{

	var tc_version = getCookie(tc_cookie);

	if (tc_version == null) 

		return false;

	if (tc_version == tc_ver) 

		return true;

	else

		return false;

}

//  Function to set cookie to indicate Terms & Conditions has been read

function setTermsAndConditionsRead(toPage) 

{

	var expdate = new Date();

	// Correct for Mac date bug - call only once for given Date object!

	fixCookieDate(expdate); 

	// tc_expire_day hrs from now

	expdate.setTime(expdate.getTime() + (tc_expire_day * 24 * 60 * 60 * 1000)); 

	// set cookie  

	setCookie(tc_cookie, tc_ver, expdate, "/");//, cargosmart_domain);

	// close current window

	//window.close()

	if (!self.opener) self.opener = self;
	if (toPage=="undefined") 
	{ 
		if (self.opener.location.href.indexOf('register/default.htm') > -1 ) {
			self.opener.registerURL();
		}
	}

	if (!(toPage=="undefined")) 

	{ 
		if (toPage.indexOf('csApp=') > -1)  { 
		       self.opener.location.href=tc_url.substring(0,tc_url.length-19)+"access.htm?"+toPage+"&isWait=1";
		}
		else { self.opener.location.href=toPage; 
		}

	}

	self.close();	

}

// Function to determine if cookie has been enabled in the client browser

function isCookieEnabled() 

{

	var test_cookie = "cs_test1";

	deleteCookie(test_cookie);

	setCookie(test_cookie, "1");

	var exists = getCookie(test_cookie);

	return exists;

}

// Function to return the value of the cookie specified by "name".

function getCookie (name) 

{

	var arg = name + "=";

	var alen = arg.length;

	var clen = document.cookie.length;

	var i = 0;

	while (i < clen) 

	{

		var j = i + alen;

		if (document.cookie.substring(i, j) == arg)

			return getCookieVal (j);

		i = document.cookie.indexOf(" ", i) + 1;

		if (i == 0) break; 

	}

	return null;

}

// Function to return the decoded value of a cookie

function getCookieVal (offset) 

{

	var endstr = document.cookie.indexOf (";", offset);

	if (endstr == -1) endstr = document.cookie.length;

	return unescape(document.cookie.substring(offset, endstr));

}

// Function to create or update a cookie.

function setCookie(name,value,expires,path,domain,secure) 

{

	document.cookie = name + "=" + escape (value) +

		((expires) ? "; expires=" + expires.toGMTString() : "") +

		((path) ? "; path=" + path : "") +

		((domain) ? "; domain=" + domain : "") +

		((secure) ? "; secure" : "");

}

// Function to delete a cookie. (Sets expiration date to start of epoch)

function deleteCookie (name,path,domain) 

{

	if (getCookie(name)) 

	{

		document.cookie = name + "=" +

		((path) ? "; path=" + path : "") +

		((domain) ? "; domain=" + domain : "") +

		"; expires=Thu, 01-Jan-70 00:00:01 GMT";

	}

}

/*
 * Function to check cookie csuid to indicate whether or not show the message page
 */
function checkCSUIDCookie(formElement, formName) {
	defStr = "";
	if (isCookieEnabled()) {
		defStr = getCookie(csuid_cookie)
	}
	if ( defStr == null ) { defStr = "" }
	document.forms[formName].elements[formElement].value = defStr;
}

function setCSUIDCookie(formElement, formName) {
	var expdate = new Date();
	fixCookieDate(expdate); 
	expdate.setTime(expdate.getTime() + (tc_expire_day * 24 * 60 * 60 * 1000)); 
	setCookie(csuid_cookie, document.forms[formName].elements[formElement].value, expdate, "/");//, cargosmart_domain);
}


function checkCSPSLCookie(formElement, formName) {
	defStr = "";
	if (isCookieEnabled()) {
		defStr = getCookie(cspsl_cookie)
	}
	if ( defStr == null ) { defStr = "EN" }
	document.forms[formName].elements[formElement].value = defStr;
}

function setCSPSLCookie(formElement, formName) {
	var expdate = new Date();
	fixCookieDate(expdate); 
	expdate.setTime(expdate.getTime() + (tc_expire_day * 24 * 60 * 60 * 1000)); 
	setCookie(cspsl_cookie, document.forms[formName].elements[formElement].value, expdate, "/");//, cargosmart_domain);
}

//downtime
function modDTObject(name, value, datetime ){
this.name = name ;
this.value = value ;
this.datetime = datetime;
}	

var modDT = new Array();
modDT[0]  = new modDTObject("CargoSmart News",true,"");
modDT[1]  = new modDTObject("Alliances",true,"");
modDT[2]  = new modDTObject("Reports",true,"");
modDT[3]  = new modDTObject("Shipping Instructions",true,"");
modDT[4]  = new modDTObject("Bill of Lading Document Manager",true,"");
modDT[5]  = new modDTObject("Invoices and Payment",true,"");
modDT[6]  = new modDTObject("Cargo Tracking",true,"");
modDT[7]  = new modDTObject("Vessel Tracking",true,"");
modDT[8]  = new modDTObject("North America Rail Tracing",true,"");
modDT[9]  = new modDTObject("Sailing Schedule",true,"");
modDT[10] = new modDTObject("Booking Request",true,"");
modDT[11] = new modDTObject("User & Company Profile",true,"");
modDT[12] = new modDTObject("Relationship Manager",true,"");
modDT[13] = new modDTObject("Registration",true,"");
modDT[14] = new modDTObject("Order CargoSmart Desktop Installation CD",true,"");
modDT[15] = new modDTObject("Forgotten Password",true,"");

function DoFindCT(stype, url){
    var bl_no ='';
    var cont_no ='';
    var booking_no ='';
    if(stype == "bl")
    {
      bl_no = trim(theElements['BL_No'].value);
      if(bl_no == ''){
        alert('Please enter B/L #.');
        return;
      }
      dcsMultiTrack('DCS.dcssip','ct.oocl.com','DCS.dcsuri',url,'DCSext.BLNo', bl_no);
    }
    else if(stype == "cont")
    {
      cont_no = trim(theElements['Cont_No'].value);
      if(cont_no == ''){
        alert('Please enter Container #.');
        return;
      }
        dcsMultiTrack('DCS.dcssip','ct.oocl.com','DCS.dcsuri',url,'DCSext.CTNNo',cont_no);
    }
    //Modified by Denny on 28/05/2007
    //start
    else if(stype == "booking")
    {
      booking_no = trim(theElements['Booking_No'].value);
      if(booking_no == ''){
        alert('Please enter Booking No #.');
        return;
      }
      
      dcsMultiTrack('DCS.dcssip','ct.oocl.com','DCS.dcsuri',url,'DCSext.BKNo',booking_no);
    }
    //end
    
    SetExpressLink('ct',bl_no,cont_no,'','','',booking_no);
}

function SetExpressLink(stype, s1, s2, s3, s4 ,s5 ,s6) //parameter "s5,s6" added by Denny , s5 = carrier_id , s6 = booking_no
{
    var vturl = "/Pages/ExpressLink.aspx?eltype=";
    //var vturl = "/oocl/Includes/eLink/TestRT.aspx?eltype=";
    if(stype == "vt"){
      vturl = vturl + "vt&vel_name=" + s1 + "&voyage=" + s2 + "&port=" + s3;
    }else if(stype == "ss"){
      vturl = vturl + "ss&origin_city=" + s1 + "&origin_country=" + s2 + "&dest_city=" + s3 + "&dest_country=" + s4;
    }else if(stype == "ct"){
      vturl = vturl + "ct&bl_no=" + s1 + "&cont_no=" + s2 + "&booking_no=" + s6;
    }
    //Modified by Denny on 09/05/2007
    //start
    else if(stype == "rt"){
        vturl = vturl + "rt&carrier_id=" + s5 + "&cont_no=" + s2;
        //alert(vturl);
    }
    //end
    
    if(window.NewWindow)
    {
      if(!NewWindow.closed){
        NewWindow.close();
      }
    }
    if(stype == "rt")
    {
        NewWindow = window.open(vturl,'ExpressRT','left=160,top=100,width=800,height=600,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=yes');
        NewWindow.window.focus();
    }
    else
    {
        NewWindow = window.open(vturl,'vt','left=160,top=100,width=800,height=600,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=yes');
        NewWindow.window.focus();
    }
}

