//--------------------------------------------------------
// File    : common.js 
// Purpose : Collection of common client-side scripts for
//           the SG Corporate Intranet. 
//--------------------------------------------------------

function OpenHelp(pcLink)
//--------------------------------------------------------
// function   : OpenHelp
// Purpose    : open a help file in a new popup window.
// Parameters : pcLink = URL or network path
//--------------------------------------------------------
{
	var lcWinType="menubar=no," +
				  "toolbar=no," +
				  "resizable=yes," +
				  "scrollbars=yes," +
				  "status=1," + 
				  "width=630," +
				  "height=500," +
				  "top=1," +
				  "left=1";
	var AppWin = window.open (pcLink,"",lcWinType);
}

function OpenSgContacts(pcLink)
//--------------------------------------------------------
// function   : OpenSgContacts
// Purpose    : open SG Contacts in a new popup window.
// Parameters : pcLink = URL or network path
//--------------------------------------------------------
{
	var lcWinType="menubar=no," +
				  "toolbar=no," +
				  "resizable=yes," +
				  "scrollbars=yes," +
				  "status=0," + 
				  "width=650," +
				  "height=435," +
				  "top=1," +
				  "left=1";
	var AppWin = window.open (pcLink,"",lcWinType);
}

function OpenContactEmail(pcUrl)
//--------------------------------------------------------
// function   : OpenContactEmail
// Purpose    : Open an SG Contact email address in a new 
//              popup window.
// Parameters : pcUrl = Exchnage URL.
//--------------------------------------------------------
{
	var lcWinType="menubar=no," +
				  "toolbar=no," +
				  "resizable=yes," +
				  "scrollbars=yes," +
				  "status=0," + 
				  "width=500," +
				  "height=200," +
				  "top=1," +
				  "left=1";
	var pcLink = "http://sgnt/SgContacts/GetSgContact.asp" +
			     "?url=" + pcUrl;
	var AppWin = window.open (pcLink,"",lcWinType);
}

function OpenDrillDown(pcLink)
//--------------------------------------------------------
// function   : OpenDrillDown
// Purpose    : open a drill down report in a new popup window.
// Parameters : pcLink = URL or network path
//--------------------------------------------------------
{
	var lcWinType="menubar=yes," +
				  "toolbar=no," +
				  "resizable=yes," +
				  "scrollbars=yes," +
				  "status=1," + 
				  "width=700," +
				  "height=500," +
				  "top=1," +
				  "left=1";
	var AppWin = window.open (pcLink,"",lcWinType);
}

function OpenLink(pcLink,pnBehavior)
//--------------------------------------------------------
// function   : OpenLink
// Purpose    : override default hyperlink behavior.
// Parameters : pcLink = URL or network path
// Parameters : pnBehavior = 1 to preserve browser history,
//                           2 to replace history
//--------------------------------------------------------
{
   if(pnBehavior == 1)
   {
       location.href = pcLink;
   }
   else
   {
       location.replace(pcLink);
   }
}

function ConfirmLink(pcMsg,pcLink,pnBehavior)
//--------------------------------------------------------
// function   : ConfirmLink
// Purpose    : ask user to confirm execution of link.
// Parameters : pcMsg = user prompt
// Parameters : pcLink = URL or network path
// Parameters : pnBehavior = 1 to preserve browser history,
//                           2 to replace history
//--------------------------------------------------------
{
	if(confirm(pcMsg))
	{
	   if(pnBehavior == 1)
	   {
	       location.href = pcLink;
	   }
	   else
	   {
	       location.replace(pcLink);
	   }
	}
}

function ShowHide(pcID, pnStatus)
//--------------------------------------------------------
// function   : ShowHide
// Purpose    : show or hide a block of html.
// Parameters : pcID = value for id attribute of an html tag
//              pnStatus = 1 to show, 0 to hide.
// Note       : Modified from a script by Martial B of 
//              http://getElementById.com/
//--------------------------------------------------------
{
	if(document.getElementById)
	{
		var el = document.getElementById(pcID);

		if(pnStatus == 1)
		{
			el.style.display = "block";
		}
		else
		{
			el.style.display = "none";
		}
	}
}

function ShowHideAll(pcTagName, pnStatus)
//--------------------------------------------------------
// function   : ShowHideAll
// Purpose    : show or hide all html tags that match pcTagName.
// Parameters : pcTagName = an html tag name
//              pnStatus = 1 to show, 0 to hide.
// Note       : Modified from a script by Martial B of 
//              http://getElementById.com/
//--------------------------------------------------------
{
	var i;
	for(i = 0; i < document.all.length; i++) 
	{
        if(document.all(i).tagName == pcTagName)
		{
    		if(pnStatus == 1)
    		{
    			document.all(i).style.display = "block";
    		}
    		else
    		{
    			document.all(i).style.display = "none";
    		}
		}
	}
}

function ToggleShowHide(pcID)
//--------------------------------------------------------
// function   : ToggleShowHide
// Purpose    : Toggle between show and hide for a block of html.
// Parameters : pcID = value for id attribute of an html tag
// Note       : Modified from a script by Martial B of 
//              http://getElementById.com/
//--------------------------------------------------------
{
	if(document.getElementById)
	{
		var el = document.getElementById(pcID);

		if(el.style.display != "block")
		{
			el.style.display = "block";
		}
		else
		{
			el.style.display = "none";
		}
	}
}

function GetActiveForm()
// --------------------------------------------------------------
// Function : GetActiveForm
// Purpose  : Returns cookie value for "ActiveForm"
// --------------------------------------------------------------
{ 
   	//alert(document.cookie);
	
	var laCookieVals;   //holds all cookies for current document.
	var laSgCookieVals; //holds all sgintranet cookies.
	var lcActivePage;   //current value for ActivePage.
	lcActivePage = "";
	
	laCookieVals = document.cookie.split(";");
    
	for(var i = 0; i < laCookieVals.length; i++)
	{
	 	if(laCookieVals[i].substr(0,11) == "sgintranet=")
		{
		 	laSgCookieVals = laCookieVals[i].substr(11).split("&");
			
         	for(var i = 0; i < laSgCookieVals.length; i++)
         	{
			 	if(laSgCookieVals[i].substr(0,11) == "ActivePage=")
				{
				 	lcActivePage = laSgCookieVals[i].substr(11);
					//alert(lcActivePage)
				}
			}
		}
	}
	return(lcActivePage);
}

function OpenExcelFile(pcFileName)
// --------------------------------------------------------------
// Function : OpenExcelFile
// Purpose  : Open a file into a local instance of Excel 
//            and retain the network path name.
// --------------------------------------------------------------
{
	var excelApp;
    excelApp = new ActiveXObject("excel.Application");
	excelApp.workbooks.Open(pcFileName);
	excelApp.Visible = true;
}

function OpenAccessFile(pcFileName)
// --------------------------------------------------------------
// Function : OpenAccessFile
// Purpose  : Open a file into a local instance of Access 
//            and retain the network path name.
// --------------------------------------------------------------
{
	var AccessApp;
    AccessApp = new ActiveXObject("Access.Application");
	AccessApp.OpenCurrentDatabase(pcFileName);
	AccessApp.Visible = true;
}

function OpenArchiveFolder(pcFldPath)
// --------------------------------------------------------------
// Function : OpenArchiveFolder
// Purpose  : Open a folder in windows explorer instead of IE.
// --------------------------------------------------------------
{
	var oShell = new ActiveXObject("Shell.Application");
	oShell.Explore(pcFldPath);
}

function isLetter(c)
// --------------------------------------------------------------
// Function : isLetter
// Purpose  : Returns true if "c" is a letter.
// --------------------------------------------------------------
{   
    return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) );
}

function isDigit(c)
// --------------------------------------------------------------
// Function : isDigit
// Purpose  : Returns true if "c" is a digit.
// --------------------------------------------------------------
{   
    return ((c >= "0") && (c <= "9"));
}

