﻿function convertcheckboxitem(choosedAns, count, questionIndex) {
	for (var x = 0; x < count; x++){
		document.getElementById('checkboxitem_'+questionIndex+'_'+x).className = "checkboxitem";
    }
	
	document.getElementById('checkboxitem_'+questionIndex + '_'+choosedAns).className = "checkboxitemactive";
	
	document.getElementById('hdnAnswer'+questionIndex).value = choosedAns;
}

function convertcheckboxhomeitem(checkboxhomeitem) {
	document.getElementById('checkboxhomeitem1').className = "checkboxhomeinactive";
	document.getElementById('checkboxhomeitem2').className = "checkboxhomeinactive";
	document.getElementById('checkboxhomeitem3').className = "checkboxhomeinactive";
	document.getElementById('checkboxhomeitem4').className = "checkboxhomeinactive";
	
	document.getElementById(checkboxhomeitem).className = "checkboxhomeactive";
}

function setText(ctrl, text)
{
	if(document.getElementById(ctrl.id).value == "")
		document.getElementById(ctrl.id).value = text;
}

function removeText(ctrl, text)
{
	if(document.getElementById(ctrl.id).value == text)
		document.getElementById(ctrl.id).value = "";
}

function checkAnswer(questionIndex,questionsCount)
{
try{
	var answer = document.getElementById('hdnAnswer'+questionIndex).value;
	var rightAnswer = document.getElementById('hdnRightAnswer'+questionIndex).value;
	if(answer == "")
	{
		alert('لابد من اختيار إجابة للسؤال');
	}
	else
	{
		if(answer == rightAnswer)
		{
			document.getElementById('lblQResult'+questionIndex).style.color='green';
			document.getElementById('lblQResult'+questionIndex).innerText = 'إجابة صحيحة';
			document.getElementById('lblQResult'+questionIndex).textContent = 'إجابة صحيحة';
			var rAnswesr = parseInt(document.getElementById('ctl00_spWebPartManager1_g_1645e06f_ee29_41e0_9676_e5e9198cdf24_hdnRightAnswers').value);
			document.getElementById('ctl00_spWebPartManager1_g_1645e06f_ee29_41e0_9676_e5e9198cdf24_hdnRightAnswers').value = rAnswesr+1;
			
		}
		else
		{
			document.getElementById('lblQResult'+questionIndex).style.color='red';
			document.getElementById('lblQResult'+questionIndex).innerText = 'إجابة خاطئة';
			document.getElementById('lblQResult'+questionIndex).textContent = 'إجابة خاطئة';
		}
		if(questionIndex < questionsCount-1)
		{
			document.getElementById('lnkNextQ'+questionIndex).style.display='block';
		}
		else
		{
			document.getElementById('lnkFinalResult').style.display='block';
		}
		document.getElementById('lnkSubmit'+questionIndex).style.display='none';
	}
	
	}
	catch(e)
	{
	alert(e);
	}
}

function showFinalResult(questionsCount)
{
	var name = document.getElementById('ctl00_spWebPartManager1_g_1645e06f_ee29_41e0_9676_e5e9198cdf24_hdnName').value;
	var sex = document.getElementById('ctl00_spWebPartManager1_g_1645e06f_ee29_41e0_9676_e5e9198cdf24_hdnSex').value;
	var plaingrade = parseInt(document.getElementById('ctl00_spWebPartManager1_g_1645e06f_ee29_41e0_9676_e5e9198cdf24_hdnRightAnswers').value);
	var gradeText = "";
	grade = (plaingrade*100)/questionsCount;
	document.getElementById('ctl00_spWebPartManager1_g_1645e06f_ee29_41e0_9676_e5e9198cdf24_listDiv'+(questionsCount-1)).style.display = 'none';
	if(grade >= 50)
	{
		if(grade >=50 && grade <65 )
			gradeText = "جيد"; 
		else if(grade >=65 && grade <80 )
			gradeText = "جيد جدا"; 
		else
			gradeText = "ممتاز"; 
		document.getElementById('ctl00_spWebPartManager1_g_1645e06f_ee29_41e0_9676_e5e9198cdf24_listDivSuccess').innerHTML=	"<div class='testarea'><br/><br/><br/><h3 align='center'>لقد حصلت على مجموع "+plaingrade+" من "+questionsCount+" </h3><br/><br/><h3 align='center'>أحسنت يا "+name+"</h3></div>";
		document.getElementById('ctl00_spWebPartManager1_g_1645e06f_ee29_41e0_9676_e5e9198cdf24_listDivSuccess').style.display = 'block';
		_doPrint(name, sex, gradeText);
	}
	else
	{
		document.getElementById('ctl00_spWebPartManager1_g_1645e06f_ee29_41e0_9676_e5e9198cdf24_listDivFail').innerHTML = "<div class='testarea'><br/><br/><br/><h3 align='center'>لقد حصلت على مجموع "+plaingrade+" من "+questionsCount+" </h3><br/><br/><h3 align='center'>حظ سعيد المرة القادمة</h3></div>";
		document.getElementById('ctl00_spWebPartManager1_g_1645e06f_ee29_41e0_9676_e5e9198cdf24_listDivFail').style.display = 'block';
	}
}

function showQuestion(questionIndex)
{
	var nextQuestion = questionIndex+1;
	document.getElementById('ctl00_spWebPartManager1_g_1645e06f_ee29_41e0_9676_e5e9198cdf24_listDiv'+questionIndex).style.display = 'none';
	document.getElementById('ctl00_spWebPartManager1_g_1645e06f_ee29_41e0_9676_e5e9198cdf24_listDiv'+nextQuestion).style.display = 'block';
}

function _doPrint(childName, sex, childGrade)
{
	var div = document.getElementById("cert-img");
	var win = window.open("","win","width=820,height=650");
	var frame="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
	frame += "<html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html; charset=windows-1256' />";
	frame += "<style type='text/css'><!--";
	frame += "body {margin: 0px; color: #C00; font-family:Arial, Helvetica, sans-serif;";
	frame += "font-size:40px; font-weight:bold; }-->";
	frame += "</style></head>";
	frame += "<body style='background-color:#fff'>";
	frame += "<table width='800' border='0' cellspacing='0' cellpadding='0'>";
	frame += "<tr><td colspan='3'><img src='/siteimages/cert/img-top.jpg' width='800' height='323' /></td></tr>";
	frame += "<tr><td width='151'><img src='/siteimages/cert/name-left.jpg' width='151' height='61' /></td>";
	frame += "<td width='524' align='center'>";
    frame += childName;
    frame += "</td><td width='125'><img src='/siteimages/cert/name-right.jpg' width='125' height='61' /></td>";
    if(sex==0)
    	frame += "</tr><tr><td colspan='3'><img src='/siteimages/cert/middle.jpg' width='800' height='92' /></td>";
    else
    	frame += "</tr><tr><td colspan='3'><img src='/siteimages/cert/middle-f.png' width='800' height='92' /></td>";    
    frame += "</tr><tr><td width='151'><img src='/siteimages/cert/rate-left.jpg' width='151' height='59' /></td>";
    frame += "<td width='524' align='center'>";
    frame += childGrade;
	frame += "</td><td width='125'><img src='/siteimages/cert/rate-right.jpg' width='125' height='59' /></td>";
	frame += "</tr><tr><td colspan='3'><img src='/siteimages/cert/Down.jpg' width='800' height='67' /></td>";
	//frame += "</tr></table></body></html>";
	frame += "</tr></table><div id='divPrint' width='100%' align='center'><button id='btnPrint' onclick=\"document.getElementById('divPrint').style.display='none'; btnClose.click();window.print();\">طباعة</button>&nbsp;<button style='display:none' id='btnClose' onclick='close();'>إغلاق</button><button id='btnCloseWindow' onclick='window.close();'>إغلاق</button></div></body></html>";
	win.document.write(frame);
}
							
function clearPassText(field)
{
	if(window['ActiveXObject'] && window['XMLHttpRequest'])
	{
	    if (field.style.background == 'url(/siteimages/passpack.png) no-repeat')     	field.style.background = 'url(/siteimages/passpackwhite.png) no-repeat';    	
	}
	else
	{
	    if (field.value == "كلمة المرور") 
	    {
	    	field.value = '';
	    	field.type='password';
	    }
	}
}

function setPassText(field)
{
	if(window['ActiveXObject'] && window['XMLHttpRequest'])
	{
	    if (field.value == '')     	field.style.background = 'url(/siteimages/passpack.png) no-repeat';
	}
	else
	{
	    if (field.value == '') 
	    {
	    	field.type = 'text' ;
	    	field.value = "كلمة المرور";
	    }
    }
}

function clearMailText(field)
{
    if (field.defaultValue == field.value)     	field.value = '';
}

function setMailText(field)
{
    if (field.value == '')     	field.value = field.defaultValue;
}
