﻿// JScript File
//=========================================================
//use for links to the "IPEDS Data Feedback Report" like on peer.aspx
function openpopup2()
{
    var popurl="npec.aspx";
    var winpops=window.open(popurl,"","width=400,height=338,scrollbars=yes,menubar=no,screenX=0,screenY=0,top=0,left=0");
}
//=========================================================
//open the upload help page from the peer selection page
function openpopup_uploadhelp()
{
    var popurl="uploadhelp.aspx";
    var winpops=window.open(popurl,"","width=400,height=338,scrollbars=yes,menubar=no,screenX=0,screenY=0,top=0,left=0");
}

//=========================================================
//Opens popup window for chart descriptions links on the variables page.
function openchartpopup(chartid)
{
    var popurl="chartdescription.aspx?chartid=" + chartid;
    var winpops=window.open(popurl,"","width=400,height=338,scrollbars=yes,menubar=no,screenX=0,screenY=0,top=0,left=0");
}

//=========================================================
//use for links to the "IPEDS Data Feedback Report" like on peer.aspx
function openwwpdpopup(url)
{
    var popurl = 'wwpd/?wwpd=' + url;
    var winpops=window.open(popurl,"","width=400,height=338,scrollbars=yes,menubar=no,screenX=0,screenY=0,top=0,left=0");
}

//=========================================================
//open the power user login window
function openPowerUserPopup(url)
{
    var winpops=window.open(url,'pu',"width=519,height=260,screenX=0,screenY=0,top=0,left=0,resizable=Yes,scrollbars=yes,menubar=yes");
}
//=========================================================
//Called from default.aspx when the linkbutton is clicked before continuing to the peer page
//this just sets the focus instution before post
function setFocusInstitution(sUnitid)
{   document.getElementById(GetClientIdFor_Input("__EXPT_Focus__")).value=sUnitid;
}

//=========================================================
//This function will make sure at least one has text entered
//used on peer selection page
function AtLeastOneRequired_PeerAddByName()
{   var oFields;
    oFields = window.document.getElementsByTagName("input");
	for(var x = 0;x<oFields.length;x++)
	{   if(oFields[x].name.search("TextBox_Name")>0)
	    {   //look for at least one with input
	        if(lTrim(oFields[x].value)!=""){ return true; }
	    }
	}	
	alert("Please enter at least one institution name.");
	//no input was found
	return false;
}

//=========================================================
//lTrim--small function to trim blank spaces from a string
//Last Modified: 1/19/06 By: JLM  	
function lTrim(sStr) 
{   while (sStr.substring(0,1) == ' ')
    {   sStr = sStr.substring(1, sStr.length);
    }
    return sStr;
}//end lTrim()

//=========================================================
//Make sure at least one selection has been selected.
//used on chartSelection.aspx
//Created 7/10/2007 -sls
function selectAtLeastOne()
{
    var oFields = window.document.getElementsByName("charts");
    var results = false
    for(var x=0;x<oFields.length;x++)
    {
        if (oFields[x].checked == true)
        {
            results = true;
        }//end if        
    }//end for
    
    if (results == false)
        alert("You must select at least one chart to include in  your custom report.")
        
    return results
}//end function 

//=========================================================
//Select all function. Selects all Variable in the same 
//group on the variables page.
//Created 6/25/2007 -sls
function selectAllVar(sTargetBoxName, sToggleBoxID)
{
    var bToggleValue = window.document.getElementById(sToggleBoxID).checked;
    var num = sTargetBoxName.indexOf(":");      
    var oFields = window.document.getElementsByTagName("input");
    
    for(var x=0;x<oFields.length;x++)
    {
       var temp = oFields[x].name.substring(0,num + 1);
       alert(temp);
       if (sTargetBoxName == temp)
       {             
              oFields[x].checked = bToggleValue;
       }//end if
    }//end for
    bToggleValue = null
}//end function

//=========================================================
//Toggle the checkboxes with names matching the sTargetBoNme 
// according to the current state of sToggleBoxID.
//used on peerresults to select/deselect checkboxes.
function ToggleCheckboxesByName(sToggleBoxID, sTargetBoxName)
{   var bToggleValue = window.document.getElementById(sToggleBoxID).checked;
    //get all relevant boxes
    var oFields = window.document.getElementsByName(sTargetBoxName);
    for(var x=0;x<oFields.length;x++)
    {   oFields[x].checked=bToggleValue;
    }
}

//Used to check or uncheck all checkboxes within a given element [name].
//[toggleField] is the field that contains the true/false value.
//Author: Andy Simpson, HigherEd.org
function toggleAll(name, toggleField){
    var toggler  = document.getElementById(toggleField);
    var bOn = toggler.value;
    var list = document.getElementsByName(name); 
    
    for(var x=0; x<=list.length-1; x++){
        if (bOn=='true'){
            list[x].checked=false;
        }else{
            list[x].checked=true;
        }
    }
    
    if (bOn=='true'){
        toggler.value = "false";
    }else{
        toggler.value = "true";
    }
   
}

function toggleAllWithin(element, toggleField){
    var toggler  = document.getElementById(toggleField);
    var bOn = toggler.value;
    var list = getElementsByClassName(element,'input',''); 

    for(var x=0; x<=list.length-1; x++){
        if (bOn=='true'){
            list[x].checked=false;
        }else{
            list[x].checked=true;
        }
    }
    
    if (bOn=='true'){
        toggler.value = "false";
    }else{
        toggler.value = "true";
    }
}


//Used to get all elements by class name Or all elements within a containing element [oElm]
function getElementsByClassName(sElm, strTagName, strClassName){
    var oElm = document.getElementById(sElm);
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
//=========================================================
//Check the results page checkboxes to make sure at least one is selected
// before allowing the user to continue.
function AtLeastOneRequired_PeerResults()
{   var iCount=0;
    //check the "Additional" section
    var oFieldsAdditional = window.document.getElementsByName("Additional_Unitids_Added");
    for(var x=0;x<oFieldsAdditional.length;x++)
    {   if(oFieldsAdditional[x].checked==true) 
        {   iCount++;
            if(iCount>100)
            {   alert("You have exceeded the 100 institution limit.");
                return false;
            }
        }
    }

    //check the "Original" section
    var oFieldsOriginal = window.document.getElementsByName("Original_Unitids_Added");
    for(var x=0;x<oFieldsOriginal.length;x++)
    {   if(oFieldsOriginal[x].checked==true)
        {   iCount++;
            if(iCount>100)
            {   alert("You have exceeded the 100 institution limit.");
                return false;
            }
        }    
    }

    if(iCount==0)
    {   alert("Please select at least one institution.");
        return false;
    }
    else
    {   return true;
    }
}

//=========================================================
//Make sure at least one variable is selected on the variable selection page.
function AtLeastOneRequired_Variables(){
    var theForm = document.aspnetForm;
    var iCount = 0;
    if(document.getElementById("ctl00_ctl00_ExPTContent_ContentPlaceHolder1_RadioButton1").checked==true) {
        //Variables
        theForm.action="stats.aspx";
        var oFields = document.getElementById("ctl00_ctl00_ExPTContent_ContentPlaceHolder1_panel1").getElementsByTagName("input");
        for(var x=0;x<oFields.length;x++)
        {   //only look at checkboxes with "|" in the name
            if(oFields[x].id.indexOf(":")>0 && oFields[x].type=="checkbox")
            {   if(oFields[x].checked==true)
                {   iCount++;
                    return true;
                }
            }
        }
        if(iCount==0){   
            alert("You must select at least 1 variable to continue.");
            return false;
        }else{
            return true;
        }    
    }else{
        //Charts
        theForm.action="customDFR.aspx";
        var oFields = document.getElementById("ctl00_ctl00_ExPTContent_ContentPlaceHolder1_panel2").getElementsByTagName("input");
        for(var x=0;x<oFields.length;x++)
        {   //only look at checkboxes with "|" in the name
            if(oFields[x].type=="checkbox")
            {   if(oFields[x].checked==true)
                {   iCount++;
                    return true;
                }
            }
        }
        if(iCount==0){   
            alert("You must select at least 1 chart to continue.");
            return false;
        }else{
            return true;
        }   
    }

    

}

//=========================================================
//Called from the masterpage to open the nces_warning popup
function openpopup_nceswarning()
{   var popurl="nces_warning.aspx";
    var winpops=window.open(popurl,"","width=500,height=600,scrollbars=yes,menubar=no,screenX=0,screenY=0,top=0,left=0");
}

//=========================================================
//Called from the nces_warning popup
function readWarning()
{   window.opener.SaveDataUsageSelection("1");
    self.close();
    //this reference to "aspnetForm" may need to be modified since .net changes the name
    window.opener.document.aspnetForm.submit();
}

//=========================================================
//Called from the nces_warning popup
function noreadWarning()
{   window.opener.SaveDataUsageSelection("0");
    self.close(); 
}

//=========================================================
//User will select "agree" or "disagree" for the nces popup
//this function accepts "True" or "False"
//This function is called from the nces popup
//function SaveDataUsageSelection(sValue)
//{   document.getElementById(GetClientIdFor_Input("__EXPT_ViewedPopup__")).value=sValue;
//}

//=========================================================
//This is called on default.aspx to attempt to automatically open the nces popup
// the popup will probably be blocked by the browser, but the user will still have a link
// for opening it manually.
//function ShowPopupOnFirstLoad()
//{   if(document.getElementById(GetClientIdFor_Input("__EXPT_ViewedPopup__")).value=='1')
//    {   //user has already clicked through the popup, allow them to continue
//    }
//    else
//    {   //show the popup
//        openpopup_nceswarning();
//    }
//}

//=========================================================
//.NET changes the client id, so find the full version of it with this function
function GetClientIdFor_Input(sOriginalName)
{   var oFields = window.document.getElementsByTagName("input");
    for(var x=0;x<oFields.length;x++)
    {   if(oFields[x].id.match(sOriginalName))
        {   return oFields[x].id;
        }
    }
    //not found
    return "";
}

//=========================================================
function GetClientIdFor_Div(sOriginalName)
{   var oFields = window.document.getElementsByTagName("div");
    for(var x=0;x<oFields.length;x++)
    {   if(oFields[x].id.match(sOriginalName))
        {   return oFields[x].id;
        }
    }
    //not found
    return "";
}
//=========================================================
//change the form action according to what the user picked
//used on outputSelection.aspx
function setDestinationDFRPage(sFormName, sRadio1, sRadio2)
{
    //set the form action according to which radio is selected
    if(document.getElementById(GetClientIdFor_Input(sRadio1)).checked==true)
        document.getElementById(sFormName).action="variableSelection.aspx";
    else
        document.getElementById(sFormName).action="chartSelection.aspx";
    //submit the form
    document.getElementById(sFormName).submit();
}

function closeExportWindow()
{
    var div = document.getElementById(GetClientIdFor_Div("divExport"));
    div.style.display = 'none';
}
function openExportWindow()
{
    var div = document.getElementById(GetClientIdFor_Div("divExport"));
    div.style.display='';
    div.className = 'Export';

}


function SelectSchool(unitid){
    document.getElementById("ctl00_ctl00_ExPTContent___EXPT_Focus__").value=unitid;
    
    document.aspnetForm.action="peer.aspx"
    document.aspnetForm.submit();
}

function DownloadDFR(){
    var list = document.getElementById("DFRPeers");
    var selectedIndex = list.selectedIndex;
    var value = list[selectedIndex].value;
    var location = "pdf/IPEDSDFR2009_" + value.toString() + ".pdf"
    var winDFR=window.open(location,"winDFR","width=770,height=600,scrollbars=yes,menubar=no,screenX=0,screenY=0,top=0,left=0");
    //document.location = ;
}