//*******IE or NS********//
if(parseInt(navigator.appVersion.charAt(0)) >= 4) {
	isNS4 = (navigator.appName == "Netscape") ? true : false;
	isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
	isDOM = document.getElementById ? true : false;
 }
 

//******Acation 選項********//

if (isDOM && window.Event){
	window.captureEvents(Event.KEYPRESS);
	document.onkeydown=  keyPressed;
}

var keypressCode;

function keyPressed(e)
{
	(window.Event) ? keypressCode=e.which : keypressCode=event.keyCode;
}


function checkchinese(str) {
  var strlen=str.length;
  if(strlen>0){
    var oldstrlen=str.length
    for(var i=0;i<strlen;i++) {
      c='';  c = escape(str.charAt(i));
      if( c.charAt(0) == '%') {
        cc = c.charAt(1);//IE~u,NS~A
        if(cc =='A' ||cc =='u'){ return true; }
      }
    }
  return false; } else { return false; }
}

function trim(strText) { 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

/*function Keychange() {
  var data=document.form.I6.value;
  var datalen=data.length;
  var isChinese=checkchinese(data);
  if(isChinese) var max=70;  else  var max=160;
  if(datalen > max) {
    document.form.I6.value=data.substr(0,max);
    datalen=document.form.I6.value.length;  
    alert("字數已超過限制！");
  }
   if(isIE4) {  document.all.counter.innerText=max-datalen;  }
   if(isNS4) {  document.form.counter.value=max-datalen;  }
}
*/

function CountTxtLen_general(){
	document.write("<font style='font-size:9pt'>行動電話：中英文70個字或英文159個字；");
	//document.write("呼叫器：中英文30個字或英文60個字，");
	if(isIE4){document.write("剩餘&nbsp;<b><span id=counter style='color:red;'>160</span></b>&nbsp;個字")}
	if(isNS4) {document.write("剩餘&nbsp;<span><input readonly type=text size=3 maxlength=3 name=counter value=160 onblur=\"readonly(this.form)\"></span>&nbsp;個字")}
	document.write("</font><br>");
}

function Keychange() {   	
  if (document.form.subI6.value != ""){	  	
  	document.form.I6.value += trim(document.form.subI6.value);  	
  	document.form.subI6.value = "";
  }
  var data=document.form.I6.value; 
  var datalen = data.length;
  var isChinese=checkchinese(data);
  if(isChinese) var max=70;  else  var max=160; 
   
 
  if(datalen > max) {   		
 	document.form.I6.value=data.substr(0,max); 	
 	document.form.subI6.value = data.substr(max,datalen); 	
   	datalen=document.form.I6.value.length;
   	
  }
     	
  if (document.form.subI6.value.length > max){
  	document.form.subI6.value = document.form.subI6.value.substr(0,max);    	 	
  	alert("字數已超過限制!!");
  }	
  var data1len = document.form.subI6.value.length;	 
  if(isIE4) {
  	document.all.counter.innerText=max-datalen;
  	document.all.counter1.innerText=max-data1len;
  }
  if(isNS4) {  
  	document.form.counter.value=max-datalen;
  	document.form.counter1.value=max-data1len;
  }
}

function Keychange1() {		
	 var data=document.form.msgboard.value; 
	 var datalen = data.length;
	 var isChinese=checkchinese(data);
	 if(isChinese) var max=70;  else  var max=160; 
	   
	 if (document.form.Sync.checked){	 	
	 	if (datalen <= max){
	 		document.form.I6.value = data;
	 		document.form.subI6.value = "";
	 	}		 	
		else {
			if (document.form.IsOverlen.value == "0"){
				alert('超過簡訊長度限制,會多一封簡訊!!');
				document.form.IsOverlen.value = "1";
			}	   		
			document.form.I6.value=data.substr(0,max); 	
		 	document.form.subI6.value = data.substr(max,datalen); 			   		   	
		}
		     	
		if (document.form.subI6.value.length > max){
		  	document.form.subI6.value = document.form.subI6.value.substr(0,max);    	 			  	
		}	
		var data1len = document.form.I6.value.length;
		var data2len = document.form.subI6.value.length;	 
		if(isIE4) {
		  	document.all.counter1.innerText=max-data1len;
		  	document.all.counter2.innerText=max-data2len;
		}
		if(isNS4) {  
		  	document.form.counter1.value=max-data1len;
		  	document.form.counter2.value=max-data2len;
		}
	}	
}

function subKeychange1(obj) {
	if (obj){
		var data=document.form.all[obj].value;
		var datalen=data.length;
		var isChinese=checkchinese(data);
		if(isChinese) var max=70;  else  var max=160;
		if(datalen > max) {			
			document.form.all[obj].value = data.substr(0,max);
			datalen=document.form.all[obj].value.length;  
		}		
		if (obj == "subI6"){
			var tmpcoun = "counter2";
		}	 	
		else if (obj == "I6"){
			var tmpcoun = "counter1";
		}
		else
			var tmpcoun = "counter";	
			
		if(isIE4) {  document.all[tmpcoun].innerText=max-datalen;  }
		if(isNS4) {  document.form[tmpcoun].value=max-datalen;  }
	}
}


function CountTxtLen(){
	//document.write("<font style='font-size:9pt'>行動電話：中英文70個字或英文159個字；");
	//document.write("呼叫器：中英文30個字或英文60個字，");
	if(isIE4){document.write("剩餘&nbsp;<b><span id=counter style='color:red;'>160</span>／<span id=counter1 style='color:red'>160</span></b>&nbsp;個字")}
	if(isNS4) {document.write("剩餘&nbsp;<span><input readonly type=text size=3 maxlength=3 name=counter value=160 onblur=\"readonly(this.form)\"></span>&nbsp;個字")}
	//document.write(",</font><br><font style='font-size:9pt;color:red;'>＊如果超過限制長度，會變成發兩封簡訊＊");
	//document.write("</font><br>");
}

function CountTxtLen1(name1){
	if (name1 == "counter1") var Item = 1;
	else			 var Item = 2;	
	if(isIE4){document.write("第 "+Item+" 封簡訊，剩&nbsp;<b><span id=" + name1 + " style='color:red;'>60</span></b>&nbsp;個字")}
	if(isNS4) {document.write("第 "+Item+" 封簡訊，剩&nbsp;<span><input readonly type=text size=3 maxlength=3 name=" + name1 + " value=60 onblur=\"readonly(this.form)\"></span>&nbsp;個字")}
	document.write("</font><br>");
}


function hideall(tmpNum) {
    	for (var i=1;i<=tmpNum;i++){
	    var object = 'MSG' + i;
	    if (document.layers && document.layers[object])
	        document.layers[object].visibility = 'hidden';
	    else if (document.all)
	        document.all[object].style.visibility = 'hidden';
	}
}

function Key(){
	if (window.event.button == "2" || window.event.button== "3"){
		return false;
	}
}

function CheckKey(object){
	var Fname = document.form.elements;
	for (i1=0; i1<Fname.length; i1++) { if (Fname[i1].name == object) break; }
	var Obj = Fname[i1];
	//var Obj = document.form.all[object];
	if (isIE4) {
		if (event.keyCode == 13){
			event.keyCode = 0;
			Obj.focus();
		}
	} else if (isDOM) {
		if (keypressCode == 13){
			keypressCode = 0;
			if (Obj) Obj.focus();
		}
	}
	return(0);
}

/**** 以下程式用於檢視任何資料用的POPUP視窗,如:逐筆調訂,檢視詳細資料等 ****/
/**** 彈跳視窗的長寬採動態決定方式 ****/

function ViewDetail(tmpURL,tmpWidth,tmpHeight){
	if (tmpWidth == null){
		switch (screen.width){
			case 800: var tmpWidth = 400; break;
			default: var tmpWidth = 400; break;
		}
	}
	if (tmpHeight == null){
		switch (screen.height){
			case 600: var tmpHeight = screen.height - 50; break;
			default: var tmpHeight = screen.height - 120; break;
		}
	}
	var tmpLeft = (screen.width-tmpWidth)/2;
	var tmpTop = 50;
	var Win1 = window.open(tmpURL,"Win1","width=" + tmpWidth +",height=" + tmpHeight +",left=" + tmpLeft + ",top=" + tmpTop + ",scrollbars=Yes","alwaysRaised=yes");
	//window.open(tmpURL);
}


//以下程式〔addOption〕〔deleteOption〕〔sortOptions〕主要是
//對Select Box進行Sorting

function deleteOption(object,index) {
    object.options[index] = null;
}

function addOption(object,text,value) {
    var defaultSelected = false;
    var selected = false;
    var optionName = new Option(text, value, defaultSelected, selected)
    object.options[object.length] = optionName;
    object.options[object.length-1].selected = false;
    
}

function sortOptions(what) {
    var copyOption = new Array();
    for (var i=0;i<what.options.length;i++){
        copyOption[i] = new Array(what[i].text, what[i].value);
    }

    copyOption.sort();

    for (var i=what.options.length-1;i>-1;i--)
        deleteOption(what,i);

    for (var i=0;i<copyOption.length;i++)
        addOption(what,copyOption[i][0],copyOption[i][1])
}

//---從object1加入/移除到object2
function AddORDel(object1,object2){
	var Obj = document.form.elements;
	for (i1=0; i1<Obj.length; i1++) { if (Obj[i1].name == object1) break; }
	for (i2=0; i2<Obj.length; i2++) { if (Obj[i2].name == object2) break; }
	//Msg = i1 + ", " + i2 + ", " + object1 + ", " + object2;
	//alert(Msg);
	var Obj1 = Obj[i1];
	var Obj2 = Obj[i2];
	if (Obj1.options[0].value != ""){
		Flag = true;
		var UserList_Name = new Array();
		var UserList_Account = new Array();
		var UserList_Choose = new Array();
		for (var i=0;i< Obj1.options.length;i++){
			var IsExisted = 0;
			UserList_Name[i] = Obj1.options[i].text;
			UserList_Account[i] = Obj1.options[i].value;
			UserList_Choose[i] = 0;
			if (Obj1.options[i].selected){
				UserList_Choose[i] = 1;
				for (var j=0;j< Obj2.options.length;j++){
					if (Obj2.options[j].value == Obj1.options[i].value){
						IsExisted = 1;
						break;
					}
				}
				if (IsExisted == 0){
					if ((Obj2.options.length > 0) && (Obj2.options[0].value == "")){
						Obj2.options.length = 0;
					}
					var new_option = new Option;
					new_option.text = Obj1.options[i].text;
					new_option.value = Obj1.options[i].value;
					Obj2.options[Obj2.length] = new_option;
					Obj1.options[i].selected = false;
				}
			}
		}
		for (var i=Obj1.options.length-1;i>=0 ;i--){
			if (UserList_Choose[i] == 1){
				Obj1.options[i] = null;
			}
		}
		/*
		Obj1.options.length = 0;
		for (var i=0;i<UserList_Name.length;i++){
			if (UserList_Choose[i] == 0){
				Obj1.options.length++;
				Obj1.options[Obj1.options.length-1].text = UserList_Name[i];
				Obj1.options[Obj1.options.length-1].value = UserList_Account[i];
			}
		}
		if (Obj1.options.length == 0){
			Obj1.options.length++;
			Obj1.options[0].value = "";
			Obj1.options[0].text = "                   ";
		}
		*/
	}
	//sortOptions(Obj1);
	//sortOptions(Obj2);
	
}

//---從object1全部加入/移除到object2
function AddORDelAll(object1,object2){
	var Obj = document.form.elements;
	for (i1=0; i1<Obj.length; i1++) { if (Obj[i1].name == object1) break; }
	for (i2=0; i2<Obj.length; i2++) { if (Obj[i2].name == object2) break; }
	var Obj1 = Obj[i1];
	var Obj2 = Obj[i2];
	if (Obj2.options.length != 0 ) {
		if ((Obj2.options[0].value == null) || (Obj2.options[0].value == "")){
			Obj2.options.length = 0;
		}
	}
	if (Obj1.options[0].value != ""){
		Flag = true;
		for (var i=0; i< Obj1.options.length;i++){
			var IsExisted = 0;
			for (var j=0;j< Obj2.options.length;j++){
				if (Obj2.options[j].value == Obj1.options[i].value){
					IsExisted = 1;
				}
			}	
			if (IsExisted == 0){	
				Obj2.options.length++;
				Obj2.options[Obj2.options.length-1].text = Obj1.options[i].text;
				Obj2.options[Obj2.options.length-1].value = Obj1.options[i].value;
			}
			Obj1.options[i].selected = false;
		}
		Obj1.options.length = 0;
		if (Obj1.options.length == 0){
			Obj1.options.length++;
			Obj1.options[0].value = "";
			Obj1.options[0].text = "                   ";
		}
	}
	sortOptions(Obj1);
	sortOptions(Obj2);
}

// for Main1
function Keychange_main1() {
  var data=document.form.I6.value;
  var datalen=data.length;
  var isChinese=checkchinese(data);
  if(isChinese) var max=70;  else  var max=160;
  if(datalen > max) {
    document.form.I6.value=data.substr(0,max);
    datalen=document.form.I6.value.length;  
    alert("字數已超過限制！");
  }
   if(isIE4) {  document.all.counter.innerText=max-datalen;  }
   if(isNS4) {  document.form.counter.value=max-datalen;  }
}

function CountTxtLen_main1(){
	//document.write("<font style='font-size:9pt'>行動電話：中英文70個字或英文159個字；");
	//document.write("呼叫器：中英文30個字或英文60個字，");
	if(isIE4){document.write("剩餘&nbsp;<b><span id=counter style='color:red;'>160</span></b>&nbsp;個字")}
	if(isNS4) {document.write("剩餘&nbsp;<span><input readonly type=text size=3 maxlength=3 name=counter value=160 onblur=\"readonly(this.form)\"></span>&nbsp;個字")}
	//document.write("</font><br>");
}

/*
HM_DOM = document.getElementById ? true : false;
HM_IE  = document.all ? true : false;
HM_NS4 = document.layers ? true : false;

function HM_f_ToggleElementList(show,elList,toggleBy) {
      if(!(HM_DOM||HM_IE||HM_NS4)) return true;

      if(HM_NS4&&(toggleBy=="tag")) return true;

      for(var i=0; i<elList.length; i++) {
         var ElementsToToggle = [];
         switch(toggleBy) {
            case "tag":
               ElementsToToggle = (HM_DOM) ? document.getElementsByTagName(elList[i]) :
                                  document.all.tags(elList[i]);
               break;
            case "id":
               ElementsToToggle[0] = (HM_DOM) ? document.getElementById(elList[i]) :
                                     (HM_IE) ? document.all(elList[i]) : 
                                     document.layers[elList[i]];
               break;
         }
         for(var j=0; j<ElementsToToggle.length; j++) {
            var theElement = ElementsToToggle[j];
            if(!theElement) continue;
            if(HM_DOM||HM_IE) {
               theElement.style.visibility = show ? "visible" : "hidden";
            } else if (HM_NS4) {
               theElement.visibility = show ? "visible" : "hide";
            }
         }
      }
      return true;
}
*/


// amway infor.js

var titleimage="<div align=\"center\"><img src=\"/images/top.jpg\" width=\"785\" height=\"73\" usemap=\"#Map\" border=\"0\"></div>"
var titleimageMap="<map name=\"Map\"><area shape=\"rect\" coords=\"586,45,645,63\" href=\"http://www.amway.com.tw\" target=\"_blank\" alt=\"安麗台灣\" title=\"安麗台灣\"><area shape=\"rect\" coords=\"651,46,704,63\" href=\"http://www.amway.com.tw/service/amwaynet/service_10.asp\" target=\"_blank\" alt=\"簡訊說明\" title=\"簡訊說明\"><area shape=\"rect\" coords=\"712,46,777,64\" href=\"mailto:service_taiwan@amway.com\" alt=\"窵信給安麗\" title=\"窵信給安麗\"></map>"
var footertext="<table width=\"800\" align=\"center\"><tr><td class=\"bottonBg\" height=\"15\"><div align=\"center\"><p><font style=\'font-size:9pt\'>中華電信股份有限公司　版權所有 &copy; 2006 CHT Inc. All Rights Reserved.　最佳瀏覽解析度1024X768</font></div></td></tr></table>"


function printtitleimage() {
         document.write(titleimage)
		 document.write(titleimageMap)
}

function printfootertext(){
        document.write(footertext)
}

