
DOM = (document.getElementById) ? true : false;
IE = (document.all) ? true : false;
IE4 = IE && !DOM;

function ShowLayer(LayerId) {
	if (DOM) {
 		LayerItem = document.getElementById(LayerId).style
    	LayerItem.display = 'block';
    	LayerItem.visibility = 'visible';
	}
	if (IE4) {
 		LayerItem = document.all(LayerId).style
		LayerItem.display = 'block';		
	}
}

function HideLayer(LayerId) {
	if (DOM) {
 		LayerItem = document.getElementById(LayerId).style
    	LayerItem.display = 'none';
    	LayerItem.visibility = 'hidden';
	}
	if (IE4) {
 		LayerItem = document.all(LayerId).style
		LayerItem.display = 'none';		
	}
}

function SwitchLayer(LayerId) {
	if (DOM) {
 		LayerItem = document.getElementById(LayerId).style
		if (LayerItem.visibility == 'hidden') {
    		ShowLayer(LayerId);
		} else {
        	HideLayer(LayerId);
    	}
	
	}
	if (IE4) {
 		LayerItem = document.all(LayerId).style
		if (LayerItem.display == 'none') {
			ShowLayer(LayerId);
		} else {
			HideLayer(LayerId);
        }
	}
}

function ShowTr(TrGroup) {
	var IdName, num = 0;
	while (document.getElementById(TrGroup + '_' + num)) {
		ShowLayer(TrGroup + '_' + num);
		num++;
	}
}

function HideTr(TrGroup) {
	var IdName, num = 0;
	while (document.getElementById(TrGroup + '_' + num)) {
		HideLayer(TrGroup + '_' + num);
		num++;
	}
}

function WriteLayer(LayerId, Text) {
	if (DOM) {
 		LayerItem = document.getElementById(LayerId);
	}
	if (IE4) {
 		LayerItem = document.all(LayerId);
	}
    LayerItem.innerHTML = Text;
}

var mouseX = 0, mouseY = 0;
function page_onload() {
	//隨滑鼠位置移動
	if (!IE) document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = getMouseXY;
}

function getMouseXY(e) {
	if (IE) { 
		//加算捲軸
		if(document.body.scrollTop && document.body.scrollTop !=0) {
			scrollX = document.body.scrollLeft;
			scrollY = document.body.scrollTop;
		}
		else{
			scrollX = document.getElementsByTagName("html")[0].scrollLeft;
			scrollY = document.getElementsByTagName("html")[0].scrollTop;
		}
		mouseX = window.event.clientX + scrollX;
		mouseY = window.event.clientY + scrollY;
	} else { 
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	if (mouseX < 0){mouseX = 0;}
	if (mouseY < 0){mouseY = 0;}
	return true;
}

function FollowCursor(LayerId) {
	if (DOM) {
 		LayerObj = document.getElementById(LayerId);
	}
	if (IE4) {
 		LayerObj = document.all(LayerId);
	}
	gapX = 15; //X偏移量
	gapY = 15; //Y偏移量
	
	if (mouseX + gapX + LayerObj.clientWidth > document.body.clientWidth) {
		//右側超過視窗, 則往內修正
		mouseX = document.body.clientWidth - LayerObj.clientWidth - gapX;
	}
	if (mouseY + gapY + LayerObj.clientHeight > document.body.clientHeighth) {
		//底部超過視窗, 則往內修正
		mouseY = document.body.clientHeight - LayerObj.clientHeight - gapY;
	}

	LayerObj.style.left = mouseX + gapX + "px";
	LayerObj.style.top = mouseY + gapY + "px";
}

//Email
function check_email(email) {
	var filter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if (email == '') {
		return false;
	} else if (!filter.test(email)){
		return false;
	} else {
		return true
	}
}