/******************************************************************************
  Eion Site main Function - JavaScript
  Version Modified By Janara.
  Based upon:  http://www.eion.com.tw
*******************************************************************************/

/* PreLoader JScript. */
PreLoader('ImgObjectBlank','images/icon_blank.gif');
PreLoader('ImgCEMAdministratorOn','ButtonLibraries/CEMenuAdministratorOn.gif');
PreLoader('ImgCEMAdministratorOff','ButtonLibraries/CEMenuAdministratorOff.gif');

function changeButtonImage(element, eName, eButton) {
	var eButtonType;
	if (eButton==1) {
		eButtonType = "On";
	} else {
		eButtonType = "Off";					
	}
	element.src="ButtonLibraries/CHMenu"+eName+ eButtonType + ".gif"
}	

function PreLoader(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

//判斷 v 是否是整數 Security code, Ajax Libraries, Frameworks and Toolkits 
function IsInt(v)
{
    var vArr = v.match(/^[0-9]+$/);
    if (vArr == null)
    {
        return false;
    }
    else
    {
        return true;
    }
}

// DO COOKIE TO DOMAIN
function doCookieSetup(name, value) {
      var argv = doCookieSetup.arguments;
      var argc = doCookieSetup.arguments.length;
      var expires = (argc > 2) ? argv[2] : null;
      var path = (argc > 3) ? argv[3] : null;
      var domain = (argc > 4) ? argv[4] : null;
      var secure = (argc > 5) ? argv[5] : null;

      document.cookie = escape(name) + "=" + escape(value) +
      ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
      ((path == null) ? "" : ("; path=" + path)) +
      ((domain == null) ? "" : ("; domain=" + domain)) +
      ((secure == null) ? "" : ("; secure=" + secure));
}

// DO AJAX CONNECTION
var DataDetailsReceptacleName=null;
var xmlhttp;
function GetDbaseAjaxConnection(eValue,eId,eIds){
	createXMLHttpRequest();
	var strURL='GetDbaseAjaxValue.asp?Operation='+eValue+'&Id='+eId+'&Ids='+eIds;
	xmlhttp.open('POST',strURL,false);
	xmlhttp.Send(null);
	// responseText 服務器進程返回數據的文本版本
	// responseXML 服務器進程返回數據的兼容DOM的XML文檔對象
	// responseStream ：將返回消息視為 Stream 物件。
	var valueTemplates=xmlhttp.responseText;
	return valueTemplates;		
}

// FOR AJAX & DIV POSITION SETTINGs - valueTemplates
function createXMLHttpRequest() {
    if(window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else if(window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        // ActiveXObject("Msxml2.XMLHTTP") 
    }
}

function GetinnerHtmFills() {
	// onreadystatechange 狀態改變的事件觸發器
	// readyState 對象狀態(integer):
	// 0 = 未初始化
	// 1 = 讀取中
	// 2 = 已讀取
	// 3 = 交互中
	// 4 = 完成			
	if(xmlhttp.readyState == 4) {
	// status 服務器返回的狀態碼, 如：404 = "文件末找到" 、200 ="成功"
		if(xmlhttp.status == 200) {
		    document.getElementById(DataDetailsReceptacleName).innerHTML = xmlhttp.responseText;
		}
	}
}

function CalculateLeftOffset(embraceSettings) {
    var offset = 0;
    while(embraceSettings) {
	    offset += embraceSettings["offsetLeft"];
	    embraceSettings = embraceSettings.offsetParent;
    }
    return offset;
}

function CalculateTopOffset(embraceSettings) {
    var offset = 0;
    while(embraceSettings) {
	    offset += embraceSettings["offsetTop"];
	    embraceSettings = embraceSettings.offsetParent;
    }
    return offset;
}

function fadeObjectHighligh(objNeme,speedValue) {
	//fadeByObject=document.getElementById(objNeme);
	//fadeProcessWork=setInterval("fadeObjectProcess(fadeByObject)",speedValue)
}

function fadeObjectLowligh(objNeme,opacityValue) {
	//clearInterval(fadeProcessWork)
	//fadeByObject=document.getElementById(objNeme);
	//fadeByObject.filters.alpha.opacity=opacityValue
}
function fadeObjectProcess(fadeProcessObject) {
	if (fadeProcessObject.filters.alpha.opacity<90)
	fadeProcessObject.filters.alpha.opacity+=30
	else if (window.fadeProcessWork)
	clearInterval(fadeProcessWork)
}

 // Description.. javascript:openWindow('Url.asp',500,300,0,0,0,0);
getNewWindow=null;
function openWindow(ContentUrl,theWidth,theHeight,theScroll,theStatusbar,theMenubar,theResizable) {

        if(getNewWindow==null){
					var CoordX = (screen.width / 2) - (theWidth / 2);
					var CoordY = (screen.height / 2) - (theHeight / 2);
					getNewWindow = window.open(ContentUrl, 'PMD', 'Left='+CoordX+',Top='+CoordY+',Width='+theWidth+',Height='+theHeight+',ScrollBars='+theScroll+',Status='+theStatusbar+',Menubar='+theMenubar+',Resizable='+theResizable+'');
        }else{
                try{
                        getNewWindow.status;
                        alreadyOpenMsg = "_______________________________________________________\t\n";
                        alert(alreadyOpenMsg + "\n This sub- Windows already opened, if rewill open please first closes the sub- Windows !\n Inspects whether hid to behind ! \n" + alreadyOpenMsg + "\n");
                }catch(e){
                        getNewWindow=null;
				   openWindow(ContentUrl,theWidth,theHeight,theScroll,theStatusbar,theMenubar,theResizable);
                }
        }
}


// Description.. javascript:PopupModalDialog('Url.asp',700,520,1);
function PopupModalDialog(ContentUrl,theWidth,theHeight) {
	var showWindow = window.showModalDialog (ContentUrl,'PMD','dialogWidth='+theWidth+'px;dialogHeight='+theHeight+'px;Scrollbars=Yes;Center=1;Status=No;Help=No');
}


is = new BrowserNavigationCheck()
function BrowserNavigationCheck() {
	var bnCheck = navigator.appName
	if (bnCheck=="Netscape") this.bnCheck = "ns"
	else if (bnCheck=="Microsoft Internet Explorer") this.bnCheck = "ie"
	else this.bnCheck = "ie";
}			

var diagnoseNavigation;
var elementPointX;
var elementPointY;
function echoAlert(eInfo,element) {
	returnElementObj=element;
	// FIX TO CLICK ELEMENT OBJECT
	elementPointX=CalculateLeftOffset(returnElementObj);
	elementPointY=CalculateTopOffset(returnElementObj);
	//
	echoAlertHidden();
	diagnoseNavigation.style.visibility="visible"
	diagnoseNavigation.style.top = elementPointY+"px";
	diagnoseNavigation.style.left = elementPointX+"px";
	echoAlertShow();
}

function echoAlertShow(){
	diagnoseNavigation.style.top = elementPointY+"px";
	diagnoseNavigation.style.left = elementPointX+"px";
	diagnoseNavigation.style.top=(document.body.clientWidth /2)-(260);
	diagnoseNavigation.style.left=(document.body.clientHeight /2)-(60);
	diagnoseNavigation.style.width = 320+"px";
	diagnoseNavigation.style.height = 120+"px";
}

function echoAlertHidden(){
	diagnoseNavigation=document.getElementById("extNavigation");
	diagnoseNavigation.style.visibility="hidden"
	diagnoseNavigation.style.width = 10+"px";
	diagnoseNavigation.style.height = 10+"px";
}

function confirmDeleteCommand(ItemNAMEs) {
	return(confirm('\n確認指令 !\n請確定進行資料刪除工作 ?\t\t\n'));
}

function confirmSaveCommand(ItemNAMEs) {
	return(confirm('\n確認指令 !\n請確定進行資料更新工作 ?\t\t\n'));
}

function get_support(strName,strdoname) {
	top.location.href='mailto:' + strName + '@' + strdoname
}

function addWebTofavority(favName,favUrl) {
	var myWebName;
	var myAddress;
	myWebName = favName;
	myAddress = favUrl;

	if (navigator.appName!="Netscape"){
	window.external.AddFavorite(myAddress, myWebName);
	}else{
	window.location = myAddress;
	}
}

function GotoUrl(linkObjValue) {
	top.location.href = linkObjValue;
}

function jumpTo(s) {
	if (s.selectedIndex != 0) top.location.href = s.options[s.selectedIndex].value;return 1;
}

function changeExchangeObjColor(theMmID,theMmColor) {
	document.getElementById(theMmID).style.backgroundColor=theMmColor;
}

