﻿//on screen report when topline is selected, orig question and direction will be enabled
function OnScreenChanged(ddlonscreen,ddlorigQ,cbDirection)
{  
    
    var control1 = document.getElementById(ddlonscreen);
    var control2 = document.getElementById(ddlorigQ);
    var control3 = document.getElementById(cbDirection);
    var selectedtext = control1.options[control1.selectedIndex].text;
    
    var re = /ine/;
    //re = new RegExp('/line/');
    if(re.test(selectedtext))
    { 
       control2.disabled = false;
       control3.disabled = false;
      
    }   
    else
    {
       control2.disabled = 'disabled';
       control3.disabled = 'disabled';
    }

}

// JScript File
var filterPopUp; 
var filterID ;

function OpenFilterPage(EditFilterButtonidname,FilterDDLidname,reportid, postBack)
{
    if(filterID == null)
    {
        var filterddl = document.getElementById(FilterDDLidname);
        filterID =  filterddl.options[filterddl.selectedIndex].value;
    
    }      
    
     
	filterPopup = window.open('Filter.aspx?formname=' + document.forms[0].name + 
		'&reportid=' + reportid + '&id=' + EditFilterButtonidname + '&selected=' + filterID + '&postBack=' + postBack, 
		'FilterEditor', 'width=1000,height=800,left=200,top=250');
	 
   
}


//This function is used to set filter id for  Filter.aspx  to edit


function OnFilterDDLChanged(filterddlname)
{
     
    var filterddl = document.getElementById(filterddlname);
    filterID =  filterddl.options[filterddl.selectedIndex].value;
} 


function SetFilter(formName, id,  postBack)
{
        
	  
	
	//theform.elements[id].value = newDate;
	if (postBack)
	{  
	    window.opener.__doPostBack(id,'');
	}
	self.close();	
		
}

/* CR# 555 - Non-descript "Generating..." during data pull on GeneralReports Page
 * Added On: 2007.03.16
 * Added By: jlounder
 * Description: Moving functions to survey javascript file
 * 
 * CR #601 - Report Portal Progress Bar does not work properly with Multiple Tabs
 * Added On: 2007.04.16
 * Added By: jlounder
 * Description: Added the PageViewID as a parameter, and initialize the various variables
 * using eval and the PageViewID.
 * Removed references to the timer array because there is no reason to store timers
 * in this implementation.
 * Added a new function to handle multiple onload events for multiple tabs.
 */

function __hideNonComplete(page,tblName)
{
    var array = eval("array"+page);
    var links = eval("links"+page);
    var i = 0;
    for(i;i<array.length;i++){
        var cell = document.getElementById(tblName).rows[array[i]+1].cells[8];
        links[i] = cell.innerHTML;
        cell.innerHTML = '<a disabled="disabled">File</a><br /><a disabled="disabled">Layout</a>';
    }
}

function __updateStatus(i, min, max, page, tblName)
{
    var array = eval("array"+page);
    var links = eval("links"+page);
    var inter = eval("inter"+page);
    var curpc = eval("curpc"+page);
    var cell = document.getElementById(tblName).rows[array[i]+1].cells[7];
    if(cell!=null)
    {
        var retVal = BayaSoft.BayaSurv.ReportPortal.GeneralReports.getReportLogStatus(cell.childNodes[0].value).value;
        if(retVal!=null)
        {
            var code = retVal.substring(0,1);
            var newpc = parseInt(retVal.substring(1,3));
            var pcChange = newpc-curpc[i];
            curpc[i]=newpc;
            var newHTML = retVal.substring(3);
            if(code=="0"){
                if((pcChange<5)&&(inter[i]<min)) inter[i]+=5000;
                else if((pcChange>10)&&(inter[i]>max)) inter[i]-=5000;
                setTimeout("__updateStatus("+i+","+min+","+max+",'"+page+"','"+tblName+"')",inter[i]);
            }
            else{
                if(code=="1")
                {
                    document.getElementById(tblName).rows[array[i]+1].cells[8].innerHTML = links[i];
                }
                retVal = BayaSoft.BayaSurv.ReportPortal.GeneralReports.getReportLogDataSize(cell.childNodes[0].value).value;
                if(retVal!=null) document.getElementById(tblName).rows[array[i]+1].cells[6].innerHTML = retVal;
            }
            cell.innerHTML=newHTML;
        }
    }
}

function __addLoadEvent(func) 
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function') 
    {
        window.onload = func;
    }
    else
    {
        window.onload = function() 
        {
            if (oldonload) 
            {
                oldonload();
            }
            func();
        }
    }
}

/* end CR# 555
 * end CR# 601
 */
 
/* CR #570 - Changing "Export Format" on Survey View causes PostBack
 * Added On: 2007.03.16
 * Added By: jlounder
 * Description: Adding code to enable/disable the Export Languages drop down based on
 * the Export Format drop down's current value. Also added three lines above
 */
function __changeFormat(drpFormat, list)
{
    var formatId = drpFormat.id;
    var langId = formatId.substring(0,formatId.length-6)+"Lang";
    var drpLang = document.getElementById(langId);
    var selected = drpFormat.options[drpFormat.selectedIndex].value;
    var found = false
    for(i=0;!found && i<list.length;i++) if(list[i]==selected) found=true;
    if(found)
    {
      drpLang.disabled=false;
    }
    else
    {
      drpLang.selectedIndex = 0;
      drpLang.disabled=true;
    }
     
    
}
/* end CR#570
 */