function HandleTabClick(ControlId, SetCookie) {
	// SetCookie is default=true
	if ( typeof(SetCookie)=="undefined" ) SetCookie=true;
	// if the document contain's a editor then don't allow tab switch before is has loaded.
	if (typeof(window.attachEvent)!="undefined") { // Only check for editor loaded in IE
		if ( SetCookie && document.frames["editor"] ) {
			if ( !document.frames["editor"].DocumentComplete ) return false;
		}
	}
	try {
		if ( document.ActiveTab ) {
			document.ActiveTab.style.display ='none';
			document.getElementById('active_' + document.ActiveTab.id).style.display='none';
		}

		document.ActiveTab = document.getElementById(ControlId);
		if ( document.ActiveTab ) {
			document.ActiveTab.style.display = 'block';
			document.getElementById('active_' + ControlId).style.display='inline';
		}
		
		//if ( SetCookie ) WriteCookie("ActiveTab", ObjectId+","+ControlId, 60);
	} catch (ex) {
		alert("HandleTabClick:\n"+ex);
	}
} // HandleTabClick

/*
if ( document.body ) {
	// Interact with the object even though it is not fully loaded.
	document.body.attachEvent("onreadystatechange", ReadyStateChange);
}
*/

if ( typeof(CreateEvent)=="function" ) CreateEvent(document.body, "readystatechange", ReadyStateChange);

function ReadyStateChange() {
	if ( document.readyState=="interactive" ) {
		SizeTabs();
	}
} // ReadyStateChange

var IsSizeTabsCalled=false;
//attachEvent("onload", SizeTabs);
if ( typeof(CreateEvent)=="function" ) CreateEvent(window, "load", SizeTabs);

function SizeTabs() {
	if ( !IsSizeTabsCalled ) {
		if (typeof(window.attachEvent)!="undefined") { // IE
			var DivArray=document.body.getElementsByTagName("DIV");
		} else { // Others
			var DivArray=document.body.getElementsByTagName("TABLE");
		}
		var length=DivArray.length;
		var MaxHeight=0;
		var MaxWidth=0;
		var HeightOffset=0;
		var	GsTabHeightSet=false;
		try {
			for (var i=0; i<length; i+=1) {
				if (DivArray[i].className=="GsTab" || DivArray[i].className=="GsTabBar" || DivArray[i].className=="GsButtons") {
					if ( MaxHeight<DivArray[i].offsetHeight ) MaxHeight=DivArray[i].offsetHeight;

					// Width is normaly 100% for the DIV tags
					// Because of this get width from first child
					var TmpWidth
					if (typeof(window.attachEvent)!="undefined") { // IE
						TmpWidth=DivArray[i].childNodes[0].offsetWidth;
						TmpWidth+=DivArray[i].childNodes[0].offsetLeft*2;
					} else { // Others
						if (typeof(DivArray[i].childNodes[0].childNodes[0].childNodes[0].childNodes[0])=="Object Text") { // Mozilla treats spaces as a childNode
							TmpWidth=DivArray[i].childNodes[0].childNodes[0].childNodes[0].childNodes[0].offsetWidth;
						} else {
							TmpWidth=DivArray[i].childNodes[0].childNodes[0].childNodes[0].childNodes[1].offsetWidth;
						}
						if (!GsTabHeightSet) {
							if (typeof(DivArray[i].childNodes[0].childNodes[0].childNodes[0].childNodes[0])=="Object Text") { // Mozilla treats spaces as a childNode
								HeightOffset=DivArray[i].childNodes[0].childNodes[0].childNodes[0].childNodes[0].offsetHeight;
							} else {
								HeightOffset=DivArray[i].childNodes[0].childNodes[0].childNodes[0].childNodes[1].offsetHeight;
							}
							if (DivArray[i].className=="GsTab")	GsTabHeightSet=true;
						}
					}

					if ( MaxWidth<TmpWidth ) {
						MaxWidth=TmpWidth;
						if (typeof(window.attachEvent)!="undefined") { // Only do this in IE, others browsers acting funny
							if (DivArray[i].className=="GsTabBar") MaxWidth+=5;
						}
					}
				}
			}
		} catch (ex) {
			alert("SizeTabs, step 1\n"+ex);
		}
		try {
			for (var i=0; i<length; i+=1) {
				if (DivArray[i].className=="GsTab") {
					DivArray[i].style.height=MaxHeight;

					if ( document.ActiveTab ) {
						if ( document.ActiveTab!=DivArray[i] ) DivArray[i].style.display="none";
					} else HandleTabClick(DivArray[i].id, false);
				}
			}
		} catch (ex) {
			alert("SizeTabs, step 2\n"+ex);
		}

		try {
			if (typeof(top.dialogHeight)!="undefined") { // Popup is a Modal
				var Height=parseInt(top.dialogHeight);
				var Width=parseInt(top.dialogWidth);
			} else { // Popup is a window
				if (typeof(window.attachEvent)!="undefined") { // IE
					var Height=parseInt(document.body.clientHeight);
					var Width=parseInt(document.body.clientWidth);
				} else { // Others
					var Height=parseInt(window.outerHeight);
					var Width=parseInt(window.outerWidth);
				}
			}

			// Getting Height, If Not IE, height was found in loop of table elements
			if (typeof(window.attachEvent)!="undefined") { // IE
				HeightOffset = document.body.scrollHeight;
			}

			if ( typeof(AutoSizeDisabled)=='undefined' ) {
				var adjustHeight=Height-document.body.offsetHeight;
				var adjustWidth=Width-document.body.offsetWidth;

				if (typeof(top.dialogHeight)!="undefined") { // Popup is a Modal
					Height=HeightOffset+adjustHeight;
				} else {
					if (typeof(window.attachEvent)!="undefined") {
						Height=HeightOffset+adjustHeight+80;
					} else {
						Height=HeightOffset+document.body.offsetHeight/2+60;
						if (navigator.userAgent.indexOf("Safari")>0) {
	//						Height-=60;
						}
					}
				}
				Width=MaxWidth+adjustWidth;
 
				if (typeof(top.dialogHeight)!="undefined") { // Popup is a Modal
					top.dialogWidth = Width+'px';
					top.dialogHeight = Height+'px';
				} else { // Popup is a window
//					if (typeof(window.attachEvent)!="undefined") { // IE
					if (navigator.userAgent.indexOf("Safari")>0) {
						top.resizeTo(Width, Height);
					} else {
						top.resizeTo(Width+40, Height);
					}
//					} else { // Others
//						window.outerWidth = Width;
//						window.outerHeight = Height;
//					}
				}
			}
		} catch (ex) {
			alert("SizeTabs, step 3\n"+ex);
		}
		try {
			// Place dialog in middle of the screen.
			if (typeof(top.dialogHeight)!="undefined") { // Popup is a Modal
				top.dialogLeft=parseInt(screen.availWidth/2)-parseInt(Width/2);
				top.dialogTop=parseInt(screen.availHeight/2)-parseInt(Height/2);
			} else { // Popup is a window
				if (typeof(window.attachEvent)!="undefined") { // IE
					top.moveTo(parseInt(screen.availWidth/2)-parseInt(Width/2),parseInt(screen.availHeight/2)-parseInt(Height/2));
				} else { // Others
					window.moveTo(parseInt(screen.availWidth/2)-parseInt(Width/2),parseInt(screen.availHeight/2)-parseInt(Height/2));
				}
			}
		} catch (ex) {
			alert("SizeTabs, step 4\n"+ex);
		}

		IsSizeTabsCalled=true;
	}
} // SizeTabs

/*
		From "SizeTabs" function
		if (typeof(TypeObjectId)!='undefined') {
			var WindowSizeString=new String(ReadCookie(TypeObjectId.replace("-", "")));
			if (WindowSizeString) { // use size cookie if it exists
				var SizeArr=WindowSizeString.split(",");
				if (SizeArr.length==4) {
					if ( parseInt(SizeArr[0]) && parseInt(SizeArr[1]) && parseInt(SizeArr[2]) && parseInt(SizeArr[3]) ) {
						top.dialogWidth	 = SizeArr[0];
						top.dialogHeight = SizeArr[1];
						top.dialogLeft   = SizeArr[2];
						top.dialogTop    = SizeArr[3];
						AutoSizeDisabled=true;
					}
				}
			}
			delete WindowSizeString;
		}

		// Show last active tab.
		var ActiveTab=new String(ReadCookie("ActiveTab"));
		if ( ActiveTab ) {
			var ActiveTabArray=ActiveTab.split(","); // Format=ObjectId+","+ControlId
			if ( ActiveTabArray.length==2 ) {
				// If object was the one last open
				// then set active tab
				// else reset cookie
				if ( (!ActiveTabArray[0] || ActiveTabArray[0]==ObjectId) && !document.frames["editor"] ) HandleTabClick(ActiveTabArray[1], false);
				else WriteCookie("ActiveTab", null, 1);
			}
		}
		delete ActiveTab;

attachEvent("onresize", ResizeWindow);
function ResizeWindow() {
	if (typeof(TypeObjectId)!='undefined') {
		if (document.forms(0).length>1) {
			// save settings in cookie
			WindowSizeString=top.dialogWidth+','+top.dialogHeight+','+top.dialogLeft+','+top.dialogTop;
			WriteCookie(TypeObjectId.replace("-", ""), WindowSizeString, 60);
		}
	 }
} // ResizeWindow
*/

