﻿////////////////////////////////////////////////////////////////////////////

//---IE/NS

/*
function right(e)
{if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))   return false;
else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
	//alert("歡迎使用本軟體");
	return false;}
return true;}
document.onmousedown=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=right;
//---IE
if (window.print)
document.oncontextmenu=cancelm;
function cancelm(){return false;}

//---Disable Image
function disableclick(e) {
if (document.all) {
if (event.button==2||event.button==3) {
if (event.srcElement.tagName=="IMG"){
return false;
}
}
}
if (document.layers) {
if (e.which == 3) {
return false;
}
}
}
*/


var isFirefox;
var isIE;
isFirefox = ( navigator.appName == "Netscape" );
isIE = (navigator.appName == "Microsoft Internet Explorer" ); 
var AjaxServerPageName;
AjaxServerPageName = "server.asp";
AjaxServerPageName1 = "../server.asp";
AjaxNETPageName = "../she/server.aspx";
function getAjax(){
	var XmlHttp;	
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
	return XmlHttp;
}


//checkwait('PopupDiv', true);

//checkwait('PopupDiv', false);

function checkwait(sDivID, bState) {
    var oDiv = document.getElementById(sDivID);
    if (bState) {
		oDiv.innerHTML="資料處理中，請稍候‧‧‧‧‧";
        oDiv.style.display = 'block';
    }
    else {
        oDiv.innerHTML="";
        oDiv.style.display = 'none';
   }
}

function checkwait1(sDivID, bState, x) {
    var oDiv = document.getElementById(sDivID);    
    if (bState) {
		oDiv.style.top=x+70;
		oDiv.innerHTML="資料處理中，請稍候‧‧‧‧‧";
        oDiv.style.display = 'block';
    }
    else {
        oDiv.innerHTML="";
        oDiv.style.display = 'none';
   }
}

function getElement( id ){
	if( isIE ) {
		return document.all[ id ];
	}
	else {
		return document.getElementById( id );
	}
}




var isFirefox=(window.navigator.userAgent.indexOf("Firefox")!=-1);
// ---------------------------------------------------
function showSelectBoxes(){
	
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}
// ---------------------------------------------------
function hideSelectBoxes(){
	
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}
// ---------------------------------------------------
function showFlash(){
	
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}
	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}
// ---------------------------------------------------
function hideFlash(){
	
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}
	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}
}
// ---------------------------------------------------
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
// ---------------------------------------------------
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
// ---------------------------------------------------
function startup() {
	
	hideFlash();
	hideSelectBoxes();
	var overlayOpacity = 0.8;
	var overlayDuration = 0.2;
	var objBody = document.getElementsByTagName('body').item(0);
	var objOverlay = document.createElement('div');
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
		
	// This code inserts html at the middle of the page that looks similar to this:
	//<div id="overlay"></div>
	//<div id="lightbox">
	//	<div id="sys_msg">
	//		<a href="javascript:void(0)" title="關閉" onclick="end();"><img src="images/sys_msg_close_zh.gif" width="39" height="12" align="right" id="sys_msg_close" border="0" /></a><br /><br /><img src="images/sys_msg_save_s_zh.gif" width="135" height="29" class="sys_msg_save_icon" />
	//	</div>
	//</div>
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'block';
	objOverlay.style.minHeight = arrayPageSize[1];
	objBody.appendChild(objOverlay);
	
	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'block';
	objLightbox.style.top = (arrayPageScroll[1] + (arrayPageSize[3] / 3) + 'px');
	objBody.appendChild(objLightbox);
		
	//var objOuterImageContainer = document.createElement('div');
	//objOuterImageContainer.setAttribute('id','sys_msg');
	//objLightbox.appendChild(objOuterImageContainer);
	
	//document.getElementById('sys_msg').innerHTML = '<a href="javascript:void(0)" title="關閉" onclick="end();"><img src="<a href="http://www.x2-blog.com/x2hu/images/sys_msg_close_zh.gif" target="_blank">http://www.x2-blog.com/x2hu/images/sys_msg_close_zh.gif</a>" width="39" height="12" align="right" id="sys_msg_close" border="0" /></a><br /><br /><img src="<a href="http://www.x2-blog.com/x2hu/images/sys_msg_save_s_zh.gif" target="_blank">http://www.x2-blog.com/x2hu/images/sys_msg_save_s_zh.gif</a>" width="135" height="29" class="sys_msg_save_icon" />';
	////Generates opacity effects for startup
	start_opacity_effect_interval = setInterval("startup_opacity_effect('overlay')", 4);
}
// ---------------------------------------------------
function startup_opacity_effect(id){	
	
	element = $(id);
	if (isFirefox) {
		//for firefox
		if (element.style.MozOpacity == 0.4) clearInterval(start_opacity_effect_interval);
		alpha = (element.style.MozOpacity * 100 + 10) / 100;
		element.style.MozOpacity = alpha;	  
	}else{
		if (element.filters.alpha.opacity == 40) clearInterval(start_opacity_effect_interval);
		element.filters.alpha.opacity += 10;
	}
}
// ---------------------------------------------------
function end_opacity_effect(id){
	
	element = $(id);
	if (isFirefox) {
		//for firefox
		if (element.style.MozOpacity == 0.0) {
			clearInterval(end_opacity_effect_interval);
			//when effect done, remove the overlay div
			var objBody = document.getElementsByTagName('body').item(0);
			objBody.removeChild($('overlay'));
		}else{
			alpha = (element.style.MozOpacity * 100 - 10) / 100;
			element.style.MozOpacity = alpha;	  
		}		
	}else{
		if (element.filters.alpha.opacity == 0) {
			clearInterval(end_opacity_effect_interval);
			var objBody = document.getElementsByTagName('body').item(0);
			objBody.removeChild($('overlay'));
		}else{
			element.filters.alpha.opacity -= 10;
		}		
	}
}
// ---------------------------------------------------
function end() {
	
	showSelectBoxes();
	showFlash();
	var objBody = document.getElementsByTagName('body').item(0);
	//Generates opacity effects for end
	end_opacity_effect_interval = setInterval("end_opacity_effect('overlay')", 4);
	objBody.removeChild($('lightbox'));
}
// ---------------------------------------------------


function $(re) {
	return document.getElementById(re);
}


function Browser() { 

var ua, s, i; 

this.isIE = false; // Internet Explorer 
this.isNS = false; // Netscape 
this.version = null; 

ua = navigator.userAgent; 

s = "MSIE"; 
if ((i = ua.indexOf(s)) >= 0) { 
this.isIE = true; 
this.version = parseFloat(ua.substr(i + s.length)); 
return; 
} 

s = "Netscape6/"; 
if ((i = ua.indexOf(s)) >= 0) { 
this.isNS = true; 
this.version = parseFloat(ua.substr(i + s.length)); 
return; 
} 

// Treat any other "Gecko" browser as NS 6.1. 

s = "Gecko"; 
if ((i = ua.indexOf(s)) >= 0) { 
this.isNS = true; 
this.version = 6.1; 
return; 
} 
} 
////////////////////////////////////////////////////////////////////////////
