﻿var isIE;

if(document.all)
    isIE = true;
else
    isIE = false;

var docBody = document.documentElement;

function imgposit(x,y,e){ 
    // 事件處理
    //alert(e);
    e = e || window.event
    var obj = document.getElementById("Imgbox");
    
    //if (isIE){
    //    obj.style.posLeft = (e.clientX + x + docBody.scrollLeft);
    //    obj.style.posTop = (e.clientY + y + docBody.scrollTop);
    //}
    //else{
        obj.style.left = (e.clientX + x + docBody.scrollLeft) + 'px';
        obj.style.top = (e.clientY + y + docBody.scrollTop) + 'px';
    //}
    //alert(obj.style.Left + ':' + obj.style.Top);
} 
       
function imgset(str){ 
  var obj = document.getElementById("Imgbox") ;
  var text;
  text = '<div style="background-color:#dddddd;padding: 2px; border: 1px solid #999999;line-height: 16px;text-align:left;">' + str + '</div>';
  obj.innerHTML=text;
} 

function imghide(){ 
  var obj = document.getElementById("Imgbox") ;
  obj.innerHTML='';
} 

var KeywordInterval;
function HideKeywordDiv(){
	var oDiv = document.getElementById('divKeyword');
	
	oDiv.style.display = 'none';
	
	CancelHideKeywordDivInterval();
}

function CancelHideKeywordDivInterval(){
	if(KeywordInterval != null){
		clearInterval(KeywordInterval);
		KeywordInterval = null;
	}
}

function StartHideKeywordDivInterval(DisplayTime){
	if(KeywordInterval != null){
		clearInterval(KeywordInterval);
		KeywordInterval = null;
	}
	
	KeywordInterval = window.setInterval("HideKeywordDiv();", DisplayTime);
}

//關鍵字詳細內容

var alb_CO = null;
function show_KeyWord( str, obj, enabled) {
	if (enabled == false) {
		return;
	}
	  
	if (alb_CO != null) {
		hide_KeyWord(alb_CO);
	}

	var obj2 = document.getElementById('divKeyword');

	if (obj2 != null) {
		try {
		
    		var rect = obj.getBoundingClientRect();
	    	var left = rect.left;
		    var top = rect.top;
		    var right = rect.right ;
		    var bottom = rect.bottom;

            if (isIE) {
	            obj2.style.top = bottom + docBody.scrollTop + 3;
	            obj2.style.left = (left - 3) + docBody.scrollLeft;
            }
            else{
 
	            obj2.style.top = bottom + document.body.scrollTop + 3 + 'px';
	            obj2.style.left = (left - 3) + document.body.scrollLeft + 'px';
            }
			
		} catch(e) {
		
//			var left = realPosX(obj);
//			var top = realPosY(obj) + 20;
//			
//			obj2.style.left = left + 'px';
//			obj2.style.top = top + 'px';

            alert("無法設定新視窗位置 !!");
		}
		
        var text = '<div style="background-color:#FFFFFF;border: 1px solid #999999;Overflow:none;">' + str + '</div>';

        obj2.innerHTML = text;
		obj2.style.display = '';
		alb_CO = obj2;
		
	} else {
		alert(obj.id);
	}
	
	StartHideKeywordDivInterval(3000);
}

function hide_KeyWord(obj, enabled) {
	if (enabled == false) {
		return;
	}
	obj.style.display = 'none';
	alb_CO = null;
}

function realPosX (oTarget) {
	try {
		var realX = oTarget.offsetLeft
		if (oTarget.offsetParent.tagName.toUpperCase() != "BODY") {
			realX += realPosX(oTarget.offsetParent); 
		}
		return realX;
	} catch (e) {
		alert("realPosX: "+e);
	} 
}
function realPosY (oTarget) {
	try {
		var realY = oTarget.offsetTop;
		if (oTarget.offsetParent.tagName.toUpperCase() != "BODY") {
			realY += realPosY(oTarget.offsetParent);
		}
		return realY;
	} catch (e) { 
		alert("realPosY: "+e);
	}
}




function reSize(oW){
//        alert("resize");
//        alert("window.frames: " + window.frames);
//        alert("document.all: " + document.all);        
		try{
		    
			var oFrame;
			//oFrame = window.document.all("ifmKeyword");
			
			if (isIE)
			    oFrame = document.all("ifmKeyword");
            else
			    oFrame = window.frames["ifmKeyword"];
			
			alert("oFrame: " + oFrame);
			
			//var oBody	=	oFrame.document.body;
			
			//window.status = oW.document.height + ", " + oW.document.documentElement.scrollHeight + ", " + oW.document.body.scrollHeight + ", " + oW.document.body.offsetWidth + ", " + oW.document.body.scrollWidth
			//oFrame.style.height = oW.document.body.scrollHeight//oBody.scrollHeight + (oBody.offsetHeight - oBody.clientHeight);

            alert("oFrame.Document: " + oW.Document);
            
            alert("documentElement: " + oW.Document.documentElement);
            
            alert("body: " + oW.Document.body);
            
            alert(oFrame.Document.body);
            
            alert(oFrame.contentDocument);

			oFrame.Document ? oFrame.height = oFrame.Document.body.scrollHeight : oFrame.height = oFrame.contentDocument.body.offsetHeight + 25;

			oFrame.width = oW.document.body.scrollWidth;//oBody.scrollWidth + (oBody.offsetWidth - oBody.clientWidth);
		}
		//An error is raised if the IFrame domain != its container's domain
		catch(e) {
		    alert("Error !!");
		    //alert('Error: ' + e.number + '; ' + e.description;);
			//window.status =	'Error: ' + e.number + '; ' + e.description;
		}
		
		
	}
