// JavaScript Document


//Specify display mode. 3 possible values are:

//1) "always"- This makes the fade-in box load each time the page is displayed

//2) "oncepersession"- This uses cookies to display the fade-in box only once per browser session

//3) integer (ie: 5)- Finally, you can specify an integer to display the box randomly via a frequency of 1/integer...
// For example, 2 would display the box about (1/2) 50% of the time the page loads.
var displaymode="always"
var enablefade="yes" // ใส่ "yes" ถ้าต้องการให้มีการ Fade และใส่ "no" ถ้าไม่ต้องการให้มี
var autohidebox=["yes", 20] // ตั้งค่าว่าต้องการให้หน้าต่างหายไปเองอัตโนมัติไหม [ใส่ yes หรือ no กรณีใส่ yes ตั้งเวลาเป็นวินาทีด้วย
var showonscroll="yes" // ต้องการให้เลื่อนตาม Scrollbar ไหม ใส่ yes กับ no ลงไป
var IEfadelength=2 // จำนวนวินาที ที่ใช้ในการ Fade สำหรับ BROWSER ของ IE
var Mozfadedegree=0.05 //fade in degree for NS6+ (number between 0 and 1. Recommended max: 0.2)
////////No need to edit beyond here///////////
if (parseInt(displaymode)!=NaN)
var random_num=Math.floor(Math.random()*displaymode)
function displayfadeinbox(){
var ie=document.all && !window.opera
var dom=document.getElementById
iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
objref=(dom)? document.getElementById("fadeinbox") : document.all.fadeinbox
var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
var docwidth=(ie)? iebody.clientWidth : window.innerWidth
docheight=(ie)? iebody.clientHeight: window.innerHeight
var objwidth=objref.offsetWidth
objheight=objref.offsetHeight
objref.style.left=docwidth/2-objwidth/2+"px"
objref.style.top=scroll_top+docheight/2-objheight/2+"px"
if (showonscroll=="yes")
showonscrollvar=setInterval("staticfadebox()", 50)
if (enablefade=="yes" && objref.filters){
objref.filters[0].duration=IEfadelength
objref.filters[0].Apply()
objref.filters[0].Play()
}

objref.style.visibility="visible"

if (objref.style.MozOpacity){

if (enablefade=="yes")

mozfadevar=setInterval("mozfadefx()", 90)

else{

objref.style.MozOpacity=1

controlledhidebox()

}

}

else

controlledhidebox()

}

function mozfadefx(){

if (parseFloat(objref.style.MozOpacity)<1)

objref.style.MozOpacity=parseFloat(objref.style.MozOpacity)+Mozfadedegree

else{

clearInterval(mozfadevar)

controlledhidebox()

}

}

function staticfadebox(){

var ie=document.all && !window.opera

var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset

objref.style.top=scroll_top+docheight/2-objheight/2+"px"

}

function hidefadebox(){
objref.style.visibility="hidden"
		if (typeof showonscrollvar!="undefined")
clearInterval(showonscrollvar)

}

function controlledhidebox(){

if (autohidebox[0]=="yes"){

var delayvar=(enablefade=="yes" && objref.filters)? (autohidebox[1]+objref.filters[0].duration)*1000 : autohidebox[1]*1000

setTimeout("hidefadebox()", delayvar)

}

}

function initfunction(){

setTimeout("displayfadeinbox()", 100)

}



function get_cookie(Name) {

var search = Name + "="

var returnvalue = ""

if (document.cookie.length > 0) {

offset = document.cookie.indexOf(search)

if (offset != -1) {

offset += search.length

end = document.cookie.indexOf(";", offset)

if (end == -1)

end = document.cookie.length;

returnvalue=unescape(document.cookie.substring(offset, end))

}

}

return returnvalue;

}

if (displaymode=="oncepersession" && get_cookie("fadedin")=="" || displaymode=="always" || parseInt(displaymode)!=NaN && random_num==0){

if (window.addEventListener)

window.addEventListener("load", initfunction, false)

else if (window.attachEvent)

window.attachEvent("onload", initfunction)

else if (document.getElementById)

window.onload=initfunction

document.cookie="fadedin=yes"

}


<!--                *****************-->

var W3C=(document.getElementById)? true: false;
var IE5=(W3C && document.all)? true : false;
var NS6=(W3C && (navigator.appName=="Netscape"))? true: false;
currIDb=null; xoff=0; yoff=0;
currRS=null; rsxoff=0; rsyoff=0;
oldac=null; newac=null; zdx=1; mx=0; my=0;

var idlist=new Array();
idlist.btns=new Array();
idlist.btns[0]=new Image(); idlist.btns[0].src="winmin.gif";
idlist.btns[1]=new Image(); idlist.btns[1].src="winmax.gif";
idlist.btns[2]=new Image(); idlist.btns[2].src="winclose.gif";
idlist.btns[3]=new Image(); idlist.btns[3].src="winresize.gif";

function hidebox(id){
if(W3C){
document.getElementById(id+'_b').style.display='none';
document.getElementById(id+'_s').style.display='none';
}}

function showbox(id){
if(W3C){
var bx=document.getElementById(id+'_b').style;
var sh=document.getElementById(id+'_s').style;
bx.display='block';
sh.display='block';
sh.zIndex=++zdx;
bx.zIndex=++zdx;
}}

function minimize(){
if(W3C){
this.IDS[0].style.height=(IE5)? '28px':'24px';
this.IDS[3].style.height='28px';
this.IDS[2].style.display='none';
this.IDS[4].style.display='none';
setTimeout('NS6bugfix()',100);
}}

function restore(){
if(W3C){
var h=this.IDS[10];
this.IDS[0].style.height=h+'px'; //box
this.IDS[3].style.height=(IE5)? h+'px':h+5+'px'; //shd
this.IDS[2].style.display='block';
this.IDS[4].style.display='block'; 
setTimeout('NS6bugfix()',100);
}}

function NS6bugfix(){
self.resizeBy(0,1);
self.resizeBy(0,-1);
}

function trackmouse(evt){
mx=(IE5)?event.clientX+document.body.scrollLeft:evt.pageX;
my=(IE5)?event.clientY+document.body.scrollTop:evt.pageY;
if(!NS6)movepopup();
if((currIDb!=null)||(currRS!=null))return false;
}

function movepopup(){
if((currIDb!=null)&&W3C){
var x=mx+xoff;
var y=my+yoff;
currIDb.style.left=x+'px';
currIDs.style.left=x+8+'px';
currIDb.style.top=y+'px';
currIDs.style.top=y+8+'px';
}
if((currRS!=null)&&W3C){
var rx=mx+rsxoff;
var ry=my+rsyoff;
var c=currRS;
c.style.left=Math.max(rx,((NS6)?92:88))+'px';
c.style.top=Math.max(ry,((NS6)?72:68))+'px';
c.IDS[0].style.width=Math.max(rx+((NS6)?8:12),100)+'px';
c.IDS[0].style.height=Math.max(ry+((NS6)?8:12),80)+'px';
c.IDS[1].style.width=Math.max(rx+((NS6)?3:4),((NS6)?95:92))+'px';
c.IDS[5].style.left=parseInt(c.IDS[1].style.width)-48+'px';
c.IDS[3].style.width=Math.max(rx+12,((NS6)?104:100))+'px';
c.IDS[3].style.height=Math.max(ry+((NS6)?13:12),((NS6)?86:80))+'px';
c.IDS[2].style.width=Math.max(rx-((NS6)?5:-5),((NS6)?87:92))+'px';
c.IDS[2].style.height=Math.max(ry-((NS6)?28:24),44)+'px';
c.IDS[10]=parseInt(c.IDS[0].style.height);
}}

function startRS(evt){
var ex=(IE5)?event.clientX+document.body.scrollLeft:evt.pageX;
var ey=(IE5)?event.clientY+document.body.scrollTop:evt.pageY;
rsxoff=parseInt(this.style.left)-ex;
rsyoff=parseInt(this.style.top)-ey;
currRS=this;
if(NS6)this.IDS[2].style.overflow='hidden';
return false;
}

function stopdrag(){
currIDb=null;
NS6bugfix();
}

function grab_id(evt){
var ex=(IE5)?event.clientX+document.body.scrollLeft:evt.pageX;
var ey=(IE5)?event.clientY+document.body.scrollTop:evt.pageY;
xoff=parseInt(this.IDS[0].style.left)-ex;
yoff=parseInt(this.IDS[0].style.top)-ey;
currIDb=this.IDS[0];
currIDs=this.IDS[3];
return false;
}

function subBox(x,y,w,h,bgc,id){
var v=document.createElement('div');
v.setAttribute('id',id); 
v.style.position='absolute';
v.style.left=x+'px';
v.style.top=y+'px';
v.style.width=w+'px';
v.style.height=h+'px';
v.style.backgroundColor=bgc;
v.style.visibility='visible';
v.style.padding='0px 0px 0px 0px';
return v;
}

function popUp(x,y,w,h,cid,text,bgcolor,textcolor,fontstyleset,title,titlecolor,titletextcolor,bordercolor,scrollcolor,shadowcolor,showonstart,isdrag,isresize,doold){
if(W3C){
var tw, th;
w=Math.max(w,100);
h=Math.max(h,80);
var rdiv=new subBox(w-((IE5)?12:8),h-((IE5)?12:8),7,7,'',cid+'_rs');
if(isresize){
rdiv.innerHTML='<img src="winresize.gif" width="7" height="7">';
rdiv.style.cursor='move';
}
tw=(IE5)?w:w+4;
th=(IE5)?h:h+6;
var shadow=new subBox(x+8,y+8,tw,th,shadowcolor,cid+'_s');
if(IE5)shadow.style.filter="alpha(opacity=50)";
if(NS6)shadow.style.MozOpacity=.5;
shadow.style.zIndex=++zdx;
var tw,th;
var outerdiv=new subBox(x,y,w,h,bordercolor,cid+'_b');
outerdiv.style.borderStyle="outset";
outerdiv.style.borderWidth="1px";
outerdiv.style.borderColor=bordercolor;
outerdiv.style.zIndex=++zdx;
tw=(IE5)?w-8:w-5;
th=(IE5)?h+4:h-4;
var titlebar=new subBox(2,2,tw,20,titlecolor,cid+'_t');
titlebar.style.overflow="hidden";
titlebar.style.cursor="default";
titlebar.innerHTML='<span style="position:absolute; left:3px; top:1px; font:bold 10pt sans-serif; color:'+titletextcolor+'; height:18px; overflow:hidden; clip-height:16px;">'+title+'</span><span id="'+cid+'_btt" style="position:absolute; width:48px; height:16px; left:'+(tw-48)+'px; top:2px;"><img src="winmin.gif" width="16" height="16" id="'+cid+'_min"><img src="winmax.gif" width="16" height="16"  id="'+cid+'_max"><img src="winclose.gif" width="16" height="16" id="'+cid+'_cls"></span>';
tw=(IE5)?w-7:w-13;
th=(IE5)?h-36:h-36;
var content=new subBox(2,24,tw,th,bgcolor,cid+'_c');
content.style.borderColor=bordercolor;
content.style.borderStyle="inset";
content.style.borderWidth="1px";
content.style.overflow="auto";
content.style.padding="0px 2px 0px 4px";
content.style.font=fontstyleset;
content.style.color=textcolor;
if(IE5)content.style.scrollbarBaseColor=scrollcolor;
content.innerHTML=text;
outerdiv.appendChild(titlebar);
outerdiv.appendChild(content);
outerdiv.appendChild(rdiv);
document.body.appendChild(shadow);
document.body.appendChild(outerdiv);
if(!showonstart)hidebox(cid);
var IDS=new Array();
IDS[0]=document.getElementById(cid+'_b');
IDS[1]=document.getElementById(cid+'_t');
IDS[2]=document.getElementById(cid+'_c');
IDS[3]=document.getElementById(cid+'_s');
IDS[4]=document.getElementById(cid+'_rs');
IDS[5]=document.getElementById(cid+'_btt');
IDS[6]=document.getElementById(cid+'_min');
IDS[7]=document.getElementById(cid+'_max');
IDS[8]=document.getElementById(cid+'_cls');
IDS[9]=cid;
IDS[10]=h;
this.IDb=IDS[0]; this.IDb.IDS=IDS;
this.IDt=IDS[1]; this.IDt.IDS=IDS;
this.IDc=IDS[2]; this.IDc.IDS=IDS;
this.IDs=IDS[3]; this.IDs.IDS=IDS;
this.IDrs=IDS[4]; this.IDrs.IDS=IDS;
this.IDbtt=IDS[5]; this.IDbtt.IDS=IDS;
this.IDmin=IDS[6]; this.IDmin.IDS=IDS;
this.IDmax=IDS[7]; this.IDmax.IDS=IDS;
this.IDcls=IDS[8]; this.IDcls.IDS=IDS;
this.IDb.activecolor=titlecolor;
this.IDb.inactivecolor=scrollcolor;
if(oldac!=null)oldac.IDS[1].style.backgroundColor=oldac.inactivecolor;
oldac=this.IDb;
this.IDcls.onclick=new Function("hidebox('"+cid+"');");
if(isresize){
this.IDmin.onclick=minimize;
this.IDmax.onclick=restore;
this.IDrs.onmousedown=startRS;
this.IDrs.onmouseup=new Function("currRS=null");
}
this.IDb.onmousedown=function(){
   if(oldac!=null){
   //if(NS6)oldac.IDS[2].style.overflow='hidden';
   oldac.IDS[1].style.backgroundColor=oldac.inactivecolor;
   }
   if(NS6)this.IDS[2].style.overflow='auto';
   oldac=this;
   this.IDS[1].style.backgroundColor=this.activecolor;
   this.IDS[3].style.zIndex=++zdx;
   this.style.zIndex=++zdx;
   }
if(isdrag){
this.IDt.onmousedown=grab_id;
this.IDt.onmouseup=stopdrag;
}
}else{
if(doold){
var ctr=new Date();
ctr=ctr.getTime();
var win=window.open("" , "abc"+ctr , "status=no,menubar=no,width="+w+",height="+h+",resizable=yes,scrollbars=yes");
var t='<html><head><title>'+title+'</title></head><body bgcolor="'+bgcolor+'"><font style="font:'+fontstyleset+'; color:'+textcolor+'">'+text+'</font></body></html>';
win.document.write(t);
win.document.close();
}}}

if(NS6)setInterval('movepopup()',40);

if(W3C){
document.onmousemove=trackmouse;
document.onmouseup=new Function("currRS=null");
}


