function resize_layer(id){

if (document.all){
   if (document.all[id] == null){
	return;
   }
}


var newHeight

  if (document.all){
    
    newHeight = parent.document.body.scrollHeight - 114;

    document.all[id].style.top = 85;

    document.all[id].style.height = newHeight +"px"
	
    document.all[id].style.width = "100%";
  }
  
  else if(document.getElementById) {

   

    newHeight = parent.document.body.scrollHeight - 114;

    document.getElementById(id).style.height = newHeight +"px"
	
    document.getElementById(id).style.width = "100%";
  }

} 

function expandTree() {

	parent.TreeAppFrame.location = "Treeview.aspx?Expanded=True";


}

function refreshTree() {

	parent.TreeAppFrame.location = "Treeview.aspx";
}


function refreshTree2() {

	parent.TreeAppFrame.location = "../Treeview.aspx";

}


function expandeFolderTree() {

	parent.TreeAppFrame.location = "eFolderTree.aspx?Expanded=True";


}

function refresheFolderTree()
{
	parent.TreeAppFrame.location = "eFolderTree.aspx";
}

function renewFolderTree()
{
	parent.TreeAppFrame.location = "../eFolderTree.aspx";
}


function refreshLanguage()
{
	var sURL
	sURL = parent.PrimaryAppFrame.location.href;
	parent.PrimaryAppFrame.location.href = sURL;

/*
if (sURL.indexOf("ShowHandoutPageTable2.aspx") > 0)
{
	parent.PrimaryAppFrame.location.href = "HandoutPage/ShowHandoutPageTable2.aspx";
}
*/

}


function Button_Clicked(sId, sArgs) {

if (document.all){
    
    	
    document.all['ButtonType'].value = sId;
  }
  
  else if(document.getElementById) {

   	
    document.getElementById('ButtonType').value = sId;
  }

}

function ShowArtSearchDialog(sImageControl)
{

var strReturn; 

strReturn=window.open('../Art/ShowArtTable.aspx?ImageControl=' + sImageControl,null,'status:no;dialogWidth:800px;dialogHeight:500px;dialogHide:true;help:no;scroll:auto');
strReturn.focus;

//alert(strReturn.toString());

//if (strReturn != null) 
//{
//     document.getElementById(sImageControl).src=strReturn.toString;
//}
}

function ReturnSelectedImage(sFileName,sImageControl,sArtId)
{
window.opener.document.getElementById(sImageControl).text = sFileName;
window.opener.document.Form1.__EVENTTARGET.value = "updateimage";
window.opener.document.Form1.__EVENTARGUMENT.value = sFileName + "," + sImageControl + "," + sArtId;
window.opener.document.Form1.submit();
//window.returnValue = sFileName; 
window.close();

}

function ShoweFolderDialog(sSelectedHandout)
{

var strReturn; 

strReturn=window.open('../eFolderTreeFoldersOnly.aspx?SelectedHandout=' + sSelectedHandout,null,'status:no,height=316,width=500,help:no,scroll:no');
strReturn.focus;

//if (strReturn != null) 
//{
//     document.getElementById(sImageControl).src=strReturn.toString;
//}
}

function ShowFolderFileDialog(id)
{
	var strReturn; 
	strReturn = window.open('../Files/eFolderDialog.aspx?id=' + id,null,'status:no,height=316,width=500,help:no,scroll:no');
	strReturn.focus;
}


function ShowFolderDialog(sSelectedHandout)
{

var strReturn; 

strReturn=window.open('../ShareHandoutDialog.aspx?SelectedHandout=' + sSelectedHandout,null,'status:no,height=316,width=500,help:no,scroll:no');
strReturn.focus;

//if (strReturn != null) 
//{
//     document.getElementById(sImageControl).src=strReturn.toString;
//}
}

function ShowAddMultipleDialog()
{

var strReturn; 
strReturn=window.open('../AddMultipleToEFolder.aspx',null,'status:no,height=316,width=500,help:no,scroll:no'); 
strReturn.focus();

//if (strReturn != null) 
//{
//     document.getElementById(sImageControl).src=strReturn.toString;
//}
}

function ShowAddMultipleFilesDialog()
{
	var strReturn; 
	strReturn=window.open('../AddMultipleToEFolder.aspx?File=f',null,'status:no,height=316,width=500,help:no,scroll:no'); 
	strReturn.focus();
}

function AddFileToeFolder(sNodeId) {
	var sWork = "";
	if (sNodeId === undefined) {
		alert("Please Select an eFolder.");
	} else {
		sWork = sNodeId;
		if (sWork.length > 1) {
			var vWork = sWork.split("_");
			document.frmMain.hidSID.value = vWork[1];
			document.frmMain.action = "eFolderDialog.aspx" + document.location.search;
			document.frmMain.submit();
		}
	}
	return false;
}


function AddToeFolder(sNodeId)
{

if(sNodeId === undefined){
  alert("Please select an eFolder.");
}
else{
   window.opener.document.Form1.__EVENTTARGET.value = "AddeFolder";
   window.opener.document.Form1.__EVENTARGUMENT.value = sNodeId;
   window.opener.document.Form1.submit();

   window.close();
}
}

function AddToFolder(sNodeId)
{
  
if(sNodeId === undefined){
  alert("Please select a folder.");
  return false;
}

else if(sNodeId.indexOf("ch_") == -1)
{
  alert("Please select a chapter node");
  return false;
}

else
{
   window.opener.document.Form1.__EVENTTARGET.value = "AddFolder";
   window.opener.document.Form1.__EVENTARGUMENT.value = sNodeId;
   window.opener.document.Form1.submit();

   window.close();
}
}

/*
function AddMultipleToeFolder(sNodeId)
{
  
if(sNodeId === undefined)
{
  alert("Please select an eFolder.");
}
else{
   window.opener.document.Form1.__EVENTTARGET.value = "AddeFolder";
   window.opener.document.Form1.__EVENTARGUMENT.value = sNodeId;
   window.opener.document.Form1.submit();

   window.close();
}

}
*/

function redirectSearchPage(sURL)
{
//redirect the search page to the proper frame

  parent.PrimaryAppFrame.location.href = sURL;

}

function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}

/*
 * This function allows us to navigate from the search page to the browse section 
 * and select the correct node in the tree, and navigate to the correct page in the 
 * main frame.
 */
function navigateFromSearch(sTreeNodeId,sNavigateTo){

parent.TreeAppFrame.location.href = "../treeview.aspx?SelectedNode=" + sTreeNodeId;

parent.PrimaryAppFrame.location.href = sNavigateTo;

}

function searchSelectAll(toggleButton) {
  var oForm = toggleButton.form;
  var bIsChecked = true;
 
  for (var iElement=0; iElement < oForm.elements.length; iElement++) {
 
    if (oForm.elements[iElement].type == 'checkbox') {
       oForm.elements[iElement].checked = bIsChecked;
    }
  }
}

function searchDeSelectAll(toggleButton) {
  var oForm = toggleButton.form;
  var bIsChecked = false;
 
  for (var iElement=0; iElement < oForm.elements.length; iElement++) {
 
    if (oForm.elements[iElement].type == 'checkbox') {
       oForm.elements[iElement].checked = bIsChecked;
    }
  }
}


function doPrint(sURL)
{
	
	//alert("reached doPrint with: " + sURL);
	
//	parent.parent.parent.parent.topFrame.document.all.PrintContainer.src = sURL;

	parent.parent.parent.parent.PrintFrame.location = sURL;
}

function promptAddCoversheet(sURL)
{

   var sReturn; 

   //sReturn = window.showModalDialog('../PrintEngine/Dialog.html',null,'status:no;dialogWidth:370px;dialogHeight:170px;dialogHide:yes;unadorned:yes;help:no;scroll:auto');

   //If yes then redirect to add coversheet, retain passed arguments
   //if (sReturn == "yes")
   //{
   //   location.href = "../HandoutCoversheet/AddHandoutCoversheetRecord.aspx?RedirectURL=" + sURL;
   //}
   //else
   //{
      doPrint(sURL);
   //}

}
function promptAddCoversheet1(sURL)
{

   //var sReturn; 

   //sReturn = window.showModalDialog('../PrintEngine/Dialog.html',null,'status:no;dialogWidth:370px;dialogHeight:170px;dialogHide:yes;unadorned:yes;help:no;scroll:auto');

   //If yes then redirect to add coversheet, retain passed arguments
   //if (sReturn == "yes")
   //{
      location.href = "../HandoutCoversheet/AddHandoutCoversheetRecord.aspx?RedirectURL=" + sURL;
   //}
   //else
   //{
   //   doPrint(sURL);
   //}

}

function returnAnswer(sAnswer)
{

window.returnValue = sAnswer; 
window.close();

}

function showPageNotFound()
{

document.all.PageNotFound.innerHTML = "Page not found";
}

function editProfile(sPersonId)
{

strReturn=window.open('../Person/EditPersonRecord2.aspx?Person=' + sPersonId ,null,'status:no,height=420,width=500,help:no,scroll:no');


}

function loadReport(sURL)
{

frames["ViewFrame"].location.href = sURL;


}

function AddFileToFolder(sNodeId) {
	var sWork = "";
	if (sNodeId === undefined) {
		alert("Please select an element.");
	} else {
		sWork = sNodeId;
		if (sWork.length > 1) {
			var vWork = sWork.split("_");
			sWork = vWork[0];
			if (sWork.toUpperCase() != "SID") {
				alert("Please select a section.");
			} else {
				document.frmMain.hidSID.value = vWork[1];
				document.frmMain.action = "AddtoFolder.aspx" + document.location.search;
				document.frmMain.submit();
			}
		}
	}
	return false;
}

function AddFileToFolderClose() {
	//Additional operations here
	window.close();
}

function AddFileToeFolderClose() {
	//Additional operations here
	window.close();
}

function SetToYear(ddlFromYear,ddlToYear,ddlFromMonth,ddlToMonth)
{
	var FddlYear = document.getElementById("ddlFromYear");
	var TddlYear = document.getElementById("ddlToYear");
	var FddlMonth = document.getElementById("ddlFromMonth");
	var TddlMonth = document.getElementById("ddlToMonth");
	
	var fYear = FddlYear.options[FddlYear.selectedIndex].value;
	var tYear = TddlYear.options[TddlYear.selectedIndex].value;
	var fMonth = FddlMonth.options[FddlMonth.selectedIndex].value;
	var tMonth = TddlMonth.options[TddlMonth.selectedIndex].value;
	
	if(fYear == tYear)
	{
		return true;
	}
	else
	{
		alert('Please Select To Year properly');
		return false;
	}
}

function Validate(txtFirst,txtSecond)
{
	var txtFirstName = document.getElementById(txtFirst);
	var txtLastName = document.getElementById(txtSecond);
	if(txtFirstName.value != '')
	{
		txtLastName.disabled = true;
		txtLastName.style.backgroundColor = 'LightGray';
		txtFirstName.disabled = false;
	}
	else if(txtLastName.value != '')
	{
		txtFirstName.disabled = true;
		txtFirstName.style.backgroundColor = 'LightGray';
		txtLastName.disabled = false;
	}
	else
	{
		txtFirstName.disabled = false;
		txtFirstName.style.backgroundColor = '';
		txtLastName.disabled = false;
		txtLastName.style.backgroundColor = '';
	}
}
globalFlag=false;
function fnValidatePwds(lblMessage,VOldPasswordFV,VNewPasswordFV,VConfirmPasswordFV,lblOldPwdErrMessge,lblNewPwdErrMessage,lblConfirmPwdErrMessage,lblcmpValidatroMessage)
{
	var Flag = false;
	var msgMessage = document.getElementById(lblMessage);
	var OldPwd = document.getElementById(VOldPasswordFV);
	var NewPwd = document.getElementById(VNewPasswordFV);
	var CnfrmPwd = document.getElementById(VConfirmPasswordFV);
	var msgOldPwd = document.getElementById(lblOldPwdErrMessge);
	var msgNewPwd = document.getElementById(lblNewPwdErrMessage);
	var msgCnfrmPwd = document.getElementById(lblConfirmPwdErrMessage);
	var msgCnfrmValidation = document.getElementById(lblcmpValidatroMessage);
	msgOldPwd.innerText="";
	msgNewPwd.innerText="";
	msgCnfrmPwd.innerText="";
	msgCnfrmValidation.innerText="";
	msgMessage.innerText="";
	if(OldPwd.value == "" || OldPwd == null)
	{
		Flag=true;
		msgOldPwd.innerText = "A value for Password is required.";
		msgOldPwd.style.display="block";
	}
	if(NewPwd.value == "" || NewPwd == null)
	{
		Flag=true;
		msgNewPwd.innerText = "A value for New Password is required.";
		msgNewPwd.style.display="block";
	}
	if(CnfrmPwd.value == "" || CnfrmPwd == null)
	{
		Flag=true;
		msgCnfrmPwd.innerText = "A value for Confirm Password is required.";
		msgCnfrmPwd.style.display="block";
	}
	if(Flag==true)
	{
		return false;
	}
	if(NewPwd.value != CnfrmPwd.value)
	{
		msgCnfrmValidation.innerText = "Password Mismatch.";
		NewPwd.value="";
		CnfrmPwd.value="";
		msgCnfrmValidation.style.display="block";
		return false;
	}
	else
	{
		Flag=false;
		msgOldPwd.style.display="none";
		msgNewPwd.style.display="none";
		msgCnfrmPwd.style.display="none";
		msgCnfrmValidation.style.display="none";
		return true;
	}
}

