// JavaScript Document

/**
 *  弹出信息窗口 HzMessageBox
 *
 *  HzMessageBox.alert('messages');
 */
var HzMessageBox = new Object();

//图片目录
HzMessageBox.imageDir = APP.BASE_DIR + 'images/hzmessagebox/';

//Loading 图片地址
HzMessageBox.loadingGIF = APP.BASE_DIR + 'images/ajax-loader.gif';

//弹出层信息
HzMessageBox.operateFrame = function (params)
{
	var htmlcode = "<style type='text/css'>";
	htmlcode += ".operateframe{background:#FFFFFF;border:8px solid #6699CC;overflow:visible;text-align:left;padding:8px;}";
	htmlcode += ".operateframe-top{width:100%;cursor:move;}";
	htmlcode += ".operateframe .operateframe-title{font-weight:bold;font-size:14px;color:#663399;float:left;}";
	htmlcode += ".operateframe a.operateframe-colse{display:block;width:14px;height:14px; line-height:14px; font-size:1px;";
	htmlcode += "background:url(" + HzMessageBox.imageDir + "cancelbutton.gif); float:right;}";
	
	htmlcode += ".operateframe .operateframe-content{clear:both; margin:5px 0px 0px;}";
	htmlcode += "a.operateframe-colse:hover{background:url(" + HzMessageBox.imageDir + "cancelbutton.gif) right;}</style><div class='operateframe'";
		
	if(typeof(params) == 'string'){
		var params = {'body':params};
	}else if(!params){
		var params = {};
	}
	params.width = params.width || 300;
	
	var style = '';
	if(params.width) style += 'width:' + params.width + 'px;';
	if(params.height) style += 'height:' + params.height + 'px;';
		
	if(style != ''){
		htmlcode += ' style="' + style + '" ';
	}
	htmlcode += '><div class="operateframe-word"><div class="operateframe-top"><div class="operateframe-title">';
	htmlcode += params.title ? params.title : '';
	htmlcode += '</div>';
		
	if(params.closebtn !== false)
	{
		htmlcode += '<a href="javascript:" class="operateframe-colse" onclick="HzMessageBox.doClose()"></a>';
	}
		
	if(typeof(params.load) != "undefined"
	&& typeof(params.body) == "undefined"){
		params.body = "<div style=\"text-align:center;\"><img src='"+ HzMessageBox.loadingGIF +"' height='48' width='48' /></div>";
	}
	
	htmlcode += '</div><div class="operateframe-content">'+ params.body +'</div></div></div>';
	
	HzMessageBox.display(htmlcode);
		
	if(typeof(params.load) != "undefined")
		$(".operateframe-content").load(params.load);
		
	$('.operateframe-top').asfmanDrag($('.hzmsgbox-content-word').get(0));
}

//基本的信息显示
HzMessageBox.display = function (message)
{
	var msgbox = HzMessageBox.buildBoxObject();
	msgbox.html(message).show();
	HzMessageBox.makePosition();
	msgbox.hide().fadeIn('fast');
}

//创建hzmsgbox 的Dom 对象
HzMessageBox.buildBoxObject = function ()
{
	if(!$('.hzmsgbox').get(0))
	{
		var htmlcode = "<style type='text/css'>";
		htmlcode += ".hzmsgbox{width:100%;height:100%;position:absolute; left:0; top:0; z-index:999;display:none;}";
		htmlcode += ".hzmsgbox-filbg{width:100%;height:100%; position:absolute; background:#000;z-index:1000;filter:alpha(opacity=20);";
		htmlcode += "-moz-opacity: 0.20;opacity:0.20;}";
		htmlcode += ".hzmsgbox-content-box{z-index:1100;position:absolute;}";
		htmlcode += ".hzmsgbox-content-word{background:#FFFFFF; margin:0 auto;position:absolute;left:300px;top:100px;}";
		htmlcode += "</style>";
		htmlcode += "<div class='hzmsgbox'>";
		htmlcode += "<div class='hzmsgbox-filbg'></div><div class='hzmsgbox-content-box'><div class='hzmsgbox-content-word'></div></div></div>";
		$(htmlcode).appendTo('body');
	}
	$('.hzmsgbox,.hzmsgbox-filbg').css('height',document.documentElement.scrollHeight).show();
	//$('.hzmsgbox-filbg').fadeTo('fast',0.5);
	
	return $('.hzmsgbox-content-word');
}

//设置正确的位置
HzMessageBox.makePosition = function ()
{
	var top = (document.documentElement.clientHeight - $('.hzmsgbox-content-word')[0].offsetHeight) / 2;
	top += document.documentElement.scrollTop;
	
	//$('.hzmsgbox-content-word').css('top',top);
		
	var left = (document.documentElement.clientWidth - $('.hzmsgbox-content-word')[0].offsetWidth) / 2;
	left += document.documentElement.scrollLeft;
	
	//$('.hzmsgbox-content-word').css('left',left);
}

//显示加载Loading
HzMessageBox.displayLoading = function ()
{
		HzMessageBox.display("<img src='"+ HzMessageBox.loadingGIF +"' height='48' width='48' />");
}

//关闭弹出层
HzMessageBox.doClose = function ()
{
	//$('.hzmsgbox').fadeOut('fast',function ()
	//{
		$('.hzmsgbox').remove();
	//});
}

/*
	动态创建缩略图
	  
	<img src="test.jpg" onload="makeSmallSize(this,150,150);" />
 */
function makeSmallSize(obj,mh,mw)
{
	if(!obj) return ;
	
	var h = obj.height;
	var w = obj.width;
	if(h < mh && w < mw) return ;
	
	var ratio = mh / h;
	if(w * ratio > mw)
	{
		ratio = mw / w;
	}
	
    obj.height = h * ratio;
    obj.width = w * ratio;
}

/*
	检测EMAIL.
	
	isEmail('xxxx@xxx.xxx');
*/
function isEmail(value) 
{
	return /^[0-9a-zA-Z\-\_\.]+@([0-9a-zA-Z\-\_]+\.)+([a-zA-Z]{2,3})$/.test(value);
}

/*
	取随机数
 
	var rm =  randomEncrypt();	
 */
function randomEncrypt()
{ 
	var date = new Date(); 
	var times1970 = date.getTime(); 
	var times = date.getDate() + "" + date.getHours() + "" + date.getMinutes() + "" + date.getSeconds(); 
	var encrypt = times * times1970; 
	if(arguments.length == 1)
	{ 
		return arguments[0] + encrypt; 
	}
	else
	{ 
		return encrypt; 
	} 
} 

