var abackstroke = 47
//var last_mod_date_tou = ""
var last_mod_date_pss = "."
var last_mod_date_tou_format = "17 February 2008"
var last_mod_date_pss_format = "17 February 2008"
var last_mod_date_csda_format = "31 August 2004"
var csda_ver = "2.0"
var legal_year = "2000 - 2010"
var numOfCustomer = "45,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 = "";


FULL= "toolbar,directories,resizable,status,scrollbars,menubar,location,"
NONE= "scrollbars,resizable,status,"
MENUONLY= "menubar,scrollbars,resizable,status,"
ALL = ""
waiturl = "http://www.cargosmart.com/cs.htm"
serverurl = "http://www.cargosmart.com/default.htm"
cnserverurl = "http://www.cargosmart.cn/default.htm"
csserverurl = serverurl.substring(0,serverurl.length-11)+"carriers/home.htm"
appurl = "http://app2.cargosmart.com/cs/"
appweburl = "http://app2.cargosmart.com/"
appservlet = "http://app2.cargosmart.com/cs/servlet/icss"
appSSLservlet = "https://app1.cargosmart.com/cmf/servlet/icss"
appPUBservlet = "https://app2.cargosmart.com/cs/servlet/icss"
appMCIservlet = "https://app3.cargosmart.com/mci/servlet/icss"
appSSLPUBservlet = "https://app2.cargosmart.com/cs/servlet/icss"

appdomain = "; domain=.cargosmart.com"

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 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, windowType)
                                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, windowType)
                                newWindow.window.focus()
		                form.submit()
		                var_proceed = true                                
                        }
                }
                else
                {
                        form.target = "_self"
                	form.submit()
                }
        }
        else 
        { return }
} else 
        { alert('Please wait while processing...')}        
}
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
		form.elements['user_id.value'].value ="";
		form.elements['password.value'].value ="";
	}
} else 
        { alert('Please wait while processing...')} 
}
function getWindowName(aWinName)
{
	setMyCookie();//for the defect of confirm dialog disalbed the timeOut everyMinute()
	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*$/, ''); 
   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++
  }
}
