<?php
require_once($application_path . "view/header.tpl.php");
?>
<style type="text/css">

#main_tble {
	border: 10px #0099FF solid;
}

.select_box {
	color: #000;
	font-size:12px;
}
.tbl_cell {
	border: thin solid #333;
	font-size:<?php echo 12+$font_increase_value; ?>px;
	vertical-align: middle;
	padding:0px 5px 0px 5px;
}
.tbl_cellHdr {
	border: thin solid #333;
	background-color:#CCC;
	//background-color:#FF9;
	font-size:<?php echo 12+$font_increase_value; ?>px;
	vertical-align: middle;
	padding:10px;
	color:#000;
}
.tbl_cellHdr_str {
	border: thin solid #333;
	background-color:#91C8FF;
	font-size:<?php echo 10+$font_increase_value; ?>px;
	vertical-align: middle;
	padding:10px;
	color:#000;
}
.tbl_cellHdr_chr {
	border: thin solid #333;
	background-color: #ff00ff;
	font-size:<?php echo 10+$font_increase_value; ?>px;
	vertical-align: middle;
	padding:10px;
	color:#000;
}
.tbl_cellHdr_avg {
	border: thin solid #333;
	background-color:#FFFFCC;
	font-size:<?php echo 10+$font_increase_value; ?>px;
	vertical-align: middle;
	padding:10px;
	color:#000;
}
.tbl_cellHdr_pos {
	border: thin solid #333;
	background-color: #00FF00;
	font-size:<?php echo 10+$font_increase_value; ?>px;
	vertical-align: middle;
	padding:10px;
	color:#000;
}
.tbl_cellHdr_neg {
	border: thin solid #333;
	background-color: #FF0000;
	font-size:<?php echo 10+$font_increase_value; ?>px;
	vertical-align: middle;
	padding:10px;
	color:#000;
}
.filt_txt {
	font-size:<?php echo 10+$font_increase_value; ?>px;
	font-weight:bold;
	color:#fff;
	vertical-align:top;
}
.indx {
	font-size:<?php echo 9+$font_increase_value; ?>px;
	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:<?php echo 12+$font_increase_value; ?>px;
	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:<?php echo 12+$font_increase_value; ?>px;
	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:<?php echo 12+$font_increase_value; ?>px;
} 
 a {
	 text-decoration:none;
 }
 .qheader {
	 border:thin dotted;
	 height:20px;
 }
.qheader:hover { 
    background-color: yellow;
} 

.targetmg {
	text-decoration:underline;
	font-size:<?php echo 12+$font_increase_value; ?>px;
}
.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;

	try {
		 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;
			 }	 
		 }
	}
	catch(e) {
	}
	finally {
	}

	 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!="Q8") { document.getElementById("Q8").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!="Q13") { document.getElementById("Q13").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("Q8").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("Q13").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/pcd/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('pcd/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('pcd/managetarget.php', 'tragetWindow','toolbar=false,width='+w+',height='+h+',left='+left+',top='+top+',resizable=yes,scrollbars=yes');		
	
}

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

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() {
	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() {
	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();
	//}
}

function apply_filter() {
	document.forms[0].action ="brandanalysis";
	document.forms[0].submit();
}
function clear_filter(ctrl) {
	if(ctrl==0) {	
		document.forms[0].action ="brandanalysis?clear_filter=1"
		document.forms[0].submit();
	}
	else {
		if(ctrl==1) {	
			document.getElementById("sel_prof_catg").selectedIndex = -1;
		}
		else if(ctrl==2) {
			document.getElementById("sel_health_fac").selectedIndex = -1;
		}
		else if(ctrl==3) {
			document.getElementById("sel_target").value=0;
		}
		else if(ctrl==4) {
			document.getElementById("sel_bnch").value=0;
		}
	}
}
function alertno_data() {
	alert("No data found to export");
}
function sel_lang(lan) {
	document.forms[0].action ="brandanalysis?lan=" + lan;
	document.forms[0].submit();
}
</script>

</head>
<body>

<!-- page content -->
<div class="right_col" role="main">
        <form action="" enctype="multipart/form-data" method="post">
        <!-- main div-->
        <div id='mdiv' class='maindiv'>
            <div id='idiv' class='intdiv'>
                <div>
           
                    
                    <table id="main_tble">
                 
                        <tr>
                            <td>
                              <table width="100%" border="0" cellpadding="5px">
        
                                    <tr>
                                      <td align="left" valign="top" nowrap bgcolor="#0099FF" class="filt_txt"><?php  
                                    echo $language_array['catg_filter'];
                                    ?><br>
                                        <br><!-- <a href="#" onClick="apply_filter()"><img src="pcd/images/tick.png" title="<?php  
                                    echo $language_array['apply_filter'];
                                    ?>" border="0"></a><a href="#" onClick="clear_filter(1)"><img src="pcd/images/cross.png" title="<?php  
                                    echo $language_array['clear_filter'];
                                    ?>" border="0"></a> --></td>
                                      <td align="left" valign="top" bgcolor="#0099FF" class="filt_txt">
                                          <select name="sel_prof_catg[]" size="7" multiple id="sel_prof_catg" style="width: 100%" class="select_box">
                                            <?php
                                            foreach($catg_filter as $cfky=>$cf) {
                                                echo '<option value="'. $cfky.'"';
                                                if(in_array($cfky,$_SESSION["seas_brd_filter_prof"])) echo "selected";
                                                echo '>'.$cf. '</option>';
                                            }
                                            ?>
                                          </select></td>
                                      <td align="left" valign="top" nowrap bgcolor="#0099FF"><a href="#" onClick="clear_filter(1)"><img src="pcd/images/cross.png" alt="" border="0" title="<?php  
                                    echo $language_array['clear_filter'];
                                    ?>"></a></td>
                              <td align="left" valign="top" nowrap bgcolor="#0099FF" class="filt_txt"><?php  
                                    echo $language_array['fac_filter'];
                                    ?><br>
                                        <br><!-- <a href="#" onClick="apply_filter()"><img src="pcd/images/tick.png" title="<?php  
                                    echo $language_array['apply_filter'];
                                    ?>" border="0"></a> <a href="#" onClick="clear_filter()"><img src="pcd/images/cross.png" title="<?php  
                                    echo $language_array['clear_filter'];
                                    ?>" border="0"></a>
                                      <br>--></td>
                                  <td align="left" valign="top" bgcolor="#0099FF" class="filt_txt"><select name="sel_health_fac[]" size="7" multiple id="sel_health_fac" style="width: 100%"  class="select_box">
                                    <?php
                                            foreach($fac_filter as $cfky=>$cf) {
                                                echo '<option value="'. $cfky.'"';
                                                if(in_array($cfky,$_SESSION["seas_brd_filter_hlth"])) echo "selected";
                                                echo '>'.$cf. '</option>';
                                            }
                                            ?>
                                  </select></td>
                                        <td align="left" valign="top" bgcolor="#0099FF"><a href="#" onClick="clear_filter(2)"><img src="pcd/images/cross.png" alt="" border="0" title="<?php  
                                    echo $language_array['clear_filter'];
                                    ?>"></a></td>
                                <td align="left" valign="top" nowrap bgcolor="#0099FF" class="filt_txt"><?php  
                                    echo $language_array['surveytopics'];
                                    ?></td>
                                        <td align="center" valign="top" bgcolor="#0099FF" class="filt_txt">
                                        <select name="sel_survey_topic" id="sel_survey_topic" style="width: 100%" onChange="showDetails(this.value)" class="select_box">
                                        <option value="99" <?php if($_SESSION["seas_brd_filter_topic"]==99) echo "selected"; ?>><?php  
                                    echo $language_array['overall'];
                                    ?></option>
                                          
                                            <?php
                                            foreach($Question_Array as $qky=>$Questions) {
                                                $qnum = substr($qky,1);
                                                if($qnum<99) {
                                                    echo '<option value="'. $qnum .'"';
                                                    if($_SESSION["seas_brd_filter_topic"]== $qnum) {
                                                        echo "selected";
                                                    }
                                                    echo '>' . $Questions[0] . '</option>';
                                                }
                                            }
                                            ?>                                  
                                      </select>                               
                                      <br>
                                      <br>
                                      
                                      <?php
                                      if($_SESSION["seas_brd_language"]==1) {
                                       // echo '<a href="#" onClick="sel_lang(2)" title="Change view to Arabic"><img src="pcd/images/switch_1.png" border="0" align="center"></a>';
                                        echo '<a href="#" onClick="apply_filter()"><img src="pcd/images/submit_en.png" border="0" align="center"></a>';
                                        echo '<a href="#" onClick="clear_filter(0)"><img src="pcd/images/reset_en.png" border="0" align="center"></a>';
                                      }
                                      else {
                                        //echo '<a href="#" onClick="sel_lang(1)" title="Change view to English"><img src="pcd/images/switch_2.png" border="0" align="center"></a>';  
                                        echo '<a href="#" onClick="apply_filter()"><img src="pcd/images/submit_ar.png" border="0" align="center"></a>';
                                        echo '<a href="#" onClick="clear_filter(0)"><img src="pcd/images/reset_ar.png" border="0" align="center"></a>';
                                      }
                                      ?>
        
                                  </td>
                                  </tr>
                                    <tr>
                                      <td align="left" valign="middle" nowrap bgcolor="#0099FF" class="filt_txt targetmg"><a href="#" onClick="opentarget()" title="<?php  
                                    echo $language_array['manage_target'];
                                    ?>"><?php  
                                    echo $language_array['target'];
                                    ?></a></td>
                                      <td align="left" valign="middle" bgcolor="#0099FF"  class="filt_txt"><select name="sel_target" id="sel_target" style="width: 100%" class="select_box">
                                        <option value="0" <?php if($_SESSION["seas_brd_filter_sel_target"]==0) echo "selected"; ?> ><?php  
                                    echo $language_array['total_sample'];
                                    ?></option>
                                        <?php
                                        if($_SESSION["seas_brd_language"]==2) {
                                            $tarsql = "select tar_id,case when length(tar_desc_ar)>0 then tar_desc_ar else tar_desc end as tar_desc  from seas_brd_target order by tar_desc";	
                                        }
                                        else {
                                            $tarsql = "select tar_id,tar_desc  from seas_brd_target order by tar_desc";
                                        }								
                                        $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><!-- <input name="apply_target" type="button" value="<?php echo $language_array['apply']; ?>" onClick="Apply_Tgt_Bmk()" style="width:20%; font-size:10px; background-color:#69C; padding:2px">--></td>
                                      <td width="30" align="left" valign="middle" nowrap bgcolor="#0099FF" class="filt_txt"><a href="#" onClick="clear_filter(3)"><img src="pcd/images/cross.png" alt="" border="0" title="<?php  
                                    echo $language_array['clear_filter'];
                                    ?>"></a></td>
                                      <td align="left" valign="middle" nowrap bgcolor="#0099FF" class="filt_txt"><?php  
                                    echo $language_array['benchmark'];
                                    ?></td>
                                      <td align="left" valign="middle" bgcolor="#0099FF" class="filt_txt"><select name="sel_bnch" id="sel_bnch" style="width: 100%" class="select_box">
                                        <option value="0" <?php if($_SESSION["seas_brd_filter_sel_bnch"]==0) echo "selected"; ?> >
                                          <?php  
                                    echo $language_array['no_benchmark'];
                                    ?>
                                        </option>
                                        <?php
                                        if($_SESSION["seas_brd_language"]==2) {
                                            $tarsql = "select tar_id,case when length(tar_desc_ar)>0 then tar_desc_ar else tar_desc end as tar_desc  from seas_brd_target order by tar_desc";	
                                        }
                                        else {
                                            $tarsql = "select tar_id,tar_desc  from seas_brd_target order by tar_desc";
                                        }
                                        $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 width="30" align="left" valign="middle" bgcolor="#0099FF" class="filt_txt"><!--<input name="apply_target" type="button" value="<?php echo $language_array['apply']; ?>" onClick="Apply_Tgt_Bmk()" style="width:20%; font-size:10px; background-color:#69C; padding:2px">--><a href="#" onClick="clear_filter(4)"><img src="pcd/images/cross.png" alt="" border="0" title="<?php  
                                    echo $language_array['clear_filter'];
                                    ?>"></a></td>
                                      <td colspan="2" align="left" valign="middle" nowrap bgcolor="#0099FF" class="filt_txt"><table border="0" cellpadding="0" cellspacing="0" width="100%">
                                        <tr>
                                          <td align="left" nowrap><input type="<?php if($trg_sample<=0) echo "button"; else echo "submit"; ?>" value="<?php  
                                    echo $language_array['exportexcel'];
                                    ?>" name="sel_export" style="background-color: #069; font-weight:bold; color:#FFF; font-size:<?php echo 10+$font_increase_value2; ?>px; padding:4px; width:30%" <?php if($trg_sample<=0) echo "onclick='alertno_data();'";?>>
                                            <input type="button" value="<?php  
                                    echo $language_array['importdata'];
                                    ?>" name="sel_import" style="background-color: #333; font-weight:bold; color:#FFF; font-size:<?php echo 10+$font_increase_value2; ?>px; padding:4px; width:25%" onClick="ImportData()">
                                            <input type="button" value="<?php  
                                    echo $language_array['definitionsandsettings'];
                                    ?>" name="sel_import" style="background-color: #FF0; font-weight:bold; color:#F00; font-size:<?php echo 10+$font_increase_value2; ?>px; padding:4px; width:45%" onClick="oOptions()">
                                            </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,$language_array);
            //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>
</div>
<!-- /page content -->
<?php
if($_SESSION["seas_brd_filter_topic"] >0) {
	
	echo "<script>";
	echo 	"showDetails(".$_SESSION["seas_brd_filter_topic"].");";
	echo "</script>";

}
?>

<?php
require_once($application_path . "view/footer.tpl.php");
?>
