function parseStringInsideQuotes(inString) {
	var outString = "";
	var testChar;

	for (var i = 0; i < inString.length; i++) {
		testChar = inString.charAt(i);

		if (testChar == "\\")
			outString += "\\\\";
		else if (testChar == "\"")
			outString += "\\\"";
		else if (testChar == "'")
			outString += "\\'";
		else
			outString += testChar;
	}

	return outString;
}

function windowOpen(inURL) {
	var gotoURL = "/eng/misc/mi_redi_page.jsp?oldURL=" + escape(parseStringInsideQuotes(inURL));
	var wndGoto = window.open(gotoURL, "wndNameGoto", "status,titlebar,width=500,height=325,hotkeys=0");
	if (wndGoto != null)
		wndGoto.focus();
}

function dtextOn(imgNum) {
  if (document.images && isLoaded) {
    document["dtext"].src = "images/hp_0" + imgNum + "_word.gif";
  }
}

function dtextOff() {
  if (document.images && isLoaded) {
    document["dtext"].src = "images/spacer.gif";
  }
}

function imgOn(imgname) {
  if (document.images && isLoaded) {
    var src = document[imgname].src;
    var mode = src.lastIndexOf("_off");
    if (mode != -1)
      document[imgname].src = src.substring(0,mode) + "_on.gif";
  }

}

function imgOff(imgname) {
  if (document.images && isLoaded) {
    var src = document[imgname].src;
    var mode = src.lastIndexOf("_on");
    if (mode != -1)
      document[imgname].src = src.substring(0,mode) + "_off.gif";
  }
}

function imgChg(imgname) {
  document.chgImg.src = "images/" + imgname + ".gif";
}
 
function imgRst() {
  document.chgImg.src = "images/hp_tagl1.gif";
}

function imgRst_700() {
  document.chgImg.src = "images/hp_tagl1_700.gif";
}

function newWindow() {
	camWindow = window.open('images/hp_prom1.gif','camWin','toobar=no,location=no,scrollbars=no,width=300,height=300')
}

function goSection(formname) {
    var temp = formname.options[formname.selectedIndex].value;
	if (temp != "") {
		if (temp.toLowerCase().indexOf("javascript:") != -1) {
			temp = temp.substring(11,temp.length);
			eval(temp);
		} else {
			location = temp;
		}
	}
}

function wm_sethome(formname) {
        var country = "";
        var expdate = new Date ();

	switch (formname.selectedIndex) {
		case 1:
			country = "international";
			break;
		case 3:
			country = "canada";
			break;
		case 4: //Mexico
			country = "spanish";
			break;
		case 5:
			country = "usa";
			break;
		case 7:
			country = "china";
			break;
		case 8:
			country = "taipei";
			break;
		case 9:
			country = "japan";
			break;
		case 10:
			country = "korea";
			break;
		case 11:
			country = "malaysia";
			break;
		case 12:
			country = "seasia";
			break;
		case 13:
			country = "thailand";
			break;
		case 15: //Austria
			country = "german";
			break;
		case 16:
			country = "france";
			break;
		case 17: //Germany
			country = "german";
			break;
		case 18:
			country = "italy";
			break;
		case 19:
			country = "russia";
			break;
		case 20:
			country = "spanish";
			break;
		case 21: //Switzerland
			country = "german";
			break;
		case 22:
			country = "uk";
			break;
		case 23:
			country = "australia";
			break;
		case 24: //New Zealand
			country = "australia";
			break;
		default: return;
	}
        expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 182 * 1000));
        SetCookie('HKTA_country',''+country,expdate,'/','.discoverhongkong.com');
	return;
}

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 getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

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" : "");
}

funcloaded = true;

