// JavaScript Document
var ITMessageBox_LIST = new Array();

// Constructor
function ITMessageBox( instanceName, title, imgPath, width, framsworkWidth  ){
	this.name = instanceName;
	this.imgPath = imgPath;
	this.width = width;
	this.title = title;
	this.frameworkWidth = framsworkWidth;
	
	// Register to global message box list.
	ITMessageBox_LIST[ this.name ] = this;
	
	// Assign Function
	this.initial = __ITMessageBox_initial;
	this.resetPos = __ITMessageBox_resetMsgBoxPos;
	this.closeDialog = __ITMessageBox_closeMsgBox;
	this.showMsg = __ITMessageBox_showMsgBox;

	return this;
}

// Class Methods
function __ITMessageBox_initial(){
	if ( document.getElementById( this.name ) ){
		alert( "[Error] The name of Message Box already in used~!!!" );
	}
	
	if ( document.getElementById( this.name + "Shadow" ) == null ){
		var objBg = document.createElement('div');
		objBg.id = this.name + "Shadow";
		objBg.style.position = "absolute";
		objBg.style.display = "none";
		objBg.style.top = '0px';
		objBg.style.left = '0px';
		objBg.style.backgroundColor = '#000000';
		objBg.style.opacity = '0.3';
		objBg.style.filter = 'alpha(opacity=30)';
		objBg.style.cursor = 'pointer';
		//objBg.setAttribute('onclick', 'ITMessageBox_LIST["'+ this.name +'"].closeDialog();');
		objBg.onclick = new Function('ITMessageBox_LIST["'+ this.name +'"].closeDialog();'); 
		objBg.style.zIndex = 999;
		document.body.appendChild(objBg);
	}
	if ( document.getElementById( this.name ) == null ){
		var obj = document.createElement('div');
		obj.id =  this.name;
		obj.style.position = "absolute";
		obj.style.display = "none";
		obj.style.top = '0px';
		obj.style.left = '0px';
		obj.style.width = this.width + 'px';
		obj.style.zIndex = 1000;
		
		obj.innerHTML = '<table width="'+ this.width +'" cellspacing="0" cellpadding="0" border="0"><tr height="23"><td style="background-image:url('+
						this.imgPath + '/dialog_title_l.gif); width:15px;"></td><td style="background-image:url('+ this.imgPath + '/dialog_title_m.gif); width:'+ (this.width - 30) +'px; font-family:Arial; font-size:12px; color:#FFFFFF; font-weight:bold;">' + this.title + '</td><td style="background-image:url('+ this.imgPath + '/dialog_title_r.gif); width:15px;"></td></tr><tr height=200 valign=middle><td bgColor="#FFFFFF" ></td><td bgColor="#FFFFFF" align=center id="' + this.name + 'Message"></td><td bgColor="#FFFFFF" ></td></tr><tr height=60 valign=top><td bgColor="#FFFFFF" ></td><td bgColor="#FFFFFF" align=center><input type="image" id="'+ this.name +'closebt" src="'+ this.imgPath + '/btn_ok.gif" onmouseover="this.src=\''+ this.imgPath + '/btn_ok_o.gif\'" onmouseout="this.src=\''+ this.imgPath + '/btn_ok.gif\'" style="cursor:pointer" onclick="ITMessageBox_LIST[\''+ this.name +'\'].closeDialog();"></td><td bgColor="#FFFFFF" ></td></tr></table>';
//						this.imgPath + '/dialog_title_l.gif); width:15px;"></td><td style="background-image:url('+ this.imgPath + '/dialog_title_m.gif); width:'+ (this.width - 30) +'px; font-family:Arial; font-size:12px; color:#FFFFFF; font-weight:bold;">' + this.title + '</td><td style="background-image:url('+ this.imgPath + '/dialog_title_r.gif); width:15px;"></td></tr><tr height=200 valign=middle><td bgColor="#FFFFFF" ></td><td bgColor="#FFFFFF" align=center id="' + this.name + 'Message"></td><td bgColor="#FFFFFF" ></td></tr><tr height=60 valign=top><td bgColor="#FFFFFF" ></td><td bgColor="#FFFFFF" align=center><img src="'+ this.imgPath + '/btn_ok.gif" onmouseover="this.src=\''+ this.imgPath + '/btn_ok_o.gif\'" onmouseout="this.src=\''+ this.imgPath + '/btn_ok.gif\'" style="cursor:pointer" onclick="ITMessageBox_LIST[\''+ this.name +'\'].closeDialog();"></td><td bgColor="#FFFFFF" ></td></tr></table>';
		
		document.body.appendChild(obj);
	}
}

function __ITMessageBox_resetMsgBoxPos(){
	var selfObj = document.getElementById( this.name );
	
	if ( selfObj ){
		if (selfObj.style.display == 'block'){
			selfObj.style.left = ((document.body.clientWidth - this.width)/2) + 'px';
			selfObj.style.top = (document.body.scrollTop + (document.body.clientHeight - selfObj.offsetHeight)/2) + 'px';
			
			var shadow = document.getElementById(this.name + 'Shadow');
			shadow.style.width = (document.body.clientWidth < this.frameworkWidth) ? this.frameworkWidth : document.body.clientWidth;
			shadow.style.height = document.body.scrollHeight;
		}
	}
}

function __ITMessageBox_closeMsgBox(){
	if (document.getElementById( this.name )){
		document.getElementById( this.name ).style.display='none';
	}else{
		alert(this + ' not found.');
	}
	document.getElementById( this.name + 'Shadow').style.display='none';
}

function __ITMessageBox_showMsgBox( msg ){
	if ( document.getElementById( this.name ) == null ){
		this.initial();
	}
	
	var msgObj = document.getElementById( this.name + 'Message' );
	msgObj.innerHTML = msg;
	
	var obj = document.getElementById( this.name );
	obj.style.display = 'block';
	obj.style.left = ((document.body.clientWidth - this.width)/2) + 'px';
	obj.style.top = (document.body.scrollTop + (document.body.clientHeight - obj.offsetHeight)/2) + 'px';
	
/*	
	obj.innerHTML = msg + '<div style="text-align:center; padding:10px;"><a href="javascript:ITMessageBox_LIST[\''+ this.name +'\'].closeDialog();">close</a></div>';
	obj.style.display = 'block';
*/	
	var shadow = document.getElementById( this.name + 'Shadow');
	shadow.style.width = document.body.scrollWidth;
	shadow.style.height = document.body.scrollHeight;
	shadow.style.display = 'block';
	
	document.getElementById( this.name +'closebt').focus();
}


// Global funciton
function resetMsgBoxPos(){
	for ( dialog in ITMessageBox_LIST ){
		dialog.resetPos();
	}
}

/*
// no effect ++
// Register Global Event
if (window.addEventListener){
	window.addEventListener('onresize', resetMsgBoxPos, false);
	window.addEventListener('onscroll', resetMsgBoxPos, false);
}else if (window.attachEvent){
	window.attachEvent('onresize', resetMsgBoxPos);
	window.attachEvent('onscroll', resetMsgBoxPos);
}else{
	window.onresize = window.onscroll = resetMsgBoxPos;
}
// no effect --
*/