// JavaScript Document
var my_alert_timeout;
var winwidth=0;
var winheight=0;
var button_timeout_remain;
var my_alert_button_timeout;
winwidth=getWindowWidth();
winheight=getWindowHeight();

var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE);

var tempX=0;
var tempY=0;
var top=0;
var visiblelayer=0;
method='';

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

function getMouseXY(e) {
    top = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
   if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + top - 15

  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY - 10;

  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return true;
}

function getWindowHeight() {
var windowHeight=0;
if (typeof(window.innerHeight)=='number') {
windowHeight=window.innerHeight;
}
else {
if (document.documentElement&&
document.documentElement.clientHeight) {
windowHeight=
document.documentElement.clientHeight;
}
else {
if (document.body&&document.body.clientHeight) {
windowHeight=document.body.clientHeight;
}
}
}
return windowHeight;
}

function getWindowWidth() {
var windowWidth=0;
if (typeof(window.innerWidth)=='number') {
windowWidth=window.innerWidth;
}
else {
if (document.documentElement&&
document.documentElement.clientWidth) {
windowWidth=
document.documentElement.clientWidth;
}
else {
if (document.body&&document.body.clientWidth) {
windowWidth=document.body.clientWidth;
}
}
}
return windowWidth;
}

function my_alert(alert_text, button_text, my_width, my_height, textcolor, bgcolor, my_opacity, js_after, timeout){
	clearTimeout(my_alert_timeout);
	clearTimeout(my_alert_button_timeout);
	button_timeout_remain=0;
	if (document.getElementById){
		if (!textcolor) textcolor="#FFFFFF";
		if (!bgcolor) bgcolor="#014576";
		if (!button_text) button_text="OK";
		if (!my_opacity) my_opacity=100;
		if (!js_after) js_after='';
		if (!timeout) timeout=30;
		if (!my_width) my_width=280;
		if (!my_height) my_height=210;
		
		var alert_box=document.getElementById('__my_alert_box_');
		var alert_box_cont=document.getElementById('__my_alert_box_container_');
		if (alert_text!=''){
		 alert_text=alert_text.replace('\n','<br />');
		 alert_box_cont.style.width=winwidth-30;
		 alert_box_cont.style.height=my_height+'px';
		 alert_box_cont.style.top=((tempY-my_height/2>0) ? tempY-my_height/2 : 0)+'px';
		 alert_box_cont.style.left='0px';
		 alert_box.style.left=((tempX-my_width/2>0) ? tempX-my_width/2 : 0)+'px';//(winwidth-width)/2;
		 alert_box.style.top='0px'; //(winheight-height)/2;
		 alert_box.style.width=my_width+'px';
		 alert_box.style.height=my_height+'px';
		 alert_box.style.backgroundColor=bgcolor;
		 alert_box.style.color=textcolor;
		 alert_box.style.padding='5px';
		 alert_box.style.border='2px solid #FFBB00';
		 alert_box_cont.style.opacity=my_opacity/100;
		 alert_box_cont.style.MozOpacity=my_opacity/100;
		 alert_box_cont.style.filter='alpha(opacity='+my_opacity+')';
		 
		 alert_box_text=document.getElementById('__my_alert_text_');
		 alert_box_text.style.color=textcolor;
		 alert_box_text.innerHTML=alert_text;

		 alert_box_button=document.getElementById('__my_alert_button_');
		 alert_box_button.innerHTML='<input id="_my_alert_button_" type="button" onclick="my_alert_close(); '+js_after+'" value="'+button_text+' ('+timeout+')">';
		 _my_alert_button_=document.getElementById('_my_alert_button_');
		 _my_alert_button_.style.color=textcolor;
		 button_timeout_remain=timeout;
		 print_button_value(button_text);
		 my_alert_timeout=setTimeout('\''+js_after+'\'',timeout*1000);
		}
	}else{
		alert('alert_text');
		eval(js_after);
	}
}

function my_alert_close(){
	clearTimeout(my_alert_timeout);
	clearTimeout(my_alert_button_timeout);
	button_timeout_remain=0;

		var alert_box=document.getElementById('__my_alert_box_');
		var alert_box_cont=document.getElementById('__my_alert_box_container_');
		 alert_box_cont.style.width=0;
		 alert_box_cont.style.height=0;
		 alert_box_text.innerHTML='';
		 alert_box_button.innerHTML='';
		 alert_box.style.left=0;
		 alert_box.style.top=0;
		 alert_box.style.width=0;
		 alert_box.style.height=0;
		 alert_box.style.padding='0px';
		 alert_box.style.border='none';
}

function my_alert_init(){
	document.write('<div id="__my_alert_box_container_" style="position:absolute; text-align:center; vertical-align:middle; top:0px; left:0px; width:0px; height:0px;"><div id="__my_alert_box_" style="position:absolute; text-align:center; vertical-align:middle; top:0px; left:0px; width:0px; height:0px;"><table width="100%" height="100%" border="0"><tr><td style="text-align:center;" id="__my_alert_text_"></td></tr><tr><td style="height:20px; text-align:center;" id="__my_alert_button_"></td></tr></table></div></div>')
}

var _my_alert_button_;

function print_button_value(button_text){
	if (button_timeout_remain==0) my_alert_close();
	_my_alert_button_.value=button_text+' ('+button_timeout_remain+')';
	button_timeout_remain=button_timeout_remain-1;
	my_alert_button_timeout=setTimeout('print_button_value(\''+button_text+'\');',1000);
}
