/*
function preloadImages() {
  var streGRIDwebSource = "http://projects.pechan.com/epa/egridweb/image/";
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=streGRIDwebSource+a[i];}}
}
*/

function onLoad(){
	//try #1 for IE blinking
	//preloadImages('tab-left.png','tab-right.png','tab-left-active.png','tab-right-active.png');		
	//try #2 for IE blinking
	//try {document.execCommand('BackgroundImageCache', false, true);}catch(e) {}

	var objApplicationContainer = document.getElementById("eGRIDweb-container");
	if (objApplicationContainer)
		objApplicationContainer.className = "";
}

function step1_onLoad(){
	onLoad();
	//both of the following fail in IE7 - aparently, IE does views dynamic input type modification as illegal
	//document.frmDataFilterAndPreview.btnDisplayData.type = "submit";document.frmDataFilterAndPreview.btnDisplayData.setAttribute("type", "submit");

	var objViewDataButton = document.getElementById("btnDisplayData");
	if (objViewDataButton)
		objViewDataButton.className = "";	
}

function step2_EGCL_EGCO_PRCL_PRCO_onLoad(){
	onLoad();
//	var locationBasedLabel = document.getElementsByName("frmLocationSelection_viewDetail_locationBased_label");
//	var ownerBasedLabel = document.getElementsByName("frmOwnerSelection_viewDetail_ownerBased_label");
//	document.getElementById("frmLocationSelection_viewDetail_locationBased_label").setAttribute("class", "");
//	document.getElementById("frmOwnerSelection_viewDetail_ownerBased_label").setAttribute("class", "");
	document.getElementById("frmLocationSelection_viewDetail_locationBased_label").className="";
	document.getElementById("frmOwnerSelection_viewDetail_ownerBased_label").className="";
}

function step3_onLoad(){
	onLoad();
	//bCookiesEnabled is defined in _header.cfm
	if (bCookiesEnabled){
		//alert("cookies!");
		var objExportButton = document.getElementById("btneGRIDwebExport");
		if (objExportButton)
			objExportButton.disabled = false;	
	}
}

/****************************************************************************************************/

function frmYearSelection_yearChanged(){
	document.frmYearSelection.submit();
}
//I tried to consolidate this function with frmYearSelection_yearChanged but was getting script errors
function frmYearSelection_viewDetail_yearChanged(){
	document.frmYearSelection_viewDetail.submit();
}

function step1_frmAggregationSelection_aggregationChanged(){
	document.frmAggregationSelection.submit();
}

function cboAggregationSpecificFilterDetail_changed(){
	step1_frmDataFilterAndPreview_onSubmit();
	return false;
}

function locationBasedSelected(){
	document.frmLocationSelection_viewDetail.submit();
}

function ownerBasedSelected(){
	document.frmOwnerSelection_viewDetail.submit();
}

/****************************************************************************************************/
/*
function step1_SelectAll(bSelectAll){
	var i = 0;
	for(i=0; i<document.frmDataFilterAndPreview.elements.length; i++)
		if (document.frmDataFilterAndPreview.elements[i].name == "ckKey")
			document.frmDataFilterAndPreview.elements[i].checked = bSelectAll;
}
*/

function step1_frmDataFilterAndPreview_onSubmit(bViewDataButtonClicked){
	document.frmDataFilterAndPreview.action = "view.cfm";
	if (bViewDataButtonClicked != null)
		//strDataFilterAndPreviewFormAction_viewData is defined in view.cfm
		document.frmDataFilterAndPreview.action = strDataFilterAndPreviewFormAction_viewData;
	document.frmDataFilterAndPreview.submit();
}

function step1_ViewData(btn){
	//count the "selected" checkboxes

	var i = 0;
	var nBoxesChecked = 0;
	for(i=0; i<document.frmDataFilterAndPreview.elements.length; i++)
		if (document.frmDataFilterAndPreview.elements[i].name == "ckKey"
			&& document.frmDataFilterAndPreview.elements[i].checked)
			nBoxesChecked++;
	var bDataSelected = nBoxesChecked > 0 || document.frmDataFilterAndPreview.allSelectedKeys.value.length > 0;
	
	if (strDataFilterAndPreviewFormAction_viewData == "view_us.cfm"
		|| btn.name == "btnDisplayAllData"
		|| bDataSelected)
		step1_frmDataFilterAndPreview_onSubmit(true);	
	return false;
}


function eGRIDweb_print(){
	window.print();
	return false;
}
