﻿
function showAppNET (
	appName,
	page,
	initialPage,
	loadingPage)
{
	goTo ("Menu_Banner", "page_Menu_Side_Top.aspx?AppName='" + appName + "'");
	goTo ("Instance_Banner", "../page_Blank_Side.aspx");
	goTo ("Instance", "../page_Blank_Side.aspx");

	//goTo ("Tab", "../page_Blank.aspx");
	goTo ("General", "page_Menu_General.aspx?AppID='-1'");

	goTo ("Content", initialPage);
	goTo ("Topic_Banner", "../topics/page_Topics_Banner.aspx?AppName='" + appName + "'");
	goTo ("Topic", page);   

	changeRows("Left", 0);
	if (typeof (loadingPage) == 'undefined'
		|| loadingPage == null
		|| loadingPage == '')
	{
		changeRows ("Right", 1);
	}
	else
	{
		goTo ('Content_Right', loadingPage);
		changeRows ("Right", 5);
	}
	return null;
}

function goTo (target, targetURL) 
{
   if ((target && targetURL) && (target.length>0) && (targetURL.length>0)) 
   {
		if ((target=="_new") || (target=="_self")) 
		{
 			this.location.replace(targetURL);
		} 
		else if (target=="_parent") 
		{
			if (document.parentWindow) 
			{
   				document.parentWindow.document.location.replace(targetURL);
   			} 
   			else if (parent.frames) 
   			{
   				parent.location.replace(targetURL);
   			}
		} 
		else if (target=="_top") 
		{
			window.document.location.replace (targetURL);
		} 
		else 
		{
			if (document.parentWindow) 
			{
				if (top.frames[target])
				{
					top.frames[target].location.replace(targetURL);
				}
			} 
			else if (parent.frames) 
			{
				if (parent.frames[target])
				{
	   				parent.frames[target].location.replace(targetURL);
	   			}
		    }	
		}
   }
   return null;
}

function changeRows (
	targetFrame,
	iType)
{
  /* iType values:
  * Left Frame:
  * 0 - All frames visible
  * 1 - Topic frame max, all other hidden
  * Right Frame:
  * 0 - Content, tab and menu frames visible
  * 1 - Content visible; tab, menu frames hidden
  * 2 - Content and menu frames visible
  */
   var r;
   if (targetFrame && targetFrame.length>0)
   {
      if (targetFrame == "Left")
      {
			if (iType == 0) r = "45,20,*,0,0,0";		// Maximise Topic Frame
			if (iType == 1) r = "45,20,275,20,*,0";      // Show all frames
      }
      else if (targetFrame == "Right")
      {
 		 if (iType == 0) r = "45,53,20,*,17";	// Show all frames
 		 if (iType == 1) r = "45,0,0,*,17";		// Maximise Content Frame
		 if (iType == 2) r = "45,0,20,*,17";	// Show only menu and content frames
		 if (iType == 3) r = "45,33,20,*,17";	// Tab size minus 20 (to exclude Version div)
		 if (iType == 4) r = "45,60,0,*,17";	
		 if (iType == 5) r = "45,0,0,*,17";		// Maximise Content_Right Frame (Indicate loading progress).
      }      
		if (document.parentWindow) 
		{
			if (top.frames[targetFrame])
			{
				top.frames[targetFrame].rows = r;
				if (iType == 5)
				{
					if (top.frames['Views']) top.frames['Views'].cols = "0%, 0%, 100%";
				}
				else // For all other iTypes show Content frame 100% again.
				{
					if (top.frames['Views']) top.frames['Views'].cols = "0%, 100%, 0%";
				}
			}
			else
			{
				var url = document.location.href;
				url = url.substring (8, url.lastIndexOf ('/'));
				if (top.frames["Resizer"])
				{
					top.frames["Resizer"].location.replace ('http://' + url + '/../Resizer.aspx?targetFrame=' + targetFrame + '&iType=' + iType);
				}
			}
		}
		else if (parent.document && parent.document.getElementById) 
		{
			parent.document.getElementById(targetFrame).rows = r;
			if (iType == 5)
			{
				if (parent.document.getElementById('Views')) parent.document.getElementById('Views').cols = "0%, 0%, 100%";
			}
			else // For all other iTypes show Content frame 100% again.
			{
				if (parent.document.getElementById('Views')) parent.document.getElementById('Views').cols = "0%, 100%, 0%";
			}
	   }
		return true;
    } 
	else 
	{
        return false;
    }
}

function changeCols (targetFrame, iType)
{
/* iType values:
 * 0 - Content visible
 * 1 - Content hidden
 */
/*var c="0,100%,0";
var sCols;

   //if (document.parentWindow) sCols = document.parentWindow.parent.document.Script.frames["Views"].cols;
   //if (sCols=="6%,0%,94%") c="0,100%,0";
   if (iType==0) c="0,100%,0";
   if (iType==1) c="6%,0,94%";

   if (targetFrame && targetFrame.length>0) 
   { 
      if (document.parentWindow) 
      {
      alert ('1');
		document.parentWindow.parent.document.Script.frames[targetFrame].cols = c;
	  }
      else if (parent.document && parent.document.getElementById)
      { 
      alert ('2');
		parent.document.getElementById(targetFrame).cols = c;
	  }

      if (c=="0,100%,0") 
      {
      alert ('3');
		if (document.parentWindow) 
		{
		alert ('4');
			document.parentWindow.parent.document.Script.frames["Content_Right"].location.replace ("<%=sFilePath%>/page_Blank.htm");
		}
		else if (parent.frames) 
		{
		alert ('5');
			parent.frames["Content_Right"].location.replace("<%=sFilePath%>/page_Blank.htm");
		}
      }
      return true;
   } else {
      return false;
   }*/
}

function getSourceElement(e)
{
	if (window.event)
	{
		return window.event.srcElement;
	}
	else if (e && e.target)
	{
		if (typeof e.target.nodeType == 'undefined')
		{
			return e.target;
		}
		else if (e.target.nodeType == 3)
		{
			return e.target.parentNode;
		}
		else
		{
			return e.target;
		}
	}
}


function MM_findObj(n, d)
{
	//v4.01
	var p,i,x;
	if (!d)
		d=document;
	if ((p = n.indexOf("?")) > 0 && parent.frames.length)
	{
		d = parent.frames[n.substring(p+1)].document;
		n = n.substring(0,p);
	}
	if (!(x = d[n]) && d.all)
		x = d.all[n];
	for (i = 0; !x && i < d.forms.length; i++)
		x = d.forms[i][n];
	for (i = 0; !x && d.layers && i < d.layers.length; i++)
		x = MM_findObj(n,d.layers[i].document);
	if (!x && d.getElementById)
		x = d.getElementById(n);
	return x;
}


function clearTabs ()
{
	// Check for 'Tabs' frame as it won't exist when we are in the popup user picker.
	if (typeof (top.frames["Tab"]) != 'undefined')
	{
		top.frames["Tab"].document.getElementById("spnTabs").innerHTML = '';
	}
}


function addTab (
	tabIDOrScript,
	tabName,
	status)
{
	// Check for 'Tabs' frame as it won't exist when we are in the popup user picker.
	if (typeof (top.frames["Tab"]) == 'undefined')
	{
		return;
	}

	var gif = getTabGif (status);
	var cursor = getTabCursor (status);

	var onclick = null;
	if (status == 2) // 2 = disabled
	{
		onclick = '';
	}
	else
	{
		if (tabIDOrScript.indexOf ("btn") > -1)
		{
			onclick = 'var btn = top.Content.document.getElementById(\'' + tabIDOrScript + '\'); if (btn != null) { btn.click(); SelectTab(this); }';
		}
		else // It's a script
		{
			onclick = tabIDOrScript + ' SelectTab (this);';
		}
	}


	var tabs = top.frames["Tab"].document.getElementById("spnTabs");
	tabs.innerHTML += 
		'  <table cellSpacing="0" cellpadding="0" align="left" border="0">'
		+ '  <tbody>'
		+ '    <tr align="center">'
		+ '      <td width="116" height="29" class="tabStrip" style="cursor: ' + cursor + '; background-Image: ' + gif + '" onclick="' + onclick + '">'
		+ '<b>' + tabName + '</b>'
		+ '      </td>'
		+ '    </tr>'
		+ '	 </tbody>'
		+ '</table>';
}


function SelectTab (td)
{
	// Set the tab with the selected gif to an unselected gif.
	var spnTabs = td.parentElement.parentElement.parentElement.parentElement;
	for (var i = 0; i < spnTabs.children.length; i++)
	{
		var tdTab = spnTabs.children[i].firstChild.firstChild.firstChild;
		if (tdTab.style.backgroundImage == getTabGif (1))
		{
			tdTab.style.backgroundImage = getTabGif (0);
			td.style.cursor = getTabCursor (0);
		}
	}

	// Set the current tab to selected gif.
	td.style.backgroundImage = getTabGif (1);
	td.style.cursor = getTabCursor (1);
}


function clearToolbarButtons ()
{
	// Check for 'Tabs' frame as it won't exist when we are in the popup user picker.
	if (typeof (top.frames["Tab"]) != 'undefined')
	{
		top.frames["Tab"].document.getElementById("spnToolbar").innerHTML = '';
	}
}


// Builds up the HTML of a button and adds it to the toolbar's innerHTML.
function addToolbarButton (buttonIDOrScript, buttonName, status)
{
	// Check for 'Tabs' frame as it won't exist when we are in the popup user picker.
	if (typeof (top.frames["Tab"]) == 'undefined')
	{
		return;
	}

	// The script that must get executed when the button is clicked.
	var onclick = '';
	if (buttonIDOrScript.indexOf ("btn") > -1)
	{
		onclick = 'top.Content.document.getElementById(\'' + buttonIDOrScript + '\').click();';
	}
	else // It's a script.
	{
		onclick = buttonIDOrScript;
	}

	var toolbar = top.frames['Tab'].document.getElementById('spnToolbar');
	toolbar.innerHTML +=
		'<input type="button" id="' + buttonIDOrScript + '"'
		+ ' onclick="' + onclick + '"'
		+ ' class="toolbar tbButton"'
		+ ' style="cursor: hand"'
		+ ' value="' + buttonName + '"'
		+ '>';
	
	// Put a space after the worklist navigation buttons.
	if (buttonIDOrScript == 'btnWorkListNext')
	{
	    toolbar.innerHTML += '&nbsp;&nbsp;';
	}

	
	if (status == 0)
	{
		status = false;
	}
	else if (status == 1)
	{
		status = true;
	}
	toggleToolbarButton (buttonIDOrScript, status);
}


function toggleToolbarButton (
	buttonName,
	enabled)
{
	var disabled = !enabled;
	var spnToolbar = top.frames["Tab"].document.getElementById("spnToolbar");
	for (var i = 0; i < spnToolbar.children.length; i++)
	{
		if (buttonName == spnToolbar.children[i].id)
		{
			spnToolbar.children[i].disabled = disabled;
			return;
		}
	}
}



function getTabGif (status)
{
	var gif = 'url(WebResource.axd?d=TMh7Hdq4BXsVJUzFvkCs-a_h2bXH6Mnb9hRPyay1scPKqs1bcGTKMe-bWQ2hboqOqAN7Nrv7bHI5RSJnliQLEA2&t=637419021180000000)';
	if (status == 0)
	{
		gif = 'url(WebResource.axd?d=TMh7Hdq4BXsVJUzFvkCs-a_h2bXH6Mnb9hRPyay1scP5Ua2Z8JzV8tz8IAB28bujmdp84XHKCmjoPrWPskcamw2&t=637419021180000000)';
	}
	else if (status == 1)
	{
		gif = 'url(WebResource.axd?d=TMh7Hdq4BXsVJUzFvkCs-a_h2bXH6Mnb9hRPyay1scPKqs1bcGTKMe-bWQ2hboqOqAN7Nrv7bHI5RSJnliQLEA2&t=637419021180000000)';
	}
	else if (status == 2)
	{
		gif = 'url(WebResource.axd?d=TMh7Hdq4BXsVJUzFvkCs-a_h2bXH6Mnb9hRPyay1scNyQEwamDHdOh4YJTZTGYkfjgG2gIrwMykL12fRgV3hqQ2&t=637419021180000000)';
	}
	return gif;
}


function getTabCursor (status)
{
	var cursor = "default";
	if (status == 0)
	{
		cursor = "hand";
	}
	else if (status == 1)
	{
		cursor = "hand";
	}
	else if (status == 2)
	{
		cursor = "default";
	}
	return cursor;
}

function reloadBanner (
	projectVersionID)
{
	document.parentWindow.parent.frames ('IframeHeader').document.location 
		= document.parentWindow.parent.frames ('IframeHeader').document.location 
		+ "&projectVersionID=" + projectVersionID;
}

function MakePrinterFriendly()
{
    var isOpera = navigator.userAgent.indexOf('Opera') > -1;
    var isIE = navigator.userAgent.indexOf('MSIE') > 1 && !isOpera
		 || navigator.userAgent.indexOf('Trident/') > 1 && !isOpera;
    var isMoz = navigator.userAgent.indexOf('Mozilla/5.') == 0 && !isOpera;
    var isMozFirefox = isMoz && navigator.userAgent.indexOf('Firefox') > -1;

    // First resize all textareas to fit their content.
    var tAreas = document.getElementsByTagName('textarea');
    for (var t = 0; t < tAreas.length; t++)
    {
        tAreas[t].style.height = tAreas[t].scrollHeight;
        if (isMoz)
        {
            tAreas[t].style.height = tAreas[t].scrollHeight + 10; // Add few px to get rid of scrollbar.
        }
        tAreas[t].style.overflow = 'hidden'; // Hide V-scrollbar
    }

    if (typeof (printPreview) != 'undefined')
    {
        printPreview();
    }
}