<!--

var GoodChr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var NumChr = "0123456789";
var BadChr = "'\"+";
var chkNum = 1;
var link;
var autoc1 = 1;
var autoc2 = 1;

window.onloadListeners = new Array();
window.addOnLoadListener = function(listener){
	window.onloadListeners[window.onloadListeners.length] = listener;
}

//****************************************************************************************************//

function ajax(){
	var xmlHttp;
	var divid;
	var xmlobj;

	var createXMLHttp = function(){
		if (window.XMLHttpRequest){
			xmlHttp = new XMLHttpRequest();
		}else if (window.ActiveXObject){
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	var createQueryString = function(num,cnum){
		return "num=" + num + "&cnum=" + cnum;
	}

	this.top_listCase = function(num,url,divName,cnum){
		createXMLHttp();
		divid = divName;
		if(document.getElementById(divid) == null){
			return;
		}
		xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 1){
				document.getElementById(divid).innerHTML = "建立連線中...";
			}
			else if (xmlHttp.readyState == 2){
				document.getElementById(divid).innerHTML = "傳送資料中...";
			}
			else if (xmlHttp.readyState == 3){
				document.getElementById(divid).innerHTML = "接收資料中...";
			}
			else if (xmlHttp.readyState == 4){
				document.getElementById(divid).innerHTML = "解析資料中...";
				if (xmlHttp.status == 200){
					document.getElementById(divid).innerHTML = xmlHttp.responseText;
					if (num == 4 || num == 6){
						setTimeout('autoChange("1")',10000);
					}
					else if (num == 8 || num == 9){
						setTimeout('autoChange("2")',10000);
					}
				}
			}
		};
		xmlHttp.open("POST", url);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send(createQueryString(num,cnum));
	};
}

//****************************************************************************************************//

function isGoodId(input, length1, length2) {
  if (input.length < length1 || input.length > length2 || !isGoodChr(input) || isBadChr(input)) {
  // if (!isGoodChr(input) || isBadChr(input)) {
    return false;
  }

  return true;
}

//****************************************************************************************************//

// Use this function to retrieve a cookie.
function getCookie(name) {
  var cname = name + "=";
  var dc = document.cookie;
  if (dc.length > 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
      begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
      }
  }
  return null;
}

//****************************************************************************************************//

// Use this function to save a cookie.
function setCookie(name, value, expires) {
  document.cookie = name + "=" + escape(value) + "; path=/" +
  ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}

//****************************************************************************************************//

// Use this function to delete a cookie.
function delCookie(name) {
  document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

function chkBrowser() {
  var bName = navigator.appName;
  var bVer = parseInt(navigator.appVersion);

  if (bName == "Netscape" && bVer >= 4) br = "n4";		// Netscape 4.x
  else if (bName == "Netscape" && bVer == 3) br = "n3";		// Netscape 3.x
  else if (bName == "Netscape" && bVer == 2) br = "n2";		// Netscape 2.x
  else if (bName == "Microsoft Internet Explorer" && bVer >= 4) br = "e4";		// IE 4.x or newer
  else if (bName == "Microsoft Internet Explorer") br = "e3";		// IE 3.x
  else br = "n2";		// if none of these are found, default to Netscape 2

  return br;
}

//****************************************************************************************************//

function varIsNull(value) {
  return (value==null || value=="") ? true : false;
}


//****************************************************************************************************//

function isROCIdentNo(s) {
	var c, n, i;
	var t = "ABCDEFGHJKLMNPQRSTUVXYWZIO";

	c = s.substring(0,1);
	c = t.indexOf(c.toUpperCase());
	if ((s.length != 10) || (c < 0)) return false;

	n = parseInt(c/10) + c%10*9 + 1;
	for (i = 1; i<9; i++) n = n + parseInt(s.substring(i, i+1)) * (9-i);
	n = (10 - (n % 10)) % 10;
	if (n != parseInt(s.substring(9, 10))) return false;

	return true;
}

//****************************************************************************************************//

function isForeIdentNo(s) {
	var c, c1, c2, c3, n, i;
	var t = "ABCDEFGHJKLMNPQRSTUVXYWZIO";

	c = s.substring(8,9);
	c = t.indexOf(c.toUpperCase());
	if ((s.length != 10) || (c < 0)) return false;

	c = s.substring(9,10);
	c = t.indexOf(c.toUpperCase());
	if ((s.length != 10) || (c < 0)) return false;

	c1 = s.substring(0,4);
	c2 = s.substring(4,6);
	c3 = s.substring(6,8);
	if (!isTrueYear(c1, -15, -100)) return false;
	if (!isTrueDay(c1, c2, c3)) return false;

	return true;
}

//****************************************************************************************************//

function isCorpNo(value) {
  if (value.length != 8) return false;
  if (!isNumChr(value)) return false;

  return true;
}

//****************************************************************************************************//

function isTrueYear(value, upline, downline) {

  if (isNaN(value)) return false;
  if (!isNumChr(value)) return false;

  var d = new Date();
  var nowYear = d.getFullYear();
  if (value > (nowYear + upline) || value < (nowYear + downline)) return false;

  return true;
}

//****************************************************************************************************//

function isTrueDay(year, month, day) {
  var m1 = "01, 03, 05, 07, 08, 10, 12";
  var m2 = "04, 06, 09, 11";
  var m3 = "02";

  if (m2.indexOf(month) != -1 && day == "31") return false;
  if (month == m3) {
    if (year % 4 == 0) {
      if (day == "30" || day == "31") return false;
    }
    else {
      if (day == "29" || day == "30" || day == "31") return false;
    }
  }

  return true;
}

//****************************************************************************************************//

function isUrl(value) {
  if (value.indexOf("http://") == -1) {
    value = "http://" + value;
  }
  if (value.indexOf(".") == -1) return false;
  if (isBadChr(value)) return false;

  return true;
}

//****************************************************************************************************//

function isMail(email) {
  if (email.length < 5) { return false; }
  if (email.indexOf("@") == -1) { return false; }
  if (email.indexOf(".") == -1) { return false; }

  return true;
}

//****************************************************************************************************//

function isGoodChr(value) {
  for (var i = 0; i < value.length; i++) {
    if (GoodChr.indexOf(value.charAt(i)) == -1) {
      return false;
    }
  }

  return true;
}

//****************************************************************************************************//

function isNumChr(value) {
  for (var i = 0; i < value.length; i++) {
    if (NumChr.indexOf(value.charAt(i)) == -1) {
      return false;
    }
  }

  return true;
}

//****************************************************************************************************//

function isBadChr(value) {
  for (var i = 0; i < value.length; i++) {
    if (BadChr.indexOf(value.charAt(i)) != -1) {
      return true;
    }
  }

  return false;
}

//****************************************************************************************************//

function go(url) {
  window.location.href = url;
}

//****************************************************************************************************//

function setBgColor(obj, color) {
  obj.style.backgroundColor = color;
}

//****************************************************************************************************//

function setColor(obj, color) {
  obj.style.color = color;
}

//****************************************************************************************************//

function setVisible(obj, status) {
  if (status) {
    obj.style.visibility = "";
  }
  else {
    obj.style.visibility = "hidden";
  }
}

//****************************************************************************************************//

function setImgSrc(obj, src) {
  obj.src = src;
}

//****************************************************************************************************//

function ChangeOptions(objMaster, objSlave, newArray, keyVal) {

  var keyInd  = objMaster.options[objMaster.selectedIndex].value;

  for (var i = objSlave.options.length - 1; i >= 0 ; i--) {
    objSlave.options[i] = null;
  }

  var ind = 0;
  for (var i = 0; i < newArray.length; i++) {
    if (newArray[i][0] == keyInd) {
      objSlave.options[ind] = new Option(newArray[i][2], newArray[i][1]);
      if (keyVal == newArray[i][1]) objSlave.selectedIndex = ind;
      ind++;
    }
  }

}

//****************************************************************************************************//

function chkField(isBad, obj, msg) {
  if (isBad) {
    alert(msg);
    obj.focus();
    return false;
  }

  return true;
}

//****************************************************************************************************//

function goConfirm(msg, url) {
  if (window.confirm(msg)) {
    go(url);
  }
}

//****************************************************************************************************//

function openWindow(url, target, style, moveX, moveY) {
  var theWin = window.open(url, target, style);
  theWin.moveTo(moveX, moveY);
  theWin.focus();
}

//****************************************************************************************************//

function openConfirm(msg, url, target, style, moveX, moveY) {
  if (!varIsNull(msg)) {
    if (window.confirm(msg)) {
      openWindow(url, target, style, moveX, moveY);
    }
  }
  else {
    openWindow(url, target, style, moveX, moveY);
  }
}

//****************************************************************************************************//

function stripslashes(value) {
  var retval = value;

  while (retval.indexOf("\\") != -1) {
    retval = retval.substring(0, retval.indexOf("\\")) + retval.substring(retval.indexOf("\\") + 1, retval.length);
  }

  return retval;
}

//****************************************************************************************************//

function showChange(image1,image2,imageName,ckd,noid){
	var targ1 = document.getElementById(image1);
	var targ2 = document.getElementById(image2);

	targ1.src = imageName + ckd + "_2.jpg";
	targ2.src = imageName + "0" + (ckd - (ckd - (2 / ckd))) + "_1.jpg";
	
	if (noid == 4){
    idenxajx();
	}
	else if (noid == 6){
    idenxajx2();
	}
	else if (noid == 8){
    idenxajx3();
	}
	else if (noid == 9){
    idenxajx4();
	}
}

//****************************************************************************************************//

function addBookmarkForBrowser() {
   if (document.all){
      window.external.AddFavorite("http://www.twindustry.com", "台灣工業經貿網");
   } else {
      window.sidebar.addPanel("台灣工業經貿網", "http://www.twindustry.com", "");
   }
}

//****************************************************************************************************//

function changeSec(num){
	var sImgAry = document.getElementsByName("sImg");

	sImgAry[(chkNum - 1)].src = "images/table/topbut_" + chkNum + "_1.gif";
	sImgAry[(num - 1)].src = "images/table/topbut_" + num + "_2.gif";
	document.getElementById("secDivbg").style.backgroundImage = "url(images/table/table_tun" + num + ".jpg)";
	document.getElementById("secWhe").value = num;
	
	chkNum = num;
}

//****************************************************************************************************//

function siteMsg(){
	var smgAjax = new ajax();
	smgAjax.top_listCase(1,"../includes/leftTop.php","siteMsg");
}
window.addOnLoadListener(siteMsg);

//****************************************************************************************************//

function kokusai(){
	var kouAjax = new ajax();
	kouAjax.top_listCase(11,"../includes/topCase.php","kokusaiMsg");
}
// window.addOnLoadListener(kokusai);

//****************************************************************************************************//

function todaySite(){
	var tdsAjax = new ajax();
	tdsAjax.top_listCase(15,"../includes/topCase.php","todaySite");
}
// window.addOnLoadListener(todaySite);

//****************************************************************************************************//

function universty(){
	var uwAjax = new ajax();
	uwAjax.top_listCase(13,"../includes/topCase.php","universty");
}
// window.addOnLoadListener(universty);

//****************************************************************************************************//

function fsType(){
	var tpAjax = new ajax();
	tpAjax.top_listCase(19,"../includes/topCase.php","fsType");
}
// window.addOnLoadListener(fsType);

//****************************************************************************************************//

function monof(){
	var tpAjax = new ajax();
	tpAjax.top_listCase(27,"../includes/topCase.php","monof",0);
}
// window.addOnLoadListener(monof);

//****************************************************************************************************//

function productImage(){
	var pdAjax = new ajax();
	pdAjax.top_listCase(5,"../includes/topCase.php","productImage");
}
// window.addOnLoadListener(productImage);

//****************************************************************************************************//

function lessInfo(){
	var liAjax = new ajax();
	liAjax.top_listCase(29,"../includes/topCase.php","lessInfo");
}

//****************************************************************************************************//

function idenxajx(){
	var idxAjax = new ajax();
	idxAjax.top_listCase(4,"../includes/topCase.php","idenx2");
}
// window.addOnLoadListener(idenxajx);
//****************************************************************************************************//

function idenxajx2(){
	var idxAjax = new ajax();
	idxAjax.top_listCase(6,"../includes/topCase.php","idenx2");
}

//****************************************************************************************************//

function idenxajx3(){
	var idxAjax = new ajax();
	idxAjax.top_listCase(8,"../includes/topCase.php","ietox2");
}
// window.addOnLoadListener(idenxajx3);
//****************************************************************************************************//

function idenxajx4(){
	var idxAjax = new ajax();
	idxAjax.top_listCase(9,"../includes/topCase.php","ietox2");
}

//****************************************************************************************************//

function listProducts(){
	//var prodAjax = new ajax();
	//prodAjax.top_listCase(21,"../includes/topCase.php","productsList","1&tid=" + document.getElementById("tid").options[document.getElementById("tid").selectedIndex].value + "&sid=" + document.getElementById("sid").options[document.getElementById("sid").selectedIndex].value);
  sagasi();
}
window.addOnLoadListener(listProducts);
//****************************************************************************************************//

function setMember(){
	var memAjax = new ajax();
	memAjax.top_listCase(20,"../includes/topCase.php","memberOnly","1&rand_num=" + document.getElementById("randNum").value);
}
window.addOnLoadListener(setMember);
//****************************************************************************************************//

function setSagasi(){
	if (document.getElementById("secWhe").value != 1){
  	changeSec(document.getElementById("secWhe").value);
	}
}
window.addOnLoadListener(setSagasi);
//****************************************************************************************************//

function epaper(){
	var epaAjax = new ajax();
	epaAjax.top_listCase(17,"../includes/topCase.php","epaper","1&type_id=" + document.getElementById("type_id").value);
}
// window.addOnLoadListener(epaper);

//****************************************************************************************************//

function tokes(){
	var epaAjax = new ajax();
	epaAjax.top_listCase(16,"../includes/topCase.php","tokes");
}
// window.addOnLoadListener(tokes);

//****************************************************************************************************//

function mykyakus(){
	var mkuAjax = new ajax();
	mkuAjax.top_listCase(26,"../includes/topCase.php","myKyaku");
}
// window.addOnLoadListener(mykyakus);
//****************************************************************************************************//

function finance(){
	var financeAjax = new ajax();
	financeAjax.top_listCase(30,"../includes/topCase.php","finance");
}
//****************************************************************************************************//
//請使用window.addOnLoadListener(lester);來註冊要由window.onload來執行的功能
window.onload = function (){
	for (var i = 0;i < window.onloadListeners.length;i++){
		var func = window.onloadListeners[i];
		func.call();
	}
}

//****************************************************************************************************//

function sagasi(){
	var sgiAjax = new ajax();
	link = "1";
	if (document.getElementById("tid")){
		var tidObj = document.getElementById("tid");
		link += "&tid=" + tidObj.options[tidObj.selectedIndex].value;
	}
	if (document.getElementById("sid")){
		var sidObj = document.getElementById("sid");
		link += "&sid=" + sidObj.options[sidObj.selectedIndex].value;
	}
	if (document.getElementById("addr1")){
		var addr1Obj = document.getElementById("addr1");
		link += "&addr1=" + addr1Obj.options[addr1Obj.selectedIndex].value;
	}
	if (document.getElementById("key_word") && document.getElementById("key_word").value != "請輸入關鍵字"){
		var addr1Obj = document.getElementById("key_word");
		link += "&key_word=" + addr1Obj.value;
	}
	link += "&chkAction=" + document.getElementById("secWhe").value;
	sgiAjax.top_listCase(21,"../includes/topCase.php","productsList",link);
}

//****************************************************************************************************//

function changeTypePage(num){
	var ctp = new ajax();
	ctp.top_listCase(19,"../includes/topCase.php","fsType","1&pageNo=" + num);
}

//****************************************************************************************************//

function tmp27(num){
	var ctp = new ajax();
	ctp.top_listCase(27,"../includes/topCase.php","monof",num);
}

//****************************************************************************************************//

function changSelect1(num,cnum){
	ShowCustomerIMG(num,cnum);
	var selAjax = new ajax();
	selAjax.top_listCase(18,"../includes/topCase.php","secType",num + "&types=" + cnum);
}

//****************************************************************************************************//

function ShowCustomerIMG(num,cnum){
	var selAjax = new ajax();
	selAjax.top_listCase(28,"../includes/topCase.php","cusIMG",num + "&types=" + cnum);
}

//****************************************************************************************************//

function changSelect2(num,cnum){
	var sel2Ajax = new ajax();
	sel2Ajax.top_listCase(24,"../includes/topCase.php","secCustomer",num + "&types=" + cnum);
}

//****************************************************************************************************//

function chkForm(){
	if (document.getElementById("user_id").value == ""){
		alert("請輸入帳號!");
		document.getElementById("user_id").focus();
		return false;
	}
	if (document.getElementById("passwd").value == ""){
		alert("請輸入密碼!!!");
		document.getElementById("passwd").focus();
		return false;
	}
	if (document.getElementById("randNum").value != document.getElementById("mod_chk").value){
		alert("確認碼錯誤,請重新輸入!!!");
		document.getElementById("mod_chk").focus();
		return false;
	}
	//document.formLog.submit();
	var logAjax = new ajax();
	logAjax.top_listCase(20,"../includes/topCase.php","memberOnly","1&action=login&user_id=" + document.getElementById("user_id").value + "&passwd=" + document.getElementById("passwd").value);
}

//****************************************************************************************************//

function user_logout(){
  var lotAjax = new ajax();
	lotAjax.top_listCase(20,"../includes/topCase.php","memberOnly","1&action=logout&rand_num=" + document.getElementById("randNum").value);
}

//****************************************************************************************************//

function linkCustomer(custId, custType){
	var lkct = new ajax();
	lkct.top_listCase(22,"../includes/topCase.php","productsList",custId+"&custType="+custType);
}

//****************************************************************************************************//

function changeListPage(num,cnum){
	var lctp = new ajax();
	lctp.top_listCase(21,"../includes/topCase.php","productsList","1&pageNo=" + num + "&pageNext=" + cnum + "&" + link);
}

//****************************************************************************************************//

function setCustomerUser(cid){
	document.getElementById("customer").value = cid;
}

//****************************************************************************************************//

function udCustomers(cid){
	var upcAjax = new ajax();
	upcAjax.top_listCase(25,"../includes/topCase.php","listCustomers",cid);
}

//****************************************************************************************************//

function imgSetd(){
	var tplImgDir = document.getElementById("tplImgDir");
	var tag1 = document.getElementById("table07_1");
	var tag2 = document.getElementById("table06_1");
	
	tag1.src = tplImgDir.value + "/table/table07_title01_2.jpg";
	tag2.src = tplImgDir.value + "/table/table06_title01_2.jpg";
}
addOnLoadListener(imgSetd);
//****************************************************************************************************//

function autoChange(num){
	if (num == 1){
		var chkn = (2 / autoc1);
		var table = "7";
		var cnum = (6 - ((chkn % 2) * 2));
	}else{
    var chkn = (2 / autoc2);
    var table = "6";
    var cnum = (8 + (2 - (2 / chkn)));
	}
	
	showChange('table0' + table + '_' + chkn,'table0' + table + '_' + (2 / chkn),document.getElementById("tplImgDir").value + '/table/table0' + table + '_title','0' + chkn,cnum);
	
	if (num == 1){
		autoc1 = chkn;
	}else{
    autoc2 = chkn;
	}
}

//****************************************************************************************************//

//-->

