// JavaScript Document
window.onload = function(){ preloadedImages(); }
function preloadedImages() 
{
	var heavyImage = new Array();
	
	heavyImage[41] = new Image(); 
	heavyImage[41].src = "buttons/video_close.jpg";
	
	heavyImage[0] = new Image(); 
	heavyImage[0].src = "buttons/menu_on_01.jpg";
	heavyImage[1] = new Image(); 
	heavyImage[1].src = "buttons/menu_on_02.jpg";
	heavyImage[2] = new Image(); 
	heavyImage[2].src = "buttons/menu_on_03.jpg";
	heavyImage[3] = new Image(); 
	heavyImage[3].src = "buttons/menu_on_04.jpg";
	heavyImage[4] = new Image(); 
	heavyImage[4].src = "buttons/menu_on_05.jpg";
	heavyImage[5] = new Image(); 
	heavyImage[5].src = "buttons/menu_on_06.jpg";
	heavyImage[6] = new Image(); 
	heavyImage[6].src = "buttons/menu_on_07.jpg";
	heavyImage[7] = new Image(); 
	heavyImage[7].src = "buttons/menu_on_08.jpg";
	
	heavyImage[8] = new Image(); 
	heavyImage[8].src = "buttons/sub_about_01.png";
	heavyImage[9] = new Image(); 
	heavyImage[9].src = "buttons/sub_about_02.png";
	heavyImage[10] = new Image(); 
	heavyImage[10].src = "buttons/sub_about_03.png";
	heavyImage[11] = new Image(); 
	heavyImage[11].src = "buttons/sub_about_04.png";
	heavyImage[12] = new Image(); 
	heavyImage[12].src = "buttons/sub_about_05.png";
	heavyImage[13] = new Image(); 
	heavyImage[13].src = "buttons/sub_about_06.png";
	
	heavyImage[14] = new Image(); 
	heavyImage[14].src = "buttons/sub_laws_01.png";
	heavyImage[15] = new Image(); 
	heavyImage[15].src = "buttons/sub_laws_02.png";
	heavyImage[16] = new Image(); 
	heavyImage[16].src = "buttons/sub_laws_03.png";
	heavyImage[17] = new Image(); 
	heavyImage[17].src = "buttons/sub_laws_04.png";
	
	heavyImage[18] = new Image(); 
	heavyImage[18].src = "buttons/sub_flight_01.png";
	heavyImage[19] = new Image(); 
	heavyImage[19].src = "buttons/sub_flight_02.png";
	heavyImage[20] = new Image(); 
	heavyImage[20].src = "buttons/sub_flight_03.png";
	heavyImage[21] = new Image(); 
	heavyImage[21].src = "buttons/sub_flight_04.png";
	heavyImage[22] = new Image(); 
	heavyImage[22].src = "buttons/sub_flight_05.png";
	heavyImage[23] = new Image(); 
	heavyImage[23].src = "buttons/sub_flight_06.png";
	
	heavyImage[24] = new Image(); 
	heavyImage[24].src = "buttons/sub_publications_01.png";
	heavyImage[25] = new Image(); 
	heavyImage[25].src = "buttons/sub_publications_02.png";
	heavyImage[26] = new Image(); 
	heavyImage[26].src = "buttons/sub_publications_03.png";
	heavyImage[27] = new Image(); 
	heavyImage[27].src = "buttons/sub_publications_04.png";
	
	heavyImage[28] = new Image(); 
	heavyImage[28].src = "buttons/sub_guide_01.png";
	heavyImage[29] = new Image(); 
	heavyImage[29].src = "buttons/sub_guide_02.png";
	heavyImage[30] = new Image(); 
	heavyImage[30].src = "buttons/sub_guide_03.png";
	
	heavyImage[35] = new Image(); 
	heavyImage[35].src = "buttons/sub_aviation_01.png";
	heavyImage[36] = new Image(); 
	heavyImage[36].src = "buttons/sub_aviation_02.png";
	heavyImage[37] = new Image(); 
	heavyImage[37].src = "buttons/sub_aviation_03.png";
	heavyImage[38] = new Image(); 
	heavyImage[38].src = "buttons/sub_aviation_04.png";
	heavyImage[39] = new Image(); 
	heavyImage[39].src = "buttons/sub_aviation_05.png";
	heavyImage[40] = new Image(); 
	heavyImage[40].src = "buttons/sub_aviation_06.png";
	
}
	
var div_id;
var old_div_id;
var div_obj;
var new_div_obj;
var old_div_obj;
var showTimeoutId;
var hideTimeoutId;
var img_obj;	//圖片對象
var img_src;    //圖片源
var is_on = 0;	//是否改變圖片 1表示是,0表示否;


function getObj(d){
	return document.getElementById(d);
}
function show(d1, imgid, ison, imgsrc){
	old_div_id = div_id;
	div_id = d1;
	var arr = div_id.split("-");
	old_div_obj = div_obj;
	new_div_obj = getObj(d1);
	
		if(hideTimeoutId)
		{
			clearTimeout(hideTimeoutId);
			if(old_div_obj!=new_div_obj)
			{
				hide1();
			}
		}
		div_obj = new_div_obj;
		if(imgid){img_obj = getObj(imgid);}
		if(ison){is_on = ison;}
		if(imgsrc){img_src = imgsrc;}
		
		showTimeoutId = setTimeout(show1,100);
}
function hide(d2, imgid, ison, imgsrc){
	div_id = d2;
	div_obj = getObj(d2);
	//var arr = div_id.split("-");

		if(showTimeoutId)
		{
			clearTimeout(showTimeoutId);
		}
		
		if(imgid)img_obj = getObj(imgid);
		if(ison)is_on = ison;
		if(imgsrc)img_src = imgsrc;
		
		hideTimeoutId = setTimeout(hide1,400);
}
function show1(){
	if(is_on == 1)
	{
		if(img_obj && img_src)
		{
			img_obj.src= img_src;
		}
		is_on = 0;
	}
	if(div_obj.style.display!="block")
   	{
		div_obj.style.display="block";
	}
	
	clearTimeout(showTimeoutId);
}
function hide1(){
	if(is_on == 1)
	{
		if(img_obj && img_src)
		{
			img_obj.src= img_src;
		}
		is_on = 0;
	}
	if(div_obj.style.display!="none")
   	{
		div_obj.style.display="none";
	}
	
	clearTimeout(hideTimeoutId);
}
function show2(d1, imgid, ison, imgsrc){
	
	if(imgid)img_obj = getObj(imgid);
	if(ison)is_on = ison;
	if(imgsrc)img_src = imgsrc;
	if(is_on == 1)
	{
		if(img_obj && img_src)
		{
			img_obj.src= img_src;
		}
		is_on = 0;
	}
	if(document.getElementById(d1).style.display!="block")
   	{
		document.getElementById(d1).style.display='block';
	}
}
function hide2(d1, imgid, ison, imgsrc){
	
	if(imgid)img_obj = getObj(imgid);
	if(ison)is_on = ison;
	if(imgsrc)img_src = imgsrc;
	if(is_on == 1)
	{
		if(img_obj && img_src)
		{
			img_obj.src= img_src;
		}
		is_on = 0;
	}
	if(document.getElementById(d1).style.display!="none")
   	{
		document.getElementById(d1).style.display='none';
	}
}
function show3(imgid, ison, imgsrc){
	
	if(hideTimeoutId)
	{
		hide1();
	}
	
	if(imgid)img_obj = getObj(imgid);
	if(ison)is_on = ison;
	if(imgsrc)img_src = imgsrc;
	if(is_on == 1)
	{
		if(img_obj && img_src)
		{
			img_obj.src= img_src;
		}
		is_on = 0;
	}
}
function hide3(imgid, ison, imgsrc){
	
	if(imgid)img_obj = getObj(imgid);
	if(ison)is_on = ison;
	if(imgsrc)img_src = imgsrc;
	if(is_on == 1)
	{
		if(img_obj && img_src)
		{
			img_obj.src= img_src;
		}
		is_on = 0;
	}
}

function trimString(string)
{
    var ret = string.replace(/(^\s*)|(\s*$)/g, "");
    return ret;
}

function checkNoSpecialChars(string)
{
	var pattern = /^(\w|[^\x00-\xff]|\.|-| )+$/;
	if(!pattern.test(string))
	{
		return false;
	}
	return true;
}

function checkStringLength(string,minLength,maxLength)
{
    /*
	var re=/[\u4E00-\u9FA5]/g;
	var r_len = string.length
	if(re.test(string))
	{
		var c_len = string.match(re).length;
		var a_len = string.length;
		r_len = a_len+c_len;

	}
    */
    var r_len = string.replace(/[^\x00-\xff]/g,"**").length;
	if((r_len<minLength)||(r_len > maxLength))
	{
		return false;
	}
	return true;
}


function checkForm(){
   
   var form = document.searchform;

   var searchkey = form.searchkey;
   var searchkey_val = trimString(searchkey.value);
   if(searchkey_val == ""){
		alert('請輸入搜索的關鍵字');
		searchkey.focus();
		searchkey.select();
		return false;
	}
	else if(checkStringLength(searchkey_val,4,40) == false){
		alert('搜索的關鍵字太短');
		searchkey.focus();
		searchkey.select();
		return false;
	}
	searchkey.value = searchkey_val;
	
    document.searchform.submit();
    return true;
	
}

function langClick(mylang){
	
	//var fname = window.location.href.match(/.+\/([^?]*)/)[1];
	var fname = window.location.href;
	
	if(mylang === 1){
		window.location = fname.replace('/chinese/','/english/');
	}else if(mylang === 2){
		window.location = fname.replace('/chinese/','/portuguese/');
	}else{
		window.location = fname;
	}	
}

function clickCount(myhref){
	
	var jx2 = new Ajax();
	var url = "../count2/stats.php";
	var send = "myrequest=" + myhref;
	jx2.post(url, send, function(str) {
    });
}

  var jx = new Ajax();
  var url = "../count2/stats.php";
  var url2 = location.href.split("?");
  var send = "myrequest=" + url2[0];
  jx.post(url, send, function(str) {
							  
  });


