﻿/*CnvpCmsV2009
作者:随风缘
*/
var windowID = "CCD3-8BA6-8758-59A3";
var topWindow;
var topDocument;
if (self.location != top.location) {
    topWindow = window.parent;
    topDocument = topWindow.document;
}
else {
    topWindow = window;
    topDocument = document;
}
/*
var topWindow = window.parent;
var topDocument = topWindow.document;
*/


var WebUI_Url_Hint            = "/common/popup/hint/";
var WebUI_Dialog_Url          = "/common/popup/dialog/";
/*------------------------------------------------------------------*/
var CnvpCms=new Object();
CnvpCms.Cookie={
	set:function(name,value,expires,path,domain){
		if(typeof expires=="undefined"){
			expires=new Date(new Date().getTime()+24*3600*100);
		}
		topDocument.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "; path=/") + ((domain) ? ";domain=" + domain : "");
	},
	get:function(name){
	var arr = topDocument.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
		if(arr!=null){
			return unescape(arr[2]);
		}
		return null;
	},
	clear:function(name,path,domain){
		if(this.get(name)){
		    topDocument.cookie = name + "=" + ((path) ? "; path=" + path : "; path=/") + ((domain) ? "; domain=" + domain : "") + ";expires=Fri, 02-Jan-1970 00:00:00 GMT";
		}
	}
};
/////////////////////////////
//弹出提示框
/////////////////////////////
CnvpCms.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);
};
/////////////////////////////
//操作成功提示框
/////////////////////////////
CnvpCms.Succeed = function(successstr, locationurl) {
    var oDialog = new ClassDialog('2', '操作成功', 300, 150, 1, true);
    oDialog.init();
    oDialog.event(successstr, '');
    if (locationurl == null) {
        oDialog.button('dialogSubmit', '');
    }
    else {
        oDialog.button('dialogSubmit', 'topWindow.frames["rightframe"].location.href="' + locationurl + '"');
    }
}
/////////////////////////////
//弹出确认框
//例如:
//1、CnvpCms.Confirm("是否操作", act, null) //函数不加()
//2、CnvpCms.Confirm("是否操作", "alert('yes')", "alert('no')")
/////////////////////////////
CnvpCms.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);
};
/////////////////////////////
//弹出模拟窗口
/////////////////////////////
CnvpCms.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();
	}
};
/////////////////////////////
//弹出加载层
/////////////////////////////
CnvpCms.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();
	}
};
////////////////////////////////////////////////////////////////////////////////////////////
//提示层
////////////////////////////////////////////////////////////////////////////////////////////
CnvpCms.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" : topDocument.getElementById(obj); }
	this.init = function(_showTitleBar) {
	    topDocument.body.oncontextmenu = function() { return false; };
	    topDocument.body.onselectstart = function() { return false; };
	    topDocument.body.ondragstart = function() { return false; };
	    topDocument.body.onsource = function() { return false; };
	    $('dialogCase') ? $('dialogCase').parentNode.removeChild($('dialogCase')) : function() { };
	    $('windowMask') ? $('windowMask').parentNode.removeChild($('windowMask')) : function() { };

	    var oDiv = topDocument.createElement('span');
	    oDiv.id = "dialogCase";
	    oDiv.innerHTML = sBox;
	    topDocument.body.appendChild(oDiv);
	    var oMask = topDocument.createElement('div');
	    oMask.id = 'windowMask';
	    topDocument.body.appendChild(oMask);
	    gWindowMask = $("windowMask");
	    gWindowMask.style.display = "none";
	    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');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' width='"+width+"' height='"+height+"' frameborder='0' scrolling='" + _sMode + "'></iframe>";
			$("dialogFrame").src = _sUrl;
		}
	}
	this.reset = function(callReturnFunc){
		gDialogIsShown = false;
		topDocument.body.oncontextmenu = function() { return true; };
		topDocument.body.onselectstart = function() { return true; };
		topDocument.body.ondragstart = function() { return true; };
		topDocument.body.onsource = function() { return true; };
		$('dialogCase').parentNode.removeChild($('dialogCase'));
		$('windowMask').parentNode.removeChild($('windowMask'));
		gWindowMask=null;
		if (callReturnFunc == true && gReturnFunc != null) {
		    gReturnVal = topWindow.dialogFrame.returnVal;
			topWindow.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;
	    theWidth = topDocument.body.clientWidth;
	    theHeight = topDocument.body.clientHeight;
	    $(_sId).style.display = '';
	    $(_sId).style.position = "absolute";
	    $(_sId).style.left = (theWidth / 2) - ($(_sId).offsetWidth / 2) + "px";
	    $(_sId).style.top = (theHeight / 2 + topDocument.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 = topDocument.getElementsByTagName("SELECT"); for (i = 0; x && i < x.length; i++) { x[i].style.visibility = "visible"; } }
	HideSelectBoxes = function() { var x = topDocument.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 = topDocument.getElementById("dialogBox");
        var oWidth = dialogBoxDiv.offsetWidth;
        var oHeight = dialogBoxDiv.offsetHeight;
        var theBody = topDocument.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 (topWindow.innerHeight != topWindow.undefined)//FF
    {
        return topWindow.innerHeight;
    }
    if (topDocument.compatMode == 'CSS1Compat')//IE
    {
        return topDocument.documentElement.clientHeight;
    }
    if (topDocument.body)//other
    {
        return topDocument.body.clientHeight;
    }
    return topWindow.undefined;
}
function getViewportWidth() {
    var offset = 20;
    var width = null;
    if (topWindow.innerWidth != topWindow.undefined)//FF
    {
        return topWindow.innerWidth - offset;
    }
    if (topDocument.compatMode == 'CSS1Compat')//IE
    {
        return topDocument.documentElement.clientWidth;
    }
    if (topDocument.body)//other
    {
        return topDocument.body.clientWidth;
    }
    return topWindow.undefined;
}
function getScrollTop() {
    if (self.pageYOffset) { return self.pageYOffset; }
    else if (topDocument.documentElement && topDocument.documentElement.scrollTop) { return topDocument.documentElement.scrollTop; }
    else if (topDocument.body) { return topDocument.body.scrollTop; }
}
function getScrollLeft() {
    if (self.pageXOffset) { return self.pageXOffset; }
    else if (topDocument.documentElement && topDocument.documentElement.scrollLeft) { return topDocument.documentElement.scrollLeft; }
    else if (topDocument.body) { return topDocument.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]);
                }
                CnvpCms.Popup.show(this.href, width, height, null);
                return false;
            }
        }
    }
}
function setDialogTitle(){
	try {
	    topDocument.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 = topDocument.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;
		topDocument.body.appendChild(hintObj);
	}
}
////////////////////////////////////////////////////////////////////////////////////////////