// common javascript for community emergency program review
// Brad Judson
<!-- Version June 10 2005 0900   -->

var webURL = "http://www.pep.bc.ca/cepr/";
//var webURL = "http://www.geoinfosolutions.com/CEPR/";
//var webURL = "";
var numQuestions = 123; // if review[52] then use 53

choice = new Array(numQuestions);

data_names = new Array();
data_values = new Array();
var data_count = 0;

var authority;
var user;
var version;

var saveURL = "http://www.pep.bc.ca/cepr/review.html?choices=";

ds = location.search;
ds+= "&";  // PUT A DUMMY & AT END OF STRING, FOR SEARCH PURPOSES
var sl = ds.length;
var startidx = 1;
var endidx = 0;
var cstring;
var dname;
var dvalue;

if (sl > 1) {

do 
{
endidx = ds.indexOf("&",startidx);
if (endidx !=-1) {
  cstring = ds.substring(startidx, endidx); 
//  alert("cstring in main code is "+cstring)
  startidx = endidx + 1;
  data_names[data_count]  =  get_data_name(cstring);
  data_values[data_count] = get_data_value(cstring);

  data_count++};
}
while (endidx !=-1 & endidx != (ds.length -1));

}


function get_data_name(cstring) {
var m = cstring.indexOf("=",0)
//alert(m)
if (m != -1) {
  return cstring.substring(0, m)
  } else {
  return null}
}

function get_data_value(cstring) {
var converted
var m = cstring.indexOf("=", 0 )

if (m != -1) {
  converted = cstring.substring(m+1, cstring.length)
  } else  {
  return null }

// If it reaches here, a value string has been found. Now remove '+' space-placeholders, and 
// unescape to remove Unicode strings.

do {
converted=converted.replace("+"," ")}
while (converted.indexOf("+",0) != -1);

converted = unescape(converted)

return converted 

} // end of function.

var ArrayArg;

function substring2(string, start, length) {
//used like the mid$ function in VB
    return string.substring(start, start+length);
}



function loadArray(userarray){
	//load review array from the string
	//fill in the array used to hold all the user input from the argument userarray
	for (i=0; i <numQuestions; i++){
		choice[i]=substring2(userarray,i,1);	
	}

	//alert(choice[0]);
}

function passArray(){
//create the argument string userarray from the choice[i] array
	var userarray = ""
	for (i=0; i <numQuestions; i++){
		userarray = userarray +choice[i];	
	}
	return userarray;
}





      var pix = new Array ( "tip.gif",
                            "tip2.gif")

      var numImages = 2
      var nowShowing = 0

      function cycle()
      {
        if (document.images) 
	{
	  nowShowing++
	  nowShowing = nowShowing % numImages
	}

	document.helptip.src = pix[nowShowing]  
	setTimeout( "cycle()", 1000 )
      }


var possScore=new Array(8);
var actScore=new Array(8);

function createBarchart(){

//section one PROGRAM
actScore[1]=0;
	for (i=1; i <23; i++){	
		if(choice[i]==0){
			actScore[1]=actScore[1] + 1*(review[i][5]);
		}
		else if(choice[i]==1){
			actScore[1]=actScore[1] + Math.round(1*(review[i][5]/2));
		}
	}
	

//alert(actScore[1]);

//var P0 = "P0";   //administration
//var P23 = "P23"; //hrva
//var P42 = "P42";
//var P56 = "P56";
//var P73 = "P73";
//var P106 = "P106";
//var P114 = "P114";
//note that the break point for the scoring is the section title line number.  This number can easily be obtained by moving the cursor over the helptip on the line and viewing the number in the status bar at the bottom of explorer.
//after updating the ranges below, update the variables (as above) in the eprhelp.js file.


//section two HRVA
actScore[2]=0;
	for (i=23; i <42; i++){	
		if(choice[i]==0){
			actScore[2]=actScore[2] + 1*(review[i][5]);
		}
		else if(choice[i]==1){
			actScore[2]=actScore[2] + Math.round(1*(review[i][5]/2));
		}
	}	

//alert(actScore[2]);


//section three MITIGATION
actScore[3]=0;
	for (i=42; i <56; i++){	
		if(choice[i]==0){
			actScore[3]=actScore[3] + 1*(review[i][5]);
		}
		else if(choice[i]==1){
			actScore[3]=actScore[3] + Math.round(1*(review[i][5]/2));
		}
	}	

//alert(actScore[3]);
 
//section four PREPAREDNESS
actScore[4]=0;
	for (i=56; i <73; i++){	
		if(choice[i]==0){
			actScore[4]=actScore[4] + 1*(review[i][5]);
		}
		else if(choice[i]==1){
			actScore[4]=actScore[4] + Math.round(1*(review[i][5]/2));
		}
	}	

//alert(actScore[4]);

//section five RESPONSE
actScore[5]=0;
	for (i=73; i <106; i++){	
		if(choice[i]==0){
			actScore[5]=actScore[5] + 1*(review[i][5]);
		}
		else if(choice[i]==1){
			actScore[5]=actScore[5] + Math.round(1*(review[i][5]/2));
		}
	}	

//alert(actScore[5]);

//section six RECOVERY
actScore[6]=0;
	for (i=106; i <114; i++){	
		if(choice[i]==0){
			actScore[6]=actScore[6] + 1*(review[i][5]);
		}
		else if(choice[i]==1){
			actScore[6]=actScore[6] + Math.round(1*(review[i][5]/2));
		}
	}	

//alert(actScore[6]);

//section seven EVALUATION
actScore[7]=0;
	for (i=114; i <123; i++){	
		if(choice[i]==0){
			actScore[7]=actScore[7] + 1*(review[i][5]);
		}
		else if(choice[i]==1){
			actScore[7]=actScore[7] + Math.round(1*(review[i][5]/2));
		}
	}	

//alert(actScore[7]);


}

