//©2008 FilBalad.com
//All rights reserved
function UserQValidateInputs()
{
	var IsValidData = true;
	var PostedData = "";
	QTitle = document.AskQuestionfrm.QTitle.value
	if (QTitle == "")
	{
		alert("من فضلك أدخل عنوان للسؤال");
        AskQuestionfrm.QTitle.focus();
		return false;
	}
	
	QBody	= document.AskQuestionfrm.QuestionTxtAr.value
	if (QBody == "")
	{
		alert("من فضلك أدخل تفاصيل السؤال");
        AskQuestionfrm.QuestionTxtAr.focus();
		return false;
	}
	
	QSec	= document.AskQuestionfrm.SectioncmbBx.value
	if (QSec == 0)
	{
		alert("من فضلك أختر مجال السؤال");
        AskQuestionfrm.SectioncmbBx.focus();
		return false;
	}
	HideName = document.AskQuestionfrm.HideNameChkBox.value
	NotifyMe = document.AskQuestionfrm.NotifyMeChkBox.value
	
	PostedData = 'QSecId='+escape(QSec);
	PostedData = PostedData+'&QTitle='+escape(QTitle);	
	PostedData = PostedData+'&QBody='+escape(QBody);
	PostedData = PostedData+'&HideNameVal='+escape(HideName);	
	PostedData = PostedData+'&NotifyMeVal='+escape(NotifyMe);	
	PostedData = PostedData+'&action=insert'; 
	if(IsValidData)
	{		
		//alert(PostedData)	
		Filbalad.Submit('newQuestion.asp',PostedData,'newQuestionMsg',callBackPostQues);		
	}		
	//AskQuestionfrm.action = "newQuestion.asp?action=insert";
	//AskQuestionfrm.submit();
}
function callBackPostQues(xmlHttp,resObject)
	{ 	
	 if(xmlHttp.readyState==4)	 
		{ 			
			var ReqTxt = xmlHttp.responseText.split("$$")
			//alert(parseInt(ReqTxt[0]))
			if(parseInt(ReqTxt[0])==0)
			{
				showLogin();
			}
			if(parseInt(ReqTxt[0])==1)
			{
				if(document.getElementById('QTitle'))
				{					
					document.AskQuestionfrm.QTitle.value	='';
					document.AskQuestionfrm.QuestionTxtAr.value	='';
				}				
			}
			resObject.innerHTML= ReqTxt[1];													
		}
	}

function GetSubSections()
{
	//Retrieve Id of Section Selected
	CurrSecId    = document.AskQuestionfrm.SectioncmbBx.value

	//Reset all Subsections
	document.AskQuestionfrm.SubSectioncmbBx.length = 0
	
	//Creat Default Option
	document.AskQuestionfrm.SubSectioncmbBx.options[0] = new Option('تخصص السؤال','0')
	
	//Reset Option Counter
	OptionIndex = 1
	
	for(i=0;i<SecInfoArr.length;i++)
	{	
		//Retrieve SecId-SubSecId-SubSecName Value
		SecInfoVal		= SecInfoArr[i]
		SecSepIndex		= SecInfoVal.lastIndexOf("/")
		SubSecSepIndex	= SecInfoVal.lastIndexOf("-")
		
		SecIdVal		= SecInfoVal.substring(0,SecSepIndex)
		if (CurrSecId == SecIdVal)
		{
			SubSecIdVal		= SecInfoVal.substring(SecSepIndex+1,SubSecSepIndex)
			SubSecName		= SecInfoVal.substring(SubSecSepIndex+1,SecInfoVal.length)
			document.AskQuestionfrm.SubSectioncmbBx.options[OptionIndex] = new Option(SubSecName,SubSecIdVal)	
			OptionIndex		= OptionIndex + 1
		}	
	}
}


function ChangeNameCheck()
{
	ChkBoxValue =	document.AskQuestionfrm.ShowNameChkBox.value
	if (ChkBoxValue=="1")
	{	
		document.AskQuestionfrm.ShowNameChkBox.checked	= false
		document.AskQuestionfrm.ShowNameChkBox.value	= 0
		
	}
	else
	{
		document.AskQuestionfrm.ShowNameChkBox.checked	= true
		document.AskQuestionfrm.ShowNameChkBox.value	= 1
	}
}

function ChangeNotifyCheck()
{
	if (document.AskQuestionfrm.NotifyMeChkBoxVal.value=="0")
	{	
		document.AskQuestionfrm.NotifyMeChkBoxVal.value	= 1		
	}
	else
	{
		document.AskQuestionfrm.NotifyMeChkBoxVal.value	= 0
	}
}
