﻿ function displayGraph(frm, chbox, imgid, url){ 
    var query = ""; 
    for( var i = 0; i < document.forms[frm.id].elements.length; i++)   
    { 
        if(document.forms[frm.id].elements[i].checked)
            query += document.forms[frm.id].elements[i].name.replace('_','=') + "&";
    }
     
     if(query != "") 
     {
        query = query.substring(0,query.length-1); 
        var baseurl = url.substring(0,url.indexOf("?"));
        var image = document.getElementById(imgid);
        var wh = url.substring(url.indexOf("W="));
        image.src = baseurl + "?"+ query + "&" + wh; 
     }
     else
     {
        alert("You should check atleast one Item to display the Graph");
        chbox.checked = 1;                
      }
     
}

function ChangeType(ele)
{
    var theForm = document.getElementById(ele.form.id);
    var Fe = theForm.elements; 
    var QueryString = new Array();
    var CheckedRegions = false;
    for (var x=0; x<Fe.length; x++)
    {
        if (Fe[x].type=="checkbox")
        {
            if (Fe[x].checked)
            {
                CheckedRegions = true;
                QueryString.push(Fe[x].name.replace(/_/g,'='));
            }
        }
        /*
        else if (Fe[x].type=="radio")
        {
            if (Fe[x].checked)
            {
                 QueryString.push(Fe[x].name + "=" + Fe[x].value);
            }
        }
        */
    }
    
    if (!CheckedRegions)
    {
        window.alert("You should check atleast one Item to display the Graph");
        ele.checked = true;
        return;
    }
    /*
    var CT = theForm.CT.options;
    if (CT.selectedIndex > 0)
    {
        QueryString.push("CT=" + CT[CT.selectedIndex].value);
    }
    var ST = theForm.ST.options;
    if (ST.selectedIndex > 0)
    {
        QueryString.push("ST=" + ST[ST.selectedIndex].value);
    }
    
    var D3 = theForm.D3.options;
    if (D3[D3.selectedIndex].value == "true")
    {
        QueryString.push("D3=true");
    }
    */
    var chartid = theForm.chartid.value;
    var chartrawpath = theForm.chartrawpath.value;
    document.getElementById(chartid).src = chartrawpath + "&" + QueryString.join("&");
}

function ChangeTypeWithFName(formID)
{
    var theForm = document.getElementById(formID);
    var Fe = theForm.elements; 
    var QueryString = new Array();
    var CheckedRegions = false;
    for (var x=0; x<Fe.length; x++)
    {
        if (Fe[x].type=="checkbox")
        {
            if (Fe[x].checked)
            {
                CheckedRegions = true;
                QueryString.push(Fe[x].name.replace(/_/g,'='));
            }
        }
    }
    
    if (!CheckedRegions)
    {
        window.alert("You should check atleast one Item to display the Graph");
        ele.checked = true;
        return;
    }
    var chartid = theForm.chartid.value;
    var chartrawpath = theForm.chartrawpath.value;
    document.getElementById(chartid).src = chartrawpath + "&" + QueryString.join("&");
}

function gE(id)
{
	return document.getElementById(id);
}

function GoTab(id,activeLinkIndex,contentId)
{
	if (activeLinkIndex==undefined)
	{
		activeLinkIndex = 0;
	}
	sweepTabs();
	gE(id).className = 'active';
	gE(id).getElementsByTagName('a')[0].className = 'active';
	//get subnav if it exists
	if (gE('sub_' + id) != null)
	{
		GoSubnav('sub_' + id, activeLinkIndex);
	}
	if (contentId != undefined)
	{
		sweepContent();
		gE('dmgsc_' + contentId).style.display = 'block';
		if(contentId != "schoolsmap")
		{
		    ChangeTypeWithFName("form_chart" + contentId);
		}
	}
}

function sweepContent()
{
	var divs = document.getElementsByTagName("div");
	for (var x = 0; x < divs.length; x++)
	{
		if (divs[x].id.substr(0,6) == 'dmgsc_')
		{
			divs[x].style.display = 'none';
		}
	}
}

function GoSubnav(id,activeLinkIndex)
{
	sweepSubnavs();
	gE(id).style.display = 'block';
	var links = gE(id).getElementsByTagName('a');
	for (var x=0;x < links.length;x++)
	{
		if (x==activeLinkIndex)
		{
			links[x].className = 'active';
		}
		else
		{
			links[x].className = 'norm';
		}
	}
}

function sweepSubnavs()
{
	var divs = document.getElementsByTagName("div");
	for (var x = 0; x < divs.length; x++)
	{
		if (divs[x].id.substr(0,8) == 'sub_dmgs')
		{
			divs[x].style.display = 'none';
		}
	}
}
function sweepTabs()
{
	var lis = document.getElementsByTagName("li");
	for (var x = 0; x < lis.length; x++)
	{
		if (lis[x].id.substr(0,4) == 'dmgs')
		{
			lis[x].className = 'norm';
			lis[x].getElementsByTagName('a')[0].className = 'norm';
		}
	}
}
