//Open messageBox window

//messageStatus0 saves return value that type is 0;messageStatus1 saves return value that type is 1;
//return "OK" when click button "OK" ;return "Cancel" when click button "Cancel" ;return "Esc" when click image "X" ;
var messageStatus0=null;
var messageStatus1=null;
var messageStatus2=null;
//messageBox handle
var openWinMessageBox;
//return result from function messageBox
var resWinMessageBox ;
//check handle "openWinMessageBox" exist or not
var messageBoxExistFlag = false;
//save temporary value when click button.
var resArray ;
//
var intervalHandle ;
//
var messageBox_strOk = 'OK';
var messageBox_strCancel = 'Cancel';
var messageBox_strContinue = 'Continue';

function showMessageBox( _title, _messageContent, _type, _callbackFuncName, _width, _height)
{
	openWinMessageBox = messageBox( _title, _messageContent, _type, _callbackFuncName, _width, _height);
}

function messageBox( _title, _messageContent, _messageBoxType, _callbackFuncName, _width, _height)
{
	if(_callbackFuncName!=null && _callbackFuncName!="" && _callbackFuncName=="isNoSlots"){
	}else{
		initMessageButtonValue();
	}
	
		
	if(messageBoxExistFlag)
		resWinMessageBox.reshow( _title, _messageContent, _messageBoxType, _callbackFuncName, _width, _height);
	else
	{
	    resWinMessageBox = new messageDialog( _title, _messageContent, _messageBoxType, _callbackFuncName, _width, _height);
	    resWinMessageBox.show();	    
	    messageBoxExistFlag = true;
	}
	return resWinMessageBox;
}
function closeMessageBoxBase(obj,type,funcName)
{
	//???????0??????result[0]???1??????result[1]?
	//???????????????????MessageBox?
	messageStatus0=null;
	messageStatus1=null;
	messageStatus2=null;
	if(type==0){
		messageStatus0 = obj.id;
	}
	else if(type==1){
		messageStatus1 = obj.id;
	}
	else if(type==2){
		messageStatus2 = obj.id;
	}
	if(funcName!=null && funcName!="" && funcName!="isNoSlots"){
			openWinMessageBox.reset();	
	}
	if(funcName!=null && funcName!="" && funcName!="undefined")
		eval(funcName+'()');
}
function messageDialog( _title, _messageContent, _messageBoxType, _callbackFuncName, _width, _height)
{
    var title ;
    var messageContent ;
	var type ;
	var callbackFuncName ;
    var sFunc ;
    var sBody ;
    var sBox ;
    var strMask ;
	title = "&nbsp;"+_title;
	messageContent = _messageContent;
	type = _messageBoxType;
	callbackFuncName = _callbackFuncName;
	var titleLen = title.length;
	var messageLen = messageContent.length;
    var width = messageLen*10<500 ? messageLen*10<250 ? 250 : messageLen*10 : 500 ;
    var height = parseInt(messageLen/10)+100 ;
    if(_width!=null && _width!="")
    	width = _width;
    if(_height!=null && _height!="")
    	height = _height;
    var path = contextpath+"/images/";
	var strClose = '<input type="image" id="messageBoxClose" value="Esc" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" src="' + path + 'dialogClose0.gif" border="0" width="17" height="17" onmouseover="this.src=\'' + path + 'dialogCloseF.gif\';" onmouseout="this.src=\'' + path + 'dialogClose0.gif\';" align="absmiddle" />';

    strBody = '\
        <table id="messageBodyBox" border="0" align="center" cellpadding="0" cellspacing="0">\
            <tr height="10"><td colspan="3" align="center"></td></tr>\
            <tr>\
                <td width="20"></td>\
                <td id="messageMsg" style="font-family:arial;font-size:12px;color:#46597E;width:'+width+'px;"></td>\
                <td width="20"></td>\
            </tr>\
            <tr height="20"><td colspan="3" align="center"></td></tr>\
            <tr><td id="messageFunc" colspan="3" align="center"></td></tr>\
            <tr height="10"><td colspan="3" align="center"></td></tr>\
        </table>\
    ';
    strBox = '\
        <table id="messageBox" width="' + width + 'px;" border="0" cellpadding="0" cellspacing="0" style="border:0px none;display:none;z-index:999;">\
        	<tr bgcolor="">\
                <td>\
                    <table onselectstart="return false;" style="-moz-user-select:none;" width="100%" border="0" cellpadding="0" cellspacing="0">\
                        <tr>\
                            <td id="messageBoxTitle" style="font-family:arial;color:White;cursor:move;font-size:80%;font-weight:bold;background: url(\''+path+'blog.gif\'); height:19px; padding-left:5px;">&nbsp;Message</td>\
                            <td id="messageClose" width="19" align="center" valign="middle" style="background: url('+path+'blog.gif)">\
                                ' + strClose + '\
                            </td>\
                        </tr>\
                    </table>\
                </td>\
            </tr>\
            <tr id="messageHeight" style="height:' + height + 'px;">\
                <td id="messageBody" style="border:1px solid #A7C4E1;border-top:0px none;background:#fff;color:#A7C4E1;">' + strBody + '</td>\
            </tr>\
        </table>\
    ';
    var sffsetTop = 0;
    //strMask = '<table id="maskbody" top="' + document.body.scrollTop + 'px;" width="' + document.body.offsetWidth + 'px;" height="' + document.body.scrollHeight + 'px;" border="2" cellpadding="2" cellspacing="2" style="border:0px none;display:none;z-index:998;"><tr><td></td></tr></table>';
    strMask = '<table id="maskbody" width="' + document.body.offsetWidth + 'px;" height="' + document.body.scrollHeight + 'px;" border="2" cellpadding="2" cellspacing="2" style="border:0px none;display:none;z-index:998;"><tr><td></td></tr></table>';
	//?????????????????0????????1???????default????????
	if(_messageBoxType==0)
		strFunc = '<input id="OK" type="button" style="width:72px;height:25px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #46597E;" value="'+messageBox_strOk+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
	else if(_messageBoxType==1)
		strFunc = '<input id="OK" type="button" style="width:72px;height:25px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #46597E;" value="'+messageBox_strOk+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />&nbsp;&nbsp;&nbsp;&nbsp;<input id="Cancel" type="button" style="width:72px;height:25px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #46597E;" value="'+messageBox_strCancel+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
	else if(_messageBoxType==2)
		strFunc = '<input id="Continue" type="button" style="width:72px;height:25px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #46597E;" value="'+messageBox_strContinue+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />&nbsp;&nbsp;&nbsp;&nbsp;<input id="Cancel" type="button" style="width:72px;height:25px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #46597E;" value="'+messageBox_strCancel+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
	else
		strFunc = '<input id="OK" type="button" style="width:72px;height:25px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #46597E;" value="'+messageBox_strOk+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
    this.init = function(){
        var oDivMask = document.createElement('div');
        oDivMask.id = "mask";
        oDivMask.innerHTML = strMask;
        oDivMask.style.border = "#000000";
        //oDivMask.style.width=document.body.clientWidth;
        //oDivMask.style.height=0;
        document.body.appendChild(oDivMask);
        var oDiv = document.createElement('span');
        oDiv.id = "messageBoxCase";
        oDiv.innerHTML = strBox;
        document.body.appendChild(oDiv);
	    document.getElementById('messageBoxTitle').innerHTML = title;
	    document.getElementById('messageMsg').innerHTML = messageContent;
	    document.getElementById('messageFunc').innerHTML = strFunc;
    }
    //?????????
    this.show = function()
    {
    	document.getElementById('messageBodyBox') ? function(){} : this.init();
    	this.middlemask('maskbody');
    	this.middle('messageBox');
    	enableMaskMessage();
    }
    //?????????????
    this.middle = function(_sId){
        document.getElementById(_sId)['style']['display'] = '';
        document.getElementById(_sId)['style']['position'] = "absolute";
        document.getElementById(_sId)['style']['left'] = (document.body.clientWidth / 2) - (document.getElementById(_sId).offsetWidth / 2);
        document.getElementById(_sId)['style']['top'] = (document.body.clientHeight / 2 + document.body.scrollTop) - (document.getElementById(_sId).offsetHeight / 2);
        new Draggable(_sId, {revert:true});
    }
    this.middlemask = function(_sId){
        document.getElementById(_sId)['style']['display'] = '';
        document.getElementById(_sId)['style']['position'] = "absolute";
        document.getElementById(_sId)['style']['left'] = (document.body.clientWidth / 2) - (document.getElementById(_sId).offsetWidth / 2);
        document.getElementById(_sId)['style']['top'] = 0;
    }
    //???????
    this.reset = function()
    {
    	//document.getElementById('mask').style.display='none';
    	document.getElementById('messageBoxCase').style.display='none';
    	disableMaskMessage();
    }
    //????????????
    this.initVar = function( _title, _messageContent, _messageBoxType, _callbackFuncName, _width, _height){
    	title = "&nbsp;"+_title;
    	messageContent = _messageContent;
		type = _messageBoxType;
		callbackFuncName = _callbackFuncName;
		var titleLen = title.length;
		var messageLen = messageContent.length;
		if(titleLen>40)
		{
	    	//alert("?????");
	    	return ;
		}
	    var width = messageLen*10<500 ? messageLen*10<250 ? 250 : messageLen*10 : 500 ;
	    var height = parseInt(messageLen/10)+100 ;
	    if(_width!=null && _width!="")
	    	width = _width;
	    if(_height!=null && _height!="")
	    	height = _height;
	    var path = contextpath+"/images/";
    	var strClose = '<input type="image" id="messageBoxClose" value="Esc" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" src="' + path + 'dialogClose0.gif" border="0" width="17" height="17" onmouseover="this.src=\'' + path + 'dialogCloseF.gif\';" onmouseout="this.src=\'' + path + 'dialogClose0.gif\';" align="absmiddle" />';
    
    strBody = '\
        <table id="messageBodyBox" border="0" align="center" cellpadding="0" cellspacing="0">\
            <tr height="10"><td colspan="3" align="center"></td></tr>\
            <tr>\
                <td width="20"></td>\
                <td id="messageMsg" style="font-family:arial;font-size:12px;color:#46597E;width:'+width+'px;"></td>\
                <td width="20"></td>\
            </tr>\
            <tr height="20"><td colspan="3" align="center"></td></tr>\
            <tr><td id="messageFunc" colspan="3" align="center"></td></tr>\
            <tr height="10"><td colspan="3" align="center"></td></tr>\
        </table>\
    ';
    strBox = '\
        <table id="messageBox" width="' + width + 'px;" border="0" cellpadding="0" cellspacing="0" style="border:0px none;display:none;z-index:999;">\
        	<tr bgcolor="">\
                <td>\
                    <table onselectstart="return false;" style="-moz-user-select:none;" width="100%" border="0" cellpadding="0" cellspacing="0">\
                        <tr>\
                            <td id="messageBoxTitle" style="font-family:arial;color:White;cursor:move;font-size:80%;font-weight:bold;background: url(\''+path+'blog.gif\'); height:19px; padding-left:5px;">&nbsp;Message</td>\
                            <td id="messageClose" width="19" align="center" valign="middle" style="background: url('+path+'blog.gif)">\
                                ' + strClose + '\
                            </td>\
                        </tr>\
                    </table>\
                </td>\
            </tr>\
            <tr id="messageHeight" style="height:' + height + 'px;">\
                <td id="messageBody" style="border:1px solid #A7C4E1;border-top:0px none;background:#fff;color:#A7C4E1;">' + strBody + '</td>\
            </tr>\
        </table>\
    ';
    strMask = '<table id="maskbody" width="' + document.body.offsetWidth + 'px;" height="' + document.body.clientHeight + 'px;" border="2" cellpadding="2" cellspacing="2" style="border:0px none;display:none;z-index:998;"><tr><td></td></tr></table>';
		//?????????????????0????????1???????default????????
	if(_messageBoxType==0)
		strFunc = '<input id="OK" type="button" style="width:72px;height:25px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #46597E;" value="'+messageBox_strOk+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
	else if(_messageBoxType==1)
		strFunc = '<input id="OK" type="button" style="width:72px;height:25px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #46597E;" value="'+messageBox_strOk+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />&nbsp;&nbsp;&nbsp;&nbsp;<input id="Cancel" type="button" style="width:72px;height:25px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #46597E;" value="'+messageBox_strCancel+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
	else if(_messageBoxType==2)
		strFunc = '<input id="Continue" type="button" style="width:72px;height:25px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #46597E;" value="'+messageBox_strContinue+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />&nbsp;&nbsp;&nbsp;&nbsp;<input id="Cancel" type="button" style="width:72px;height:25px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #46597E;" value="'+messageBox_strCancel+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
	else
		strFunc = '<input id="OK" type="button" style="width:72px;height:25px;border:0;line-height:20px;background: url('+path+'btn_big.gif); color: #46597E;" value="'+messageBox_strOk+'" onclick="closeMessageBoxBase(this,'+type+',\''+callbackFuncName+'\');" />';
    }
    //????????????
    this.initData = function(){
	    document.getElementById('messageBoxTitle').innerHTML = title;
	    document.getElementById('messageMsg').innerHTML = messageContent;
	    document.getElementById('messageFunc').innerHTML = strFunc;
    }
    //????????????????????
    this.reshow = function( _title, _messageContent, _messageBoxType, _callbackFuncName, _width, _height){
    	selectIdArray.length=0;
    	this.initVar(_title, _messageContent, _messageBoxType, _callbackFuncName, _width, _height);
    	document.getElementById('messageBoxCase').innerHTML = strBox;
    	this.initData();
    	document.getElementById('mask').style.display='';
    	document.getElementById('messageBoxCase').style.display='';
    	this.middlemask('maskbody');
    	this.middle('messageBox');
    	enableMaskMessage();
    }
}

//set mask (add function start)
var selectIdArray = new Array();
var objElement;
var intervalHandle ;
var intervalHandleMask ;
var browerType=new function(){
	this.isOpera=(window.opera&&navigator.userAgent.match(/opera/gi))?true:false;
	this.isIE=(!this.isOpera&&document.all&&navigator.userAgent.match(/msie/gi))?true:false;
	this.isSafari=(!this.isIE&&navigator.userAgent.match(/safari/gi))?true:false;
	this.isGecko=(!this.isIE&&navigator.userAgent.match(/gecko/gi))?true:false;
	this.isFirefox=(!this.isIE&&navigator.userAgent.match(/firefox/gi))?true:false;
};
function enableMaskMessage()
{
	getSelectIdArray();
	disableSelect(selectIdArray);
	intervalHandle = setInterval("moveMaskDivMessage()",300); 
}
function disableMaskMessage()
{
	document.getElementById('mask').style.display='none';
	enableSelect(selectIdArray);
	clearInterval(intervalHandle);
}
function getSelectIdArray()
{
	if(browerType.isIE)
	{
		var allElement = document.getElementsByTagName('SELECT');
		for( i=0,len=allElement.length; i<len; i++)
		{
			if(allElement[i].style.display!='none')
			{
				selectIdArray.push(allElement[i]);
			}
		}
	}
	if(document.getElementById('seminarvideo'))
	{
		var embed = document.getElementById('seminarvideo');
		selectIdArray.push(embed);
	}
}
function disableSelect(objArray)
{
	for(i=0,len=objArray.length; i<len; i++)
	{
		if(objArray[i].id)
		{
			if("seminarvideo"==objArray[i].id)
				objArray[i].style.display='none';
			else
			{
				if(browerType.isIE)
				{
					objArray[i].style.display='none';
				}
			}
		}
		else
		{
			if(browerType.isIE)
			{
				objArray[i].style.display='none';
			}
		}
	}
}
function enableSelect(objArray)
{
	for(i=0,len=objArray.length; i<len; i++)
	{
		if(objArray[i].id)
		{
			if("seminarvideo"==objArray[i].id)
				objArray[i].style.display='';
			else
			{
				if(browerType.isIE)
				{
					objArray[i].style.display='';
				}
			}
		}
		else
		{
			if(browerType.isIE)
			{
				objArray[i].style.display='';
			}
		}
	}
}
function moveMaskDivMessage()
{
	document.getElementById('maskbody')['style']['left'] = 0;//(document.body.clientWidth / 2) - (document.getElementById('maskbody').offsetWidth / 2)-320;
	document.getElementById('maskbody')['style']['top'] = 0;//(document.body.clientHeight / 2 + document.body.scrollTop) - (document.getElementById('maskbody').offsetHeight / 2)-320;
}
function textEditorInitVoke()
{
	getSelectIdArray();
	disableSelect(selectIdArray);
}
//set mask (end)
