var isIE = (!document.all && document.getElementById) ? 0 : 1;;

function RenderNWR(){
   var nwr = document.getElementById("nwr");
   if (!nwr){
      return;
   }
   var onclick_ok = true;
   var onmouseover_in = false;
   var divs = new Array();
   var timer;
   var timer_id;
   divs = nwr.getElementsByTagName("div");
   nwr.onmouseover = function(){
	  onmouseover_in = true;
   }
   nwr.onmouseout = function(){
      onmouseover_in = false;
   }
   if (isIE) {
      var scrolldelay = nwr.getAttribute("className") || 4.5;
   }
   else {
  	  var scrolldelay = nwr.getAttribute("class") || 4.5;
   }
   if(isNaN(scrolldelay)){
      nwr.style.display = "none";
	  return;
   }
   scrolldelay = Math.max(parseFloat(scrolldelay) * 1000 ,1000);
   for (var i=0; i<divs.length; i++) {
      divs[i].style.top = nwr.offsetHeight*2 + "px";
	  divs[i].i = i;
	  if(divs[i].id == null || divs[i].id == ""){
	     divs[i].id = "_marquee_" + i;
	  }
	  divs[i].flyin = function(){
	     onclick_ok = true;
	     this.style.visibility = "visible";
		 timer_id = this.i;
         timer = setTimeout("document.getElementById('" + this.id + "').flyout()",scrolldelay);
	  }
	  divs[i].ondblclick = function(){
	     if (onclick_ok == true){
		    clearTimeout(timer);
            var next_div = this.i + 1;
		    if (next_div == divs.length){
		       next_div = 0;
		    }
	        this.style.top = nwr.offsetHeight*2 + "px";
		    next_div = divs[next_div];
	        next_div.style.visibility = "visible";
	        next_div.style.top = "0px";
		    next_div.flyin();
		 }
	  }
	  divs[i].flyout = function(){
         if ((onmouseover_in == true)&&(parseFloat(this.style.top) == 0)){
            setTimeout("document.getElementById('" + this.id + "').flyout()",50);
         }
		 else if (timer_id != this.i){
		 }
	     else {
		    onclick_ok = false;
	        var next_div = this.i + 1;
		    if (next_div == divs.length){
		       next_div = 0;
		    }
		    next_div = divs[next_div];
	        this.top = parseFloat(this.style.top);
		    if (this.top == 0){
	           next_div.style.top = this.offsetHeight + "px";
	           next_div.style.visibility = "visible";
		    }
	        next_div.top = parseFloat(next_div.style.top);
            if (next_div.top - 2 < 0){
		       next_div.style.top = "0px";
            }
		    else {
		       next_div.style.top = next_div.top - 2 + "px";
	        }
	        this.style.top = this.top - 2 + "px";
		    if (next_div.top > 0){
               setTimeout("document.getElementById('" + this.id + "').flyout()",50);
		    }
            else {
		       next_div.flyin();
		    }
	     }
	  }
   }
   if(divs.length > 0){
	  divs[0].style.top = "0";
	  divs[0].flyin();
   }
}

function ImgClick() {
   var imgclick = document.getElementsByTagName("a");
   for(var i=0;i<imgclick.length;i++){
      if (imgclick[i].rel){
		 imgclick[i].style.cursor="pointer";
         imgclick[i].onclick = function() {
            Pimg = this.rel;
            this.rel=this.getElementsByTagName("img")[0].src;
            this.getElementsByTagName("img")[0].src = Pimg;
            if (this.getElementsByTagName("input")[0]) {
               if (this.getElementsByTagName("input")[0].value){this.getElementsByTagName("input")[0].value="";}
               else {this.getElementsByTagName("input")[0].value=1;}
            }
         }
      }
   }
}



function toggleMenu(currMenu) {
   var thisMenu = document.getElementById(currMenu).style;
   if(currMenu.length>4){
	   var thisimgs = document.getElementById(currMenu+ "_img");
   }
   if (currMenu) {
      if (thisMenu.display == "block") {
		 if(currMenu.length>4){ 
		 thisimgs.setAttribute("class",  "menu_h3");
         thisimgs.setAttribute("className",  "menu_h3");
		 }
		 thisMenu.display = "none";
	  }
	  else if (thisMenu.display == "none"){
		 if(currMenu.length>4){ 
		 thisimgs.setAttribute("class",  "menu_h3_2");
         thisimgs.setAttribute("className",  "menu_h3_2");
		 }
		 thisMenu.display = "block";
	  }
   }
}

function browser() {
   var screen_a = document.getElementById("screen_a");
   var screen_b = document.getElementById("screen_b");
   if (screen_a){
	      screen_a.value=screen.colorDepth + ' 位元全彩';
   }
   if (screen_b){
	      screen_b.value=(screen.width+' x '+screen.height);
   }
}





function upload(upload_div,textarea_id,cgi,theme) {
   if (!document.getElementById("upload_key_"+upload_div)){
      var cell2 = document.createElement("div");
      cell2.setAttribute("id","upload_key_"+upload_div);
      cell2.innerHTML ="1";
      cell2.style.display = 'none';
      document.getElementById(upload_div).appendChild(cell2);
   }
   if ((document.getElementById("upload_key_"+upload_div).innerHTML == 1)&&(document.getElementById("upload_"+upload_div))) {
	  document.getElementById("upload_"+upload_div).style.display = 'none';
	  document.getElementById("upload_key_"+upload_div).innerHTML = '2';
   }
   else if ((document.getElementById("upload_key_"+upload_div).innerHTML == 2)&&(document.getElementById("upload_"+upload_div))) {
	  document.getElementById("upload_"+upload_div).style.display = 'block';
	  document.getElementById("upload_key_"+upload_div).innerHTML = '1';
   }
   else {
      var uploadHttp;
      if(window.XMLHttpRequest) {
         uploadHttp = new XMLHttpRequest();
      }
      else if(window.ActiveXObject) {
         uploadHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
	  var cell = document.createElement("div");
      cell.setAttribute("id","upload_"+upload_div);
      document.getElementById(upload_div).appendChild(cell);
	  cell.innerHTML=" &nbsp;&nbsp;Loading...";
      var url = 'upload.cgi?sr=upload_xml&textarea_id='+textarea_id+"&cgi="+cgi+"&theme="+theme;
      uploadHttp.open("GET",url, true);
      uploadHttp.onreadystatechange = function () {
      if (uploadHttp.readyState == 4) {
         if (uploadHttp.status == 200){
		    if (uploadHttp.responseXML.getElementsByTagName("html")[0]) {
               document.getElementById("upload_"+upload_div).innerHTML=uploadHttp.responseXML.getElementsByTagName("html")[0].childNodes[0].nodeValue;
		    }
			else {
	           document.getElementById(upload_div).removeChild(cell);
			   alert(uploadHttp.responseXML.getElementsByTagName("error")[0].childNodes[0].nodeValue); 
			}
         }
         else {
			 document.getElementById(upload_div).removeChild(cell);
			 alert("系統沒有回應，請重新嘗試"); 
		 }
	  }
      };
      uploadHttp.send(null);
   }
}

function query(name) {
   var Temp_value =  document.getElementsByName(name)[0].value;
   Temp_value = Temp_value.replace(/&/g, "%26");
   return Temp_value;
}

function sorry(name) {
	alert("本區尚未開放"); 
}