<?php
session_start();
include_once("config.php");
include_once("data_definitions.php");
include_once("print_section1.php");
error_reporting(0);
//Handle sessions
if(!isset($_SESSION['seas_user_id'])) $_SESSION['seas_user_id']=0;
if($_SESSION['seas_user_id'] <=0) {
	$_SESSION['PCD_page_ref']="report.php";
	header("location:login.php");
}

$usr_opts = explode(",",$_SESSION['PCD_user_opts']);

if(!isset($_SESSION["seas_brd_filter_prof"]))    $_SESSION["seas_brd_filter_prof"]=0;
if(!isset($_SESSION["seas_brd_filter_hlth"]))    $_SESSION["seas_brd_filter_hlth"]=0;
if(!isset($_SESSION["seas_brd_filter_sel_target"]))  $_SESSION["seas_brd_filter_sel_target"]=0;
if(!isset($_SESSION["seas_brd_filter_sel_bnch"]))    $_SESSION["seas_brd_filter_sel_bnch"]=0;

if(!isset($_SESSION["seas_brd_filter_topic"]))   $_SESSION["seas_brd_filter_topic"]=99;
if(!isset($_SESSION["seas_brd_filter_export"]))  $_SESSION["seas_brd_filter_export"]=0;

if(!isset($_SESSION["seas_brd_filter_condition"]))  $_SESSION["seas_brd_filter_condition"]="";
if(!isset($_SESSION["seas_brd_bnch_filter_condition"]))  $_SESSION["seas_brd_bnch_filter_condition"]="";

if(isset($_REQUEST['sel_prof_catg']))     $_SESSION["seas_brd_filter_prof"]   = $_REQUEST['sel_prof_catg'];
if(isset($_REQUEST['sel_health_fac']))    $_SESSION["seas_brd_filter_hlth"]   = $_REQUEST['sel_health_fac'];
if(isset($_REQUEST['sel_prof_catg']))     $_SESSION["seas_brd_filter_prof"]   = $_REQUEST['sel_prof_catg'];
if(isset($_REQUEST['sel_target']))     	  $_SESSION["seas_brd_filter_sel_target"]   = $_REQUEST['sel_target'];
if(isset($_REQUEST['sel_bnch']))     	  $_SESSION["seas_brd_filter_sel_bnch"]   = $_REQUEST['sel_bnch'];
if(isset($_REQUEST['sel_survey_topic']))  $_SESSION["seas_brd_filter_topic"]  = $_REQUEST['sel_survey_topic'];
if(isset($_REQUEST['sel_export']))        $_SESSION["seas_brd_filter_export"] = $_REQUEST['sel_export'];


if($_SESSION["seas_brd_filter_sel_target"] >0 || $_SESSION["seas_brd_filter_sel_bnch"] >0) {
	$_SESSION["seas_brd_filter_prof"]=0;
	$_SESSION["seas_brd_filter_hlth"]=0;
}

$_SESSION["seas_brd_filter_condition"]="";
if($_SESSION["seas_brd_filter_prof"] >0) {
	$_SESSION["seas_brd_filter_condition"] .= " V1=" . $_SESSION["seas_brd_filter_prof"];
}
if($_SESSION["seas_brd_filter_hlth"] >0) {
	if(strlen($_SESSION["seas_brd_filter_condition"]) >0) $_SESSION["seas_brd_filter_condition"] .= " and ";
	$_SESSION["seas_brd_filter_condition"] .= " V5=" . $_SESSION["seas_brd_filter_hlth"];
}
if(strlen($_SESSION["seas_brd_filter_condition"]) >0) {
	$_SESSION["seas_brd_filter_condition"] = " (" . $_SESSION["seas_brd_filter_condition"] . ") ";
}

if($_SESSION["seas_brd_filter_sel_target"] >0) {
	$tr_condition = "";
	$tr_sql  = "select distinct dfields from seas_brd_target_dat where tar_id=" . $_SESSION["seas_brd_filter_sel_target"];
	$tr_rslt = mysql_query($tr_sql);
	while($tr_rw=mysql_fetch_assoc($tr_rslt)) {
		$tr_opts="";
		$tr_sql2  = "select distinct opts from seas_brd_target_dat where tar_id=" . $_SESSION["seas_brd_filter_sel_target"] . ' and dfields = "'. $tr_rw['dfields'].'"';
		$tr_rslt2 = mysql_query($tr_sql2);
		while($tr_rw2=mysql_fetch_assoc($tr_rslt2)) {
			if(strlen($tr_opts)>0) $tr_opts .= ",";
			$tr_opts .= $tr_rw2['opts'];
		}
		if(strlen($tr_condition)>0) $tr_condition .=  " AND ";
		$tr_condition .= " (" . $tr_rw['dfields'] ." in (" . $tr_opts . ")) ";
	}
	
	if(strlen($tr_condition)>0) $tr_condition = " (" . $tr_condition . ") ";
	$_SESSION["seas_brd_filter_condition"] = $tr_condition;
}

$_SESSION["seas_brd_bnch_filter_condition"] = "";
if($_SESSION["seas_brd_filter_sel_bnch"] >0) {
	$bn_condition = "";
	$bn_sql  = "select distinct dfields from seas_brd_target_dat where tar_id=" . $_SESSION["seas_brd_filter_sel_bnch"];
	$bn_rslt = mysql_query($bn_sql);
	while($bn_rw=mysql_fetch_assoc($bn_rslt)) {
		$bn_opts="";
		$bn_sql2  = "select distinct opts from seas_brd_target_dat where tar_id=" . $_SESSION["seas_brd_filter_sel_bnch"] . ' and dfields = "'. $bn_rw['dfields'].'"';
		$bn_rslt2 = mysql_query($bn_sql2);
		while($bn_rw2=mysql_fetch_assoc($bn_rslt2)) {
			if(strlen($bn_opts)>0) $bn_opts .= ",";
			$bn_opts .= $bn_rw2['opts'];
		}
		if(strlen($bn_condition)>0) $bn_condition .=  " AND ";
		$bn_condition .= " (" . $bn_rw['dfields'] ." in (" . $bn_opts . ")) ";
	}
	
	if(strlen($bn_condition)>0) $bn_condition = " (" . $bn_condition . ") ";
	$_SESSION["seas_brd_bnch_filter_condition"] = $bn_condition;
}
// End Sessions

// Computations
$rmode = true; // Computation mode: True for Weighted

// Total Samples
$t_sql = "select sum(weight) from seas_brd_dat";
$t_rslt= mysql_query($t_sql);
$t_array = mysql_fetch_array($t_rslt);
$tot_sample = round($t_array[0],0);

// Target Base
if(strlen($_SESSION["seas_brd_filter_condition"]) >0) {
	$sqlcond = $_SESSION["seas_brd_filter_condition"];
}
else {
	$sqlcond = "1=1";
}
$t_sql = "select sum(weight) from seas_brd_dat where " . $sqlcond;
$t_rslt= mysql_query($t_sql);
$t_array = mysql_fetch_array($t_rslt);
$trg_sample = round($t_array[0],0);

// Benchmark Base
if(strlen($_SESSION["seas_brd_bnch_filter_condition"]) >0) {
	$sqlcond2 = $_SESSION["seas_brd_bnch_filter_condition"];
}
else {
	$sqlcond2 = "1=1";
}
$b_sql = "select sum(weight) from seas_brd_dat where " . $sqlcond2;
$b_rslt= mysql_query($b_sql);
$b_array = mysql_fetch_array($b_rslt);
$bnch_sample = round($b_array[0],0);



mysql_free_result($t_rslt);
// Percentage
$per_sample = round(($trg_sample/$tot_sample)*100,0);
$bper_sample = round(($bnch_sample/$tot_sample)*100,0);

// Define Report Array
$Q2_a = getValues($rmode,"V9_1"); //array(60,20,82.4,49.7,71.26); // Any Agree, Any DisAgree, Strength, Character, Average, Nuetral, Total
$Q2_b = getValues($rmode,"V9_2"); //array(41,37,82.7,4.5,59.81);
$Q2_c = getValues($rmode,"V9_3"); //array(46,29,77.5,23.5,63.81);
$Q2_d = getValues($rmode,"V9_4"); //array(69,15,85.6,64.8,76.71);
$Q2_e = getValues($rmode,"V9_5"); //array(57,24,84.8,41.0,68.89);
$Q2_f = getValues($rmode,"V9_6"); //array(44,29,76.9,20.2,63.69);
$Q2_g = getValues($rmode,"V9_7"); //array(41,33,78.1,11.1,60.70);
$Q2 = array($Q2_a,$Q2_b,$Q2_c,$Q2_d,$Q2_e,$Q2_f,$Q2_g);
$Question_Array["Q2"][3]=$Q2;

$Q2_S_Avg = getAvg($Q2,2);
$Q2_C_Avg = getAvg($Q2,3);
$Q2_A_Avg = getAvg($Q2,4);
$Q2_N_Avg = getAvg($Q2,1);
$Q2_P_Avg = getAvg($Q2,0);

$Q2_S_Avg2 = getAvg($Q2,9);
$Q2_C_Avg2 = getAvg($Q2,10);
$Q2_A_Avg2 = getAvg($Q2,11);
$Q2_N_Avg2 = getAvg($Q2,8);
$Q2_P_Avg2 = getAvg($Q2,7);

$Question_Array["Q2"][5]=array($Q2_S_Avg,$Q2_C_Avg,$Q2_P_Avg,$Q2_N_Avg,$Q2_A_Avg,$Q2_S_Avg2,$Q2_C_Avg2,$Q2_P_Avg2,$Q2_N_Avg2,$Q2_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Q5_a = getValues($rmode,"V13_1"); //array(0,0,0,0,0);
$Q5_b = getValues($rmode,"V13_2"); //array(0,0,0,0,0);
$Q5_c = getValues($rmode,"V13_3"); //array(0,0,0,0,0);
$Q5_d = getValues($rmode,"V13_4"); //array(0,0,0,0,0);
$Q5 = array($Q5_a,$Q5_b,$Q5_c,$Q5_d);
$Question_Array["Q5"][3]=$Q5;

$Q5_S_Avg = getAvg($Q5,2);
$Q5_C_Avg = getAvg($Q5,3);
$Q5_A_Avg = getAvg($Q5,4);
$Q5_N_Avg = getAvg($Q5,1);
$Q5_P_Avg = getAvg($Q5,0);

$Q5_S_Avg2 = getAvg($Q5,9);
$Q5_C_Avg2 = getAvg($Q5,10);
$Q5_A_Avg2 = getAvg($Q5,11);
$Q5_N_Avg2 = getAvg($Q5,8);
$Q5_P_Avg2 = getAvg($Q5,7);

$Question_Array["Q5"][5]=array($Q5_S_Avg,$Q5_C_Avg,$Q5_P_Avg,$Q5_N_Avg,$Q5_A_Avg, $Q5_S_Avg2,$Q5_C_Avg2,$Q5_P_Avg2,$Q5_N_Avg2,$Q5_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Q6_a = getValues($rmode,"V14_1"); //array(0,0,0,0,0);
$Q6_b = getValues($rmode,"V14_2"); //array(0,0,0,0,0);
$Q6_c = getValues($rmode,"V14_3"); //array(0,0,0,0,0);
$Q6 = array($Q6_a,$Q6_b,$Q6_c);
$Question_Array["Q6"][3]=$Q6;

$Q6_S_Avg = getAvg($Q6,2);
$Q6_C_Avg = getAvg($Q6,3);
$Q6_A_Avg = getAvg($Q6,4);
$Q6_N_Avg = getAvg($Q6,1);
$Q6_P_Avg = getAvg($Q6,0);

$Q6_S_Avg2 = getAvg($Q6,9);
$Q6_C_Avg2 = getAvg($Q6,10);
$Q6_A_Avg2 = getAvg($Q6,11);
$Q6_N_Avg2 = getAvg($Q6,8);
$Q6_P_Avg2 = getAvg($Q6,7);

$Question_Array["Q6"][5]=array($Q6_S_Avg,$Q6_C_Avg,$Q6_P_Avg,$Q6_N_Avg,$Q6_A_Avg, $Q6_S_Avg2,$Q6_C_Avg2,$Q6_P_Avg2,$Q6_N_Avg2,$Q6_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Q7_a = getValues($rmode,"V15_1"); //array(0,0,0,0,0);
$Q7_b = getValues($rmode,"V15_2"); //array(0,0,0,0,0);
$Q7_c = getValues($rmode,"V15_3"); //array(0,0,0,0,0);
$Q7 = array($Q7_a,$Q7_b,$Q7_c);
$Question_Array["Q7"][3]=$Q7;

$Q7_S_Avg = getAvg($Q7,2);
$Q7_C_Avg = getAvg($Q7,3);
$Q7_A_Avg = getAvg($Q7,4);
$Q7_N_Avg = getAvg($Q7,1);
$Q7_P_Avg = getAvg($Q7,0);

$Q7_S_Avg2 = getAvg($Q7,9);
$Q7_C_Avg2 = getAvg($Q7,10);
$Q7_A_Avg2 = getAvg($Q7,11);
$Q7_N_Avg2 = getAvg($Q7,8);
$Q7_P_Avg2 = getAvg($Q7,7);

$Question_Array["Q7"][5]=array($Q7_S_Avg,$Q7_C_Avg,$Q7_P_Avg,$Q7_N_Avg,$Q7_A_Avg, $Q7_S_Avg2,$Q7_C_Avg2,$Q7_P_Avg2,$Q7_N_Avg2,$Q7_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Q9_a = getValues($rmode,"V17_1"); //array(0,0,0,0,0);
$Q9_b = getValues($rmode,"V17_2"); //array(0,0,0,0,0);
$Q9_c = getValues($rmode,"V17_3"); //array(0,0,0,0,0);
$Q9 = array($Q9_a,$Q9_b,$Q9_c);
$Question_Array["Q9"][3]=$Q9;

$Q9_S_Avg = getAvg($Q9,2);
$Q9_C_Avg = getAvg($Q9,3);
$Q9_A_Avg = getAvg($Q9,4);
$Q9_N_Avg = getAvg($Q9,1);
$Q9_P_Avg = getAvg($Q9,0);

$Q9_S_Avg2 = getAvg($Q9,9);
$Q9_C_Avg2 = getAvg($Q9,10);
$Q9_A_Avg2 = getAvg($Q9,11);
$Q9_N_Avg2 = getAvg($Q9,8);
$Q9_P_Avg2 = getAvg($Q9,7);

$Question_Array["Q9"][5]=array($Q9_S_Avg,$Q9_C_Avg,$Q9_P_Avg,$Q9_N_Avg,$Q9_A_Avg, $Q9_S_Avg2,$Q9_C_Avg2,$Q9_P_Avg2,$Q9_N_Avg2,$Q9_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Q10_a = getValues($rmode,"V18_1"); //array(0,0,0,0,0);
$Q10_b = getValues($rmode,"V18_2"); //array(0,0,0,0,0);
$Q10_c = getValues($rmode,"V18_3"); //array(0,0,0,0,0)
$Q10 = array($Q10_a,$Q10_b,$Q10_c);
$Question_Array["Q10"][3]=$Q10;

$Q10_S_Avg = getAvg($Q10,2);
$Q10_C_Avg = getAvg($Q10,3);
$Q10_A_Avg = getAvg($Q10,4);
$Q10_N_Avg = getAvg($Q10,1);
$Q10_P_Avg = getAvg($Q10,0);

$Q10_S_Avg2 = getAvg($Q10,9);
$Q10_C_Avg2 = getAvg($Q10,10);
$Q10_A_Avg2 = getAvg($Q10,11);
$Q10_N_Avg2 = getAvg($Q10,8);
$Q10_P_Avg2 = getAvg($Q10,7);

$Question_Array["Q10"][5]=array($Q10_S_Avg,$Q10_C_Avg,$Q10_P_Avg,$Q10_N_Avg,$Q10_A_Avg, $Q10_S_Avg2,$Q10_C_Avg2,$Q10_P_Avg2,$Q10_N_Avg2,$Q10_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Q11_a = getValues($rmode,"V19_1"); //array(0,0,0,0,0);
$Q11_b = getValues($rmode,"V19_2"); //array(0,0,0,0,0);
$Q11_c = getValues($rmode,"V19_3"); //array(0,0,0,0,0);
$Q11 = array($Q11_a,$Q11_b,$Q11_c);
$Question_Array["Q11"][3]=$Q11;

$Q11_S_Avg = getAvg($Q11,2);
$Q11_C_Avg = getAvg($Q11,3);
$Q11_A_Avg = getAvg($Q11,4);
$Q11_N_Avg = getAvg($Q11,1);
$Q11_P_Avg = getAvg($Q11,0);

$Q11_S_Avg2 = getAvg($Q11,9);
$Q11_C_Avg2 = getAvg($Q11,10);
$Q11_A_Avg2 = getAvg($Q11,11);
$Q11_N_Avg2 = getAvg($Q11,8);
$Q11_P_Avg2 = getAvg($Q11,7);

$Question_Array["Q11"][5]=array($Q11_S_Avg,$Q11_C_Avg,$Q11_P_Avg,$Q11_N_Avg,$Q11_A_Avg, $Q11_S_Avg2,$Q11_C_Avg2,$Q11_P_Avg2,$Q11_N_Avg2,$Q11_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Q12_a = getValues($rmode,"V20_1"); //array(0,0,0,0,0);
$Q12_b = getValues($rmode,"V20_2"); //array(0,0,0,0,0);
$Q12_c = getValues($rmode,"V20_3"); //array(0,0,0,0,0);
$Q12_d = getValues($rmode,"V20_4"); //array(0,0,0,0,0);
$Q12_e = getValues($rmode,"V20_5"); //array(0,0,0,0,0);
$Q12_f = getValues($rmode,"V20_6"); //array(0,0,0,0,0);
$Q12 = array($Q12_a,$Q12_b,$Q12_c,$Q12_d,$Q12_e,$Q12_f);
$Question_Array["Q12"][3]=$Q12;

$Q12_S_Avg = getAvg($Q12,2);
$Q12_C_Avg = getAvg($Q12,3);
$Q12_A_Avg = getAvg($Q12,4);
$Q12_N_Avg = getAvg($Q12,1);
$Q12_P_Avg = getAvg($Q12,0);

$Q12_S_Avg2 = getAvg($Q12,9);
$Q12_C_Avg2 = getAvg($Q12,10);
$Q12_A_Avg2 = getAvg($Q12,11);
$Q12_N_Avg2 = getAvg($Q12,8);
$Q12_P_Avg2 = getAvg($Q12,7);

$Question_Array["Q12"][5]=array($Q12_S_Avg,$Q12_C_Avg,$Q12_P_Avg,$Q12_N_Avg,$Q12_A_Avg, $Q12_S_Avg2,$Q12_C_Avg2,$Q12_P_Avg2,$Q12_N_Avg2,$Q12_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Q14_a = getValues($rmode,"V22_1"); //array(0,0,0,0,0);
$Q14_b = getValues($rmode,"V22_2"); //array(0,0,0,0,0);
$Q14_c = getValues($rmode,"V22_3"); //array(0,0,0,0,0);
$Q14_d = getValues($rmode,"V22_4"); //array(0,0,0,0,0);
$Q14_e = getValues($rmode,"V22_5"); //array(0,0,0,0,0);
$Q14_f = getValues($rmode,"V22_6"); //array(0,0,0,0,0);
$Q14 = array($Q14_a,$Q14_b,$Q14_c,$Q14_d,$Q14_e,$Q14_f);
$Question_Array["Q14"][3]=$Q14;

$Q14_S_Avg = getAvg($Q14,2);
$Q14_C_Avg = getAvg($Q14,3);
$Q14_A_Avg = getAvg($Q14,4);
$Q14_N_Avg = getAvg($Q14,1);
$Q14_P_Avg = getAvg($Q14,0);

$Q14_S_Avg2 = getAvg($Q14,9);
$Q14_C_Avg2 = getAvg($Q14,10);
$Q14_A_Avg2 = getAvg($Q14,11);
$Q14_N_Avg2 = getAvg($Q14,8);
$Q14_P_Avg2 = getAvg($Q14,7);

$Question_Array["Q14"][5]=array($Q14_S_Avg,$Q14_C_Avg,$Q14_P_Avg,$Q14_N_Avg,$Q14_A_Avg, $Q14_S_Avg2,$Q14_C_Avg2,$Q14_P_Avg2,$Q14_N_Avg2,$Q14_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Q17_a = getValues($rmode,"V25_1"); //array(0,0,0,0,0);
$Q17_b = getValues($rmode,"V25_2"); //array(0,0,0,0,0);
$Q17_c = getValues($rmode,"V25_3"); //array(0,0,0,0,0);
$Q17_d = getValues($rmode,"V25_4"); //array(0,0,0,0,0);
$Q17_e = getValues($rmode,"V25_5"); //array(0,0,0,0,0);
$Q17 = array($Q17_a,$Q17_b,$Q17_c,$Q17_d,$Q17_e);
$Question_Array["Q17"][3]=$Q17;

$Q17_S_Avg = getAvg($Q17,2);
$Q17_C_Avg = getAvg($Q17,3);
$Q17_A_Avg = getAvg($Q17,4);
$Q17_N_Avg = getAvg($Q17,1);
$Q17_P_Avg = getAvg($Q17,0);

$Q17_S_Avg2 = getAvg($Q17,9);
$Q17_C_Avg2 = getAvg($Q17,10);
$Q17_A_Avg2 = getAvg($Q17,11);
$Q17_N_Avg2 = getAvg($Q17,8);
$Q17_P_Avg2 = getAvg($Q17,7);

$Question_Array["Q17"][5]=array($Q17_S_Avg,$Q17_C_Avg,$Q17_P_Avg,$Q17_N_Avg,$Q17_A_Avg, $Q17_S_Avg2,$Q17_C_Avg2,$Q17_P_Avg2,$Q17_N_Avg2,$Q17_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Q18_a = getValues($rmode,"V26_1"); //array(0,0,0,0,0);
$Q18_b = getValues($rmode,"V26_2"); //array(0,0,0,0,0);
$Q18_c = getValues($rmode,"V26_3"); //array(0,0,0,0,0);
$Q18_d = getValues($rmode,"V26_4"); //array(0,0,0,0,0);
$Q18_e = getValues($rmode,"V26_5"); //array(0,0,0,0,0);
$Q18_f = getValues($rmode,"V26_6"); //array(0,0,0,0,0);
$Q18_g = getValues($rmode,"V26_7"); //array(0,0,0,0,0);
$Q18_h = getValues($rmode,"V26_8"); //array(0,0,0,0,0);
$Q18_i = getValues($rmode,"V26_9"); //array(0,0,0,0,0);
$Q18_j = getValues($rmode,"V26_10"); //array(0,0,0,0,0);
$Q18_k = getValues($rmode,"V26_11"); //array(0,0,0,0,0);
$Q18 = array($Q18_a,$Q18_b,$Q18_c,$Q18_d,$Q18_e,$Q18_f,$Q18_g,$Q18_h,$Q18_i,$Q18_j,$Q18_k);
$Question_Array["Q18"][3]=$Q18;

$Q18_S_Avg = getAvg($Q18,2);
$Q18_C_Avg = getAvg($Q18,3);
$Q18_A_Avg = getAvg($Q18,4);
$Q18_N_Avg = getAvg($Q18,1);
$Q18_P_Avg = getAvg($Q18,0);

$Q18_S_Avg2 = getAvg($Q18,9);
$Q18_C_Avg2 = getAvg($Q18,10);
$Q18_A_Avg2 = getAvg($Q18,11);
$Q18_N_Avg2 = getAvg($Q18,8);
$Q18_P_Avg2 = getAvg($Q18,7);

$Question_Array["Q18"][5]=array($Q18_S_Avg,$Q18_C_Avg,$Q18_P_Avg,$Q18_N_Avg,$Q18_A_Avg, $Q18_S_Avg2,$Q18_C_Avg2,$Q18_P_Avg2,$Q18_N_Avg2,$Q18_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Q22_a = getValues($rmode,"V30_1"); //array(0,0,0,0,0);
$Q22_b = getValues($rmode,"V30_2"); //array(0,0,0,0,0);
$Q22_c = getValues($rmode,"V30_3"); //array(0,0,0,0,0);
$Q22_d = getValues($rmode,"V30_4"); //array(0,0,0,0,0);
$Q22_e = getValues($rmode,"V30_5"); //array(0,0,0,0,0);
$Q22_f = getValues($rmode,"V30_6"); //array(0,0,0,0,0);
$Q22_g = getValues($rmode,"V30_7"); //array(0,0,0,0,0);
$Q22_h = getValues($rmode,"V30_8"); //array(0,0,0,0,0);
$Q22 = array($Q22_a,$Q22_b,$Q22_c,$Q22_d,$Q22_e,$Q22_f,$Q22_g,$Q22_h);
$Question_Array["Q22"][3]=$Q22;

$Q22_S_Avg = getAvg($Q22,2);
$Q22_C_Avg = getAvg($Q22,3);
$Q22_A_Avg = getAvg($Q22,4);
$Q22_N_Avg = getAvg($Q22,1);
$Q22_P_Avg = getAvg($Q22,0);

$Q22_S_Avg2 = getAvg($Q22,9);
$Q22_C_Avg2 = getAvg($Q22,10);
$Q22_A_Avg2 = getAvg($Q22,11);
$Q22_N_Avg2 = getAvg($Q22,8);
$Q22_P_Avg2 = getAvg($Q22,7);

$Question_Array["Q22"][5]=array($Q22_S_Avg,$Q22_C_Avg,$Q22_P_Avg,$Q22_N_Avg,$Q22_A_Avg, $Q22_S_Avg2,$Q22_C_Avg2,$Q22_P_Avg2,$Q22_N_Avg2,$Q22_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Q23_a = getValues($rmode,"V31_1"); //array(0,0,0,0,0);
$Q23_b = getValues($rmode,"V31_2"); //array(0,0,0,0,0);
$Q23_c = getValues($rmode,"V31_3"); //array(0,0,0,0,0);
$Q23_d = getValues($rmode,"V31_4"); //array(0,0,0,0,0);
$Q23_e = getValues($rmode,"V31_5"); //array(0,0,0,0,0);
$Q23 = array($Q22_a,$Q22_b,$Q22_c,$Q22_d,$Q22_e);
$Question_Array["Q23"][3]=$Q23;

$Q23_S_Avg = getAvg($Q23,2);
$Q23_C_Avg = getAvg($Q23,3);
$Q23_A_Avg = getAvg($Q23,4);
$Q23_N_Avg = getAvg($Q23,1);
$Q23_P_Avg = getAvg($Q23,0);

$Q23_S_Avg2 = getAvg($Q23,9);
$Q23_C_Avg2 = getAvg($Q23,10);
$Q23_A_Avg2 = getAvg($Q23,11);
$Q23_N_Avg2 = getAvg($Q23,8);
$Q23_P_Avg2 = getAvg($Q23,7);

$Question_Array["Q23"][5]=array($Q23_S_Avg,$Q23_C_Avg,$Q23_P_Avg,$Q23_N_Avg,$Q23_A_Avg, $Q23_S_Avg2,$Q23_C_Avg2,$Q23_P_Avg2,$Q23_N_Avg2,$Q23_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Q24_a = getValues($rmode,"V32"); //array(0,0,0,0,0);
$Q24 = array($Q24_a);
$Question_Array["Q24"][3]=$Q24;

$Q24_S_Avg = getAvg($Q24,2);
$Q24_C_Avg = getAvg($Q24,3);
$Q24_A_Avg = getAvg($Q24,4);
$Q24_N_Avg = getAvg($Q24,1);
$Q24_P_Avg = getAvg($Q24,0);

$Q24_S_Avg2 = getAvg($Q24,9);
$Q24_C_Avg2 = getAvg($Q24,10);
$Q24_A_Avg2 = getAvg($Q24,11);
$Q24_N_Avg2 = getAvg($Q24,8);
$Q24_P_Avg2 = getAvg($Q24,7);

$Question_Array["Q24"][5]=array($Q24_S_Avg,$Q24_C_Avg,$Q24_P_Avg,$Q24_N_Avg,$Q24_A_Avg, $Q24_S_Avg2,$Q24_C_Avg2,$Q24_P_Avg2,$Q24_N_Avg2,$Q24_A_Avg2);
//***-------------------------------------------------------------------------------***//

$Strength_Avg  = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0);
$Character_Avg = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0);
$Average_Avg   = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0);


$Overall_S_Avg = round(($Q2_S_Avg+$Q5_S_Avg+$Q6_S_Avg+$Q7_S_Avg+$Q9_S_Avg+$Q10_S_Avg+$Q11_S_Avg+$Q12_S_Avg+$Q14_S_Avg+$Q17_S_Avg+$Q18_S_Avg+$Q22_S_Avg+$Q23_S_Avg+$Q24_S_Avg) / 14,0);
$Overall_C_Avg = round(($Q2_C_Avg+$Q5_C_Avg+$Q6_C_Avg+$Q7_C_Avg+$Q9_C_Avg+$Q10_C_Avg+$Q11_C_Avg+$Q12_C_Avg+$Q14_C_Avg+$Q17_C_Avg+$Q18_C_Avg+$Q22_C_Avg+$Q23_C_Avg+$Q24_C_Avg) / 14,0);
$Overall_A_Avg = round(($Q2_A_Avg+$Q5_A_Avg+$Q6_A_Avg+$Q7_A_Avg+$Q9_A_Avg+$Q10_A_Avg+$Q11_A_Avg+$Q12_A_Avg+$Q14_A_Avg+$Q17_A_Avg+$Q18_A_Avg+$Q22_A_Avg+$Q23_A_Avg+$Q24_A_Avg) / 14,0);
$Overall_N_Avg = round(($Q2_N_Avg+$Q5_N_Avg+$Q6_N_Avg+$Q7_N_Avg+$Q9_N_Avg+$Q10_N_Avg+$Q11_N_Avg+$Q12_N_Avg+$Q14_N_Avg+$Q17_N_Avg+$Q18_N_Avg+$Q22_N_Avg+$Q23_N_Avg+$Q24_N_Avg) / 14,0);
$Overall_P_Avg = round(($Q2_P_Avg+$Q5_P_Avg+$Q6_P_Avg+$Q7_P_Avg+$Q9_P_Avg+$Q10_P_Avg+$Q11_P_Avg+$Q12_P_Avg+$Q14_P_Avg+$Q17_P_Avg+$Q18_P_Avg+$Q22_P_Avg+$Q23_P_Avg+$Q24_P_Avg) / 14,0);

// Bench mark
$Overall_S_Avg2 = round(($Q2_S_Avg2+$Q5_S_Avg2+$Q6_S_Avg2+$Q7_S_Avg2+$Q9_S_Avg2+$Q10_S_Avg2+$Q11_S_Avg2+$Q12_S_Avg2+$Q14_S_Avg2+$Q17_S_Avg2+$Q18_S_Avg2+$Q22_S_Avg2+$Q23_S_Avg2+$Q24_S_Avg2) / 14,0);
$Overall_C_Avg2 = round(($Q2_C_Avg2+$Q5_C_Avg2+$Q6_C_Avg2+$Q7_C_Avg2+$Q9_C_Avg2+$Q10_C_Avg2+$Q11_C_Avg2+$Q12_C_Avg2+$Q14_C_Avg2+$Q17_C_Avg2+$Q18_C_Avg2+$Q22_C_Avg2+$Q23_C_Avg2+$Q24_C_Avg2) / 14,0);
$Overall_A_Avg2 = round(($Q2_A_Avg2+$Q5_A_Avg2+$Q6_A_Avg2+$Q7_A_Avg2+$Q9_A_Avg2+$Q10_A_Avg2+$Q11_A_Avg2+$Q12_A_Avg2+$Q14_A_Avg2+$Q17_A_Avg2+$Q18_A_Avg2+$Q22_A_Avg2+$Q23_A_Avg2+$Q24_A_Avg2) / 14,0);
$Overall_N_Avg2 = round(($Q2_N_Avg2+$Q5_N_Avg2+$Q6_N_Avg2+$Q7_N_Avg2+$Q9_N_Avg2+$Q10_N_Avg2+$Q11_N_Avg2+$Q12_N_Avg2+$Q14_N_Avg2+$Q17_N_Avg2+$Q18_N_Avg2+$Q22_N_Avg2+$Q23_N_Avg2+$Q24_N_Avg2) / 14,0);
$Overall_P_Avg2 = round(($Q2_P_Avg2+$Q5_P_Avg2+$Q6_P_Avg2+$Q7_P_Avg2+$Q9_P_Avg2+$Q10_P_Avg2+$Q11_P_Avg2+$Q12_P_Avg2+$Q14_P_Avg2+$Q17_P_Avg2+$Q18_P_Avg2+$Q22_P_Avg2+$Q23_P_Avg2+$Q24_P_Avg2) / 14,0);

//Calculate Index
$qopts =array("a","b","c","d","e","f","g","h","i","j","k");
$qst   =array("Q2","Q5","Q6","Q7","Q9","Q10","Q11","Q12","Q14","Q17","Q18","Q22","Q23","Q24");

foreach($qst as $qss) {
	$qsd = $$qss;
	for($is=0;$is<count($qsd);$is++) {
		$qo=$qopts[$is];
		$qvar = $qss . "_" . $qo;
		
		if(strlen($_SESSION["seas_brd_bnch_filter_condition"])>0) {
			${$qss."_IDX"}[$qo][0] =round((${$qvar}[2]/${$qvar}[9])*100,0);
			${$qss."_IDX"}[$qo][1] =round((${$qvar}[3]/${$qvar}[10])*100,0);
			${$qss."_IDX"}[$qo][2] =round((${$qvar}[4]/${$qvar}[11])*100,0);
			${$qss."_IDX"}[$qo][3] =round((${$qvar}[1]/${$qvar}[8])*100,0);
			${$qss."_IDX"}[$qo][4] =round((${$qvar}[0]/${$qvar}[7])*100,0);
		}
		else {
			${$qss."_IDX"}[$qo][0] =round((${$qvar}[2]/${$qss."_S_Avg"})*100,0);
			${$qss."_IDX"}[$qo][1] =round((${$qvar}[3]/${$qss."_C_Avg"})*100,0);
			${$qss."_IDX"}[$qo][2] =round((${$qvar}[4]/${$qss."_A_Avg"})*100,0);
			${$qss."_IDX"}[$qo][3] =round((${$qvar}[1]/${$qss."_N_Avg"})*100,0);
			${$qss."_IDX"}[$qo][4] =round((${$qvar}[0]/${$qss."_P_Avg"})*100,0);
		}
		
		$Question_Array[$qss][4][]=array(${$qss."_IDX"}[$qo][0],${$qss."_IDX"}[$qo][1],${$qss."_IDX"}[$qo][2],${$qss."_IDX"}[$qo][3],${$qss."_IDX"}[$qo][4]);
	}
}

//Calculate Over All Index
$qst   =array("Q2","Q5","Q6","Q7","Q9","Q10","Q11","Q12","Q14","Q17","Q18","Q22","Q23","Q24");

foreach($qst as $qss) {
	if(strlen($_SESSION["seas_brd_bnch_filter_condition"])>0) {
		${$qss."_IDX_OV"}[0] =round((${$qss."_S_Avg"}/$Overall_S_Avg2)*100,0);
		${$qss."_IDX_OV"}[1] =round((${$qss."_C_Avg"}/$Overall_C_Avg2)*100,0);
		${$qss."_IDX_OV"}[2] =round((${$qss."_A_Avg"}/$Overall_A_Avg2)*100,0);
		${$qss."_IDX_OV"}[3] =round((${$qss."_N_Avg"}/$Overall_N_Avg2)*100,0);
		${$qss."_IDX_OV"}[4] =round((${$qss."_P_Avg"}/$Overall_P_Avg2)*100,0);
	}
	else {
		${$qss."_IDX_OV"}[0] =round((${$qss."_S_Avg"}/$Overall_S_Avg)*100,0);
		${$qss."_IDX_OV"}[1] =round((${$qss."_C_Avg"}/$Overall_C_Avg)*100,0);
		${$qss."_IDX_OV"}[2] =round((${$qss."_A_Avg"}/$Overall_A_Avg)*100,0);
		${$qss."_IDX_OV"}[3] =round((${$qss."_N_Avg"}/$Overall_N_Avg)*100,0);
		${$qss."_IDX_OV"}[4] =round((${$qss."_P_Avg"}/$Overall_P_Avg)*100,0);
	}
	
	$Question_Array[$qss][6]=array(${$qss."_IDX_OV"}[0],${$qss."_IDX_OV"}[1],${$qss."_IDX_OV"}[4],${$qss."_IDX_OV"}[3],${$qss."_IDX_OV"}[2]);
}


$Question_Array["Q99"][4]=array(
							array($Q2_IDX_OV[0],$Q2_IDX_OV[1],$Q2_IDX_OV[2],$Q2_IDX_OV[3],$Q2_IDX_OV[4]),
							array($Q5_IDX_OV[0],$Q5_IDX_OV[1],$Q5_IDX_OV[2],$Q5_IDX_OV[3],$Q5_IDX_OV[4]),
							array($Q6_IDX_OV[0],$Q6_IDX_OV[1],$Q6_IDX_OV[2],$Q6_IDX_OV[3],$Q6_IDX_OV[4]),
							array($Q7_IDX_OV[0],$Q7_IDX_OV[1],$Q7_IDX_OV[2],$Q7_IDX_OV[3],$Q7_IDX_OV[4]),
							array($Q9_IDX_OV[0],$Q9_IDX_OV[1],$Q9_IDX_OV[2],$Q9_IDX_OV[3],$Q9_IDX_OV[4]),
							array($Q10_IDX_OV[0],$Q10_IDX_OV[1],$Q10_IDX_OV[2],$Q10_IDX_OV[3],$Q10_IDX_OV[4]),
							array($Q11_IDX_OV[0],$Q11_IDX_OV[1],$Q11_IDX_OV[2],$Q11_IDX_OV[3],$Q11_IDX_OV[4]),
							array($Q12_IDX_OV[0],$Q12_IDX_OV[1],$Q12_IDX_OV[2],$Q12_IDX_OV[3],$Q12_IDX_OV[4]),
							array($Q14_IDX_OV[0],$Q14_IDX_OV[1],$Q14_IDX_OV[2],$Q14_IDX_OV[3],$Q14_IDX_OV[4]),
							array($Q17_IDX_OV[0],$Q17_IDX_OV[1],$Q17_IDX_OV[2],$Q17_IDX_OV[3],$Q17_IDX_OV[4]),
							array($Q18_IDX_OV[0],$Q18_IDX_OV[1],$Q18_IDX_OV[2],$Q18_IDX_OV[3],$Q18_IDX_OV[4]),
							array($Q22_IDX_OV[0],$Q22_IDX_OV[1],$Q22_IDX_OV[2],$Q22_IDX_OV[3],$Q22_IDX_OV[4]),
							array($Q23_IDX_OV[0],$Q23_IDX_OV[1],$Q23_IDX_OV[2],$Q23_IDX_OV[3],$Q23_IDX_OV[4]),
							array($Q24_IDX_OV[0],$Q24_IDX_OV[1],$Q24_IDX_OV[2],$Q24_IDX_OV[3],$Q24_IDX_OV[4])
							);	

$Question_Array["Q99"][3]=array(
							array($Q2_P_Avg,$Q2_N_Avg,$Q2_S_Avg,$Q2_C_Avg,$Q2_A_Avg,0,0, $Q2_P_Avg2,$Q2_N_Avg2,$Q2_S_Avg2,$Q2_C_Avg2,$Q2_A_Avg2,0,0),
							array($Q5_P_Avg,$Q5_N_Avg,$Q5_S_Avg,$Q5_C_Avg,$Q5_A_Avg,0,0, $Q5_P_Avg2,$Q5_N_Avg2,$Q5_S_Avg2,$Q5_C_Avg2,$Q5_A_Avg2,0,0),
							array($Q6_P_Avg,$Q6_N_Avg,$Q6_S_Avg,$Q6_C_Avg,$Q6_A_Avg,0,0, $Q6_P_Avg2,$Q6_N_Avg2,$Q6_S_Avg2,$Q6_C_Avg2,$Q6_A_Avg2,0,0),
							array($Q7_P_Avg,$Q7_N_Avg,$Q7_S_Avg,$Q7_C_Avg,$Q7_A_Avg,0,0, $Q7_P_Avg2,$Q7_N_Avg2,$Q7_S_Avg2,$Q7_C_Avg2,$Q7_A_Avg2,0,0),
							array($Q9_P_Avg,$Q9_N_Avg,$Q9_S_Avg,$Q9_C_Avg,$Q9_A_Avg,0,0, $Q9_P_Avg2,$Q9_N_Avg2,$Q9_S_Avg2,$Q9_C_Avg2,$Q9_A_Avg2,0,0),
							array($Q10_P_Avg,$Q10_N_Avg,$Q10_S_Avg,$Q10_C_Avg,$Q10_A_Avg,0,0, $Q10_P_Avg2,$Q10_N_Avg2,$Q10_S_Avg2,$Q10_C_Avg2,$Q10_A_Avg2,0,0),
							array($Q11_P_Avg,$Q11_N_Avg,$Q11_S_Avg,$Q11_C_Avg,$Q11_A_Avg,0,0, $Q11_P_Avg2,$Q11_N_Avg2,$Q11_S_Avg2,$Q11_C_Avg2,$Q11_A_Avg2,0,0),
							array($Q12_P_Avg,$Q12_N_Avg,$Q12_S_Avg,$Q12_C_Avg,$Q12_A_Avg,0,0, $Q12_P_Avg2,$Q12_N_Avg2,$Q12_S_Avg2,$Q12_C_Avg2,$Q12_A_Avg2,0,0),
							array($Q14_P_Avg,$Q14_N_Avg,$Q14_S_Avg,$Q14_C_Avg,$Q14_A_Avg,0,0, $Q14_P_Avg2,$Q14_N_Avg2,$Q14_S_Avg2,$Q14_C_Avg2,$Q14_A_Avg2,0,0),
							array($Q17_P_Avg,$Q17_N_Avg,$Q17_S_Avg,$Q17_C_Avg,$Q17_A_Avg,0,0, $Q17_P_Avg2,$Q17_N_Avg2,$Q17_S_Avg2,$Q17_C_Avg2,$Q17_A_Avg2,0,0),
							array($Q18_P_Avg,$Q18_N_Avg,$Q18_S_Avg,$Q18_C_Avg,$Q18_A_Avg,0,0, $Q18_P_Avg2,$Q18_N_Avg2,$Q18_S_Avg2,$Q18_C_Avg2,$Q18_A_Avg2,0,0),
							array($Q22_P_Avg,$Q22_N_Avg,$Q22_S_Avg,$Q22_C_Avg,$Q22_A_Avg,0,0, $Q22_P_Avg2,$Q22_N_Avg2,$Q22_S_Avg2,$Q22_C_Avg2,$Q22_A_Avg2,0,0),
							array($Q23_P_Avg,$Q23_N_Avg,$Q23_S_Avg,$Q23_C_Avg,$Q23_A_Avg,0,0, $Q23_P_Avg2,$Q23_N_Avg2,$Q23_S_Avg2,$Q23_C_Avg2,$Q23_A_Avg2,0,0),
							array($Q24_P_Avg,$Q24_N_Avg,$Q24_S_Avg,$Q24_C_Avg,$Q24_A_Avg,0,0, $Q24_P_Avg2,$Q24_N_Avg2,$Q24_S_Avg2,$Q24_C_Avg2,$Q24_A_Avg2,0,0)
							);

$Question_Array["Q99"][5]=array($Overall_S_Avg,$Overall_C_Avg,$Overall_P_Avg,$Overall_N_Avg,$Overall_A_Avg, $Overall_S_Avg2,$Overall_C_Avg2,$Overall_P_Avg2,$Overall_N_Avg2,$Overall_A_Avg2);
$Question_Array["Q99"][6]=array(100,100,100,100,100);

//***-------------------------------------------------------------------------------***//
// Computations

// Handle Export to Excel Button
if(isset($_REQUEST['sel_export'])) {
	include_once("CreateExcel.php");
	exit;
}
// End Export to Excel Button
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name=Author content="Shebin">
<title>HAAD - Healthcare Professionals Satisfaction Survey - 2015</title>
<link href="http://www.arabdemog.com/haad/haad.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.tbl_cell {
	border: thin solid #333;
	font-size:12px;
}
.tbl_cellHdr {
	border: thin solid #333;
	background-color:#CCC;
	//background-color:#FF9;
	font-size:12px;
}
.tbl_cellHdr_str {
	border: thin solid #333;
	background-color:#91C8FF;
	font-size:10px;
}
.tbl_cellHdr_chr {
	border: thin solid #333;
	background-color: #fba2fb;
	font-size:10px;
}
.tbl_cellHdr_avg {
	border: thin solid #333;
	background-color:#FFFFCC;
	font-size:10px;
}
.tbl_cellHdr_pos {
	border: thin solid #333;
	background-color: #C9BBFF;
	font-size:10px;
}
.tbl_cellHdr_neg {
	border: thin solid #333;
	background-color: #FFC4C4;
	font-size:10px;
}
.filt_txt {
	font-size:10px;
	font-weight:bold;
	color:#000;
}
.indx {
	font-size:9px;
	font-style:italic;
	color:#000;
	margin:0px;
	text-align:center;
	width:100%;
}
.indx  a:link visited active{
    color: #000;
    text-decoration: none;
	cursor: help;
}

.trgt {
	font-size:12px;
	font-style: normal;
	color: #000;
	margin:0px;
	text-align:center;
	width:100%;
}
.trgt  a:link visited active{
    color: #000;
    text-decoration: none;
	cursor: help;
}


.bnch {
	font-size:12px;
	font-style: normal;
	color: #33C;
	margin:0px;
	text-align:center;
	width:100%;
}
.bnch  a:link visited active{
    color: #33C;
    text-decoration: none;
	cursor: help;
}

.question {
	font-size:12px;
} 
 a {
	 text-decoration:none;
 }
 .qheader {
	 border:thin dotted;
	 height:20px;
 }
.qheader:hover { 
    background-color: yellow;
} 

.targetmg {
	text-decoration:underline;
	font-size:12px;
}
.targetmg a:visited { color: white }
.targetmg a:link { color: white }
.targetmg a:hover { color: yellow }
.targetmg a:active { color: white }




</style>

<script>
var http = createRequestObject();
function createRequestObject() {
	var xmlhttp;
	try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) {
	try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	catch(f) { xmlhttp=null; }
    }
	if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
		xmlhttp=new XMLHttpRequest();
	}
	return  xmlhttp;
}
function refreshtarget() {
	var rnd = Math.random();
	try{
		http.open('POST', 'showtargets.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = refreshOpts;
		http.send();
	}
	catch(e){}
	finally{}
}
function refreshOpts() {
	try{
		if((http.readyState == 4)&& (http.status == 200)){
			var response = http.responseText;
			fillcombo(response,'sel_target','sel_bnch');
		}
  	}
	catch(e){
	}
	finally{}
}
function fillcombo(rsp,cmbo1,cmbo2) {
	 var s_menu1 = document.getElementById(cmbo1);
	 var s_menu2 = document.getElementById(cmbo2);
	 var s_menu1_val = s_menu1.value;
	 var s_menu2_val = s_menu2.value;
	 
	 s_menu1.innerHTML = "";
	 s_menu2.innerHTML = "";
	 var stateNodes = rsp.split(";");
	 var optionItem;
	 var textValue;

	 optionItem1 = new Option( "Total Sample", 0,  false, false);
	 optionItem2 = new Option( "No Benchmark", 0,  false, false);
	 s_menu1.options[s_menu1.length] = optionItem1;
	 s_menu2.options[s_menu2.length] = optionItem2;


	 for (r=0;r<stateNodes.length; r++)
	 {	
		 var mdata = stateNodes[r].split(":");
		 textValue=mdata[1];
		 if(textValue.length >0) {
			 optionItem1 = new Option( mdata[1], mdata[0],  false, false);
			 optionItem2 = new Option( mdata[1], mdata[0],  false, false);
			 s_menu1.options[s_menu1.length] = optionItem1;
			 s_menu2.options[s_menu2.length] = optionItem2;
		 }	 
	 }
	 
	 s_menu1.value = s_menu1_val;
	 s_menu2.value = s_menu2_val;
} 
</script>

<script>
	function ImportData() {
		window.location.href = "import.php";	
	}

	function showDetails(trEle) {
		trEle = "Q" + trEle;
		
		if(trEle!="Q2") { document.getElementById("Q2").style.display ="none";	}
		if(trEle!="Q5") { document.getElementById("Q5").style.display ="none";	}
		if(trEle!="Q6") { document.getElementById("Q6").style.display ="none";	}
		if(trEle!="Q7") { document.getElementById("Q7").style.display ="none";	}
		if(trEle!="Q9") { document.getElementById("Q9").style.display ="none";	}
		if(trEle!="Q10") { document.getElementById("Q10").style.display ="none";	}
		if(trEle!="Q11") { document.getElementById("Q11").style.display ="none";	}
		if(trEle!="Q12") { document.getElementById("Q12").style.display ="none";	}
		if(trEle!="Q14") { document.getElementById("Q14").style.display ="none";	}
		if(trEle!="Q17") { document.getElementById("Q17").style.display ="none";	}
		if(trEle!="Q18") { document.getElementById("Q18").style.display ="none";	}
		if(trEle!="Q22") { document.getElementById("Q22").style.display ="none";	}
		if(trEle!="Q23") { document.getElementById("Q23").style.display ="none";	}
		if(trEle!="Q24") { document.getElementById("Q24").style.display ="none";	}
		if(trEle!="Q99") { document.getElementById("Q99").style.display ="none";	}
		
		if(document.getElementById(trEle).style.display =="none")  {
			document.getElementById(trEle).style.display ="";
		}
		else {
			document.getElementById(trEle).style.display ="none";	
		}

		var gp=0;
		if(document.getElementById("Q2").style.display  !="none") { gp++; }
		if(document.getElementById("Q5").style.display  !="none") { gp++; }
		if(document.getElementById("Q6").style.display  !="none") { gp++; }
		if(document.getElementById("Q7").style.display  !="none") { gp++; }
		if(document.getElementById("Q9").style.display  !="none") { gp++; }
		if(document.getElementById("Q10").style.display !="none") { gp++; }
		if(document.getElementById("Q11").style.display !="none") { gp++; }
		if(document.getElementById("Q12").style.display !="none") { gp++; }
		if(document.getElementById("Q14").style.display !="none") { gp++; }
		if(document.getElementById("Q17").style.display !="none") { gp++; }
		if(document.getElementById("Q18").style.display !="none") { gp++; }
		if(document.getElementById("Q22").style.display !="none") { gp++; }
		if(document.getElementById("Q23").style.display !="none") { gp++; }
		if(document.getElementById("Q24").style.display !="none") { gp++; }
		
		if(gp==0) {
			document.getElementById("Q99").style.display ="";
		}
		else {
			document.getElementById("Q99").style.display ="none";
		}

	}

function logout() {
	window.location.href ="http://www.arabdemog.com/haad/logout.php";
}

function oOptions() {
		var w = 700;
		var h = 600;
		var left = (window.screen.width / 2) - ((w / 2) + 10);
		var top = (window.screen.height / 2) - ((h / 2) + 50);
		
		myWindow = window.open('user_options.php', 'tinyWindow','toolbar=false,width='+w+',height='+h+',left='+left+',top='+top+',resizable=yes,scrollbars=yes');	
}

function ExportExcel(mval) {
	if(mval>0) {
		document.forms[0].submit();
		/*		
		var w = 200;
		var h = 100;
		var left = (window.screen.width / 2) - ((w / 2) + 10);
		var top = (window.screen.height / 2) - ((h / 2) + 50);
		
		myWindow = window.open('CreateExcel.php', 'tinyWindow','toolbar=false,width='+w+',height='+h+',left='+left+',top='+top+',resizable=yes,scrollbars=yes');
		*/
	}
}

function opentarget() {
		var w = 700;
		var h = 600;
		var left = (window.screen.width / 2) - ((w / 2) + 10);
		var top = (window.screen.height / 2) - ((h / 2) + 50);
		
		myWindow = window.open('managetarget.php', 'tragetWindow','toolbar=false,width='+w+',height='+h+',left='+left+',top='+top+',resizable=yes,scrollbars=yes');		
	
}

function selTarget(targ) {
	var bench = document.getElementById("sel_bnch").value;
	if(targ>0) {
		if(bench == targ) {
			alert("Both target and Benchmark cannot be same");
			document.getElementById("sel_target").value=0;
		}
		else {
			document.forms[0].submit();
		}
	}
	else {
		document.forms[0].submit();
	}
}

function selBenchMark(bnch) {
	var target = document.getElementById("sel_target").value;
	if(bnch>0) {
		if(target == bnch) {
			alert("Both target and Benchmark cannot be same");
			document.getElementById("sel_bnch").value=0;
		}
		else {
			document.forms[0].submit();
		}
	}
	else {
		document.forms[0].submit();
	}
}

function selCatg(catg) {
	var target = document.getElementById("sel_target").value;
	var bench = document.getElementById("sel_bnch").value;
	
	if(target>0 || bench>0) {
		document.getElementById("sel_prof_catg").value=0;
		alert("Option is not allowed while you have already selected Target or Benchmark");
	}
	else {
		document.forms[0].submit();
	}
}

function selFacil(faci) {
	var target = document.getElementById("sel_target").value;
	var bench = document.getElementById("sel_bnch").value;
	
	if(target>0 || bench>0) {
		document.getElementById("sel_health_fac").value=0;
		alert("Option is not allowed while you have already selected Target or Benchmark");
	}
	else {
		document.forms[0].submit();
	}
}
</script>

</head>
<body>

<form action="" enctype="multipart/form-data" method="post">
<!-- main div-->
<div id='mdiv' class='maindiv'>
<!-- Header div-->
    <div id='hdiv' class='headdiv'>
        <table width='100%'>
            <tr>
            <td align='right' width='27%'>
              <img src='http://www.arabdemog.com/haad/images/haad.png' style='height:110px;width:200px;text-align:left'>
            </td>
			<td style='text-align:left;font-size:23px' width='73%'>HAAD - Healthcare Professionals Satisfaction Survey - 2015 </td>
        </table>
    </div>
<!-- End Header div-->


    <div id='idiv' class='intdiv'>
        <div>
   
			
            <table border="1" width="100%" style="background-color:#FFF; border-collapse:collapse; border: thin #000">
         
            	<tr>
                	<td>
                      <table width="100%" cellpadding="5px">

                            <tr>
                              <td align="left" valign="middle" nowrap bgcolor="#1f767b" class="filt_txt">Filter By Category : </td>
                              <td align="left" valign="middle" bgcolor="#1f767b">
                                  <select name="sel_prof_catg" id="sel_prof_catg" style="width: 100%" onChange="selCatg(this.value)">
                                    <option value="0" <?php if($_SESSION["seas_brd_filter_prof"]==0) echo "selected"; ?> >ALL</option>
                                    <option value="1" <?php if($_SESSION["seas_brd_filter_prof"]==1) echo "selected"; ?> >Physician</option>
                                    <option value="2" <?php if($_SESSION["seas_brd_filter_prof"]==2) echo "selected"; ?> >Dentist</option>
                                    <option value="3" <?php if($_SESSION["seas_brd_filter_prof"]==3) echo "selected"; ?> >Nurse \ Midwife</option>
                                    <option value="4" <?php if($_SESSION["seas_brd_filter_prof"]==4) echo "selected"; ?> >Pharmacist</option>
                                    <option value="5" <?php if($_SESSION["seas_brd_filter_prof"]==5) echo "selected"; ?> >Allied Health professional</option>
                                  </select>                    
                                </td>
                            <td align="left" valign="middle" nowrap bgcolor="#1f767b" class="filt_txt">Filter By Facility : </td>
                                <td align="left" valign="middle" bgcolor="#1f767b">
                                  <select name="sel_health_fac" id="sel_health_fac" style="width: 100%" onChange="selFacil(this.value)">
                                    <option value="0" <?php if($_SESSION["seas_brd_filter_hlth"]==0) echo "selected"; ?> >ALL</option>
                                    <option value="1" <?php if($_SESSION["seas_brd_filter_hlth"]==1) echo "selected"; ?> >ZMH</option>
                                    <option value="2" <?php if($_SESSION["seas_brd_filter_hlth"]==2) echo "selected"; ?> >Mubadala Healthcare</option>
                                    <option value="3" <?php if($_SESSION["seas_brd_filter_hlth"]==3) echo "selected"; ?> >ADNOC</option>
                                    <option value="4" <?php if($_SESSION["seas_brd_filter_hlth"]==4) echo "selected"; ?> >AD Police</option>
                                    <option value="5" <?php if($_SESSION["seas_brd_filter_hlth"]==5) echo "selected"; ?> >Zayed Higher Organization</option>
                                    <option value="6" <?php if($_SESSION["seas_brd_filter_hlth"]==6) echo "selected"; ?> >Other Government</option>
                                    <option value="7" <?php if($_SESSION["seas_brd_filter_hlth"]==7) echo "selected"; ?> >Other Private</option>
                                    <option value="8" <?php if($_SESSION["seas_brd_filter_hlth"]==8) echo "selected"; ?> >SEHA</option>
                                  </select>                    
                              </td>
                            <td align="left" valign="middle" nowrap bgcolor="#1f767b" class="filt_txt">Survey Topics : </td>
                                <td align="left" valign="middle" bgcolor="#1f767b">
                                  <select name="sel_survey_topic" id="sel_survey_topic" style="width: 100%" onChange="showDetails(this.value)">
                                    <option value="99" <?php if($_SESSION["seas_brd_filter_topic"]==99) echo "selected"; ?> >Over All</option>
                                    
                                    <option value="2" <?php if($_SESSION["seas_brd_filter_topic"]==2) echo "selected"; ?> >Q2. Work Environment</option>
                                    <option value="5" <?php if($_SESSION["seas_brd_filter_topic"]==5) echo "selected"; ?> >Q5. Evaluation Of Professional Performance</option>
                                    <option value="6" <?php if($_SESSION["seas_brd_filter_topic"]==6) echo "selected"; ?> >Q6. Experience And Achievements</option>
                                    <option value="7" <?php if($_SESSION["seas_brd_filter_topic"]==7) echo "selected"; ?> >Q7. Career</option>
                                    <option value="9" <?php if($_SESSION["seas_brd_filter_topic"]==9) echo "selected"; ?> >Q9. Innovation And Research Support</option>
                                    <option value="10" <?php if($_SESSION["seas_brd_filter_topic"]==10) echo "selected"; ?> >Q10. Work Schedule</option>
                                    <option value="11" <?php if($_SESSION["seas_brd_filter_topic"]==11) echo "selected"; ?> >Q11. Patient Care</option>
                                    <option value="12" <?php if($_SESSION["seas_brd_filter_topic"]==12) echo "selected"; ?> >Q12. Compensation And Benefits</option>
                                    <option value="14" <?php if($_SESSION["seas_brd_filter_topic"]==14) echo "selected"; ?> >Q14. Handling Challenges</option>
                                    <option value="17" <?php if($_SESSION["seas_brd_filter_topic"]==17) echo "selected"; ?> >Q17. Complaint System</option>
                                    <option value="18" <?php if($_SESSION["seas_brd_filter_topic"]==18) echo "selected"; ?> >Q18. Roles And Duties Abu Dhabi Regulatory</option>
                                    <option value="22" <?php if($_SESSION["seas_brd_filter_topic"]==22) echo "selected"; ?> >Q22. Collaboration And Support</option>
                                    <option value="23" <?php if($_SESSION["seas_brd_filter_topic"]==23) echo "selected"; ?> >Q23. Education And Training</option>
                                    <option value="24" <?php if($_SESSION["seas_brd_filter_topic"]==24) echo "selected"; ?> >Q24. Emiratis In Healthcare Career</option>
                              </select>                               <!--Export : --> 
                                <!--
                                  <select name="sel_export" id="sel_export" style="width: 100%" onChange="ExportExcel(this.value)">
                                    <option value="0" selected ></option>
                                    <option value="1" >Export Excel</option>
                                  </select>
                                -->                              </td>
                          </tr>
                            <tr>
                              <td align="left" valign="middle" nowrap bgcolor="#1f767b" class="filt_txt targetmg"><a href="#" onClick="opentarget()" title="Manage Target">Target</a></td>
                              <td align="left" valign="middle" bgcolor="#1f767b"><select name="sel_target" id="sel_target" style="width: 100%" onChange="selTarget(this.value)">
                                <option value="0" <?php if($_SESSION["seas_brd_filter_sel_target"]==0) echo "selected"; ?> >Total Sample</option>
							    <?php
								$tarsql  = "select tar_id,tar_desc from seas_brd_target order by 2";
								$tarrslt = mysql_query($tarsql);
								while($tarrow=mysql_fetch_assoc($tarrslt)) {
									echo '<option value="'. $tarrow['tar_id'] .'"';
									if($_SESSION["seas_brd_filter_sel_target"]==$tarrow['tar_id']) {
										echo "selected"; 
									}
									echo '>'. $tarrow['tar_desc'].'</option>';
								}
								?>
                              </select></td>
                              <td align="left" valign="middle" nowrap bgcolor="#1f767b" class="filt_txt">Benchmark :</td>
                              <td align="left" valign="middle" bgcolor="#1f767b"><select name="sel_bnch" id="sel_bnch" style="width: 100%" onChange="selBenchMark(this.value)">
                                <option value="0" <?php if($_SESSION["seas_brd_filter_sel_bnch"]==0) echo "selected"; ?> >No Benchmark</option>
                                <?php
								$tarsql  = "select tar_id,tar_desc from seas_brd_target order by 2";
								$tarrslt = mysql_query($tarsql);
								while($tarrow=mysql_fetch_assoc($tarrslt)) {
									echo '<option value="'. $tarrow['tar_id'] .'"';
									if($_SESSION["seas_brd_filter_sel_bnch"]==$tarrow['tar_id']) {
										echo "selected"; 
									}
									echo '>'. $tarrow['tar_desc'].'</option>';
								}
								?>
                              </select></td>
                              <td colspan="2" align="left" valign="middle" nowrap bgcolor="#1f767b" class="filt_txt"><table border="0" cellpadding="0" cellspacing="0" width="100%">
                                <tr>
                                  <td align="left" nowrap><input type="submit" value="Export Excel" name="sel_export" style="background-color: #069; font-weight:bold; color:#FFF; font-size:10px; padding:5px; width:22%">
                                    <input type="button" value="Import Data" name="sel_import" style="background-color: #333; font-weight:bold; color:#FFF; font-size:10px; padding:5px; width:20%" onClick="ImportData()">
                                    <input type="button" value="Definitions & Settings" name="sel_import" style="background-color: #FF0; font-weight:bold; color:#F00; font-size:10px; padding:5px; width:38%" onClick="oOptions()">
                                    <input type="button" value="Logout" name="sel_logout" style="background-color:  #F00; font-weight:bold; color:#FFF; font-size:10px; padding:5px; width:18%" onClick="logout()"></td>
                                </tr>
                                <tr>
                                  <td height="5px"></td>
                                </tr>
                              </table>
                                
                                
                                
                                
                                
                              </td>
                            </tr>                          
                        </table>
            		</td>
                </tr>
<?php

foreach($Question_Array as $Qkey=>$QArray) {
	echo print_section1($Qkey,$QArray,$trg_sample,$per_sample,$bnch_sample,$bper_sample,$usr_opts);
	//include_once("section_Q99.php");
}
/*
	 include_once("section_Q2.php");
	 include_once("section_Q5.php");
	 include_once("section_Q6.php");
	 include_once("section_Q7.php");
	 include_once("section_Q9.php");
	 include_once("section_Q10.php");
	 include_once("section_Q11.php");
	 include_once("section_Q12.php");
	 include_once("section_Q14.php");
	 include_once("section_Q17.php");
	 include_once("section_Q18.php");
	 include_once("section_Q22.php");
	 include_once("section_Q23.php");
	 include_once("section_Q24.php");
	 include_once("section_Q99.php");
*/	 
?>


                                   
          </table>
		</div>
</div>
</form>
</body>
</html>

             


<?php
function createGraph($qs,$rvopt=1) {

	if($_SERVER['HTTP_HOST']=="localhost") {
		$srvpath = "http://localhost/haad/";	
		$srvdir  = "C:/Program Files (x86)/Zend/Apache2/htdocs/haad/";
	}
	else {
		$srvpath = "http://www.arabdemog.com/haad/";	
		$srvdir  = "/home/arabdemog/httpdocs/haad/";
	}
	// Create graph Data
	if($rvopt==1) {
		$character=$qs[3];
		$strength =$qs[2];
	}
	else {
		$character=round($qs[3],0);
		$strength =round($qs[2],0);
	}
	// ---- //
	
			/* pChart library inclusions */
		 include_once("../pChart/class/pData.class.php");
		 include_once("../pChart/class/pDraw.class.php");
		 include_once("../pChart/class/pImage.class.php");
		
			
		 /* Create and populate the pData object */
		 $MyData = new pData();  
		 $MyData->addPoints($character,"Character"); 
		 $MyData->addPoints($strength,"Strength"); 

		 $MyData->setAxisName(0,"Age Pyramid");
		 //$MyData->addPoints(array("40+ Years","31-40 Years","21-30 Years"),"Age"); 
		 $MyData->setSerieDescription("Age","Age"); 
		 $MyData->setAbscissa("Age"); 
		 $MyData->setAxisDisplay(0,AXIS_FORMAT_CUSTOM,"YAxisFormat");
		 $serieSettings = array("R"=>145,"G"=>200,"B"=>255,"Alpha"=>100);
		 $MyData->setPalette("Strength",$serieSettings);
		
		 if($character>0) {
		 	$serieSettings = array("R"=>251,"G"=>162,"B"=>251,"Alpha"=>100);
		 }
		 else {
			$serieSettings = array("R"=>255,"G"=>0,"B"=>0,"Alpha"=>40);
		 }
		 $MyData->setPalette("Character",$serieSettings);

		
		 /* Create the pChart object */
		 $myPicture = new pImage(400,60,$MyData);
		 //$myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100));
		 //$myPicture->drawGradientArea(0,0,700,230,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20));

	
		 /* Set the default font properties */
		 $myPicture->setFontProperties(array("FontName"=>"../pChart/fonts/verdana.ttf","FontSize"=>8));
		
		 /* Draw the scale and the chart */
		 $AxisBoundaries = array(0=>array("Min"=>-50,"Max"=>100));
		 $myPicture->setGraphArea(-3,-3,390,60);
		 $myPicture->drawScale(array("DrawSubTicks"=>TRUE,"Mode"=>SCALE_MODE_MANUAL,"ManualScale"=>$AxisBoundaries,"Pos"=>SCALE_POS_TOPBOTTOM,'YMargin'=>0,'MinDivHeight'=>5, 'AxisR'=>255, 'AxisG'=>255,'AxisB'=>255 ));

		 //$myPicture->setShadow(FALSE);
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); 

		// $myPicture->drawBarChart(array("Gradient"=>TRUE,"GradientMode"=>GRADIENT_EFFECT_CAN,"DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO,"Gradient"=>TRUE,"Surrounding"=>-20,"InnerSurrounding"=>20));

		 /* Draw the chart */ 
		 $settings = array("Gradient"=>TRUE,"GradientMode"=>GRADIENT_EFFECT_CAN,"DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"DisplayR"=>0,"DisplayG"=>0,"DisplayB"=>0,"DisplayShadow"=>TRUE,"Surrounding"=>10);
		 $myPicture->drawBarChart($settings); 


		 /* Write the chart legend */
		 //$myPicture->drawLegend(365,320,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
		
		/* Render the picture (choose the best way) */ 
		$fileName= $_SERVER['DOCUMENT_ROOT'] . "/";
		$fname = "graphs/gp1_" . date("dmYHis") . rand() .".gif";
		
		$rmvfiles = "rm " . $_SERVER['DOCUMENT_ROOT'] . "/graphs/gp1*.gif";
		//shell_exec($rmvfiles);
		$myPicture->Render($fname);
		
		if($rvopt==1) {
			echo "<img src='". $srvpath .$fname. "?rnd=". rand() ."' align='center'>";				 
		}
		else {
   			return $srvdir .$fname;
		}
}
function YAxisFormat($Value) { return(abs($Value)); } 


function getValues($weighted=false,$qs) {
	
	if(strlen($_SESSION["seas_brd_filter_condition"]) >0) {
		$sqlcond = $_SESSION["seas_brd_filter_condition"] . " and ";
	}
	else {
		$sqlcond = "";
	}
	if(strlen($_SESSION["seas_brd_bnch_filter_condition"]) >0) {		// for benchmark
		$sqlcond2 = $_SESSION["seas_brd_bnch_filter_condition"] . " and ";
	}
	else {
		$sqlcond2 = "";
	}
	
	
	$response = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0);  // Any Agree, Any DisAgree, Strength, Character, Average, Nuetral, Total
												     // Any Agree, Any DisAgree, Strength, Character, Average, Nuetral, Total - for benchmark
	
	// Total
	if($weighted==false) {
		$s_sql = "select count(". $qs .") from seas_brd_dat where " . $sqlcond . $qs ." not in (9) ";
	}
	else {
		$s_sql = "select sum(weight) from seas_brd_dat where " . $sqlcond . $qs ." not in (9) ";
	}
	$s_rslt = mysql_query($s_sql);
	$s_array= mysql_fetch_array($s_rslt);
	$response[6] = $s_array[0];
	mysql_free_result($s_rslt);

		// For Benchmark
		if($weighted==false) {
			$s_sql = "select count(". $qs .") from seas_brd_dat where " . $sqlcond2 . $qs ." not in (9) ";
		}
		else {
			$s_sql = "select sum(weight) from seas_brd_dat where " . $sqlcond2 . $qs ." not in (9) ";
		}
		$s_rslt = mysql_query($s_sql);
		$s_array= mysql_fetch_array($s_rslt);
		$response[13] = $s_array[0];
		mysql_free_result($s_rslt);

		
	// Any Agree
	if($weighted==false) {
		$s_sql = "select count(". $qs .") from seas_brd_dat where " . $sqlcond . $qs ." in (5,4) ";
	}
	else {
		$s_sql = "select sum(weight) from seas_brd_dat where " . $sqlcond . $qs ." in (5,4) ";
	}

	$s_rslt = mysql_query($s_sql);
	$s_array= mysql_fetch_array($s_rslt);
	$response[0] = round(($s_array[0]/$response[6])*100,0);
	$AgreeCount = $s_array[0];
	mysql_free_result($s_rslt);

		// For Benchmark
		if($weighted==false) {
			$s_sql = "select count(". $qs .") from seas_brd_dat where " . $sqlcond2 . $qs ." in (5,4) ";
		}
		else {
			$s_sql = "select sum(weight) from seas_brd_dat where " . $sqlcond2 . $qs ." in (5,4) ";
		}
	
		$s_rslt = mysql_query($s_sql);
		$s_array= mysql_fetch_array($s_rslt);
		$response[7] = round(($s_array[0]/$response[13])*100,0);
		$AgreeCount2 = $s_array[0];
		mysql_free_result($s_rslt);

	// Nuetral
	if($weighted==false) {
		$s_sql = "select count(". $qs .") from seas_brd_dat where " . $sqlcond . $qs ." in (3) ";
	}
	else {
		$s_sql = "select sum(weight) from seas_brd_dat where " . $sqlcond . $qs ." in (3) ";
	}
	$s_rslt = mysql_query($s_sql);
	$s_array= mysql_fetch_array($s_rslt);
	$response[5] = $s_array[0];
	mysql_free_result($s_rslt);
		
		// For Benchmark
		if($weighted==false) {
			$s_sql = "select count(". $qs .") from seas_brd_dat where " . $sqlcond2 . $qs ." in (3) ";
		}
		else {
			$s_sql = "select sum(weight) from seas_brd_dat where " . $sqlcond2 . $qs ." in (3) ";
		}
		$s_rslt = mysql_query($s_sql);
		$s_array= mysql_fetch_array($s_rslt);
		$response[12] = $s_array[0];
		mysql_free_result($s_rslt);
		

	// Dis Agree
	if($weighted==false) {
		$s_sql = "select count(". $qs .") from seas_brd_dat where " . $sqlcond . $qs ." in (2,1) ";
	}
	else {
		$s_sql = "select sum(weight) from seas_brd_dat where " . $sqlcond . $qs ." in (2,1) ";
	}
	$s_rslt = mysql_query($s_sql);
	$s_array= mysql_fetch_array($s_rslt);
	$response[1] = round(($s_array[0]/$response[6])*100,0);
	$DisagreeCount = $s_array[0];
	mysql_free_result($s_rslt);
		
		// For Benchmark
		if($weighted==false) {
			$s_sql = "select count(". $qs .") from seas_brd_dat where " . $sqlcond2 . $qs ." in (2,1) ";
		}
		else {
			$s_sql = "select sum(weight) from seas_brd_dat where " . $sqlcond2 . $qs ." in (2,1) ";
		}
		$s_rslt = mysql_query($s_sql);
		$s_array= mysql_fetch_array($s_rslt);
		$response[8] = round(($s_array[0]/$response[13])*100,0);
		$DisagreeCount2 = $s_array[0];
		mysql_free_result($s_rslt);	
		
	// Average
	if($weighted==false) {
		$s_sql = "select avg(". $qs .") from seas_brd_dat where " . $sqlcond . $qs ." not in (9) ";
	}
	else {
		//$s_sql = "select avg(weight) from seas_brd_dat where " . $sqlcond . $qs ." not in (9) ";
		$s_sql = "select avg(". $qs .") from seas_brd_dat where " . $sqlcond . $qs ." not in (9) ";
	}
	$s_rslt = mysql_query($s_sql);
	$s_array= mysql_fetch_array($s_rslt);
	$response[4] = round(($s_array[0] / 5*100),0);
	mysql_free_result($s_rslt);	

		// For Benchmark
		if($weighted==false) {
			$s_sql = "select avg(". $qs .") from seas_brd_dat where " . $sqlcond2 . $qs ." not in (9) ";
		}
		else {
			//$s_sql = "select avg(weight) from seas_brd_dat where " . $sqlcond2 . $qs ." not in (9) ";
			$s_sql = "select avg(". $qs .") from seas_brd_dat where " . $sqlcond2 . $qs ." not in (9) ";
		}
		$s_rslt = mysql_query($s_sql);
		$s_array= mysql_fetch_array($s_rslt);
		$response[11] = round(($s_array[0] / 5*100),0);
		mysql_free_result($s_rslt);		
	
	// IMAGE STRENGTH
	if($response[6] >0) {
		$response[2] = round((($AgreeCount + $DisagreeCount) / $response[6])*100,0);
		$response[9] = round((($AgreeCount2 + $DisagreeCount2) / $response[13])*100,0); // For Benchmark
	}
	else {
		$response[2] = 0;
		$response[9] = 0;
	}
	// IMAGE CHARACTER
	if($AgreeCount + $DisagreeCount >0) {
		$response[3] = round((($AgreeCount - $DisagreeCount) / ($AgreeCount + $DisagreeCount))*100,0);	
		$response[10] = round((($AgreeCount2 - $DisagreeCount2) / ($AgreeCount2 + $DisagreeCount2))*100,0);	
	}
	else {
		$response[3] = 0;
		$response[10] = 0;
	}
	
	return $response;
}

function CreateRadar($Strength_Avg,$Character_Avg,$Positive_Avg,$Negative_Avg,$Average_Avg,$labls,$gtitle="") {

	$usr_opts = explode(",",$_SESSION['PCD_user_opts']);
	
	foreach($Strength_Avg as $ky=>$savg) {
			$Strength_Avg[$ky] = round($savg,0);
	}
	foreach($Character_Avg as $ky=>$savg) {
			$Character_Avg[$ky] = round($savg,0);
	}
	foreach($Positive_Avg as $ky=>$savg) {
			$Positive_Avg[$ky] = round($savg,0);
	}
	foreach($Negative_Avg as $ky=>$savg) {
			if($usr_opts[5]==1) {
				$Negative_Avg[$ky] = round($savg,0);
			}
			else {
					$Negative_Avg[$ky] = round($savg*-1,0);
			}
	}
	foreach($Average_Avg as $ky=>$savg) {
			$Average_Avg[$ky] = round($savg,0);
	}

	if($_SERVER['HTTP_HOST']=="localhost") {
		$srvpath = "http://localhost/haad/";	
	}
	else {
		$srvpath = "http://www.arabdemog.com/haad/";	
	}
	


	// Create graph Data
	//$character=$qs[3];
	//$strength =$qs[2];
	// ---- //
	
			/* pChart library inclusions */
		 include_once("../pChart/class/pData.class.php");
		 include_once("../pChart/class/pDraw.class.php");
		 if($usr_opts[5]==1) {
			 include_once("../pChart/class/pRadar.class.php"); 
		 }
		 include_once("../pChart/class/pImage.class.php"); 		 
		
			
		 /* Create and populate the pData object */
		 $MyData = new pData();  
		 //$MyData->addPoints($Strength_Avg,"Strength");   
		 //$MyData->addPoints($Character_Avg,"Character");  
		 $MyData->addPoints($Positive_Avg,"Positive");  
		 $MyData->addPoints($Negative_Avg,"Negative");  
		 //$MyData->addPoints($Average_Avg,"Average");  
		 
		 //$MyData->setSerieDescription("Strength","Opinion Strength"); 
		 //$MyData->setSerieDescription("Character","Opinion Character"); 
		 $MyData->setSerieDescription("Positive","Opinion Positive"); 
		 $MyData->setSerieDescription("Negative","Opinion Negative"); 
		 //$MyData->setSerieDescription("Average","Opinion Average"); 		 
		 $MyData->setSerieWeight("Strength",2); 

		 /* Define the absissa serie */ 
		 $MyData->addPoints($labls,"Labels"); 
		 $MyData->setAbscissa("Labels"); 

		 //$serieSettings = array("R"=>79,"G"=>129,"B"=>189,"Alpha"=>100);
		 //$MyData->setPalette("Strength",$serieSettings);
		 //$serieSettings = array("R"=>0,"G"=>176,"B"=>80,"Alpha"=>100);
		 //$MyData->setPalette("Character",$serieSettings);	
		 $serieSettings = array("R"=>0,"G"=>255,"B"=>0,"Alpha"=>100);
		 $MyData->setPalette("Positive",$serieSettings);	
		 $serieSettings = array("R"=>255,"G"=>0,"B"=>0,"Alpha"=>100);
		 $MyData->setPalette("Negative",$serieSettings);	
		 //$serieSettings = array("R"=>255,"G"=>153,"B"=>0,"Alpha"=>100);
		 //$MyData->setPalette("Average",$serieSettings);		 

	
		if($usr_opts[5]==1) {
			 /* Create the pChart object */
			 $myPicture = new pImage(800,650,$MyData); 
			 /* Set the default font properties */
			 $myPicture->setFontProperties(array("FontName"=>"../pChart/fonts/verdana.ttf","FontSize"=>7));
			 /* Enable shadow computing */  
			 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); 
			 /* Create the pRadar object */  
			 $SplitChart = new pRadar(); 
			/* Draw a radar chart */  
			 $myPicture->setGraphArea(150,20,600,600); 
			 //$Options = array("DrawPoly"=>TRUE,"PolyAlpha"=>100,"AxisRotation"=>270,"WriteValues"=>TRUE,"WriteValuesInBubble"=>TRUE,"ValueFontSize"=>7,"Layout"=>RADAR_LAYOUT_STAR,"LabelPos"=>RADAR_LABELS_HORIZONTAL,"BackgroundGradient"=>array("StartR"=>255,"StartG"=>255,"StartB"=>255,"StartAlpha"=>100,"EndR"=>207,"EndG"=>227,"EndB"=>125,"EndAlpha"=>50), "FontName"=>"../pChart/fonts/pf_arma_five.ttf","FontSize"=>6); 
			 $Options = array("DrawPoly"=>FALSE,"AxisRotation"=>270,"FixedMax"=>100,"WriteValues"=>TRUE,"WriteValuesInBubble"=>TRUE,"ValueFontSize"=>7,"Layout"=>RADAR_LAYOUT_STAR,"LabelPos"=>RADAR_LABELS_HORIZONTAL, "FontName"=>"../pChart/fonts/pf_arma_five.ttf","FontSize"=>6,"AxisAlpha"=>30); 
			 $SplitChart->drawRadar($myPicture,$MyData,$Options);
			 /* Write the chart legend */  
			 $myPicture->setFontProperties(array("FontName"=>"../pChart/fonts/verdana.ttf","FontSize"=>9)); 
			 $myPicture->drawLegend(250,640,array("Style"=>LEGEND_BOX,"Mode"=>LEGEND_HORIZONTAL)); 
		}
		else {
			 /* Create the pChart object */
			 $myPicture = new pImage(1100,650,$MyData); 
			 $myPicture->drawGradientArea(0,0,1100,650,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100)); 
			 $myPicture->drawGradientArea(0,0,1100,650,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20)); 			 
			 /* Set the default font properties */
			 $myPicture->setFontProperties(array("FontName"=>"../pChart/fonts/verdana.ttf","FontSize"=>8));
			 /* Enable shadow computing */  
			 $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); 			
			 /* Draw the chart */ 
			 $myPicture->setGraphArea(150,20,1000,400); 
			 $myPicture->drawScale(array("CycleBackground"=>TRUE,"DrawSubTicks"=>TRUE,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>10,"LabelRotation"=>45));

			$settings = array("Gradient"=>TRUE,"GradientMode"=>GRADIENT_EFFECT_CAN,"DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"DisplayR"=>0,"DisplayG"=>0,"DisplayB"=>0,"DisplayShadow"=>TRUE,"Surrounding"=>10);
			 $myPicture->drawStackedBarChart($settings); 
			 /* Write the chart legend */  
			 $myPicture->setFontProperties(array("FontName"=>"../pChart/fonts/pf_arma_five.ttf","FontSize"=>7)); 
			 $myPicture->drawLegend(1005,40,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL)); 
		}
		 

		/* Render the picture (choose the best way) */ 
		$fileName= $_SERVER['DOCUMENT_ROOT'] . "/";
		$fname = "graphs/gp1_" . date("dmYHis") . rand() .".gif";
		
		$rmvfiles = "rm " . $_SERVER['DOCUMENT_ROOT'] . "/graphs/gp3*.gif";
		//shell_exec($rmvfiles);
		$myPicture->Render($fname);
		
		if($usr_opts[5]!=1) {
			echo "<table border=5 style='border-color:#fff;border-collapse: collapse;' cellpadding=15 cellspacing=0 width='100%'>";
			echo "	<tr>";
			echo "		<td background='images/dash.png' align='center'>";
			echo 			"<strong><span class='question'>" . $gtitle . "</span></strong><br><br>";
		}

		echo "			<img src='". $srvpath .$fname. "?rnd=". rand() ."' border='0'>";

		if($usr_opts[5]!=1) {
			echo "		</td>";
			echo "	</tr>";
			echo "</table>";
		}
}

if($_SESSION["seas_brd_filter_topic"] >0) {
	
	echo "<script>";
	echo 	"showDetails(".$_SESSION["seas_brd_filter_topic"].");";
	echo "</script>";

}

function getAvg($Q,$pos) {
	$cn = count($Q);
	$sm = 0;
	foreach($Q as $Qval) {
		$sm = $sm + $Qval[$pos];
	}
	$av = round($sm/$cn,0);
	return $av;
}

function pr_index($Q) {
	echo '<p class="indx">';
	echo '<a href="#" title="Index" class="indx">';
	echo $Q;
	echo '</a>';	
	echo '</p>';
	
}
function pr_benchmark($Q) {
	if(strlen($_SESSION["seas_brd_bnch_filter_condition"])>0) {
		echo '<p class="bnch" >';
		echo '<a href="#" title="Benchmark" class="bnch">';
		echo $Q;
		echo '</a>';
		echo '</p>';
	}
}
function pr_target($Q) {
	echo '<p class="trgt">';
	echo '<a href="#" title="Target" class="trgt">';
	echo $Q;
	echo '</a>';
	echo '</p>';
}
?>