﻿// JScript File

//constants:
var smallFeatures = "height=300,width=450,left=300,menubar=no,resizable=yes,status=no,titlebar=no,toolbar=no;addressbar=no";
var smallFeaturesScroll = "height=450,width=500,left=300,menubar=no,resizable=yes,status=no,titlebar=no,scrollbars=yes,toolbar=no;addressbar=no";
var mediumFeatures = "height=400,width=650,left=300,menubar=no,resizable=yes,status=no,titlebar=no,toolbar=no";
var mediumFeaturesScroll = "height=400,width=650,left=300,menubar=no,resizable=yes,status=no,titlebar=no,toolbar=no,scrollbars=yes";
var largeFeaturesScroll = "height=750,width=900,left=50,menubar=no,resizable=yes,status=no,titlebar=no,scrollbars=yes,toolbar=no;addressbar=no";
var expensePopupFeaturesScroll = "height=600,width=500,left=100,menubar=no,resizable=yes,status=no,titlebar=no,scrollbars=yes,toolbar=no;addressbar=no";

var msSelectedCategory = "";
// functions
function toggleDisplay(strElementId, oImg){	
    var oEl = null;
    if ( strElementId ) {
        if ( strElementId.toString().indexOf("[object") > -1 ) // object
	    {
	        oEl = strElementId;
	    }
	    else
        {
	        oEl = document.getElementById(strElementId);
	    }    
	}
	if ( oEl == null ){
	    alert(strElementId + " is not in this document.");
	    return false;
	}
	var currDisp = oEl.style.display;
	var curImg = ""
	try{
	    switch ( oImg.tagName ){
	        case "IMG":
		        curImg = oImg.src;
		        break;
		    case "DIV":
		        curImg = oImg.innerHTML;
		        break;
		    default:
		        alert("No handler for '" + oImg.tagName + "'!");
		    }  
		}
	catch ( e ){
		alert('toggleDisplay(strElementId, oImg) expects oImg which was not passed in.');
	}
	var newImg = "";
	if ( curImg.indexOf("minus") > -1 ){
	    newImg = curImg.replace(/minus/g,"plus");
	}
	else if( curImg.indexOf("-") > -1 ){
	    newImg = curImg.replace(/-/g,"+");
	}
	else{
	    newImg = curImg.replace(/plus/g,"minus");
	    newImg = curImg.replace(/\+/g,"-")
	}
	var newDisp = "none";
	var bVisible = false;
	if ( currDisp == "none")
	{
		newDisp = (document.all)? "" : "table-row";
		//newImg = "../images/minus.gif";
		bVisible = true;
	}
	oEl.style.display = newDisp;
	
	switch ( oImg.tagName ){
	        case "IMG":
		        oImg.src = newImg;
		        break;
		    case "DIV":
		        oImg.innerHTML = newImg;
		        break;
		    default:
		        alert("No handler for '" + oImg.tagName + "'!");
		    }  
	
	
	return bVisible;	

}

function toggleDisplaySimple(strElementId){	
	var oEl = null;
    if ( strElementId) {
        if ( strElementId.toString().indexOf("[object") > -1 ) // object
	    {
	        oEl = strElementId;
	    } 
	    else // string
        {
	        oEl = document.getElementById(strElementId);
	    }
	}
	if ( oEl == null ){
	    alert(strElementId + " is not in this document.");
	    return false;
	}
	if ( oEl ){
	    var currDisp = oEl.style.display;
	    var newDisp = "none";
	    var bVisible = false;
	    if ( currDisp == "none")
	    {
		    newDisp = (document.all)? "block" : "table-row";
		    bVisible = true;
	    }
	    oEl.style.display = newDisp;
	}
	return bVisible;
}

function toggleDisplayByNames(sName, oImg){
    var aObj = document.getElementsByName(sName);
    if ( aObj){
        // on the first one toggle image too
        toggleDisplay( aObj[0], oImg );
        // then only the display
        for ( i=1; i < aObj.length; i++ ) {
            toggleDisplaySimple( aObj[i] );
        }
    }
    else{
        alert(sName + " is not in this document");
    }    
}

function toggleDisplaySimpleByNames(sName){
    var aObj = document.getElementsByName(sName);
    if ( aObj){
        for ( i=0; i < aObj.length; i++ ) {
            toggleDisplaySimple( aObj[i] );
        }
    }
    else{
        alert(sName + " is not in this document");
    }    
}

function toggleDisplayByEnumeratedId(sBaseId, oImg){
    var i=0;
    var obj = document.getElementById(sBaseId + i);
    // on the first one toggle image too
    if (obj) { 
        toggleDisplay( obj, oImg ); 
    
        while ( obj){        
            // then only the display
            toggleDisplaySimple( obj );
            i++;
            obj = document.getElementById(sBaseId + i);
        }
    }
    else{
        alert(sBaseId + i + " is not in this document");
    }        
}

function toggleDisplaySimpleByEnumeratedId(sBaseId){
    var i=0;
    var obj = document.getElementById(sBaseId + i);
    // on the first one toggle image too
    if (obj) {      
        while ( obj){        
            // then only the display
            toggleDisplaySimple( obj );
            i++;
            obj = document.getElementById(sBaseId + i);
        }
    }
    else{
        alert(sBaseId + i + " is not in this document");
    }
}

function tryToFocus(sControl, bSelect){
        try{
            var oEl = document.getElementById(sControl);
            if ( oEl.style.display != "none" 
                && oEl.style.visibility != "hidden" )
                {
                    oEl.focus();
                    if ( bSelect == true ){
                    oEl.select();
                    }
                }
        }
        catch(e){}
    }

function showReportPopUp(sReport, sParams, sParameterValues, sDirectPars, sOpenReportInPopup, sReportCategoryID){
    var sUrl = "ReportPopUp.aspx?Report=" + sReport;
    
    sUrl = sUrl + "&sep=|";
        
    if ( sParams ){
        sUrl = sUrl + "&p=" + sParams;
    }
    
    if ( sParameterValues ){
        sUrl = sUrl + "&pv=" + sParameterValues;
    }
    
    if ( sDirectPars ){
        sUrl = sUrl + sDirectPars;
    }
    
    if ( sOpenReportInPopup == "1" ){
        sUrl = sUrl + "&orip=1";
    }
    
    if ( sReportCategoryID ){
        msSelectedCategory = sReportCategoryID;
        sUrl = sUrl + "&cat=" + sReportCategoryID;
    }
    window.open(sUrl,"winReportPopup","location=no, height=500, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=no");

}

function showClientDoc(sFileName, sPath){
    if ( sFileName == "" ){
        return;
    }
    if ( sPath ){
        window.open(sPath + sFileName);
    }
    else{
        var sPath = "policies/";
        window.open(sPath + sFileName);
        }

    }

    function viewError(id) {
        window.open("ErrorViewPopUp.aspx?ErrorID=" + id, "ErrorViewPopUp", expensePopupFeaturesScroll);
    }


/* TIME LINE */
var resizeTimerID = null;
function onResizeForTimeline() {
    try{
        if ( tl != null ){
            if (resizeTimerID == null) {
                resizeTimerID = window.setTimeout(function() {
                    resizeTimerID = null;
                    tl.layout();
                }, 500);
            }
        }
    }
    catch(e){
        // silent
    }
}
