var cameraWin = null;
var chartWin = null;
var graphWin = null;


/*=======================================================================================================*/

function CameraCompare( frm ) {

	var camlist = null;

	for ( i = 0 ; i < frm.length ; i++ ) {
		if ( frm[i].type == "checkbox" && frm[i].checked ) {
			if ( ! camlist ) camlist = frm[i].value;
			else camlist += "," + frm[i].value;
		}
	}


	if ( ! camlist ) {
		alert( "Select one or more cameras first!\n" );
		return;
	}


	var url = "camera_chart.php?cams=" + camlist;
	if ( ! cameraWin || cameraWin.closed )
		cameraWin = open( url, "cameraWindow", "width=950,height=450,resizable=1,scrollbars=1" );
	else cameraWin.location.href = url;
	cameraWin.focus();
}


/*=======================================================================================================*/

function GraphEntryRandValues( userid ) {

	var url = "graph_entry_rand.php?userid=" + escape( userid );
	if ( chartWin && ! chartWin.closed ) chartWin.close();

	chartWin = open( url, "chartWindow", "width=900,height=450,resizable=1,scrollbars=1" );
	chartWin.focus();
}


/*=======================================================================================================*/

function GraphEntrySub( frm ) {

	var idx = frm.challenge.selectedIndex;
	var chlg = frm.challenge[idx].value;

	var url = "graph_entry_sub.php?challenge=" + escape( chlg );
	if ( chartWin && ! chartWin.closed ) chartWin.close();

	chartWin = open( url, "chartWindow", "width=950,height=450,resizable=1,scrollbars=1" );
	chartWin.focus();
}


/*=======================================================================================================*/

function GraphEntryVotes( frm ) {

	var idx = frm.challenge.selectedIndex;
	var chlg = frm.challenge[idx].value;

	var url = "graph_entry_votes.php?challenge=" + escape( chlg );
	if ( chartWin && ! chartWin.closed ) chartWin.close();

	chartWin = open( url, "chartWindow", "width=450,height=450,resizable=1,scrollbars=1" );
	chartWin.focus();
}

/*=======================================================================================================*/

function ShowChart( url ) {

	if ( chartWin && ! chartWin.closed ) chartWin.close();
	chartWin = open( url, "chartWindow", "width=650,height=450,resizable=1,scrollbars=1" );

	chartWin.focus();
}


/*=======================================================================================================*/

function ShowGraph( url ) {

	if ( ! graphWin || graphWin.closed )
		graphWin = open( url, "graphWindow", "width=650,height=450,resizable=1,scrollbars=1" );
	else graphWin.location.href = url;
	graphWin.focus();
}

