﻿//General
//for example: instead of each module writing out script found in moduleMaxMin_OnClick have the functionality cached
//

var GBL_COL_DELIMITER = String.fromCharCode(16);
var GBL_ROW_DELIMITER = String.fromCharCode(15);
var __gbl_m_bPageLoaded = false;


window.onload = __gbl_Page_OnLoad;

function __gbl_ClientAPIEnabled()
{
	return typeof(gbl) != 'undefined';
}


function __gbl_Page_OnLoad()
{
	if (__gbl_ClientAPIEnabled())
	{
		var sLoadHandlers = gbl.getVar('__gbl_pageload');
		if (sLoadHandlers != null)
			eval(sLoadHandlers);
	}
	__gbl_m_bPageLoaded = true;
}

function __gbl_KeyDown(iKeyCode, sFunc, e)
{
	if (e == null)
		e = window.event;

	if (e.keyCode == iKeyCode)
	{
		eval(unescape(sFunc));
		return false;
	}
}

function __gbl_bodyscroll() 
{
	var oF=document.forms[0];	
	if (__gbl_ClientAPIEnabled() && __gbl_m_bPageLoaded)
		oF.ScrollTop.value=gbl.dom.getByTagName("body")[0].scrollTop;
}

function __gbl_setScrollTop(iTop)
{
	if (__gbl_ClientAPIEnabled())
	{
		if (iTop == null)
			iTop = document.forms[0].ScrollTop.value;
	
		var sID = gbl.getVar('ScrollToControl');
		if (sID != null && sID.length > 0)
		{
			var oCtl = gbl.dom.getById(sID);
			if (oCtl != null)
			{
				iTop = gbl.dom.positioning.elementTop(oCtl);
				gbl.setVar('ScrollToControl', '');
			}
		}
		gbl.dom.getByTagName("body")[0].scrollTop = iTop;
	}
}

//Focus logic
function __gbl_SetInitialFocus(sID)
{
	var oCtl = gbl.dom.getById(sID);	
	if (oCtl != null && __gbl_CanReceiveFocus(oCtl))
		oCtl.focus();
}	

function __gbl_CanReceiveFocus(e)
{
	//probably should call getComputedStyle for classes that cause item to be hidden
	if (e.style.display != 'none' && e.tabIndex > -1 && e.disabled == false && e.style.visible != 'hidden')
	{
		var eParent = e.parentElement;
		while (eParent != null && eParent.tagName != 'BODY')
		{
			if (eParent.style.display == 'none' || eParent.disabled || eParent.style.visible == 'hidden')
				return false;
			eParent = eParent.parentElement;
		}
		return true;
	}
	else
		return false;
}

//Max/Min Script
function __gbl_ContainerMaxMin_OnClick(oLnk, sContentID)
{
	var oContent = gbl.dom.getById(sContentID);
	if (oContent != null)
	{
		var oBtn = oLnk.childNodes[0];
		var sContainerID = oLnk.getAttribute('containerid');
		var sCookieID = oLnk.getAttribute('cookieid');
		var sCurrentFile = oBtn.src.toLowerCase().substr(oBtn.src.lastIndexOf('/'));
		var sMaxFile;
		var sMaxIcon;
		var sMinIcon;

		if (gbl.getVar('min_icon_' + sContainerID))
			sMinIcon = gbl.getVar('min_icon_' + sContainerID);
		else
			sMinIcon = gbl.getVar('min_icon');

		if (gbl.getVar('max_icon_' + sContainerID))
			sMaxIcon = gbl.getVar('max_icon_' + sContainerID);
		else
			sMaxIcon = gbl.getVar('max_icon');

		sMaxFile = sMaxIcon.toLowerCase().substr(sMaxIcon.lastIndexOf('/'));

		var iNum = 5;
		if (oLnk.getAttribute('animf') != null)
			iNum = new Number(oLnk.getAttribute('animf'));
			
		if (sCurrentFile == sMaxFile)
		{
			oBtn.src = sMinIcon;				
			//oContent.style.display = '';
			gbl.dom.expandElement(oContent, iNum);
			oBtn.title = gbl.getVar('min_text');
			if (sCookieID != null)
			{
				if (gbl.getVar('__gbl_' + sContainerID + ':defminimized') == 'true')
					gbl.dom.setCookie(sCookieID, 'true', 365);
				else
					gbl.dom.deleteCookie(sCookieID);
			}
			else
				gbl.setVar('__gbl_' + sContainerID + '_Visible', 'true');
		}
		else
		{
			oBtn.src = sMaxIcon;				
			//oContent.style.display = 'none';
			gbl.dom.collapseElement(oContent, iNum);
			oBtn.title = gbl.getVar('max_text');
			if (sCookieID != null)
			{
				if (gbl.getVar('__gbl_' + sContainerID + ':defminimized') == 'true')
					gbl.dom.deleteCookie(sCookieID);
				else
					gbl.dom.setCookie(sCookieID, 'false', 365);				
			}
			else
				gbl.setVar('__gbl_' + sContainerID + '_Visible', 'false');			
		}
		
		return true;	//cancel postback
	}
	return false;	//failed so do postback
}

function __gbl_Help_OnClick(sHelpID)
{
	var oHelp = gbl.dom.getById(sHelpID);
	if (oHelp != null)
	{
		if (oHelp.style.display == 'none')
			oHelp.style.display = '';
		else
			oHelp.style.display = 'none';

		return true;	//cancel postback
	}
	return false;	//failed so do postback
}

function __gbl_SectionMaxMin(oBtn, sContentID)
{
	var oContent = gbl.dom.getById(sContentID);
	if (oContent != null)
	{
		var sMaxIcon = oBtn.getAttribute('max_icon');
		var sMinIcon = oBtn.getAttribute('min_icon');
		if (oContent.style.display == 'none')
		{
			oBtn.src = sMinIcon;				
			oContent.style.display = '';
			gbl.setVar(oBtn.id + ':exp', 1);
		}
		else
		{
			oBtn.src = sMaxIcon;				
			oContent.style.display = 'none';
			gbl.setVar(oBtn.id + ':exp', 0);
		}
		return true;	//cancel postback
	}
	return false;	//failed so do postback
}

//Drag N Drop
function __gbl_enableDragDrop()
{
	var aryConts = gbl.getVar('__gbl_dragDrop').split(";");	
	var aryTitles;

	for (var i=0; i < aryConts.length; i++)
	{
		aryTitles = aryConts[i].split(" ");
		if (aryTitles[0].length > 0)
		{			
			var oCtr = gbl.dom.getById(aryTitles[0]);
			var oTitle = gbl.dom.getById(aryTitles[1]);
			if (oCtr != null && oTitle != null)
			{
				oCtr.setAttribute('moduleid', aryTitles[2]);
				gbl.dom.positioning.enableDragAndDrop(oCtr, oTitle, '__gbl_dragComplete()', '__gbl_dragOver()');
			}	
		}
	}
}

var __gbl_oPrevSelPane;
var __gbl_oPrevSelModule;
var __gbl_dragEventCount=0;
function __gbl_dragOver()
{
	__gbl_dragEventCount++;
	if (__gbl_dragEventCount % 75 != 0)	//only calculate position every 75 events
		return;
	
	var oCont = gbl.dom.getById(gbl.dom.positioning.dragCtr.contID);

	var oPane = __gbl_getMostSelectedPane(gbl.dom.positioning.dragCtr);
		
	if (__gbl_oPrevSelPane != null)	//reset previous pane's border
		__gbl_oPrevSelPane.pane.style.border = __gbl_oPrevSelPane.origBorder;

	if (oPane != null)
	{		
		__gbl_oPrevSelPane = oPane;
		oPane.pane.style.border = '4px double ' + GBL_HIGHLIGHT_COLOR;
		var iIndex = __gbl_getPaneControlIndex(oCont, oPane);

		var oPrevCtl;
		var oNextCtl;
		for (var i=0; i<oPane.controls.length; i++)
		{
			if (iIndex > i && oPane.controls[i].id != oCont.id)
				oPrevCtl = oPane.controls[i];
			if (iIndex <= i && oPane.controls[i].id != oCont.id)
			{
				oNextCtl = oPane.controls[i];
				break;
			}
		}			
		
		if (__gbl_oPrevSelModule != null)
			gbl.dom.getNonTextNode(__gbl_oPrevSelModule.control).style.border = __gbl_oPrevSelModule.origBorder;
			

		if (oNextCtl != null)
		{
			__gbl_oPrevSelModule = oNextCtl;
			gbl.dom.getNonTextNode(oNextCtl.control).style.borderTop = '5px groove ' + GBL_HIGHLIGHT_COLOR;
		}
		else if (oPrevCtl != null)
		{
			__gbl_oPrevSelModule = oPrevCtl;
			gbl.dom.getNonTextNode(oPrevCtl.control).style.borderBottom = '5px groove ' + GBL_HIGHLIGHT_COLOR;
		}
	}
}

function __gbl_dragComplete()
{
	var oCtl = gbl.dom.getById(gbl.dom.positioning.dragCtr.contID);
	var sModuleID = oCtl.getAttribute('moduleid');
	
	if (__gbl_oPrevSelPane != null)
		__gbl_oPrevSelPane.pane.style.border = __gbl_oPrevSelPane.origBorder;

	if (__gbl_oPrevSelModule != null)
		gbl.dom.getNonTextNode(__gbl_oPrevSelModule.control).style.border = __gbl_oPrevSelModule.origBorder;
		
	var oPane = __gbl_getMostSelectedPane(gbl.dom.positioning.dragCtr);
	var iIndex;
	if (oPane == null)
	{
		var oPanes = __gbl_Panes();
		for (var i=0; i<oPanes.length; i++)
		{
			if (oPanes[i].id == oCtl.parentNode.id)
				oPane = oPanes[i];
		}
	}	
	if (oPane != null)
	{
		iIndex = __gbl_getPaneControlIndex(oCtl, oPane);
		__gbl_MoveToPane(oPane, oCtl, iIndex);

		gbl.callPostBack('MoveToPane', 'moduleid=' + sModuleID, 'pane=' + oPane.paneName, 'order=' + iIndex * 2); 
	}
}

function __gbl_MoveToPane(oPane, oCtl, iIndex)
{

	if (oPane != null)
	{
		var aryCtls = new Array();
		for (var i=iIndex; i<oPane.controls.length; i++)
		{
			if (oPane.controls[i].control.id != oCtl.id)
				aryCtls[aryCtls.length] = oPane.controls[i].control;

			gbl.dom.removeChild(oPane.controls[i].control);
		}
		gbl.dom.appendChild(oPane.pane, oCtl);
		oCtl.style.top=0;
		oCtl.style.left=0;
		oCtl.style.position = 'relative';
		for (var i=0; i<aryCtls.length; i++)
		{
			gbl.dom.appendChild(oPane.pane, aryCtls[i]);
		}
		__gbl_RefreshPanes();
	}
	else
	{
		oCtl.style.top=0;
		oCtl.style.left=0;
		oCtl.style.position = 'relative';
	}
}

function __gbl_RefreshPanes()
{
	var aryPanes = gbl.getVar('__gbl_Panes').split(';');
	var aryPaneNames = gbl.getVar('__gbl_PaneNames').split(';');
	__gbl_m_aryPanes = new Array();
	for (var i=0; i<aryPanes.length; i++)
	{
		if (aryPanes[i].length > 0)
			__gbl_m_aryPanes[__gbl_m_aryPanes.length] = new __gbl_Pane(gbl.dom.getById(aryPanes[i]), aryPaneNames[i]);
	}
}

var __gbl_m_aryPanes;
var __gbl_m_aryModules;
function __gbl_Panes()
{
	if (__gbl_m_aryPanes == null)
	{
		__gbl_m_aryPanes = new Array();
		__gbl_RefreshPanes();
	}
	return __gbl_m_aryPanes;
}

function __gbl_Modules(sModuleID)
{
	if (__gbl_m_aryModules == null)
		__gbl_RefreshPanes();
	
	return __gbl_m_aryModules[sModuleID];
}

function __gbl_getMostSelectedPane(oContent)
{
	var oCDims = new gbl.dom.positioning.dims(oContent);
	var iTopScore=0;
	var iScore;
	var oTopPane;
	for (var i=0; i<__gbl_Panes().length; i++)
	{
		var oPane = __gbl_Panes()[i];
		var oPDims = new gbl.dom.positioning.dims(oPane.pane);
		iScore = gbl.dom.positioning.elementOverlapScore(oPDims, oCDims);
		
		if (iScore > iTopScore)
		{
			iTopScore = iScore;
			oTopPane = oPane;
		}
	}
	return oTopPane;
}

function __gbl_getPaneControlIndex(oContent, oPane)
{
	if (oPane == null)
		return;
	var oCDims = new gbl.dom.positioning.dims(oContent);
	var oCtl;
	if (oPane.controls.length == 0)
		return 0;
	for (var i=0; i<oPane.controls.length; i++)
	{
		oCtl = oPane.controls[i];
		var oIDims = new gbl.dom.positioning.dims(oCtl.control);
		if (oCDims.t < oIDims.t)
			return oCtl.index;
	}
	if (oCtl != null)
		return oCtl.index+1;
	else
		return 0;
}

//Objects
function __gbl_Pane(ctl, sPaneName)
{
	this.pane = ctl;
	this.id = ctl.id;
	this.controls = new Array();
	this.origBorder = ctl.style.border;
	this.paneName = sPaneName;
	
	var iIndex = 0;
	var strModuleOrder='';
	for (var i=0; i<ctl.childNodes.length; i++)
	{
		var oNode = ctl.childNodes[i];
		if (gbl.dom.isNonTextNode(oNode))	
		{
			if (__gbl_m_aryModules == null)
				__gbl_m_aryModules = new Array();

			//if (oNode.tagName == 'A' && oNode.childNodes.length > 0)
			//	oNode = oNode.childNodes[0];	//GBL now embeds anchor tag 
				
			var sModuleID = oNode.getAttribute('moduleid');
			if (sModuleID != null && sModuleID.length > 0)
			{
				strModuleOrder += sModuleID + '~';
				this.controls[this.controls.length] = new __gbl_PaneControl(oNode, iIndex);
				__gbl_m_aryModules[sModuleID] = oNode.id;
				iIndex+=1;
			}
		}
	}
	this.moduleOrder = strModuleOrder;

}

function __gbl_PaneControl(ctl, iIndex)
{
	this.control = ctl;
	this.id = ctl.id;
	this.index = iIndex;
	this.origBorder = ctl.style.border;
	
}

function __gbl_SetUrl(url, ctlID)
{
    var o=document.getElementById(ctlID);
    o.value=url;
    //o.focus(); 	
}

var help_topic_desc="";
var help_topic_desc0 = "\<div align='right' style='cursor: pointer; cursor: hand;line-height=150%;color:#999999' onclick='sw_help_topic()'>\——点击此处，查阅更多关于“%%%%%%”的内容介绍\&nbsp;&nbsp</div>";
var help_topic_desc0_parameter = "";
var help_topic_title = "";
var help_topic_init = 0;
var help_particular_nav = "<br>　　如需了解有关“%%%%%%”更详细的信息，请单击<a target='blank' onclick='blur()' href='%%%URL%%%' title='%%%%%%'>这里</a>。";	// 详细帮助导航
var help_particular_url = "";				// 详细帮助的URL
var help_particular_title = "";				// 详细帮助的title

help_particular_url = "../help/help.aspx?location=";
help_particular_url0 = "../help/help.aspx";
var add_arr = new Array();



function sw_help_topic_init(title)
{
	var obj = document.getElementById("help_topic");
    var obj_icon = document.getElementById("help_topic_icon");
	help_topic_title = obj_icon.innerHTML;
	help_topic_desc = obj.innerHTML;
	help_topic_desc0_parameter = title;

	
	// 收缩后显示的内容
	help_topic_desc0 = help_topic_desc0.replace("%%%%%%", help_topic_desc0_parameter);

	
	// 帮助导航
	help_particular_nav = help_particular_nav.replace("%%%%%%", title);
	help_particular_nav = help_particular_nav.replace("%%%%%%", title);
	str_href= document.location.pathname;
	if (add_arr[str_href] == null)
	{
		// 当前页面没有帮助
		help_particular_nav = help_particular_nav.replace("%%%URL%%%", help_particular_url0);
	}
	else
	{
		// 当前页面有帮助
		help_particular_nav = help_particular_nav.replace("%%%URL%%%", add_arr[str_href]);
	}

	// 标题样式更新
	obj_icon.className = "help_topic_title";


	sw_help_topic_ex(help_topic_init);
}

function sw_help_topic()
{               
	var obj = document.getElementById("help_topic");
        var obj_icon = document.getElementById("help_topic_icon");

	if (obj.style.height == "20px")
	{
		b_status = 1;
	}	
	else
	{
		b_status = 0;
	}
	

	sw_help_topic_ex(b_status);
}

function sw_help_topic_ex(b_status)
{
	var obj = document.getElementById("help_topic");
        var obj_icon = document.getElementById("help_topic_icon");

        if (b_status == 1)
        {       
		// 打开
                obj_icon.innerHTML = "- " + help_topic_title;
                obj.style.height = "";
		obj.innerHTML = help_topic_desc + help_particular_nav;
		obj.className = "help_topic_desc";
        }       
        else
        {
		// 关闭
                obj_icon.innerHTML = "+ " + help_topic_title;
                obj.style.height = "20px";
		
		obj.innerHTML = help_topic_desc0;
		obj.className = "help_topic_desc_hidden";
        }

	try 
	{
		parent.iframeResize();       
	}
	catch(e)
	{
	}
}

function insertFlash(elm, url, w, h)
{
    if (!document.getElementById(elm)) return;
    var str = '';
    str += '<object width="'+ w +'" height="'+ h +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
    str += '<param name="movie" value="'+ url +'">';
    str += '<param name="wmode" value="opaque">';
    str += '<param name="quality" value="autohigh">';
    str += '<embed width="'+ w +'" height="'+ h +'" src="'+ url +'" quality="autohigh" wmode="transparent" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/go/getflashplayer"></embed>';
    str += '</object>';
    document.getElementById(elm).innerHTML = str;
}


function insertFlvFlash(elm,source,text,file,w,h)
{
    if (!document.getElementById(elm)) return;
    var swf_width=w;
    var swf_height=h;
    var texts=text;
    var files=file;
    var str= '';
    var src=source;
    str +=('<object type="application/x-shockwave-flash"  width="'+ swf_width +'" height="'+ swf_height +'">');
    str +=('<param name="movie" value="'+src+'"?source='+file+'><param name="quality" value="high">');
    str +=('<param name="menu" value="false"><param name="allowFullScreen" value="true" />');
    str +=('</object>');
    document.getElementById(elm).innerHTML=str;    
}



function insertPictureFlash(elm,source,values,w,h)
{
    if (!document.getElementById(elm)) return;
    var swf_width=w;
    var swf_height=h;
    var str= '';
    var src=source;
    str +=('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+ swf_width +'" height="'+ swf_height +'">');
    str +=('<param name="movie" value="'+src+'"><param name="quality" value="high">');
    str +=('<param name="wmode" value="transparent">');
    str +=('<param name="FlashVars" value="'+values+'">');
    str +=('<embed src="'+src+'" quality="high"  width="'+ swf_width +'" height="'+ swf_height +'" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    str +=('</object>');
    document.getElementById(elm).innerHTML=str;    
}

function insertHelpFlash(elm,source)
{
    if (!document.getElementById(elm)) return;
    var swf_width=790;
    var swf_height=450;
    var str= '';
    var src=source;
    str +=('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+ swf_width +'" height="'+ swf_height +'">');
    str +=('<param name="movie" value="'+src+'"><param name="quality" value="high">');
    str +=('<param name="wmode" value="transparent">');
    str +=('<embed src="'+src+'" quality="high"  width="'+ swf_width +'" height="'+ swf_height +'" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    str +=('</object>');
    document.getElementById(elm).innerHTML=str;    
}


//*******************oliver新添*********************************************
function SelectAllCheckboxes(spanChk,gvSelected){
 　var oItem = spanChk.children;
 　var theBox=(spanChk.type=="checkbox")?spanChk :panChk.children.item[0];
 　xState=theBox.checked;
 　elm=theBox.form.elements;
 　for(i=0;i<elm.length;i++)
 　 　if(elm[i].type=="checkbox" && elm[i].id!=theBox.id && elm[i].id.indexOf(gvSelected)!=-1)
 　 　 { 　　
 　 　 　   if(elm[i].checked!=xState)
 　 　 　    　　elm[i].click(); 　
 　 　 } 
} 

function __doPostBack_Ex(eventTarget, eventArgument) 
{
    var theform;
    if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
        theform = document.forms[0];
    }
    else {
        theform = document.forms[0];
    }

    if(!theform.__EVENTTARGET)
    {            
        theform.appendChild(document.createElement("<input type='hidden' name='__EVENTTARGET'>"));
    }
    
    if(!theform.__EVENTARGUMENT)
    {            
        theform.appendChild(document.createElement("<input type='hidden' name='__EVENTARGUMENT'>"));                        
    }
    
    theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
    theform.__EVENTARGUMENT.value = eventArgument;
    if ((typeof(theform.onsubmit) == "function")) 
    {
//        if(theform.onsubmit()!=false)
//        {
            theform.submit();    
//        }
    }
    else
    {            
        theform.submit();    
    }
    
    function __doPostBack(eventTarget, eventArgument)
    {
        __doPostBack_Ex(eventTarget, eventArgument);
    }
    

}

function OpenModalWindow(url,index,width,height){ 
     var res="";
     res=window.showModalDialog(url,'window','dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;status:no;dialogHide:true;help:no;scroll:no');      
    if(res!="" && res!=null && index>=0) {     
        __doPostBack_Ex('Parameters', index + res)
    }
}

//********************************************************
var popImage;
function ShowImageFiles(portal,id)
{
    var popImage=new Popup({ contentType:1,isReloadOnClose:false,width:580,height:480,prefix:"image"});
    popImage.setContent("contentUrl","/Modules/FileManagerModule/FileExplorer.aspx?type=iframe&portalname=" +portal +"&controlid=" + id);
    popImage.setContent("title","图片选择");
    popImage.build();
    popImage.show();
}


function sell()
{
    if (!IsAuthenticated())
    {
        alert("需要登录!");
        return;
    }    

    var url;
    AjaxService('/admin/Service.asmx/GetSellUrlByUserName',false,function(data){url=data.d;},"","json");
    
    if (url=="")
    {
        dialogCreateSite();
    }
    else
    {
        window.location.href=url;
    }        

}

function showtoolsbar()
{
    $("#opentoolsbar").hide();
    $("#toolsbar").show();
    $.cookie("showtoolsbar","1",{expires: 1000});    
}

function hidetoolsbar()
{
    $("#opentoolsbar").show();
    $("#toolsbar").hide();
    $.cookie("showtoolsbar","0",{expires: 1000});    

}

function goManager()
{
        window.location = "http://" + window.location.host + "/Manager/Default.aspx";
}

function RegularUrl(url,key,value)
{    
   var querystart = url.toString().indexOf("?");
    if(querystart < 0  )
    {
        url +="?"+key+"="+value;
    }
    else    if (querystart==url.length-1)
    {
        url +=key+"="+value;
    }
    else
    {
        var Re = new RegExp(key+"=[^\\s&#]*","gi");
        if (Re.test(url))
        url=url.toString().replace(Re,key+"="+value);
        else
        url += "&"+key+"="+value;
    }
    return url;
} 

　　String.format = function() {
　　 if( arguments.length == 0 )
　　 return null;
　　 var str = arguments[0];
　　 for(var i=1;i<arguments.length;i++) {
　　 var re = new RegExp('\\{' + (i-1) + '\\}','gm');
　　 str = str.replace(re, arguments[i]);
　　 }
　　 return str;
　　} 