﻿/*QcmsCmsV2009
*/
var windowID                  = "CCD3-8BA6-8758-59A3";
var WebUI_Url_Hint            = "/cmsfile/style/hint/";
var WebUI_Dialog_Url          = "/cmsfile/style/dialog/";
/*------------------------------------------------------------------*/
var QcmsCms=new Object();
QcmsCms.Cookie={
	set:function(name,value,expires,path,domain){
		if(typeof expires=="undefined"){
			expires=new Date(new Date().getTime()+24*3600*100);
		}
		document.cookie=name+"="+escape(value)+((expires)?"; expires="+expires.toGMTString():"")+((path)?"; path="+path:"; path=/")+((domain)?";domain="+domain:"");
	},
	get:function(name){
		var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
		if(arr!=null){
			return unescape(arr[2]);
		}
		return null;
	},
	clear:function(name,path,domain){
		if(this.get(name)){
			document.cookie=name+"="+((path)?"; path="+path:"; path=/")+((domain)?"; domain="+domain:"")+";expires=Fri, 02-Jan-1970 00:00:00 GMT";
		}
	}
};
/////////////////////////////
//弹出提示框
/////////////////////////////
QcmsCms.Alert=function(errstr, success, returnFunc){
	var oDialog = new ClassDialog('2', '', 300, 150, success, true);
	oDialog.init();
	oDialog.event(errstr,'');
	if (returnFunc == null)
		oDialog.button('dialogSubmit', '');
	else
		oDialog.button('dialogSubmit', returnFunc);
};
/////////////////////////////
//弹出确认框
//例如:
//1、QcmsCms.Confirm("是否操作", act, null) //函数不加()
//2、QcmsCms.Confirm("是否操作", "alert('yes')", "alert('no')")
/////////////////////////////
QcmsCms.Confirm=function(errstr, returnSubmitFunc, returnCancelFunc)
{
	var oDialog = new ClassDialog('2', '', 300, 150, "warning", false);
	oDialog.init();
	oDialog.event(errstr,'');
	oDialog.button('dialogSubmit', returnSubmitFunc);
	if (returnCancelFunc == null)
		oDialog.button('dialogCancel', '');
	else
		oDialog.button('dialogCancel', returnCancelFunc);
};
/////////////////////////////
//弹出模拟窗口
/////////////////////////////
QcmsCms.Popup={
	show:function(url, width, height, showCloseBox)
	{
	
		var oDialog = new ClassDialog('1', '&nbsp;', width, height, null, showCloseBox);
		if (url.indexOf("?") == -1)
			oDialog.open(url+"?windowCode="+windowID+(new Date().getTime()));
		else
			oDialog.open(url+"&windowCode="+windowID+(new Date().getTime()));
	},
	hide:function(){
		new ClassDialog().reset();
	}
};
/////////////////////////////
//弹出加载层
/////////////////////////////
QcmsCms.Loading={
	show:function(msgstr, width, height, showCloseBox)
	{
		var oDialog = new ClassDialog('0', 'loading', width, height, null, showCloseBox);
		oDialog.init(false);
		oDialog.html("&nbsp;&nbsp;&nbsp;<img src='" + WebUI_Dialog_Url + "loading.gif' align='absmiddle'> "+msgstr);
	},
	hide:function(){
		new ClassDialog().reset();
	}
};
////////////////////////////////////////////////////////////////////////////////////////////
//提示层
////////////////////////////////////////////////////////////////////////////////////////////
QcmsCms.Hint={
	show:function(obj, objleftoffset,objtopoffset, title, info , objheight, showtype ,objtopfirefoxoffset)
	{
		var oHint = new ClassHint(obj, objleftoffset,objtopoffset, title, info , objheight, showtype ,objtopfirefoxoffset);
		oHint.show();
	},
	hide:function(){
		new ClassHint().hide();
	}
}
////////////////////////////////////////////////////////////////////////////////////////////

var gHideSelects              = false;
var gDialogIsShown            = false;
var gWindowMask               = null;
////////////////////////////////////////////////////////////////////////////////////////////
//以下为弹出窗口的类
////////////////////////////////////////////////////////////////////////////////////////////
function ClassDialog(styletype, title, width, height, iswhat, showCloseBox){
	if(width<0 || width>getViewportWidth()-25)
		width=getViewportWidth()-25;
	if(height<0 || height>getViewportHeight()-45)
		height=getViewportHeight()-45;
	var sTitle = "提示信息";
	if (iswhat == "0")
		sTitle = "错误提示";
	else if (iswhat == "1")
		sTitle = "成功提示";
	else
	{
		if (title!='')
			sTitle = title;
	}
	var src = "";
	var path = WebUI_Dialog_Url + styletype + "/";
	var gReturnFunc;
	var gReturnVal = null;
	var sButtonFunc = '<input id="dialogSubmit" class="dialogSubmit'+styletype+'" type="button" onmouseover=BtnOver(this,"' + path + '") onmouseout=BtnOut(this,"' + path + '") value="确 认" onclick="new ClassDialog().reset();" /> <input id="dialogCancel" class="dialogCancel'+styletype+'" type="button" value="取 消" onclick="new ClassDialog().reset();" />';
	var sClose = '';
	if (showCloseBox == null || showCloseBox == true)
		sClose = '<input type="image" title="关闭当前窗口" id="dialogBoxClose" onclick="new ClassDialog().reset();" src="' + path + 'dialogCloseOut.gif" border="0" width="15" height="13" onmouseover="this.src=\'' + path + 'dialogCloseOver.gif\';" onmouseout="this.src=\'' + path + 'dialogCloseOut.gif\';" align="absmiddle" />';
	var sSuccess = '';
	if (iswhat != null)
		sSuccess = '<td width="80" align="center" valign="middle"><img id="dialogBoxFace" class="dialogBoxFace'+styletype+'" src="' + path + iswhat + '.gif" valign="absmiddle" /></td>';
	var sBody = '\
		<table id="dialogBodyBox" class="dialogBodyBox'+styletype+'" border="0" align="center" cellpadding="0" cellspacing="0" width="100%" height="100%" >\
			<tr height="10"><td colspan="4"></td></tr>\
			<tr>\
				<td width="10"></td>' + sSuccess + '<td id="dialogMsg" class="dialogMsg'+styletype+'"></td>\
				<td width="10"></td>\
			</tr>\
			<tr height="10"><td colspan="4" align="center"></td></tr>\
			<tr><td id="dialogFunc" class="dialogFunc'+styletype+'" colspan="4">' + sButtonFunc + '</td></tr>\
		</table>\
	';
	var sBox = '\
		<table id="dialogBox" class="dialogBox'+styletype+'" style="" width="' + width + '" border="0" cellpadding="0" cellspacing="0">\
			<tr id="dialogTitleHeight" height="23">\
				<td>\
					<table class="dialogTitleTable'+styletype+'" width="100%" height="23" border="0" cellpadding="0" cellspacing="0">\
						<tr>\
							<td width="6" ></td>\
							<td id="dialogBoxTitle" class="dialogBoxTitle'+styletype+'" width="' + (width-33) + '">' + sTitle + '</td>\
							<td id="dialogClose" class="dialogClose'+styletype+'" width="27" align="right" valign="middle">' + sClose + '</td>\
							<td width="6"></td>\
						</tr>\
					</table>\
				</td>\
			</tr>\
			<tr id="dialogHeight" height="' + height + '">\
				<td id="dialogBody" class="dialogBody'+styletype+'">' + sBody + '</td>\
			</tr>\
		</table>\
	';
	function $(obj){return typeof(obj)=="object" ? "obj":document.getElementById(obj);}
	this.init = function(_showTitleBar){
		document.body.oncontextmenu=function(){return false;};
		document.body.onselectstart=function(){return false;};
		document.body.ondragstart=function(){return false;};
		document.body.onsource=function(){return false;};
		$('dialogCase') ? $('dialogCase').parentNode.removeChild($('dialogCase')) : function(){};
		$('windowMask') ? $('windowMask').parentNode.removeChild($('windowMask')) : function(){};
		var oDiv = document.createElement('span');
		oDiv.id = "dialogCase";
		oDiv.innerHTML = sBox;
		document.body.appendChild(oDiv);
		var oMask = document.createElement('div');
		oMask.id = 'windowMask';
		document.body.appendChild(oMask);
		gWindowMask = $("windowMask");
		gWindowMask.style.display="block";
		var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
		if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
			gHideSelects = true;
		}
		if (gHideSelects == true) {
			HideSelectBoxes();
		}
		if (_showTitleBar == true || _showTitleBar == null)
			$("dialogTitleHeight").style.display = "block";
		else
			$("dialogTitleHeight").style.display = "none";
		operatorPlus();
	}
	//this.show = function(){$('dialogBox') ? function(){} : this.init();gDialogIsShown=true;this.middle('dialogBox');}
	this.show = function(){$('dialogBox') ? function(){} : this.init();gDialogIsShown=true;this.middle('dialogBox');operatorPlus();}
	this.html = function(_sHtml){
		this.show();
		$('dialogBody').innerHTML = _sHtml;
	}
	this.button = function(_sId, _sFuc){
		if($(_sId)){
			$(_sId).style.display = '';
			if($(_sId).addEventListener){
				if($(_sId).act){$(_sId).removeEventListener('click', function(){eval($(_sId).act);}, false);}
				$(_sId).act = _sFuc;
				$(_sId).addEventListener('click', function(){eval(_sFuc);this.reset();}, false);
			}else{
				if($(_sId).act){$(_sId).detachEvent('onclick', function(){eval($(_sId).act);});}
				$(_sId).act = _sFuc;
				$(_sId).attachEvent('onclick', function(){eval(_sFuc);});
			}
		}
	}
	this.open = function(_sUrl, _sMode, _returnFunc){
		this.show();
		gReturnFunc = _returnFunc;
		if(!_sMode || _sMode == "no" || _sMode == "yes"){
			$("dialogBody").innerHTML = "<iframe id='dialogFrame' name='dialogFrame' width='"+width+"' height='"+height+"' frameborder='0' scrolling='" + _sMode + "'></iframe>";
			$("dialogFrame").src = _sUrl;
		}
	}
	this.reset = function(callReturnFunc){
		gDialogIsShown = false;
		document.body.oncontextmenu=function(){return true;};
		document.body.onselectstart=function(){return true;};
		document.body.ondragstart=function(){return true;};
		document.body.onsource=function(){return true;};
		$('dialogCase').parentNode.removeChild($('dialogCase'));
		$('windowMask').parentNode.removeChild($('windowMask'));
		gWindowMask=null;
		if (callReturnFunc == true && gReturnFunc != null) {
			gReturnVal = window.dialogFrame.returnVal;
			window.setTimeout('gReturnFunc(gReturnVal);', 1);
		}
		if (gHideSelects == true) {
			ShowSelectBoxes();
			gHideSelects = false;
		}
	}
	this.event = function(_sMsg, _sSubmit, _sCancel, _sClose){
		this.show();
		$('dialogFunc').innerHTML = sButtonFunc;
		$('dialogClose').innerHTML = sClose;
		$('dialogBodyBox') == null ? $('dialogBody').innerHTML = sBody : function(){};
		$('dialogMsg') ? $('dialogMsg').innerHTML = _sMsg  : function(){};
		_sSubmit ? this.button('dialogSubmit', _sSubmit) | $('dialogSubmit').focus() : $('dialogSubmit').style.display = "none";
		_sCancel ? this.button('dialogCancel', _sCancel) : $('dialogCancel').style.display = "none";
		_sClose ? this.button('dialogBoxClose', _sClose) : function(){};
	}
	this.set = function(_oAttr, _sVal){
		var oDialog = $('dialogBox');
		var oHeight = $('dialogHeight');
		if(_sVal != ''){
			switch(_oAttr){
				case 'title':
					$('dialogBoxTitle').innerHTML = _sVal;
					title = _sVal;
					break;
				case 'width':
					oDialog.style.width = _sVal;
					width = _sVal;
					break;
				case 'height':
					oHeight.style.height = _sVal;
					height = _sVal;
					break;
				case 'src':
					if(parseInt(_sVal) > 0){
						$('dialogBoxFace') ? $('dialogBoxFace').src = path + _sVal + '.png' : function(){};
					}else{
						$('dialogBoxFace') ? $('dialogBoxFace').src = _sVal : function(){};
					}
					src = _sVal;
					break;
			}
		}
		//this.middle('dialogBox');
		operatorPlus();
	}
	this.middle = function(_sId){	
		var theWidth;
		var theHeight;
		if (document.documentElement && document.documentElement.clientWidth) { 
			theWidth = document.documentElement.clientWidth+document.documentElement.scrollLeft*2;;
			theHeight = document.documentElement.clientHeight+document.documentElement.scrollTop*2;; 
		} else if (document.body) { 
			theWidth = document.body.clientWidth;
			theHeight = document.body.clientHeight; 
		}else if(window.innerWidth){
			theWidth = window.innerWidth;
			theHeight = window.innerHeight;
		}
		$(_sId).style.display = '';
		$(_sId).style.position = "absolute";
		$(_sId).style.left = (theWidth / 2) - ($(_sId).offsetWidth / 2)+"px";
		if(document.all||$("user_page_top")){
			$(_sId).style.top = (theHeight / 2 + document.body.scrollTop) - ($(_sId).offsetHeight / 2)+"px";
		}else{
			var sClientHeight = parent ? parent.document.body.clientHeight : document.body.clientHeight;
			var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
			var sTop = -80 + (sClientHeight / 2 + sScrollTop) - ($(_sId).offsetHeight / 2);
			$(_sId).style.top = (theHeight / 2 + document.body.scrollTop) - ($(_sId).offsetHeight / 2)+"px";
		}
	}
	BtnOver=function(obj,path){obj.style.backgroundImage = "url("+path+"button2.gif)";}
	BtnOut=function(obj,path){obj.style.backgroundImage = "url("+path+"button1.gif)";}
	ShowSelectBoxes=function(){var x = document.getElementsByTagName("SELECT");for (i=0;x && i < x.length; i++){x[i].style.visibility = "visible";}}
	HideSelectBoxes=function(){var x = document.getElementsByTagName("SELECT");for (i=0;x && i < x.length; i++) {x[i].style.visibility = "hidden";}}
	addEvent=function(obj, evType, fn){
		if (obj.addEventListener){obj.addEventListener(evType, fn, false);return true;}
		else if (obj.attachEvent){var r = obj.attachEvent("on"+evType, fn);return r;}
		else {return false;}
	}
	removeEvent=function(obj, evType, fn, useCapture){
		if (obj.removeEventListener){obj.removeEventListener(evType, fn, useCapture);return true;}
		else if (obj.detachEvent){var r = obj.detachEvent("on"+evType, fn);return r;}
		else {alert("Handler could not be removed");}
	}
}
function exec(_sFuc){
	if(_sFuc){
		if(typeof(_sFuc)=="function"){
			_sFuc();
		}else{
			eval(_sFuc);
		}
	}
}
///////////////////////////////////////////////////////////////////////////
window.onload = formatA;
window.onscroll = operatorPlus;
window.onresize = operatorPlus;

function operatorPlus() {
	if (gDialogIsShown == true) {
		var dialogBoxDiv = document.getElementById("dialogBox");
		var oWidth = dialogBoxDiv.offsetWidth;
		var oHeight = dialogBoxDiv.offsetHeight;
		var theBody = document.getElementsByTagName("BODY")[0];
		var scTop = parseInt(getScrollTop(),10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		dialogBoxDiv.style.top = (scTop + ((fullHeight - oHeight) / 2)) + "px";
		dialogBoxDiv.style.left = (scLeft + ((fullWidth - oWidth) / 2)) + "px";
		if (gWindowMask != null) {
			var popHeight = theBody.scrollHeight;
			var popWidth = theBody.scrollWidth;
			if (fullHeight > theBody.scrollHeight) popHeight = fullHeight;
			if (fullWidth > theBody.scrollWidth) popWidth = fullWidth;
			gWindowMask.style.height = popHeight + "px";
			gWindowMask.style.width = popWidth + "px";
		}
	}
}

function getViewportHeight() {
	if (window.innerHeight!=window.undefined)//FF
	{
		return window.innerHeight;
	}
	if (document.compatMode=='CSS1Compat')//IE
	{
		return document.documentElement.clientHeight;
	}
	if (document.body)//other
	{
		return document.body.clientHeight; 
	}
	return window.undefined; 
}
function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined)//FF
	{
		return window.innerWidth-offset; 
	}
	if (document.compatMode=='CSS1Compat')//IE
	{
		return document.documentElement.clientWidth; 
	}
	if (document.body)//other
	{
		return document.body.clientWidth; 
	}
	return window.undefined; 
}
function getScrollTop() {
	if (self.pageYOffset){return self.pageYOffset;}
	else if (document.documentElement && document.documentElement.scrollTop){return document.documentElement.scrollTop;}
	else if (document.body){return document.body.scrollTop;}
}
function getScrollLeft() {
	if (self.pageXOffset){return self.pageXOffset;}
	else if (document.documentElement && document.documentElement.scrollLeft){return document.documentElement.scrollLeft;}
	else if (document.body){return document.body.scrollLeft;}
}
function formatA() {
	var elms = document.getElementsByTagName('a');
	for (i = 0; i < elms.length; i++) {
		if (elms[i].className.indexOf("popup") == 0) { 
			elms[i].onclick = function(){
				var width = 400;
				var height = 200;
				params = this.className.split('-');
				if (params.length > 2) {
					width = parseInt(params[1]);
					height = parseInt(params[2]);
				}
				QcmsCms.Popup.show(this.href,width,height,null);
				return false;
			}
		}
	}
}
function setDialogTitle(){
	try {
		document.getElementById('dialogBoxTitle').innerHTML = "<img src='" + WebUI_Dialog_Url + "ie.gif' align='absmiddle'>&nbsp;"+ window.document.title;
	}
	catch(e) {
		try {
			parent.document.getElementById('dialogBoxTitle').innerHTML = "<img src='" + WebUI_Dialog_Url + "ie.gif' align='absmiddle'>&nbsp;"+ window.document.title;
		}
		catch(e) {
		}	
	}	
}
//提示层类
ClassHint = function(obj, objleftoffset,objtopoffset, title, info , objheight, showtype ,objtopfirefoxoffset)
{
	var path = WebUI_Url_Hint;
	var imageLeft  = path+'commandbg1.gif';
	var imageRight = path+'commandbg2.gif';
	if((showtype==null)||(showtype =="")) 
		showtype = "up";
	if(showtype=="down"){
		imageLeft  = path+'commandbg3.gif';
		imageRight = path+'commandbg4.gif';
	}
	this.show = function() {
		this.init();
		var p = getposition(obj);
		$('hintIframe').style.height= objheight + "px";
		$('hintInfo').innerHTML = info;
		$('hintSpan').style.display='block';
		if(objtopfirefoxoffset != null && objtopfirefoxoffset !=0 && !isie())
			$('hintSpan').style.top=p['y']+parseInt(objtopfirefoxoffset)+"px";
		else
		{
			if(objtopoffset == 0)
			{ 
				if(showtype=="up")
				{
				 	$('hintSpan').style.top=(p['y'] - $('hintInfo').offsetHeight - 32)+"px";
				}
				else
				{
				 	$('hintSpan').style.top=(p['y'] + obj.offsetHeight + 1)+"px";
				}
			}
			else
				$('hintSpan').style.top=(p['y']+objtopoffset)+"px";
		}
		$('hintSpan').style.left=(p['x']+objleftoffset)+"px";
	}
	//隐藏提示层
	this.hide = function() {
		$('hintSpan').style.display='none';
	}
	function getposition(obj)
	{
		var r = new Array();
		r['x'] = obj.offsetLeft;
		r['y'] = obj.offsetTop;
		while(obj = obj.offsetParent)
		{
			r['x'] += obj.offsetLeft;
			r['y'] += obj.offsetTop;
		}
		return r;
	}
	function $(obj){return typeof(obj)=="object" ? "obj":document.getElementById(obj);}
	this.init = function(){
		$('hintSpan') ? $('hintSpan').parentNode.removeChild($('hintSpan')) : function(){};
		var hintObj=document.createElement("span");
		hintObj.setAttribute("id","hintSpan");
		hintObj.style.position="absolute";
		hintObj.style.display="none";
		var sBody = '<div id="hintDiv">\
				<p><img src="'+imageLeft+'" /></p>\
				<div class="hintmessagetext"><img id="hintdot" src="'+path+'dot.gif" /><span id="hintInfo" ></span></div>\
				<p><img src="'+imageRight+'" /></p>\
			</div>\
			<iframe id="hintIframe" frameborder="0" scrolling="no"></iframe>\
		';
		hintObj.innerHTML=sBody;
		document.body.appendChild(hintObj);
	}
}


