// JavaScript Document
// This document and its contents thereof belong to Dreamscape Microsystems Ltd.
level = 0;
constituency = -1;
region = -1;
maptype = 0;
thematic = 0;
election = 2004;
view = 0;
title = "";
mapChange = false;
graphChange = false;
tableChange = false;

function Init(){
	mapChange = false;
	graphChange = false;
	tableChange = false;
}

function SetLevel(value){
	if(level != value){
		level = value;
		mapChange = 
		graphChange = 
		tableChange = true;
	}
}
	
function SetConstituency(cid){
	if(cid != constituency){
		constituency = cid;
		graphChange = tableChange = true;
		if((level < 2) || (!thematic))
			mapChange = true;
	}
}
		
function SetThematic(value){
	if(thematic != value){
		thematic = value;
		mapChange = true;
	}
}
	
function SetMapType(value){
	if(maptype != value){
		maptype = value;
		tableChange = graphChange = true;
		if(thematic)
			mapChange = true;
	}
}

function SetRegion(value){
	if(region != value){
		mapChange = graphChange = tableChange = true;
		region = value;
	}
}

function SetElection(value){
	if(election != value){
		tableChange = graphChange = true;
		if(thematic)
			mapChange = true;
		else if(election < 2004 && value >= 2004)
			mapChange = true;
		else if(election >= 2004 && value < 2004)
			mapChange = true;
	}
}

function SetTitle(value){
	title = value;
	vi = Ext.getCmp('card-panel').layout.activeItem;
	
	if(vi.id == 'map-panel')
		s =  "Map : ";
	else if(vi.id == 'graph-panel')
		s = "Graph : ";

	Ext.getCmp('card-panel').setTitle(s + title);
}
	
function GetTitle(view){
	return (view == 0 ? "Map : " : "Graph : ") + title; 
}
	
function UpdateTable(){
	/*	
	grid.store.load(
	{
		params:'maptype='+ maptype + '&region=' + region + '&level=' + level + '&cid=' + constituency + '&election=' + election			
	});*/		
	if(!tableChange)
		return;
	var map = Ext.get('stats');
	map.load({
		url: 'table.php', // <-- change if necessary
		params: 'level=' + level + '&election=' + election + '&region=' + region + '&maptype=' + maptype
				+ '&thematic=' + thematic + '&cid=' + constituency,
		text: 'Updating...',
		scripts:true		
	});
	
	map.show();
}

function ShowView(index)
{		
	Ext.getCmp('card-panel').layout.setActiveItem(index);
}
	/*
	UpdateMap = function(x, y)
	{
		UpdateMapWLevel(x,y,level);
	}
	*
	UpdateMapWLevel = function(x, y, level)
	{	
		if(!Update())
			return;
		var map = Ext.get('map');

		map.load({
			url: 'map.php', // <-- change if necessary
			params: 'x=' + x + '&y=' + y + '&level=' + level + '&election=' + election + '&region=' + region + '&maptype=' + maptype
					+ '&thematic=' + thematic + '&constituency=' + constituency,
			text: 'Updating...',
			scripts:true		
		});
		
		map.show();		
	}		
	*/	
		
function UpdateMap(x, y, view)
{
	var map = Ext.get('map');

	map.load({
		url: 'map.php', // <-- change if necessary
		params: 'x=' + x + '&y=' + y + '&level=' + level + '&election=' + election + '&region=' + region + 			 					'&maptype=' + maptype 	+ '&thematic=' + thematic + '&constituency=' + constituency + '&view='+view,
		text: 'Updating...',
		scripts:true		
	});
	
	map.show();		
}
	
function UpdateGraph(view){
	if(!Update())
		return;
			
	var graph = Ext.get('graph');
	
	graph.load({
		url: 'graph.php',
		params: 'level=' + level + '&election=' + election + '&region=' + region + '&graphtype=' + graphtype 
				+ '&thematic=' + thematic + '&cid=' + constituency + '&view='+ view + '&maptype=' + maptype,
		text:'Updating...',
		scripts:true
	});
	
	graph.show();
}
	
function Update(){
	view = Ext.getCmp('card-Nav').activeItem;
	
	if(view == 0)
		UpdateMap(-1, -1, view);
	else
		UpdateGraph(view);
}
			
			
			
	
	

		
		
	
			
		
	