﻿// JavaScript Document
function changeCss(id,property,value){
  document.getElementById(id).style[property] =value
}
function changeParentCss(id,property,value){
  parent.document.getElementById(id).style[property] =value
}

//popWindow javaScript
function MakePopBg(divName){
    var bgHeight=document.documentElement.scrollHeight

	if(screen.availHeight>bgHeight)bgHeight=document.documentElement.offsetHeight

	HTML = "<div id="+divName+"></div>";
	
	popBg = document.createElement("div");
	popBg.style.backgroundColor="black";
	popBg.style.position="absolute";
	popBg.style.top="0px";
	popBg.style.right="0px";
	popBg.style.bottom="0px";
	popBg.style.left="0px";
	popBg.style.height=bgHeight+"px";
	popBg.style.width="100%"
	popBg.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=80)";
	popBg.style.backgroundImage="url(image/scriptImage/popBg.gif)";
	popBg.style.opacity="0.7";
	popBg.style.backgroundRepeat="repeat";
	popBg.style.visibility="visible";
	popBg.style.zIndex="1500";
	
	popBg.innerHTML = HTML;
    document.body.appendChild(popBg);
	
}

function openWindow(url,event){

	
	if(screen.width>1024){
	  var WPosition=document.documentElement.scrollTop+document.body.offsetHeight*0.1
	}else{
	  var WPosition=document.documentElement.scrollTop
		}
		

	
	if(!document.getElementById("popWindow")){
	HTML='<div id="popWindow">'
	HTML=HTML+'<div id="topBg"></div><div id="rightBg"></div><div id="botBg"></div><div id="leftBg"></div>'
	HTML=HTML+'<iframe src="load.html" width="100%" height="571px"  frameborder="0" name="popIframe" >'
    HTML=HTML+'<NOFRAMES></NOFRAMES></iframe>'
	HTML=HTML+'<div id="close"><a onClick="closeWindow();">關閉視窗</a></div></div>'
	
	popWindow=document.createElement("div");
	popWindow.style.position="absolute";
	popWindow.style.height="596px";
	popWindow.style.width="500px";
	popWindow.style.left="25%";
	popWindow.style.top=WPosition+"px";
	popWindow.style.zIndex="2000";
	popWindow.style.margin="0px";
	popWindow.style.padding="19px";
	popWindow.style.visibility="visible";
	
	popWindow.innerHTML = HTML;
	document.body.appendChild(popWindow);	
	
	MakePopBg("popBg");
	}else{
	popWindow.style.visibility="visible";
	popWindow.style.top=WPosition+"px";
	popBg.style.visibility="visible";
	}
	window.popIframe.location.href=url;
	addclickHandler();
	
}

function closeWindow(){
    popWindow.style.visibility="hidden";
	popBg.style.visibility="hidden";
	window.popIframe.location.href="load.html"	
}

function closeParentWindow(){
    parent.popWindow.style.visibility="hidden";
	parent.popBg.style.visibility="hidden";
	// parent.document.window.popIframe.location.href="load.html"	
}

function addclickHandler() {
   	var browser= new Object();
    browser.name=window.navigator.appName;
	
	if(browser.name.indexOf("Microsoft")!=-1){
		window.event.cancelBubble=true
		document.attachEvent("onclick", clickHandler); //IE
	}
	if(browser.name.indexOf("Netscape")!=-1)document.addEventListener("click",clickHandler, true); //FireFox
}


function clickHandler(event) {
    closeWindow();
	var browser= new Object();
    browser.name=window.navigator.appName;
	if(browser.name.indexOf("Microsoft")!=-1)document.detachEvent("onclick", clickHandler); //IE
	if(browser.name.indexOf("Netscape")!=-1)document.removeEventListener("click",clickHandler, true); //FireFox
	
}

function MM_openBrWindow(theURL) { //v2.0
  window.open(theURL,"newInfoWindow","resizable=yes,width=429,height=530,scrollbars=yes");
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function tab_switch(layer1, layer2, layer3){
	MM_changeProp(layer1,'','style.display','block','DIV')
    MM_changeProp(layer2,'','style.display','none','DIV')
    MM_changeProp(layer3,'','style.display','none','DIV')
}


function changecss(theClass,element,value) {
	//documentation for this script at http://www.shawnolson.net/a/503/
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 for (var S = 0; S < document.styleSheets.length; S++){
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    document.styleSheets[S][cssRules][R].style[element] = value;
	   }
	  }
	 }	
}
