﻿// JScript File

/*function openWindow()
{
    var kiosk;
    var width = 850;
    var height = 800;
	var wSettings = 'toolbar = no, directories = no, status = no, menubar = no, scrollbars = yes, copyhistory = no, resizable = yes';
	kiosk = window.open('logon.aspx','Assessments', wSettings);
	kiosk.resizeTo(width,height);
	kiosk.focus();
	
	var iMyWidth;
	var iMyHeight;
	//half the screen width minus half the new window width (plus 5 pixel borders).
	//get screen width: window.screen.width
	//get screen height: window.screen.height
    iMyWidth = (1280/2) - (75 + 10);
    //half the screen height minus half the new window height (plus title and status bars).
    iMyHeight = (1024/2) - (100 + 50);
	kiosk.moveTo(200,200);

}


function mdgs(int mdg)
{
    
    var kiosk;
    var width = 400;
    var height = 400;
	var wSettings = 'toolbar = no, directories = no, status = no, menubar = no, scrollbars = yes, copyhistory = no, resizable = yes';
	kiosk = window.open('mdg.aspx?mdg='+mdg,'Assessments', wSettings);
	kiosk.resizeTo(width,height);
	kiosk.focus();
	
	var iMyWidth;
	var iMyHeight;
    iMyWidth = (1280/2) - (75 + 10);
    iMyHeight = (1024/2) - (100 + 50);
	kiosk.moveTo(200,200);
} */

function validateDropDown()
{
	var array = document.getElementsByTagName("select");
	
	if (array) 
	{
    	for (var i=0; i < array.length; i++) 
		{
			var elem = array[i];
			
			if (elem.value == "") 
			{
				alert("Please fill in all of the boxes");
				return false;
			}
		}
	}	
}


function checkLocal(rowIndex)
{
    if(document.getElementsByTagName)
    {  
        var table = document.getElementById("ctl00_ContentPlaceHolder1_AssessmentCountriesGrid");
    
        if (!table)
        {
            // Not found, use IE style
            list = document.getElementById("ctl00$ContentPlaceHolder1$AssessmentCountriesGrid");
        }
                
        var rows = table.getElementsByTagName("tr");  
        
        var checkboxes = rows[rowIndex + 2].getElementsByTagName("input");
                   
        for(j = 0; j < checkboxes.length; j++)
        {             
            var localCB = checkboxes[0];
            var regionalCB = checkboxes[1];
            var nationwideCB = checkboxes[2];
        
            if (localCB.checked == true)
            {                
                regionalCB.disabled = true;
                nationwideCB.disabled = true;
            }            
            else 
            {                    
                regionalCB.disabled = false;
                nationwideCB.disabled = false;
            }
        }
    }
}

function checkRegional(rowIndex)
{
    if(document.getElementsByTagName)
    {  
        var table = document.getElementById("ctl00_ContentPlaceHolder1_AssessmentCountriesGrid");
    
        if (!table)
        {
            // Not found, use IE style
            list = document.getElementById("ctl00$ContentPlaceHolder1$AssessmentCountriesGrid");
        }
                
        var rows = table.getElementsByTagName("tr");  
        
        var checkboxes = rows[rowIndex + 2].getElementsByTagName("input");
                   
        for(j = 0; j < checkboxes.length; j++)
        {             
            var localCB = checkboxes[0];
            var regionalCB = checkboxes[1];
            var nationwideCB = checkboxes[2];
        
            if (regionalCB.checked == true)
            {                
                localCB.disabled = true;
                nationwideCB.disabled = true;
            }            
            else 
            {                    
                localCB.disabled = false;
                nationwideCB.disabled = false;
            }
        }
    }
}

function checkNationwide(rowIndex)
{
    if(document.getElementsByTagName)
    {  
        var table = document.getElementById("ctl00_ContentPlaceHolder1_AssessmentCountriesGrid");
    
        if (!table)
        {
            // Not found, use IE style
            list = document.getElementById("ctl00$ContentPlaceHolder1$AssessmentCountriesGrid");
        }
                
        var rows = table.getElementsByTagName("tr");  
        
        var checkboxes = rows[rowIndex + 2].getElementsByTagName("input");
                   
        for(j = 0; j < checkboxes.length; j++)
        {             
            var localCB = checkboxes[0];
            var regionalCB = checkboxes[1];
            var nationwideCB = checkboxes[2];
        
            if (nationwideCB.checked == true)
            {                
                regionalCB.disabled = true;
                localCB.disabled = true;
            }            
            else 
            {                    
                regionalCB.disabled = false;
                localCB.disabled = false;
            }
        }
    }
}


function checkCountriesOnload()
{
    if(document.getElementsByTagName)
    {  
        var table = document.getElementById("ctl00_ContentPlaceHolder1_AssessmentCountriesGrid");
    
        if (!table)
        {
            // Not found, use IE style
            list = document.getElementById("ctl00$ContentPlaceHolder1$AssessmentCountriesGrid");
        }
        
        
        var rows = table.getElementsByTagName("tr");  
        
        for(i = 0; i < rows.length; i++)
        {   
            var checkboxes = rows[i].getElementsByTagName("input");
            
            for(j = 0; j < checkboxes.length; j++)
            {             
                var localCB = checkboxes[0];
                var regionalCB = checkboxes[1];
                var nationwideCB = checkboxes[2];
                
                if (localCB.checked == true)
                {                
                    regionalCB.disabled = true;
                    nationwideCB.disabled = true;
                }
                
                if (regionalCB.checked == true)
                {   
                    localCB.disabled = true;             
                    nationwideCB.disabled = true;                    
                }
                
                if (nationwideCB.checked == true)
                {                                    
                    localCB.disabled = true;
                    regionalCB.disabled = true;
                }                                
            }
        }                      
    }
}


function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false;}
else {return true}
}
}


function checkRelatedQuestion()
{ 
    // First look for the firefox style   
    var list = document.getElementById("ctl00_ContentPlaceHolder1_QuestionRelated");
    
    if (!list)
    {
        // Not found, use IE style
        list = document.getElementById("ctl00$ContentPlaceHolder1$QuestionRelated");
    }
        
    var label = document.getElementById("ViewRelatedErrorLabel");    
                        
    if (list)
    { 
        if (list.value == '0')
        {            
        	label.style.display = 'block';
        	label.style.visibility = 'visible';
        	label.style.color = 'red';
      	} 
      	else 
      	{
	        label.style.display = 'none';    
	    	label.style.visibility = 'hidden';
    	    var questionId = list.value;
    	    
    	    window.open('QuestionDetails.aspx?mode=view&id=' + questionId, '','toolbar=no,location=no-directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=800,height=800');
      	}
    }
    return false;
}

function showStatusDropdown()
{
    // Get the AnotherProjectRadioList
    var yesRadio = document.getElementById("ctl00_ContentPlaceHolder1_AnotherProjectRadioList_0");
    
    if (!yesRadio)
        radio = document.getElementById("ctl00$ContentPlaceHolder1$AnotherProjectRadioList$0");
    
        
    // Get the div that holds the AssessmentStatusList
    var status = document.getElementById("StatusDropdown");
        
    var validator = document.getElementById("ctl00_ContentPlaceHolder1_AssessmentStatusValidator");
    
    if (!validator)
    {
        validator = document.getElementById("ctl00$ContentPlaceHolder1$AssessmentStatusValidator");
    }
    
    if (yesRadio)
    {    
        if (yesRadio.checked)
        {            
            // Enable the assessment status validator        	    	
            if (validator)
            {
                ValidatorEnable(validator, true); 
            }
        
            status.style.display = 'block';    
	    	status.style.visibility = 'visible';            
	    }
	    else
	    {
	        status.style.display = 'none';    
	    	status.style.visibility = 'hidden';
	    	
	    	// Disable the validator for the status drop down
    	    if (validator)
  	    	{  	
                ValidatorEnable(validator, false); 
            }
	    }
    }
    else
    {
        // Check to see if the hidden final project field is set to true
        var elem = document.getElementById("ctl00_ContentPlaceHolder1_IsFinalProjectHiddenField");
    
        if (!elem)
        {
            elem = document.getElementById("ctl00$ContentPlaceHolder1$IsFinalProjectHiddenField");
        }   
        
        if (elem.value == "true")
        {
            status.style.display = 'block';    
	    	status.style.visibility = 'visible';            
	    }
	    else
	    {
	        status.style.display = 'none';    
	    	status.style.visibility = 'hidden';
	    }                    
    }
}


// This function is called only by the AddProjects page.
function showProjectStatusDropdown()
{
    // Get the AnotherProjectRadioList
    var noRadio = document.getElementById("ctl00_ContentPlaceHolder1_AddProjectsRadioList_1");
    var yesRadio = document.getElementById("ctl00_ContentPlaceHolder1_AddProjectsRadioList_0");
    
    if (!noRadio)
        radio = document.getElementById("ctl00$ContentPlaceHolder1$AddProjectsRadioList$1");
        
    if (!yesRadio)
        radio = document.getElementById("ctl00$ContentPlaceHolder1$AddProjectsRadioList$0");
    
    
    // Enable the assessment status validator
    var validator = document.getElementById("ctl00_ContentPlaceHolder1_AssessmentStatusValidator");
    
    if (!validator)
    {
        validator = document.getElementById("ctl00$ContentPlaceHolder1$AssessmentStatusValidator");
    }
    	    	
    if (validator)
    {
        ValidatorEnable(validator, true); 
    }
    
    
    // Get the div that holds the AssessmentStatusList
    var status = document.getElementById("StatusDropdown");
     
    if (noRadio && noRadio.checked)
    {
        status.style.display = 'block';    
	    status.style.visibility = 'visible';  	    		    		    
    }
    else if (yesRadio && yesRadio.checked)
    {
        status.style.display = 'none';    
    	status.style.visibility = 'hidden';  	    		    	

    	// Disable the validator for the status drop down
    	if (validator)
    	{    	
            ValidatorEnable(validator, false); 
        }
	}
    else
    {
        // Check to see if the hidden final project field is set to true
        var noProjects = document.getElementById("ctl00_ContentPlaceHolder1_NoProjectsHiddenField");
    
        if (!noProjects)
            noProjects = document.getElementById("ctl00$ContentPlaceHolder1$NoProjectsHiddenField");
        
        var showNoProjectsRadios = document.getElementById("ctl00_ContentPlaceHolder1_ShowNoProjectsRadioHiddenField");
    
        if (!showNoProjectsRadios)
            showNoProjectsRadios = document.getElementById("ctl00$ContentPlaceHolder1$ShowNoProjectsRadioHiddenField");
            


        if (showNoProjectsRadios && showNoProjectsRadios.value == "true")
        {
            // No has been answered previously    
            if (noProjects.value == "true")
            {
                status.style.display = 'block';    
	    	    status.style.visibility = 'visible';         	
	        }
	        // First time thru, neither Yes or No has been answered
	        else if (noProjects.value == "")
	        {
	            status.style.display = 'none';    
	    	    status.style.visibility = 'hidden';    	    	
	        }
	        // Yes has been answered previously
	        else
	        {
	            status.style.display = 'none';    
	    	    status.style.visibility = 'hidden';    	    	                    
	        }                    
	    }
	    else
	    {
	        // Either not project 1 or previous project details have been displayed, therefore
	        // the question would not be in the HTML
	        var addProjects = document.getElementById("AddProjectsRadios");
	        
	        status.style.display = 'none';    
	    	status.style.visibility = 'hidden';            	                    
	    }
    }
}