﻿function __CGlobalMaster( clientID )
{
	this.clientID = clientID;
}

__CGlobalMaster.prototype.ClickCommand = function(cmdName, cmdValue)
{
	$get(this.clientID+"_hidCommand").value = cmdName;
	$get(this.clientID+"_hidValue").value = cmdValue==null ? "" : cmdValue;
	eval(unescape($get(this.clientID+"_lbCommand").href));
}
__CGlobalMaster.prototype.ExecCommand_Begin = function( args )
{
	var but = args.get_item();
	var cmd = but.get_value();
	var wwWin = window.screen.availWidth - 80;
	var hhWin = window.screen.availHeight - 80;
//alert(cmd);
	if (cmd=="Home")
	{
		document.location = "/sites/" + g_masterpage.topSiteToken;
	}
	else if (cmd.indexOf("Skin-")==0)
	{
		this.ClickCommand( "ChangeSkin", cmd.substring("Skin-".length) );
	}
	else if (cmd=="Sites")
	{
		document.location = "/ManageSites/";
	}
	else if (cmd=="SiteDesigner")
	{
		var ss = document.URL;
		var i1 = ss.toLowerCase().indexOf("/sites/");
		var i2 = ss.indexOf("?");
		ss = (i2==-1) ? ss.substring(i1) : ss.substring(i1,i2);

		var url = "/Panels/SiteDesigner/default.aspx?currentpage=" + ss;
		window.open(url, "_blank", "width="+wwWin+"px,height="+hhWin+"px,location=no,menubar=no,toolbar=no,resizable=yes");
	}
	else if (cmd=="CloneSite")
	{
		var args = new Function();
		args.obj = this;
		args.response = null;
		args.callerwindow = window;
		args.callback = "Global_CloneSite_Done";
		var url = g_global.currentProtocolAndHost + "/Panels/CloneSite/Default.aspx" + 
				"?clientID=" + this.clientID +
				"&sessid=" + g_global.sessionID +
				"&forcessl=y";
		//var bh = Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close;
		g_global.OpenWindow( url, args, 720,560, "<strong>Clone Site</strong>"); //, bh);
		
		
	/*	
		var url = g_global.currentProtocolAndHost + "/Panels/CloneSite/Default.aspx" + 
		"?clientID=" + clientID +
		"&sessid=" + g_global.sessionID +
		"&forcessl=y" + 
		"&callback=Global_CloneSite_Done" + 
		"&tm=" + (new Date()).getTime();
	g_global.OpenAJAXModalWindow(clientID,url,"Clone Site",700,500);
	*/
		//Global_CloneSite(this.clientID);
	}
	else if (cmd=="Manage_OU")
	{
		Global_Call_ManageOU();
		
		/*
		var args = new Function();
		args.obj = this;
		args.response = null;
		args.callerwindow = window;
		args.callback = "eBallots_EditOnDetails_Done";
		var url = g_global.currentProtocolAndHost + "/Membership/ManageOU/default.aspx" + 
				"?clientID=" + this.clientID +
				"&sessid=" + g_global.sessionID +
				"&forcessl=y" + 
				"&instanceID=" + this.instanceID + 
				"&ballotID=" + this.ballotID + 
				"&itemID=" + itemID + 
				"&scope=" + scope;
		var bh = Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close;
		g_global.OpenWindow( url, args, 720,560, "<strong>Manage Groups and Users</strong>", bh);
*/
	}
	else if (cmd=="Manage_Roles")
	{
		Global_Call_ManageRoles();
	}
	else if (cmd=="RunAs")
	{
		Global_RunAs(this.clientID);
	}
	else if (cmd=="RestoreUserID")
	{
		Global_RestoreUser(this.clientID);
	}
}
__CGlobalMaster.prototype.ExecCommand_End = function( args )
{
}




//------------------------------------------------
function Global_ResizeModalWindow(sender, args)
{
	try{	sender.get_contentFrame().contentWindow.Resize();	}catch(e){}
}
function Global_SetSkin_OnComplete(arg)
{
}
function Global_SetSkin_OnError(err){	alert("Error encountered on saving changes:\n\n" + g_global.GetAJAXErrorDetails(err));	}


//------------------------------------------------
function Global_Command_Click(sender, args)
{
    g_masterpage.ExecCommand_Begin(  args );
}
//------------------------------------------------
function Global_Call_ManageOU()
{
	try
	{
//		var args = new Function();
//		var url = g_global.currentProtocolAndHost + "/Membership/ManageOU/default.htm?forcessl=y";

		
		
		
		var bh = Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close;
		var args = new Function();
//		args.callback = "__CWiki_Commands_Callback"; //args.callerwindow.__CWiki_Commands_Callback";
		//		var url = g_global.currentProtocolAndHost + "/Membership/ManageOU/default.htm" +
		var url = g_global.currentProtocolAndHost + "/Membership/ManageOU/default.aspx" + 
			"?sessid=" + g_global.sessionID +
			"&forcessl=y";
		g_global.OpenWindow(url, args, 850, 580, "<strong>Groups and Users</strong>", bh);





//		window.showModalDialog(url, args, 'dialogWidth:850px; dialogHeight:580px; center:yes; edge:raised; resizable:yes; scroll:no; status:yes;'))
		
		
		
		/*
		if (window.showModalDialog(url, args, 'dialogWidth:850px; dialogHeight:580px; center:yes; edge:raised; resizable:yes; scroll:no; status:yes;'))
		{
		}
		*/
	}
	catch(e){}
}
//------------------------------------------------
function Global_Call_ManageRoles()
{
	try
	{
	/*
		var args = new Function();
		var url = g_global.currentProtocolAndHost + "/Membership/ManageRoles/default.htm?forcessl=y";
		if (window.showModalDialog(url, args, 'dialogWidth:850px; dialogHeight:580px; center:yes; edge:raised; resizable:yes; scroll:no; status:yes;'))
		{
		}
	*/
		var bh = Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close;
		var args = new Function();
		var url = g_global.currentProtocolAndHost + "/Membership/ManageRoles/default.aspx" +
			"?sessid=" + g_global.sessionID +
			"&forcessl=y";
		g_global.OpenWindow(url, args, 850, 580, "<strong>Roles and Users</strong>", bh);
	}
	catch(e){}
}
//------------------------------------------------
function Global_ChangeMode(clientID,mode)
{
	document.getElementById(clientID+"_hidCommand").value	= mode;
	eval( document.getElementById(clientID+"_lbCommand").href );
}
//------------------------------------------------
function Global_ResetPersonalization(clientID)
{
	if (confirm("You are about to resume all your personalized changes " + 
		"you've made so far under content (webparts, text) and layout on this page. " + 
		"Do you want to proceed and reset all personalizations?"))
	{
		document.getElementById(clientID+"_hidCommand").value	= "ResetPersonalization";
		eval( document.getElementById(clientID+"_lbCommand").href );
	}
}
//------------------------------------------------
function Global_RunAs(clientID)
{
	var url = g_global.currentProtocolAndHost + "/Panels/SelectPrincipal/default.htm?forcessl=y";
	var args = new Function();
	args.Mode = "OnlyUser";
	args.SiteScope = "AllSites";
	args.SelectionMode = "single";
	if (window.showModalDialog(url, args, 'dialogWidth:700px; dialogHeight:500px; center:yes; edge:raised; scroll:no; status:no;'))
	{
		document.getElementById(clientID+"_hidCommand").value = "RunAs";
		document.getElementById(clientID+"_hidValue").value = args.xRoot.selectSingleNode("I").getAttribute("id");
		eval( document.getElementById(clientID+"_lbCommand").href );
	}
}
//------------------------------------------------
function Global_RestoreUser(clientID)
{
	if (confirm("Do you want to restore original user's credentials?"))
	{
		document.getElementById(clientID+"_hidCommand").value = "RestoreUser";
		eval( document.getElementById(clientID+"_lbCommand").href );
	}
}
//------------------------------------------------
function Global_ChangePassword(returnUrl)
{
	window.location = "/Login_ChangePassword.aspx?forcessl=y&ReturnUrl=" + returnUrl;
}
//------------------------------------------------
function Global_DesignPage(clientID,siteID,pagePath)
{
//alert(clientID + "    " + siteID + "    " + pageID);
	var args = new Function();
	args.SiteID = siteID;
	args.PagePath = pagePath;
	var url = g_global.currentProtocolAndHost + "/Panels/SiteDesigner/default.aspx?forcessl=y";
	if (window.showModalDialog(url, args, 'dialogWidth:65em; dialogHeight:55em; center:yes; edge:raised; resizable:yes; scroll:no; status:yes;'))
	{
		//document.getElementById(clientID+"_hidCommand").value	= "Refresh";
		//document.getElementById(clientID+"_lbCommand").click();
	}
}
//------------------------------------------------
function Global_SiteDesigner(clientID,siteID,pagePath)
{
	var ww = window.screen.availWidth - 80;
	var hh = window.screen.availHeight - 80;
	var url = g_global.currentProtocolAndHost + 
			"/Panels/SiteDesignerAJAX/default.aspx?forcessl=y&ww="+ww+"&hh="+hh+"&siteID="+siteID+"&pagePath="+pagePath;

	window.open(url, "_blank", "width="+ww+"px,height="+hh+"px,location=no,menubar=no,toolbar=no,resizable=yes");


/*
	$get(clientID+"_lModalWinCaption").innerHTML = "Site Designer";
	
	var p = document.getElementById(clientID+"_panModal");
	p.style.height = "550px";
	p.style.width = "1000px";
	var fr = document.getElementById(clientID+"_ifrModal1");
//	fr.src = "./NewItem/default.aspx?type=" + type + 
//					"&sessid=" + document.getElementById("hidSessionID").value +
//					"&selItemPath=" + document.getElementById("hidSelectedItemPath").value;
//alert(document.getElementById(clientID+"_lbCallPopup")==null);
	g_global.FireMouseEvent( document.getElementById(clientID+"_lbCallPopup"), "click");
//alert(4);
*/
/*
//alert(clientID + "    " + siteID + "    " + pageID);
	var args = new Function();
	args.SiteID = siteID;
	args.PagePath = pagePath;
	if (window.showModalDialog("/Panels/SiteDesigner/default.aspx", args, 'dialogWidth:65em; dialogHeight:55em; center:yes; edge:raised; resizable:yes; scroll:no; status:yes;'))
	{
		//document.getElementById(clientID+"_hidCommand").value	= "Refresh";
		//document.getElementById(clientID+"_lbCommand").click();
	}
	*/
}
//------------------------------------------------
function Global_AskToLogout()
{
	return confirm('Do you want to logout?');
}
//------------------------------------------------
function Global_SysInfo(clientID)
{
	var args = new Function();
	var url = g_global.currentProtocolAndHost + "/Panels/SysInfo/default.htm?forcessl=y";
	if (window.showModalDialog(url, args, 'dialogWidth:780px; dialogHeight:580px; center:yes; edge:raised; resizable:yes; scroll:no; status:yes;'))
	{
	}
}
//------------------------------------------------
function Global_ViewStat()
{
	var args = new Function();
	var url = g_global.currentProtocolAndHost + "/Panels/SiteStatistics/default.htm?forcessl=y";
	if (window.showModalDialog(url, args, 'dialogWidth:900px; dialogHeight:700px; center:yes; edge:raised; resizable:yes; scroll:no; status:yes;'))
	{
	}
}
//------------------------------------------------
function Global_SetFocus(c)
{
	try{c.click();}catch(e){}
	try{c.focus();}catch(e){}
	try{c.select();}catch(e){}
}
//------------------------------------------------
function Global_SiteExplorer(clientID,siteID,pagePath)
{
//alert(clientID + "    " + siteID + "    " + pageID);
//	var args = new Function();
//	args.SiteID = siteID;
//	args.PagePath = pagePath;
//	if (window.showModalDialog("/Panels/SiteDesigner/default.aspx", args, 'dialogWidth:65em; dialogHeight:55em; center:yes; edge:raised; resizable:yes; scroll:no; status:yes;'))
//	{
		//document.getElementById(clientID+"_hidCommand").value	= "Refresh";
		//document.getElementById(clientID+"_lbCommand").click();
//	}
}


/*
function Global_CloneSite(clientID)
{
	var url = g_global.currentProtocolAndHost + "/Panels/CloneSite/Default.aspx" + 
		"?clientID=" + clientID +
		"&sessid=" + g_global.sessionID +
		"&forcessl=y" + 
		"&callback=Global_CloneSite_Done" + 
		"&tm=" + (new Date()).getTime();
	g_global.OpenAJAXModalWindow(clientID,url,"Clone Site",700,500);
}
*/
function Global_CloneSite_Done(clientID, res)
{
}