/*
 * Ham thuc hien chuc nang lay gia tri cua window va document
 * Type:	function
 * Name:	TNCom_getDocumentSize
 * Date:	2008/05/21
 * @param int val cac gia tri:	0: pageWidth, 1: pageHeight, 2: windowWidth, 3: windowHeight
 * @return int gia tri tra ve khi thuc hien goi ham		
 */
function TNCom_getDocumentSize(val)
{
	var xScroll,yScroll,value;
	var hasInner = typeof(window.innerWidth) == 'number';
	var hasElement = document.documentElement && document.documentElement.clientWidth;
	var numShiftY = hasInner?pageYOffset:hasElement?document.documentElement.scrollTop:document.body.scrollTop;
	if(window.innerHeight&&window.scrollMaxY)
	{
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight)
	{
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	}
	else{
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}
	var windowWidth,windowHeight;
	
	if(self.innerHeight)
	{
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}
		else{
			windowWidth=self.innerWidth;
		}
		windowHeight=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight)
	{
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}
	else if(document.body)
	{
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	if(yScroll<windowHeight){
		pageHeight=windowHeight;
	}
	else{
		pageHeight=yScroll
	}
	
	if(xScroll<windowWidth){
		pageWidth=xScroll
	}
	else{
		pageWidth=windowWidth
	}
	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight,numShiftY)	
	return arrayPageSize[val]
}// end function
/*
 * Ham thuc hien chuc nang lay gia tri cua window va document
 * Type:	function
 * Name:	TNCom_getDocumentSize
 * Date:	2008/05/21
 * @param int val cac gia tri:	0: pageWidth, 1: pageHeight, 2: windowWidth, 3: windowHeight
 * @return int gia tri tra ve khi thuc hien goi ham		
 */
function ym2_getDocumentSize(val)
{
	var xScroll,yScroll,value;
	var hasInner = typeof(window.innerWidth) == 'number';
	var hasElement = document.documentElement && document.documentElement.clientWidth;
	var numShiftY = hasInner?pageYOffset:hasElement?document.documentElement.scrollTop:document.body.scrollTop;
	if(window.innerHeight&&window.scrollMaxY)
	{
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight)
	{
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	}
	else{
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}
	
	var windowWidth,windowHeight,pageWidth,pageHeight;
	
	if(self.innerHeight)
	{
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}
		else{
			windowWidth=self.innerWidth;
		}
		windowHeight=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight)
	{
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}
	else if(document.body)
	{
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}

	if(yScroll<windowHeight){
		pageHeight=windowHeight;
	}
	else{
		pageHeight=yScroll
	}

	if(xScroll<windowWidth){
		pageWidth=xScroll
	}
	else{
		pageWidth=windowWidth
	}

	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight,numShiftY)	
	return arrayPageSize[val]
}// end function


var gMsgHtml=null;
var ym2msgbox = {		
	intWidth:1,
	dialogcommon:"#dialogcommon",
	msgcontain:"#msgcontain",
	dialogbacklayer:"#dialogbacklayer",
	show:function(boxId,msgWidth)
	{	
		
		if(gMsgHtml!=null) jQuery('body').append(gMsgHtml);
		this.intWidth=msgWidth;
		this.init();
		
		jQuery("#dialogbacklayer").height(TNCom_getDocumentSize(1));
		jQuery("#dialogbacklayer").width(TNCom_getDocumentSize(0));
		gMsgHtml=jQuery("#"+boxId);
		jQuery(this.msgcontain).html(jQuery("#"+boxId).html());
		jQuery("#"+boxId).remove();
		jQuery(this.dialogcommon).css({left: Math.round(TNCom_getDocumentSize(2)/2-this.intWidth/2) +"px"});
		
		if(jQuery.browser.msie){
		jQuery(this.dialogcommon).css({top: Math.round((TNCom_getDocumentSize(4)+TNCom_getDocumentSize(3)/8))+"px"});
		}	
		else
		{
			var ffv=parseInt(jQuery.browser.version.substr(0,1))+ parseInt(jQuery.browser.version.substr(2,1));
			if(ffv<10){
				//jQuery(this.dialogcommon).css({top:100 +"px"});
				jQuery(this.dialogcommon).css({top: Math.round((TNCom_getDocumentSize(4)+TNCom_getDocumentSize(3)/8))+"px"});
			}
			else{
				jQuery(this.dialogcommon).css({top: Math.round((TNCom_getDocumentSize(4)+TNCom_getDocumentSize(3)/8))+"px"});	
			}
		}	
		jQuery(this.dialogcommon).fadeIn(300, function()
		{
			jQuery("#dialogbacklayer").show();
			 //jQuery(this.dialogcommon).css({display:'block'}); 
		});		
		window.onresize=this.getpos;
	},
	hide:function(){
		jQuery(this.dialogbacklayer).hide();
		jQuery(this.dialogcommon).hide();
		jQuery('body').append(gMsgHtml);
		gMsgHtml=null;			
	},	
	getpos: function(){
		jQuery(ym2msgbox.dialogcommon).css({left: Math.round((TNCom_getDocumentSize(2)-ym2msgbox.intWidth)/2)+"px"});
		jQuery(ym2msgbox.dialogcommon).css({top: Math.round(TNCom_getDocumentSize(3)/5 + TNCom_getDocumentSize(4))+"px"});
	},
	init:function()
	{	
	 	var backobj=document.getElementById('dialogbacklayer');
		if (backobj == null || backobj == 'undefined'){
			jQuery('body').append('<div id="dialogbacklayer"></div><div id="dialogcommon" class="select-free"><!--[if lte IE 6.5]><iframe></iframe><![endif]--><div class="rowtop"><div class="lb_top_border_cl"></div><div class="wdialog"></div><div class="lb_top_border_cr"></div></div><div class="rowmid"><div class="wdialog"><div id="msgcontain"></div></div></div><div class="rowbot"><div class="lb_bot_border_cl"></div><div class="wdialog"></div><div class="lb_bot_border_cr"></div></div></div>');
		}
		jQuery("#dialogbacklayer").hide();
		jQuery('#dialogcommon').css('width',this.intWidth+20+'px');
		jQuery('#msgcontain').css('width',this.intWidth+'px');
		jQuery('#dialogcommon .wdialog').css('width',(this.intWidth)+'px');
	}
}
