// global vars
var reportName = '';
var global_locn = '';

// if the page is refreshed the radio buttons show as selected but retain no value
// so we must clear them upon refreshing


// a compare function for sorting by official name
function byName(a, b) {
    var anew = a.name.toLowerCase();
    var bnew = b.name.toLowerCase();
    if (anew < bnew) return -1;
    if (anew > bnew) return 1;
    return 0;
}



function compare(a, b) {
 
    if (a[1] < b[1]) {      
	return -1;   
    }   
    if (a[1] > b[1]) {      
	return 1;   
    }   
    if (a[1] == b[1]) {      
	return 0;   
    }
}


function getMap (sel) {
    map = sel.options[sel.selectedIndex].value;
    location.href = 'map_search?map=' + map;
}  
function initCap(str) {
    /* First letter as uppercase, rest lower */
    var str = str.substring(0,1).toUpperCase() + str.substring(1,str.length).toLowerCase();

    return str;
}


function schoolSelected() {
    if(!locn) {
        return 0;
    } else {
        return 1;
    }
}


function gotoDeferred(el,url) {
    if(!schoolSelected()) {
	alert(err1);
    } else {
	site = el.options[el.selectedIndex].value;
	window.open(url + '/deferred-maintenance/items-by-site?site=' + site,'myWindDeffered','width=800,resizable=yes,scrollbars=yes');
    }
}


function openReport(locn,report) {

    if( !locn || !report ) {

	if( !locn && !report ) {
	    alert( 'To open a report you must select a school and also the report that you would like to see. The school search is on the left and report options are listed on the right side.' );
	} else if( !locn ) {
	    alert( 'Please select the location using the school search.' );
	} else if( !report ) {
	    alert( 'Please select a report option on the right.' );
	} else { alert( 'unknown error!' );
	}
    } else {

      	// both locn and report are known. serve the requested report.
      	if( report == "basic_info" ) {
	    window.open('http://notebook.lausd.net/portal/page?_pageid=33,54194&_dad=ptl&_schema=PTL_EP&school_code='+locn,'myWinLAUSD','width=900,height=600,resizable=yes,scrollbars=yes,menubar=yes');
      	} else if( report == "trouble_calls" ) {
	    window.open('/fis/existing-facilities/m-and-o/maximo/calls-by-site?site=' + locn,'myWinTC','width=800,height=600,resizable=yes,scrollbars=yes,menubar=yes');
      	} else if( report == "dynamic_sep" ) {
	    window.open('/fis/existing-facilities/sep-projects-2007/one-school?locn=' + locn,'myWinSEP','width=800,height=600,resizable=yes,scrollbars=yes,menubar=yes');
      	} else if( report == "pesticide_notification" ) {
	    window.location = '/fis/existing-facilities/m-and-o/pesticide-notification/one?site=' + locn;
      	} else if( report == "bb_final" ) {
	    window.open('/fis/existing-facilities/bb-final/projects?locn=' + locn,'myWinBB','width=1000,height=600,resizable=yes,scrollbars=yes,menubar=yes');
      	} else if( report == "dsa_apps" ) {
	    window.open('/dsa-applications/?locn=' + locn,'myWinDSA','width=1000,height=600,resizable=yes,scrollbars=yes,menubar=yes,location=yes');
	} else if( report == "fac_report" ) {
	    window.location = '/fis/existing-facilities/m-and-o/principal/home/?locn=' + locn;
	} else if( report == "plot_plans" ) {
	    window.open('/fis/existing-facilities/m-and-o/plot-plans?org=' + locn, 'plotPlanWind','width=800,height=600,resizable=yes,scrollbars=yes,menubar=yes');
      	} else if( report == "plot_plans_modular" ) {
	    window.open('/fis/existing-facilities/m-and-o/plot-plans-modular?locn=' + locn, 'plotPlanModWind','width=800,height=600,resizable=yes,scrollbars=yes,menubar=yes');
	    /* functionality not available yet
	       } else if( report == "spatial" ) {
	       window.open('http://www.laschools.org/lausd-spatial/orgs/one?org_code_id=' + locn, 'spatialWind','width=800,height=600,resizable=yes,scrollbars=yes,menubar=yes');
	    */
      	} else if( report == "fact_sheets" ) {
	    window.open('/fis/existing-facilities/m-and-o/ef-projects/project-segments?locn=' + locn,"factSheetWindow","width=800,height=600,resizable=yes,scrollbars=yes,menubar=yes");	
      	} else if( report == "proj_budgets" ) {
	    window.open('http://dev.laschools.org/data-mart/projects/forms/all-budgets?locn=' + locn,"projbudgetsWindow","width=1100,height=800,resizable=yes,scrollbars=yes,menubar=yes");	
      	} else {
	    alert( 'Unknown Report Type!' );
        }
	
    }
    return;
}



