var login_url    =  "https://www.trade.338.net/its/loginEntry.do";
var logout_url  =  "http://www.trade.338.net/its/logout.do";

var currSelectedSubTab = "";
var isNav=(navigator.appName == 'Netscape');

function SubMenuItem(icode,iname, ilink,ivalue){
   this.icode= icode;
   this.iname = iname;
   this.ilink = ilink;
   this.iboxValue=ivalue;
}



// old function--------------------------------------------------------------------------------------
function MM_findObj(n, d) { //v3.0
  var p,i,x;

  if(!d){
  	d=document; 
  }
  
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; 
    n=n.substring(0,p);
  }
  
 if(!(x=d[n]) && (d)) {
    x=d.getElementById(n);
  }

  for (i=0;!x&&i<d.forms.length;i++){
    x=d.forms[i][n];
  }
  
  return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function display_button(){
   if(getCookie('LOGIN')=='1')   {
      if (document.getElementById("loginCell")){
         document.getElementById("loginCell").innerHTML = "<a href='#' onclick='javascript:ChangeLocation(logout_url);return false;' target='_top' class='LoginButton' >µn¥X</a>";
         setCookie("LOGIN",1);
      }
   }
   else {
      if (document.getElementById("loginCell")){
         document.getElementById("loginCell").innerHTML="<a href='#' onclick='javascript:ChangeLocation(login_url);return false;' target='_top' class='LoginButton' >µn¤J</a>";
         setCookie("LOGIN","");
      }
   }
}
//--------------------------------------------------------------------------------------

function changeFrames(contentURL, paramURL, to){

 //for netvigation on the same page
 if(top.document.getElementById("mainFrame")!=null){	
   if(contentURL.indexOf(top.mainFrame.location.pathname) > -1){
     top.mainFrame.location.href = contentURL;
     return;
   }
 }
 
 if(to == 0){
   if(contentURL.indexOf("#") > -1) {
      var url = contentURL.split("#");
      contentURL = url[0] + "&anchor=" + url[1];
   } //if

   top.location.href = "/its/account/productService.do?content="+contentURL+"&index="+paramURL;
 }else{
   top.leftFrame.location.href = "/its/account/productService/menu.do?index="+paramURL;
   top.mainFrame.location.href = contentURL;
 }
}


//--------------------------------------------------------------------------------------

function CreateSubMenu_url(menuNo) {
   var l_href = location.href;
   var l_href = l_href.split("?");
   var subMenu = "0";
   if(l_href.length>1){
      for (var i = 1; i<= l_href.length-1; i++) {
         var l_param = l_href[i].split("=");
         if(l_param.length>1){
            if (l_param[0] == "SM") {
               subMenu=l_param[1];
            }
         }
      }
   }
   CreateSubMenu(menuNo,subMenu);
}

function CreateSubMenu(menuNo, subMenuNo) {
   var subMenuItemName = "menu" + menuNo + sm;
   var subMenuObjArray = window[subMenuItemName];
   var tempCode="menu"+menuNo+subMenuNo;            //eg menu64
   var tempMainCode="menu"+menuNo;                  //eg menu6
   //currSelectedSubTab = "menu"+menuNo+subMenuNo;     //eg gifmenu64

   var subMenuHTML="<table border=0 cellspacing='0' cellpadding='0'><tr>";
   for (var i = 0; i<= subMenuObjArray.length-1; i++) {
      subMenuObj = subMenuObjArray[i];                         //eg subMenuObj = smItem61  OR BoxSmItem62
      var gifCell = "<td align='right'  width=25><img   id='" + "gif"  + subMenuObj.icode +"' src=' /its/images/header/bullet.gif' style=\"visibility: hidden\"></td>";
      subMenuHTML = subMenuHTML + gifCell+CreateSubMenuItem(subMenuObj);
      //alert(subMenuHTML);
   }

   subMenuHTML = subMenuHTML + "</tr></table>";
   var subMenuRow = document.getElementById('SUB_MENU_ROW');
   if (subMenuRow) subMenuRow.cells[0].innerHTML=subMenuHTML;
   changeSubTab(tempCode);
   changeMainMenu(tempMainCode);
   //changeSubTab(tempCode);
}

function CreateSubMenuItem(m) {
   if (window[m.iboxValue]){
      var str ="<td valign='bottom' id="+m.icode+" class='SubMenuOff' onMouseOver=\"MM_showHideLayers('"+m.iboxValue+"','','show');\"  onMouseOut=\"MM_showHideLayers('"+m.iboxValue+"','','hide');\">"+m.iname+"</td>";
   } else {
      var str = "<td valign='bottom'><a id="+m.icode+" class='SubMenuOff' href='#' onclick=\"javascript:SubMenuClicked('"+ m.ilink +"' ,'"+m.icode+"');return false;\" >"+m.iname+"</a></td>";
   }
   return str;
}

function changeMainMenu(code) {
   var checkMainMenu = code.substring(0,code.length);
   if(document.all[checkMainMenu]){
      document.all[checkMainMenu].className="MainMenuOn";
   }
}

function changeSubTab(code) {

   if (document.all["gif"+currSelectedSubTab]){  //currSelectedSubTab gif cell
      document.all["gif"+currSelectedSubTab].style.visibility ="hidden";
   }

   if (document.all[currSelectedSubTab]) {
      document.all[currSelectedSubTab].className = "SubMenuOff";
   }

   if (document.all["gif"+code]){
      document.all["gif"+code].style.visibility="visible";
   }

   if (document.all[code]) {
      document.all[code].className = "SubMenuOn";
   }

   currSelectedSubTab = code;
}

function SubMenuClicked(url, code) {
   changeSubTab(code);
   top.location.href=url;
}

function ChangeLocation(url,code) {
   top.location.href=url;
   //changeMainMenu(code);
}

//*******************************************************************
// Programs    : getCookie, setCookie, deleteCookie, getCookieVal
// Description : cookie will expire when the session ends
// Input    : string
// Date        : Mar 06 , 2000
// Author      : Sandy Chan
//********************************************************************

//********************************************************************
// Program     : getCookieVal
// Input     : offset of the cookie value
// Output       : 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));
}

//********************************************************************
// Program     : getCookie
// Input     : the cookie name
// Output       : if cookie exists, return the value; otherwise, return
//            null
//********************************************************************
function getCookie(name) {
   var arg = name + "=";
   var alength = arg.length;
   var clength = document.cookie.length;
   var i = 0;
   var secure = true;
   var ncookie;
   while (i < clength) {
      var j = i + alength;
      if (document.cookie.substring(i,j) == arg) {
         ncookie = getCookieVal(j);
         //alert("Get Cookie=" + ncookie);
         return ncookie;
      }
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0 )  break;
   }
   // alert("no cookie gets");
   return null;
}//getCookie

//********************************************************************
// Program     : setCookie
// Input     : name and value of the cookie
// Output       : display an alert statement
//********************************************************************
function setCookie(name, value) {
    var path = "/";
   document.cookie = escape(name) + "=" + escape(value) +
      ((path==null) ? "": ("; path=" + path)) ;
      //alert("Set Cookie="+ document.cookie);
}//setCookie

//********************************************************************
// Program     : deleteCookie
// Input     : name of the cookie
// Output       : display an alert statement
//********************************************************************
function deleteCookie(name) {
   var path = "/";
   if (getCookie(name)) {
      document.cookie = name + "=" +
         ((path) ? "; path=" + path : "") +
         "; expires=Thu, 01-Jan-70 00:00:01 GMT";
   }
   //alert("Delete Cookie=" + document.cookie);
}
