var parentWnd = self.opener;
var clickObj = null

/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!

  This is used when embedding the shopping site inside an iframe.
  Use these function to allow the iframe to resize depending on the size
  of the shopping page so that scroll bars do not show.
*************************************************************************/

function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

function getDocWidth(doc) {
  var docWt = 0, sw, ow;
  if (doc.width) docWt = doc.width;
  else if (doc.body) {
    if (doc.body.scrollWidth) docWt = sw = doc.body.scrollWidth;
    if (doc.body.offsetWidth) docWt = ow = doc.body.offsetWidth;
    if (sw && ow) docWt = Math.max(sw, ow);
  }
  return docWt;
}
/*
function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
  
    //iframeEl.style.height = "30px";
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
   
    var docHt = getDocHeight(iframeWin.document);
    var docWt = getDocWidth(iframeWin.document);
    if (docHt) iframeEl.style.height = docHt + "px";
    if (docWt) iframeEl.style.width = docWt + "px";
   //alert("height" + docHt + "px");
  }
}
*/
function loadIframe(iframeName, url) {
  if ( window.frames[iframeName] ) {
    window.frames[iframeName].location = url;   
    return false;
  }
  else return true;
}

////////////////////////////////////////////////////////////////////
// Name : ExecParentWndScript                                     //
// Parameter : sScript -- string contains parent script name and  //
//                        parameters                              //
//             close -- true/false close the child indicator      //
// Purpose : execute parent script and close the child window     //
// Author : Kevin Lam                                             //
// Date : 20 Jun 2001                                             //
////////////////////////////////////////////////////////////////////

function ExecParentWndScript(sScript, close) {
if (! parentWnd)
  return;

if (parentWnd.closed)
  return;
 parentWnd.execScript (sScript);
 //parentWnd.focus();
 if (close)
  setTimeout ("window.close", 2000);

}

function CallArticle(ArticleID) 
{
	location.href = ("default.aspx?ArticleID=" + ArticleID)
}

function CallURL(strURL) 
{
	location.href = (strURL)
}

////////////////////////////////////////////////////////////////////
// Name : getSelectedButton                                       //
// Parameter : buttonGroup - name of radio button group           //
//                                                                //
// Purpose : Finds the selected item in a radio button group      //
// Author :                                                       //
// Date :                                                         //
////////////////////////////////////////////////////////////////////
function getSelectedButton(buttonGroup)
{
	for (var i=0; i < buttonGroup.length;i++) {
		if (buttonGroup[i].checked) {
			return i
		}
	}
	return 0
}


//**************************************************************** 
// You are free to copy the "Folder-Tree" script as long as you  
// keep this copyright notice: 
// Script found in: http://www.geocities.com/Paris/LeftBank/2178/ 
// Author: Marcelino Alves Martins (martins@hks.com) December '97. 
//**************************************************************** 
 
//Log of changes: 
//       17 Feb 98 - Fix initialization flashing problem with Netscape
//       
//       27 Jan 98 - Root folder starts open; support for USETEXTLINKS; 
//                   make the ftien4 a js file 
//       
 
 
// Definition of class Folder 
// ***************************************************************** 

	
function FTB_ForeColorPicker(editor,htmlmode) {
	var color
	if (htmlmode) return;
	script = 'ftb\\ftb.colorpicker.aspx';
	if (FTB_HelperFilesParameters != '') script += '?' + FTB_HelperFilesParameters
	color = showModalDialog(script,window,'dialogWidth:210px;dialogHeight:180px;status:0;scroll:0;help:0;');
	if (color!= null)
	{
		document.all[editor].value = color;
		document.all[editor].style.backgroundColor = color;
	} 
}

function isvaliddate(day, month, year) {
	var months = Array("January","February","March","April","May","June","July","August","September","October","November","December")
	if (new Date(months[month-1]+' '+day+' '+year)) {
		var datetmp = new Date(months[month-1]+' '+day+' '+year);
		if (day==datetmp.getDate() && month==datetmp.getMonth()+1 && year==datetmp.getFullYear())
			return true;
		else
			return false;
	}
	else
		return false;
}

function isvalidemail(s) {

		if (s.length > 0) {
			if (s.indexOf("@")!=-1 && s.indexOf(".")!=-1)  {
				//email is valid
				return true;	
			}
			else {
				//email is not valid
				return false;
			}			
		}
		else {
			//if string is empty just return true as we assume 
			//the field is not mandatory.
			return true;
		}
		
}

function is_checked(sele) 
{
			var i;
			var num_of_selection;
			
			if 	(!sele)
				return false
				
			if (sele.length) {
				num_of_selection = sele.length;
				for (i = 0; i < num_of_selection; i++) 
					if  (sele[i].checked) 
						return true;
			}
			else
				return sele.checked
}


function isblank(s) {
		for( var i = 0; i < s.length; i++ ) {
			var c = s.charAt(i);
			if ( (c != ' ') && (c != '\n') && (c != '\t') )
				return false;
		}
		return true;
}

function MoveFieldUpDown(Box,Direction)
{
			var k=0
			var j=0
			
			j = Box.options.selectedIndex
			if (j < 0)
			{
				return
			} 

		//don't allow sections to move up or down 
			if (Box.options[j].value==0)
			{
				return
			} 

		//don't allow an item to move between sections 
			if (Direction == "U")
			{
				if (Box.options[j-1].value==0)
				{
					alert("You cannot move a question between sections")
					return
				} 
			}
			else
			{
				if (Box.options[j+1].value==0)
				{
					alert("You cannot move a question between sections")
					return
				} 
			}	

			OldValue = Box.options[j].value
			OldText = Box.options[j].text
			OldStyle = Box.options[j].style.cssText;
			if (Direction == "U")
			{
				if (j == 0)
				{
					return
				}
				k = j - 1

				nValue = Box.options[k].value
				nText = Box.options[k].text
				
				Box.options[j] = new Option(nText, nValue)
				Box.options[j].style.cssText = Box.options[k].style.cssText
				
				Box.options[k].value = OldValue;
				Box.options[k].text = OldText;
				Box.options[k].style.cssText = OldStyle;
				Box.options[k].selected = true
			}		

			if (Direction == "D")
			{
				if (Box.options.length == j+1)
				{
					return
				}	
				k = j + 1

				nValue = Box.options[k].value
				nText = Box.options[k].text
				
				Box.options[j] = new Option(nText, nValue)
				Box.options[j].style.cssText = Box.options[k].style.cssText

				Box.options[k].value = OldValue;
				Box.options[k].text = OldText;
				Box.options[k].style.cssText = OldStyle;
				Box.options[k].selected = true

			}
			
			
}

function move(fBox,tBox)
{
			for(var i=0; i<fBox.options.length; i++)
			{
			if(fBox.options[i].selected && fBox.options[i].value != "")
			{
				var no = new Option();
				no.value = fBox.options[i].value;
				no.text = fBox.options[i].text;
				no.style.cssText = fBox.options[i].style.cssText;				
				tBox.options[tBox.options.length] = no;
				fBox.options[i].value = "";
				fBox.options[i].text = "";
			}
			}
			BumpUp(fBox);
}

function moveall(fBox,tBox)
{
			for(var i=0; i<fBox.options.length; i++)
			{
				var no = new Option();
				no.value = fBox.options[i].value;
				no.text = fBox.options[i].text;
				no.style.cssText = fBox.options[i].style.cssText;				
				tBox.options[tBox.options.length] = no;
				fBox.options[i].value = "";
				fBox.options[i].text = "";
			}
			BumpUp(fBox);

}

function remove(fBox)
{
			for(var i=0; i<fBox.options.length; i++)
			{
			if(fBox.options[i].selected && fBox.options[i].value != "")
			{
				var no = new Option();
				no.value = fBox.options[i].value;
				no.text = fBox.options[i].text;
				no.style.cssText = fBox.options[i].style.cssText;				
				fBox.options[i].value = "";
				fBox.options[i].text = "";
			}
			}
			BumpUp(fBox);
}

function BumpUp(Box)  
{
			for(var i=0; i<Box.options.length; i++) {
			if(Box.options[i].value == "")  {
			for(var j=i; j<Box.options.length-1; j++)  {
			Box.options[j].value = Box.options[j+1].value;
			Box.options[j].text = Box.options[j+1].text;
			}
			var ln = i;
			break;
			}
			}
			if(ln < Box.options.length)  {
			Box.options.length -= 1;
			BumpUp(Box);	
			}
}

function showHideCombo(mLeft, mTop, mWidth, mHeight, showHide) {

  
  //show/hide combo only if necessary
  //var Menu = document.all[menu];
  var elm;
  //use the following array to do quick search
  //N.B. pageToSkip is a 2D array
  //each pageToSkip[] has X no. of elements
  //pageToSkip[m][0] = pageName (lowercase);
  //pageToSkip[m][n1] = controlName1
  //pageToSkip[m][n2] = controlName2 and so on ....
  
  var pageToSkip = new Array(5);
  pageToSkip[0] = new Array(2);
  pageToSkip[1] = new Array(0);
  pageToSkip[2] = new Array(0);
  pageToSkip[3] = new Array(0);
  pageToSkip[4] = new Array(0);
  pageToSkip[5] = new Array(0);
  
  
  pageToSkip[0][0] = 'projectdetails.aspx';
  pageToSkip[0][1] = 'cboProjectTemplate';
  pageToSkip[0][2] = 'cboChooseType';
  pageToSkip[1][0] = 'projecthistory.aspx';
  pageToSkip[2][0] = 'deptmembers.aspx';
  pageToSkip[3][0] = 'securitygroup.aspx';
  pageToSkip[4][0] = 'busunitmembers.aspx';
  pageToSkip[5][0] = 'project_timeline.aspx';
  
  var sURL = location.pathname.toLowerCase();
  var quickCheck = false;
  
  for (var i=0; i<pageToSkip.length; i++) {

    if (sURL.indexOf(pageToSkip[i][0]) > 0) {
      //found URL
      quickCheck = true;

      for(var j=1; j<pageToSkip[i].length; j++) {
        if (document.forms[0].elements[pageToSkip[i][j]])
          showHideElement(document.forms[0].elements[pageToSkip[i][j]], mLeft, mTop, mWidth, mHeight, showHide);
      }
    }
  }
  
  //if not using quick check, then loop thru form
  if (!quickCheck) {
    //window.status = 'mLeft=' + mLeft + ',mTop=' + mTop + ',mWidth=' + mWidth + ', mHeight=' + mHeight;
    for (var i=0; i<document.forms[0].length; i++) {
      elm = document.forms[0].elements[i];
      showHideElement(elm, mLeft, mTop, mWidth, mHeight, showHide);
    }
  }
}

function showHideElement(elm, mLeft, mTop, mWidth, mHeight, showHide) {
    var iLeft=0;
    var iTop=0;
    if (!elm.type  || elm.type == null)
      return;
    if (elm.type.substring(0,6) == "select") {
      var oCurrentNode=elm;
      while (oCurrentNode.tagName!="BODY") {
		  iLeft+=oCurrentNode.offsetLeft;
		  iTop+=oCurrentNode.offsetTop;
		  oCurrentNode=oCurrentNode.offsetParent;
      }

      var tableTop = iTop;
      var tableLeft = iLeft;
      iTop = (parseInt(tableTop) + parseInt(elm.offsetHeight));
      iLeft = (parseInt(tableLeft) + parseInt(elm.offsetWidth));

      var shCombo=0;

      //window.status = 'mLeft=' + mLeft + ', mtop=' + mTop + ',mWidth=' + mWidth + ', mHeight=' + mHeight;

      if (
        (mLeft >= tableLeft && mLeft <= iLeft && mTop >= tableTop && mTop <= iTop) ||
        ((mLeft+mWidth) >= tableLeft && (mLeft+mWidth) <= iLeft && mTop >= tableTop && mTop <= iTop) ||
        (mLeft >= tableLeft && mLeft <= iLeft && (mTop+mHeight) >= tableTop && (mTop+mHeight) <= iTop) ||
        ((mLeft+mWidth) >= tableLeft && (mLeft+mWidth) <= iLeft && (mTop+mHeight) >= tableTop && (mTop+mHeight) <= iTop) ||
        (tableLeft >=mLeft && tableLeft <= (mLeft+mWidth) && tableTop >= mTop && tableTop <= (mTop+mHeight)) ||
        (iLeft >= mLeft && iLeft <= (mLeft+mWidth) && tableTop >= mTop && tableTop <= (mTop+mHeight)) ||
        (tableLeft >=mLeft && tableLeft <= (mLeft+mWidth) && iTop >= mTop && iTop <= (mTop+mHeight)) ||
        (iLeft >= mLeft && iLeft <= (mLeft+mWidth) && iTop >= mTop && iTop <= (mTop+mHeight)) ||
        (mLeft >= tableLeft && mLeft <= iLeft && mTop <= tableTop && (mTop+mHeight) >= iTop) ||
        (mLeft >= tableLeft && mLeft <= iLeft && mTop >= tableTop && (mTop+mHeight) <= iTop) ||
        ((mLeft+mWidth) >= tableLeft && (mLeft+mWidth) <= iLeft && mTop <= tableTop && (mTop+mHeight) >= iTop) ||
        ((mLeft+mWidth) >= tableLeft && (mLeft+mWidth) <= iLeft && mTop >= tableTop && (mTop+mHeight) <= iTop) ||
        (mTop >= tableTop && mTop <= iTop && mLeft <= tableLeft && (mLeft+mWidth) >= iLeft) ||
        (mTop >= tableTop && mTop <= iTop && mLeft >= tableLeft && (mLeft+mWidth) <= iLeft) ||
        ((mTop+mHeight) >= tableTop && (mTop+mHeight) <= iTop && mLeft <= tableLeft && (mLeft+mWidth) >= iLeft) ||
        ((mTop+mHeight) >= tableTop && (mTop+mHeight) <= iTop && mLeft >= tableLeft && (mLeft+mWidth) <= iLeft) 
        )
          shCombo = 1;
        
      if (shCombo == 1) {
          elm.style.visibility = showHide;
      }
  }
}


function VerifyPassword(intMinTotalNoOfChars, intMaxTotalNoOfChars, intMinNoOfNumerics, intMinNoOfLowerCase, intMinNoOfUpperCase, intMinNoOfSpecialChars)
	{
   if  (document.frm.txtPassword.value == "")
   {
      return;
   }
    
   //check string has no spaces in it
	if (document.frm.txtPassword.value.indexOf(' ', 0) != -1)
	{
		alert("Spaces are not permitted.");
		document.frm.txtPassword.focus()
		document.frm.txtPassword.select();
		return;
	} 
	 //check minimum length of string
	var num;
	var alph;
	var passlen = document.frm.txtPassword.value.length
	if (passlen < intMinTotalNoOfChars)
	{
		alert("Your password must be at least " + intMinTotalNoOfChars + " characters long")
		document.frm.txtPassword.focus();
		return;
	}
	 //check maximum length of string
	if (passlen > intMaxTotalNoOfChars)
	{
		alert("The password must be less than " + intMaxTotalNoOfChars + " characters long")
		document.frm.txtPassword.focus();
		return;
	}
	var passval = document.frm.txtPassword.value;
		//that there is the correct number of numerics
	var i;
	var nCount 
	nCount = 0	
	outer:
	for (i=0;i<=passlen-1;i++)
	{
		var count=0;
		for (count=0;count<=9;count++)
		{
			
			if (passval.substr(i,1)  == count)
			{
				nCount = nCount + 1;
			}
			else
			{
				num = false
			}
		}	
	}

	if (nCount == intMinNoOfNumerics)
	{
		num = true	
	}

	var lowtest = "a;b;c;d;e;f;g;h;i;j;k;l;m;n;o;p;q;r;s;t;u;v;w;x;y;z" 
		//that there is the correct number of lower case letters
	var lowtestArray = lowtest.split(";")
	var j
	var lowlett

	i=0
	j=0
	nCount = 0	
	outerlettlow:
	for (i=0;i<=passlen-1;i++)
	{
		var k = lowtestArray.length
		for (j=0;j<=k-1;j++)
		{
			if (passval.substr(i,1)== lowtestArray[j])
			{
				nCount = nCount + 1;
			}
			else
			{
				lowlett = false
			}
		}
	}
	if (nCount == intMinNoOfLowerCase)
	{
		lowlett = true	
	}
	
	var upptest = "A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z" 
	//that there is the correct number of upper case letters
	var upptestArray = upptest.split(";")
	var upplett
	i=0
	j=0
	nCount = 0	
	outerlettupp:
	for (i=0;i<=passlen-1;i++)
	{
		var m = upptestArray.length
		for (j=0;j<=m-1;j++)
		{
			if (passval.substr(i,1)== upptestArray[j])
			{
				nCount = nCount + 1;
			}
			else
			{
				upplett = false
			}
		}
	}
	
	if (nCount == intMinNoOfUpperCase)
	{
		upplett = true	
	}

	
	var spectest = "!;@;#;$;%;^;&;*;(;);+;=;?;/;>;<" 
	//that there is the correct number of special characters
	var spectestArray = spectest.split(";")
	var speclett
	i=0
	nCount = 0		
	j=0
	outerlettspec:
	for (i=0;i<=passlen-1;i++)
	{
		var p = spectestArray.length
		for (j=0;j<=p-1;j++)
		{
			if (passval.substr(i,1)== spectestArray[j])
			{
				nCount = nCount + 1;
			}
			else
			{
				speclett = false
			}
		}
	}	

	if (nCount == intMinNoOfSpecialChars)
	{
		speclett = true	
	}

	if (num == false)
	{
		alert("you must have at least " +  intMinNoOfNumerics + " number(s) in your password")
		document.frm.txtPassword.value = ""
		document.frm.VerifyPassword.value = ""
		document.frm.txtPassword.focus();
		document.frm.txtPassword.select();
		return;
	}	
	if (lowlett == false)
	{
		alert("you must have at least " + intMinNoOfLowerCase + " lower case letter(s) in your password")
		document.frm.txtPassword.focus();
		return;
	}
	if (upplett == false)
	{
		alert("you must have at least " + intMinNoOfUpperCase + " upper case letter(s) in your password")
		document.frm.txtPassword.focus();
		return;
	}
	if (speclett == false)
	{
		alert("you must have at least " + intMinNoOfSpecialChars + " of the special characters in the password")
		document.frm.txtPassword.focus();
		return;
	}
	return "ValidPassword"
}


// Global variables 
// **************** 
 
USETEXTLINKS = 1 
indexOfEntries = new Array 
nEntries = 0 
doc = document 
browserVersion = 0 
selectedFolder=0
var FTB_HelperFilesParameters = 'tabid=1 ';

//**************************************************************************************************
// Session Timer Functions
//**************************************************************************************************
//You need to paste the following code in the body tag of the page you have included this file in
//onLoad="formTimer()"
//You also need to ensure that the following pages are in the same directory as the page you are adding the timer function to
//AbandonSession.asp and SessionExtension.asp
var sessionwindow=null;
var Stimer=null;
var oNewDoc;
var sessionState = "";
var TimeInMSec = 0;
var sessionTimeout = 0;
var TimeTillWarning;
var SessionSaveContent=0; // SessionSaveContent=1 currently in article edit mode. Note, this is different to
						  // radEditMode=true which means RAD editor is in edit mode.
						  // SessionSaveContent=0 not in edit mode.

function formTimer(TimeoutInMin, bSaveContent){

	SessionSaveContent=bSaveContent;

	if (!Stimer) {
		//alert('timer on')
		window.clearTimeout(Stimer)
	}
	//alert('state==' + sessionState);
	if (sessionState =="") {
		//session has just begun, so set the state to 'Current'
		sessionState = "Current";
		sessionTimeout = TimeoutInMin;
		if (sessionTimeout>4) {
			//display popup window 4 minutes before session expires
			TimeTillWarning=sessionTimeout-4;
		}
		else {
			TimeTillWarning = sessionTimeout
		}
		
		TimeInMSec = 1000*60*TimeTillWarning
		Stimer= window.setTimeout("formTimer(" + sessionTimeout + "," + SessionSaveContent + ")", TimeInMSec) 
	}
	else if (sessionState=="Current") {
		
		//session is about to expire, so set the state to 'AboutToExpire'
		sessionState = "AboutToExpire"
		
		//display the popup window if not currently displayed
		if (!sessionwindow||sessionwindow.closed) {
			sessionwindow = window.open('','','toolbar=no,width=330,height=210,titlebar=no');
			if (sessionwindow != null) {

				if (!sessionwindow.opener) {
					sessionwindow.opener = window
				}

				oNewDoc = sessionwindow.document.open();
				//write out html now!!!
				formcontent = '<html>'
				formcontent += '<body background="images/extend_bg_elcom.jpg">'
				formcontent += '<table><tr><td colspan=2><img src="images/trans.gif" width=100 height=110></td></tr><tr><td><img src="images/trans.gif" width=100 height=10></td><td valign=middle align=right>'
				formcontent += '<tr><td colspan=2><font color=white face=verdana size=1><b>There has been no activity for an extended period. Click here to extend the session or it will expire in 2 minutes.</b></font></td></tr><tr><td><img src="images/trans.gif" width=100 height=10></td><td valign=middle align=right>'
				formcontent += '<a href="SessionExtension.aspx"><img src="images/click_extend.gif" border=0 align=right></a>&nbsp;&nbsp;&nbsp;&nbsp;'
				formcontent += '</td></tr></table>'
				formcontent += '</body>'
				formcontent += '</html>'

				oNewDoc.write(formcontent);
				oNewDoc.close();
			}
		}
		else {
			//popup window already displayed, so just show it
			sessionwindow.focus();
		}	

		//give the user 2 more minutes before killing the session if they have not extended the session.
		TimeInMSec = 1000*60*2
		Stimer= window.setTimeout("formTimer(" + sessionTimeout + "," + SessionSaveContent + ")", TimeInMSec) 
	}
	else if (sessionState=="AboutToExpire") {
		//session has expired
		
		sessionState = ""

		if (!sessionwindow||sessionwindow.closed) {
			//popup window is closed, do nothing
		}
		else {
			//popup window still open, so close it
			sessionwindow.close();
		}
		//Save the article content if required (function will check if RAD editor
		//is in edit mode. If so, the content will be saved).
		if (SessionSaveContent==1) {
			saveNoCheckIn();
		}
		//kill the session 
		window.location.href = "SessionAbandon.aspx"
	}
	//alert('timeout==' + TimeInMSec + '; sessionTimeout==' + sessionTimeout + '; Stimer=='+ Stimer);
}

function resetTimer()
{
	//user has extended the session so reset the timer
	window.clearTimeout(Stimer)
	sessionState = "Current"
	TimeInMSec = 1000*60*TimeTillWarning
	//alert('TimeInMSec in resetTimer==' + TimeInMSec);
 	Stimer= window.setTimeout("formTimer(" + sessionTimeout + "," + SessionSaveContent + ")",TimeInMSec) 

}

function ShowTopMenuDisclaimer(strHref, strDisclaimerText)
{
	if (confirm(strDisclaimerText))
	{
		location.href = strHref;
	}

}
var newWnd = null;
function menuOpenWnd(sURL, sWnd, sFeature)
{
	if (newWnd != null)
		newWnd.close();
	newWnd = window.open(sURL, sWnd, sFeature);
	newWnd.focus();
	return;
}

function menuChangeImage(imgElmName, imgVarName)
{
	if (!document.images[imgElmName])
	return;
	document.images[imgElmName].src = imgVarName.src;
}

function menuChangeBGImage(elmName, imgVarName)
{

	if (!document.getElementById(elmName))
	return;
	if (!document.getElementById(elmName).style)
	return;

	document.getElementById(elmName).style.backgroundImage = 'url(' + imgVarName.src + ')';
}



