var strLocation = '';

var m_Loc = [];
m_Loc[0] = [];
m_Loc[1] = [];
m_Loc[2] = [];
m_Loc[3] = [];
m_Loc[4] = [];

var m_SubPage = [];

m_SubPage[0] = ["iBooking", "http://ibooking.atit.com.hk/ifbhk/"];
m_SubPage[1] = ["Tracking", "tracking.htm"];
m_SubPage[2] = ["Download", "download.htm"];

m_Loc[0][0] = ["", ":: Choose Location ::", ""];

m_Loc[1][0] = ["", "-- Greater China --", "Greater China"];
m_Loc[1][1] = ["Guangzhou", "Guangzhou", "guangzhou.htm"];
m_Loc[1][2] = ["Hangzhou", "Hangzhou", "hangzhou.htm"];
m_Loc[1][3] = ["Hong Kong", "Hong Kong", "hongkong.htm"];
m_Loc[1][4] = ["Nanjing", "Nanjing", "nanjing.htm"];
m_Loc[1][5] = ["Ningbo", "Ningbo", "ningbo.htm"];
m_Loc[1][6] = ["Qingdao", "Qingdao", "qingdao.htm"];
m_Loc[1][7] = ["Shanghai", "Shanghai", "shanghai.htm"];
m_Loc[1][8] = ["Shenzhen", "Shenzhen", "shenzhen.htm"];
m_Loc[1][9] = ["Taiwan", "Taiwan", "taiwan.htm"];
m_Loc[1][10] = ["Tianjin", "Tianjin", "tianjin.htm"];
m_Loc[1][11] = ["Xiamen", "Xiamen", "xiamen.htm"];

m_Loc[2][0] = ["", "-- Far East --", "Far East"];
m_Loc[2][1] = ["Cambodia", "Cambodia", "cambodia.htm"];
m_Loc[2][2] = ["India", "India", "india.htm"];
m_Loc[2][3] = ["Indonesia", "Indonesia", "indonesia.htm"];
m_Loc[2][4] = ["Malaysia", "Malaysia", "malaysia.htm"];
m_Loc[2][5] = ["Singapore", "Singapore", "singapore.htm"];
m_Loc[2][6] = ["Thailand", "Thailand", "thailand.htm"];
m_Loc[2][7] = ["Vietnam", "Vietnam", "vietnam.htm"];


m_Loc[3][0] = ["", "-- Europe --", "Europe"];
m_Loc[3][1] = ["Austria", "Austria", "austria.htm"];
m_Loc[3][2] = ["Belgium", "Belgium", "contact.htm#Belgium"];
m_Loc[3][3] = ["France", "France", "france.htm"];
m_Loc[3][4] = ["Germany", "Germany", "germany.htm"];
m_Loc[3][5] = ["Spain", "Spain", "spain.htm"];
m_Loc[3][6] = ["United Kingdom", "United Kingdom", "uk.htm"]; 

//m_Loc[3][6] = ["", "-- America --", "America"];
//m_Loc[3][6] = ["United States", "United States", "us.htm"];

m_Loc[4][0] = ["", "-- Africa --", "Africa"];
m_Loc[4][1] = ["Togo", "Togo", "togo.htm"];

var expDays = 365;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function setLocation(strLoc){
  SetCookie ('Location', strLoc, exp);
}

function getLocation(){
  var strLoc = GetCookie('Location');
  if (strLoc == null) {
    strLoc = "";
    SetCookie ('Location', strLoc, exp)	
  }
  return strLoc;
}

function printLocation(){
  document.write(getLocation());
}


function getCookieVal (offset) {  
  var endstr = document.cookie.indexOf (";", offset);  
  if (endstr == -1)    
    endstr = document.cookie.length;  
  return unescape(document.cookie.substring(offset, endstr));
}
  
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 SetCookie (name, value) {  
  var argv = SetCookie.arguments;  
  var argc = SetCookie.arguments.length;  
  var expires = (argc > 2) ? argv[2] : null;  
  var path = (argc > 3) ? argv[3] : null;  
  var domain = (argc > 4) ? argv[4] : null;  
  var secure = (argc > 5) ? argv[5] : false;  
  document.cookie = name + "=" + escape (value) + 
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
  ((path == null) ? "" : ("; path=" + path)) +  
  ((domain == null) ? "" : ("; domain=" + domain)) +    
  ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {  
  var exp = new Date();  
  exp.setTime (exp.getTime() - 1);  
  var cval = GetCookie (name);  
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}


function getLocationList(){
  var strTmp;
  strTmp = "<select name='location' class='listLocation' ";
//  strTmp += " onchange='setLocation(this.value);";
//  strTmp += " window.location.reload();
  
  strTmp += " onchange='goToPage(form.location.value);'>";
  
  strTmp += ">";
  for ( var j = 0 ; j < m_Loc.length ; j++){
    new_Loc = m_Loc[j];
    for ( var i = 0 ; i < new_Loc.length ; i++){
      strTmp += "<Option value='" + new_Loc[i][0] + "'";
      if (getLocation() != "" && getLocation() == new_Loc[i][0])
        strTmp += " selected ";
      strTmp += ">" + new_Loc[i][1] + "</Option>";
    }
  }
  strTmp += "</select>";
  return strTmp;
}

function getSubLocationList(form, j){
  var strTmp;
  strTmp = "<select name='location' class='listLocation' ";
  strTmp += " onchange='goToPage(form.location.value);'>";
    new_Loc = m_Loc[j];
    for ( var i = 0 ; i < new_Loc.length ; i++){
      strTmp += "<Option value='" + new_Loc[i][0] + "'";
      //if (getLocation() != "" && getLocation() == new_Loc[i][0])
      //  strTmp += " selected ";
      strTmp += ">" + new_Loc[i][1] + "</Option>";
    }
  strTmp += "</select>";
  return strTmp;
}

function getRegionList(region){
  var strTmp;
  strTmp = "<select name=\"location\" class=\"listLocation\" ";
  strTmp += " onChange=\"goToURL(this.value)\" ";
  strTmp += " >";

  new_Loc = m_Loc[region];
  for ( var i = 0 ; i < new_Loc.length ; i++){
    strTmp += "<Option value='" + new_Loc[i][2] + "'";
    strTmp += ">" + new_Loc[i][1] + "</Option>";
  }
  strTmp += "</select>";
  return strTmp;
}

function goToURL(strURL){
  if (strURL != "")
    self.location.href = strURL;
}

function goToPage(strURL){

  if (strURL != ""){
    for ( var j = 0 ; j < m_Loc.length ; j++){
      new_Loc = m_Loc[j];
      for ( var i = 0 ; i < new_Loc.length ; i++){
        if (strURL == new_Loc[i][0]){
          strURL = new_Loc[i][2];
          break;
        }
      }
    }
    goToURL(strURL);
  }
}

function goContactPage(strURL){

  if (strURL != ""){
    for ( var j = 0 ; j < m_Loc.length ; j++){
      new_Loc = m_Loc[j];
      for ( var i = 0 ; i < new_Loc.length ; i++){
        if (strURL == new_Loc[i][0]){
          strURL = "contact.htm#" + trim(new_Loc[i][0]);
          break;
        }
      }
    }
    goToURL(strURL);
  }
}


function getLocationListLink(){
  var strTmp;
  strTmp = "<table width=\"100%\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\">";

  for ( var j = 1 ; j < m_Loc.length ; j++){
    new_Loc = m_Loc[j];
    for ( var i = 0 ; i < new_Loc.length ; i++){
    	strTmp += "<tr>";
	if (i==0){
		strTmp += "<td class=\"txtblue\">&nbsp;&nbsp;&nbsp;<img src=\"images/arrow_blue2.gif\" >&nbsp;&nbsp;" + new_Loc[i][2] + "</td>";
	} else {
		strTmp += "<td class=\"txtgreen\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"images/arrow.gif\" vspace=\"2\">&nbsp;&nbsp;";
		strTmp += "<a href=\"" + new_Loc[i][2] + "\" class=\"txtgreen\">" + new_Loc[i][1] + "</a></td>";
		
		if (j == 2 && i == 2){
			for ( var x = 0 ; x < m_SubPage.length ; x++){
	    			strTmp += "</tr><tr>";
				strTmp += "<td class=\"txtgreen\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"images/arrow.gif\" vspace=\"2\">&nbsp;&nbsp;";
				strTmp += "<a href=\"" + m_SubPage[x][1] + "\" class=\"txtgreen\">" + m_SubPage[x][0] + "</a></td>";
			}
		}
	}
      
      strTmp += "</tr>";
    }
  }
  strTmp += "</table>";
  return strTmp;

}


function trim(str) {
  str = this != window? this : str;
  return str.replace(/[\s]*/g, '');
}


/****************************************************************/
/* PageQuery                                                    */
/****************************************************************/
function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return -1;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }	
}

var pageSection;

function init(){
	var page = new PageQuery(location.search);
	if (page.getValue("section") != -1 && page.getValue("section") != ""){
		pageSection = page.getValue("section");
	}
}

function printPageSection(){
	document.write(pageSection);
}

function getPageSection(){
	return pageSection;
}


window.onload = init;




