// S.H.
var clickSkirt;
// End S.H.
var glb_DisplayingElementID;

// display session timeout message in 5 minutes before session timeout
//if(window.location.href.toLowerCase().indexOf('/teachinglaw/generalarea') < 0 && window.location.href.toLowerCase().indexOf('logout.aspx') < 0) {
    //window.setTimeout("if(confirm('Your session is about to expire shortly. Do you want to continue?')){if(window.location.search.indexOf('?') < 0) {window.location.href=window.location.href + '?sessiontimedout=true';} else {window.location.href=window.location.href + '&sessiontimedout=true'};} else {window.location.href='/teachinglaw/logout.aspx';}", 175 * 60000); 
//} 

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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 MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// CheckIN
function CheckInAndOut(guid, changeStateTo)
{
    document.forms[0].treeAssignmentGuid.value = guid;   
    if(changeStateTo == "CheckedOut") {
        show_tree();
        showDivFullScreen(clickSkirt);
        
    }
    else {
       show_checkBoxes(guid);
       showDivFullScreen(clickSkirt);
       
       //showDivCentered(document.getElementById("progressBar"));
       //WK.Templates_PersonalBank.CheckInAndOut(guid, inOut, bankUrl, CheckInAndOut_callback);  // asynchronous call
    }
   
}
function ShowPersonalBankddl(sshowHideDropdown)
{

    var containedSelectElements = document.getElementsByTagName("select");
    if(containedSelectElements.length > 0)
    {
        
        var ReqDropdownID="";
        ReqDropdownID =containedSelectElements[0].id;
        if (ReqDropdownID.indexOf("ddlFilterAssiType") >= 0)
        {
            if (sshowHideDropdown)
                {document.getElementById("_ctl0_cntPHMainContent_IsPersonalBankEmpty").style.display="none";}
            else 
                {document.getElementById("_ctl0_cntPHMainContent_IsPersonalBankEmpty").style.display="block";}
            
            ReqDropdownID="";
        }
        ReqDropdownID = containedSelectElements[containedSelectElements.length-1].id;
        if (ReqDropdownID.indexOf("PagerAssignments") >= 0)
        {
                if (sshowHideDropdown){containedSelectElements[containedSelectElements.length-1].style.display="none";}
                else {containedSelectElements[containedSelectElements.length-1].style.display="block";}
        }
        
      }
 }



function CheckInAndOut_callback(res)
{
  document.getElementById("progressBar").style.display = 'none';
  if(document.getElementById('io' + res.value).innerHTML == 'Checked In') {
    document.getElementById('img' + res.value).src = '/teachinglaw/images/iconGreenArrowleft.gif';
    document.getElementById('io' + res.value).innerHTML = 'Checked Out';
    document.getElementById('goToStatus' + res.value).innerHTML = 'CheckedIn';
  } else {
    document.getElementById('img' + res.value).src = '/teachinglaw/images/iconBlueArrowright.gif';
    document.getElementById('io' + res.value).innerHTML = 'Checked In';
    document.getElementById('goToStatus' + res.value).innerHTML = 'CheckedOut';
  }
}

function showDivFullScreen(divObj){
	// plus 16, because it always subtracts scrollbar size, regardless of whether either is present.
	parentWinWidth = document.body.scrollWidth+16;
	parentWinHeight = document.body.scrollHeight+16;
	with (divObj.style){
		left="0px";
		top="0px";
		width=parentWinWidth+"px";
		height=parentWinHeight+"px";
		visibility = "visible";
		display = "block";
	}
	
}



function hideDiv(divName){
	var divObj = getObjectRef(divName);
	if (divObj==undefined) return;
	with(divObj.style){
		visibility = "hidden";
	}
}

function collectObjs(){
	try
	{
	clickSkirt = getObjectRef("clickSkirt");
	}
	catch(err){}
}

// this script adds a function to an eventHandler,
// allowing us to daisy-chain functions (eg; dynamically set up initialization
// for various scripts to be triggered w onLoad).
// 
function doOnEvent(anElement, anEventName, aFunction){
	if (anElement.attachEvent){
		anElement.attachEvent("on"+anEventName, aFunction);
	} else if (anElement.addEventListener){
		anElement.addEventListener(anEventName, aFunction, false);
	} else {
		var anEventHandler = anElement["on"+anEventName];
		var prevEventHandler = function(){};
		if (anEventHandler instanceof Function) prevEventHandler = anEventHandler;
		anEventHandler = function(evt) {
			prevEventHandler.call(evt);
			aFunction.call();
		}
	}
}

function show_tree() {
    showDivCentered(document.getElementById('_ctl0_cntPHMainContent_Panel1'));
   
   }

function show_checkBoxes(strGuid) {    
    showDivCentered(document.getElementById('checkInPanel' + strGuid));
   
  
}

function hide_tree() {
 
    with(document.getElementById('_ctl0_cntPHMainContent_Panel1')) {
        style.display = 'none';
    }
    
    //document.getElementById("_ctl0_cntPHMainContent_IsPersonalBankEmpty").style.display="block";
    //ShowPersonalBankddl(false);
    //document.getElementById("_ctl0_cntPHMainContent_GridView1__ctl13_PagerAssignments").style.display="block";
   
    
    hideDiv("clickSkirt");
}
function showElement(strID) {
    document.getElementById(strID).style.display = 'block';

}

function HidePBRVControls(strRVID)
{
   alert (document.getElementById(strRVID));

}

function hideElement(strID) {
 
 
    document.getElementById(strID).style.display = 'none';
    
  //  ShowPersonalBankddl(false);
}

function hideAllElements()
{
     var elem = document.getElementById(glb_DisplayingElementID);
     if(elem)
        elem.style.display = "none";
}


function refreshParentWindow()
{
    try
    {
    opener.location.reload(true);
    
    }
    catch (err){}
}

function refreshParentCloseThisWindow()
{
    try
    {
    opener.location.reload(true);
    //self.close();
    }
    catch (err){}
    finally
    {
       self.close();
    }
}


function hideShowElementByButtonClick(pButton, targetID, btnHideText, btnShowText)
{
     var elem = document.getElementById(targetID);
     
     if(elem && pButton)
     {
        hideShowElement(targetID);
        
        if(elem.style.display == "block")
        {
                     //alert('show button ');
            pButton.value = btnHideText;
        }
        else
        {
        //alert('hide button ');
            pButton.value = btnShowText;
        }
     }

}


function hideShowElement(strID) {
    var elem = document.getElementById(strID);
    
     
    if(elem)
    {
       //alert('string is' + elem.ID);
        if(elem.style.display == "block") 
        {                 
            elem.style.display = "none";
        }
        else
        {
         hideAllElements();
         elem.style.display = "block";
         glb_DisplayingElementID = elem.id;
        }
    }
} 


function SetElementValue(elementID, pValue)
{
     //alert('got function');
     var elem = document.getElementById(elementID);
     if(elem)
     {
        elem.value = pValue;
       // alert('element found '+ elem.id);
        }
        
}
        
        

function ShiftActiveXPlaceholderContent(){ 
//no def
}


// ; insert our functionality into onload and onMouseDown events, while maintaining whatever may already be there.
// NOTE: requires dom.js!
doOnEvent(window, "load", collectObjs);

//this function takes the key press
//event and triggers the click 
//event for the passed-in element
function EnterKeyToOnlick(strObjId)
{
//alert(event.keyCode);
	if(event.keyCode == 13)
	{
		document.getElementById(strObjId).click();
		return false; 
	}	
	else
		return true;
}



//this function triggers the onlick 
//event for the speciifed object id
function TriggerOnClickEvent(strObjId)
{
	try
	{
		//alert('click for ' + strObjId);
		document.getElementById(strObjId).click();
		
		return false; 
	}	
	 catch (err){}
}


//pops new window with specified height and width

/*status  The status bar at the bottom of the window. 
toolbar  The standard browser toolbar, with buttons such as Back and Forward. 
location  The Location entry field where you enter the URL. 
menubar  The menu bar of the window 
directories  The standard browser directory buttons, such as What's New and What's Cool 
resizable Allow/Disallow the user to resize the window. 
scrollbars  Enable the scrollbars if the document is bigger than the window 
height Specifies the height of the window in pixels. (example: height='350') 
width  Specifies the width of the window in pixels. 
*/

var agt=navigator.userAgent.toLowerCase(); 
var appVer = navigator.appVersion.toLowerCase(); 
var is_major = parseInt(navigator.appVersion); 
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)); 
var is_ie3 = (is_ie && (is_major < 4)); 
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) ); 
var is_ie5up = (is_ie && !is_ie3 && !is_ie4); 


function popNewWindowGoBackToPrevious(strurl)
{
    //alert("made it here " + strurl);
    try
    {
    //history.back();
    }
    catch(err){}
    Popup(strurl, "_blank", 400, 500);
}


function Popup(mypage, myname, w, h)
{ 
	//alert('page name is'+myname);
	if (myname == "_HomeworkReport")
	{
	    myname ="_blank";
	}
	
	if (navigator.appVersion.indexOf("AOL")!=-1)
	{
		newHeight = h + 25;
		newWidth = w + 25;
		winprops = 'height=' + newHeight + ',width=' + newWidth + ',scrollbars=2';
		win = window.open(mypage, myname, winprops);
		win.window.focus();
		return false;
	}
	else if (appVer.indexOf("mac") != -1 && is_ie5up) 
	{
		newHeight = h;
		newWidth = w - 16;
		winprops = 'height=' + newHeight + ',width=' + newWidth + ',scrollbars=2';
		win = window.open(mypage, myname, winprops);
		win.window.focus();
		return false;
	}
	else 
	{
		if (parseInt(navigator.appVersion) >= 4) 
		{
			var offsetW = (screen.width - w) / 2; 
			var offsetH = (screen.height - h) / 2; 
			winprops = 'height='+ h +',width='+ w +',top='+ offsetH +',left='+ offsetW + ',scrollbars=1,resizable=1';
			win = window.open(mypage, myname, winprops);
			win.window.focus();
			return false;
		}
		else 
		{
			alert('page name is'+myname);
			
			newHeight = h + 25;
			newWidth = w + 25;
			winprops = 'height=' + newHeight + ',width=' + newWidth + ',scrollbars=2';
			win = window.open(mypage, myname, winprops);
			win.window.focus();
			return false;
		}
	}
	return false;
} 

function PopupScroll(mypage, myname, w, h, scroll, toolbar) 
{ 
	//scroll = 'yes'; 
	//toolbar = 'yes'; 

	if (navigator.appVersion.indexOf("AOL") != -1) 
	{
		newHeight = h + 25;
		newWidth = w + 25;
		winprops = 'height=' + newHeight + ',width=' + newWidth+',scrollbars='+scroll+',toolbar='+toolbar;
		win = window.open(mypage, myname, winprops);
		win.window.focus();
		return false;
	}
	else if (appVer.indexOf("mac") != -1 && is_ie5up ) 
	{
		newHeight = h;
		newWidth = w - 16;
		winprops = 'height=' + newHeight + ',width=' + newWidth+',scrollbars='+scroll+',toolbar='+toolbar;
		win = window.open(mypage, myname, winprops);
		win.window.focus();
		return false;
	}
	else 
	{
		if (parseInt(navigator.appVersion) >= 4) 
		{
			var offsetW = (screen.width - w) / 2; 
			var offsetH = (screen.height - h) / 2; 
			winprops = 'height='+ h +',width='+ w +',top='+ offsetH +',left='+ offsetW+',scrollbars='+scroll+',toolbar='+toolbar;
			win = window.open(mypage, myname, winprops)
			win.window.focus();		
			return false;
		}
		else 
		{
			newHeight = h + 25;
			newWidth = w + 25;
			winprops = 'height=' + newHeight + ',width=' + newWidth+',scrollbars='+scroll+',toolbar='+toolbar;
			win = window.open(mypage, myname, winprops);
			win.window.focus();
			return false;
		} 
	}
} 

function PopupPollScroll(mypage, myname, w, h, scroll) 
{ 


	//scroll = 'yes'; 
	toolbar = 'yes';

	if (navigator.appVersion.indexOf("AOL") != -1) 
	{
		newHeight = h + 25;
		newWidth = w + 25;
		winprops = 'height=' + newHeight + ',width=' + newWidth+',scrollbars='+scroll;
		win = window.open(mypage, myname, winprops);
		win.window.focus();
	}
	else if (appVer.indexOf("mac") != -1 && is_ie5up ) 
	{
		newHeight = h;
		newWidth = w - 16;
		winprops = 'height=' + newHeight + ',width=' + newWidth+',scrollbars='+scroll;
		win = window.open(mypage, myname, winprops);
		win.window.focus();
	}
	else 
	{
		if (parseInt(navigator.appVersion) >= 4) 
		{
			var offsetW = (screen.width - w) / 2; 
			var offsetH = (screen.height - h) / 2; 
			winprops = 'height='+ h +',width='+ w +',top='+ offsetH +',left='+ offsetW+',scrollbars='+scroll;
			win = window.open(mypage, myname, winprops);
			win.window.focus();
		}
		else 
		{
			newHeight = h + 25;
			newWidth = w + 25;
			winprops = 'height=' + newHeight + ',width=' + newWidth+',scrollbars='+scroll;
			win = window.open(mypage, myname, winprops);
			win.window.focus();
		} 
	}
}
