//* popup message window display lib */
//* created by okazaki@bamboo-waves.com */
//* this product use YAHOO UI */
//* IF : fncPopupStart() */
//*      fncPopClose()   */
//*      fncDelCookie()   */

//global parameters //
var winw; //msgbox width
var winh; //msgbox height
var clw; //client width
var clh; //client height
var offsw; //offset x
var offsh; //offset y
var br; //browser :ns/ie/op

br=brchk();
fncPopupinit();

if (conloadstart=="on"){
	if (getcookie("popup")=="1"){
		//nop
	}
	else{
		setcookie("popup","1");
		YAHOO.util.Event.addListener(window, "load", fncPopupStart);
	}
}
function fncPopupinit(){
	document.write('<div id="popupwall" style="z-index:10;position:absolute;overflow:hidden;font-size:10px;text-align:right;"></div>');
	document.write('<div id="popupmsg" style="z-index:11;position:absolute;overflow:scroll;"></div>');
}

function fncDelCookie(){
	setcookie("popup","0");
}

function fncPopupStart(){

	clw = getWidth();
	clh = getHeight();
	offsw = getOffsetX();//document.documentElement.scrollLeft;
	offsh = getOffsetY();//document.documentElement.scrollTop;

	YAHOO.util.Dom.setStyle('popupmsg' , 'top' , 0);
	YAHOO.util.Dom.setStyle('popupmsg' , 'left' , 0);

	if (cmsg_width=="full"){
		winw=clw*0.8;
	}
	else{
		winw=cmsg_width;
		if(winw>clw){
			winw=clw;
		}
	}
	if (cmsg_height=="full"){
		winh=clh*0.8;
	}
	else{
		winh=cmsg_height;
		if(winh>clh){
			winh=clh;
		}
	}

	//init
	YAHOO.util.Dom.setStyle('popupwall' , 'left' , offsw);
	YAHOO.util.Dom.setStyle('popupwall' , 'top' , offsh);

	if (br=="ns"){
		YAHOO.util.Dom.setStyle('popupwall' , 'width' , '100%');
		YAHOO.util.Dom.setStyle('popupwall' , 'height' , '100%');
		clw = getWidth();
		clh = getHeight();
	}
	else{
		YAHOO.util.Dom.setStyle('popupwall' , 'width' , clw);
		YAHOO.util.Dom.setStyle('popupwall' , 'height' , clh);
	}


	YAHOO.util.Dom.setStyle('popupwall' , 'background-color' , cwall_bgcolor);
	YAHOO.util.Dom.setStyle('popupwall' , 'color' , cwall_color);
	YAHOO.util.Dom.setStyle('popupwall' , 'opacity' , cwall_opacity);

	tox=(clw - winw)/2 +offsw;
	toy=(clh - winh)/2 +offsh;
	var myAnim = new YAHOO.util.Motion('popupmsg', {points: { to:[tox, toy] } }, 1, YAHOO.util.Easing.easeOut);
	myAnim.animate();

	var attributes = {
	                   width: { to: winw },
	                   height: { to: winh }
	                  };
	var myAnim = new YAHOO.util.Anim('popupmsg', attributes, 1, YAHOO.util.Easing.easeOut);
	myAnim.animate();


	YAHOO.util.Dom.setStyle('popupmsg' , 'background-color' , cmsg_bgcolor);
	YAHOO.util.Dom.setStyle('popupmsg' , 'color' , cmsg_color);
	YAHOO.util.Dom.setStyle('popupmsg' , 'opacity' , 0.2);
	document.getElementById('popupmsg').innerHTML="";

	YAHOO.util.Dom.setStyle('popupmsg' , 'border' , '1px solid black');
	document.getElementById('popupmsg').innerHTML="<b>Loading...</b><br>";

	setTimeout('subfncPopup1("popupmsg")',1000);
}

function subfncPopup1(id){
	var myAnim = new YAHOO.util.ColorAnim(id, { opacity: { from: 0.2, to: cmsg_opacity } }, 1, YAHOO.util.Easing.easeOut);
	myAnim.animate();

	setTimeout('subfncPopup2("'+ id +'")',1);
}

function subfncPopup2(id){
	document.getElementById(id).innerHTML=cmsgstr;
	YAHOO.util.Dom.setStyle('popupmsg' , 'opacity' , 1);

	YAHOO.util.Event.addListener('popupwall', ccloseact, fncPopClose);
	document.getElementById('popupwall').innerHTML="<div style='' id='wallhead'>Please "+ccloseact+" to popup close...</div><div id='wallfoot'>produced by <a href='http://www.bamboo-waves.com' target='_blank'>bamboo-waves</a></div>";

	if (cautohidden=="on"){
		setTimeout('fncPopClose()',cautohiddentime);
	}
}


function fncPopClose(){

	var myAnim = new YAHOO.util.ColorAnim('popupmsg', { opacity: { from: cmsg_opacity, to: 0 } }, 1, YAHOO.util.Easing.easeOut);
	myAnim.animate();

	var myAnim = new YAHOO.util.ColorAnim('popupwall', { opacity: { from: cwall_opacity, to: 0 } }, 1, YAHOO.util.Easing.easeOut);
	myAnim.animate();

	setTimeout('subfncPopClose1()',2000);

}

function subfncPopClose1(){

	YAHOO.util.Dom.setStyle('popupwall' , 'width' , 0);
	YAHOO.util.Dom.setStyle('popupwall' , 'height' , 0);
	YAHOO.util.Dom.setStyle('popupwall' , 'top' , 0);
	YAHOO.util.Dom.setStyle('popupwall' , 'left' , 0);
	YAHOO.util.Dom.setStyle('popupwall' , 'opacity' , 0);
	YAHOO.util.Dom.setStyle('popupwall' , 'background-color' , 'white');
	YAHOO.util.Dom.setStyle('popupmsg' , 'border' , '0');
	YAHOO.util.Dom.setStyle('popupmsg' , 'top' , 0);
	YAHOO.util.Dom.setStyle('popupmsg' , 'left' , 0);
	YAHOO.util.Dom.setStyle('popupmsg' , 'width' , 0);
	YAHOO.util.Dom.setStyle('popupmsg' , 'height' , 0);

}

function brchk(){
	if(window.opera){
		return "op";
	}
	  else if(document.all){
		return "ie";
	}
	  else if(document.layers||document.getElementById){
		return "ns";
	}
}

function getWidth(){
	  if(window.opera){
	          return window.innerWidth;
	}
	  else if(document.all){
		return (document.documentElement.clientWidth);
	}
	  else if(document.layers||document.getElementById){
	          return window.innerWidth;
	}
}

function getHeight(){
	  if(window.opera){
	          return  window.innerHeight;
	}
	  else if(document.all){
		return (document.documentElement.clientHeight);
	}
	  else if(document.layers||document.getElementById){
	          return window.innerHeight;
	}
}

function getOffsetX(){
	if(window.opera){
	          return 0;
	}
	  else if(document.all){
		if (document.body.scrollLeft == 0){
			return document.documentElement.scrollLeft;
		}
		else{
			return document.body.scrollLeft;
		}
	}
	  else if(document.layers||document.getElementById){
	          return pageXOffset;
	}
}

function getOffsetY(){

	if(window.opera){
	          return 0;
	}
	  else if(document.all){
		if (document.body.scrollTop == 0){
			return document.documentElement.scrollTop;
		}
		else{
			//alert(document.body.scrollTop);
			return document.body.scrollTop;
		}
	}
	  else if(document.layers||document.getElementById){
	          return pageYOffset;
	}
}

function getMouseX(e){
	  if(window.opera){
	          return e.clientX;
	}
	  else if(document.all){
		if (document.body.scrollLeft == 0){
			return document.documentElement.scrollLeft+event.clientX;
		}
		else{
			return document.body.scrollLeft+event.clientX;
		}
	}
	  else if(document.layers||document.getElementById){
	          return e.pageX;
	}
}

function getMouseY(e){
	  if(window.opera){
	          return e.clientY;
	}
	  else if(document.all){
		if (document.body.scrollTop == 0){
			return event.clientY+document.documentElement.scrollTop;
		}
		else{
			return document.body.scrollTop+event.clientY;
		}

	}
	  else if(document.layers||document.getElementById){
	          return e.pageY;
	}
}

document.onmousemove = xyget
function xyget(e){
	mx=getMouseX(e);
	my=getMouseY(e);
}

window.onresize = winresize;
function winresize(){

	var wkclw = getWidth();
	var wkclh = getHeight();
	if(clw < wkclw){
		clw = wkclw;
	}
	if(clh < wkclw){
		clh = wkclw;
	}
	offsw = getOffsetX();//document.documentElement.scrollLeft;
	offsh = getOffsetY();//document.documentElement.scrollTop;

	if (cmsg_width=="full"){
		winw=clw*0.8;
	}
	else{
		winw=cmsg_width;
		if(winw>clw){
			winw=clw;
		}
	}
	if (cmsg_height=="full"){
		winh=clh*0.8;
	}
	else{
		winh=cmsg_height;
		if(winh>clh){
			winh=clh;
		}
	}
	YAHOO.util.Dom.setStyle('popupwall' , 'width' , clw);
	YAHOO.util.Dom.setStyle('popupwall' , 'height' , clh);
	YAHOO.util.Dom.setStyle('popupwall' , 'z-index' , 100);

	var wkclw = getWidth();
	var wkclh = getHeight();
	YAHOO.util.Dom.setStyle('popupmsg' , 'left' , (wkclw - winw)/2 +offsw);
	YAHOO.util.Dom.setStyle('popupmsg' , 'top' , (wkclh - winh)/2 +offsh);
	YAHOO.util.Dom.setStyle('popupmsg' , 'width' , winw);
	YAHOO.util.Dom.setStyle('popupmsg' , 'height' , winh);
}

function getcookie(id) {
	var buf=(document.cookie+";").match(id+"=([^;]*);");
	if(buf!=null){
		return unescape(buf[1]);
	}else{
		return null;
	}
}

function setcookie(id,value) {
	var limitdays = 1;
	var expires  = new Date();
	expires.setTime(expires.getTime() + (limitdays * 1000 * 60 * 60 * 24));
	document.cookie = id + "=" + value +"; expires="+expires.toGMTString();
}
