//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\\
//this file is included at Nadaw admin,MatrialCms Admin sections    \\
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\\
var myWin
function getFocus() {
   foc=document.activeElement;
   return foc;
}
function Check_Focus()
{
	var hActiveElement;
	//if (window.opener && !window.opener.closed)
	//{
		var parfoc=window.document.activeElement;
		param=foc
	//}

	if (param!=null)
	{
		hActiveElement=param;
	}
	else
	{
		hActiveElement=parfoc;
	}

	if (hActiveElement.id=="idContent")
	{
	 return true;
	}

	else
	{
	 return false;
	//window.close()
	}
}
function ModifyCordinate(TipType) {
	try {
		var x = (ns4)? e.pageX : event.x;
		var y = (ns4)? e.pageY : event.y+document.body.scrollTop;
	
		if(document.body.clientWidth-x<100) {
			if(TipType==1)//in case of Aiah 
				x=x-250;
			else if(TipType==2)//in case of Sourah
				x=x-150;
			else if(TipType==3)//in case of Tekrar
				x=x-50;
		}
	
		TipObj.moveTo(x,y);
	}catch(e){}
}

function ShowMargenTip(tipNo) {
	try {
		str='<table border=0 bgcolor=#bacaa3><tr><td bgcolor=oldlace>';
		str+='<FONT Face="Simplified Arabic" lang=ar Size="3"><Div align="right" dir="rtl">';
		str+=tip(tipNo);
		str+='</Div></B></FONT>';
		str+='</td></tr></Table>';
		TipObj.write(str);
		//modify the cordinate of the tip
		ModifyCordinate(-1);
		//show the tip a while then hide it
		TipObj.show();
	}catch(e){}
}

function tip(tipNo) {
	try {
		var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		var strurl= "/MaterialCMS/getTip.asp?id="+tipNo;
		xmlhttp.Open("Get",strurl, false);
		xmlhttp.Send(); 
		var sbody=xmlhttp.responseText;
		return (sbody);
	}catch(e){}
}
function HideTip() {
	try {
		TipObj.hide();
		TipObj.write("");
	}catch(e){}
}
function ShowMargenWin(tipNo) {
	try {
		str='<FONT Face="Simplified Arabic" lang=ar Size="3"><Div align="right" dir="rtl">';
		str+=tip(tipNo);
		str+='</Div></B></FONT>';
		myWin=window.open("","DisplayWin","resizable,scrollbars,height=200,width=600");
		myWin.document.write("<title>هوامش</title>");
		myWin.document.write(str);
		myWin.document.write("<br><center><a href='javascript:this.close();'>خروج</a></center>");
		myWin.document.close();
	}catch(e){}
}

function ShowMargenWinClose() {
	myWin.close();
}

function editorInDesignMode() {
	if (isHTMLMode)	{
		alert(" 'Edit HTML' من فضلك  أزل العلامة التي بجوار ");
		return false;
	}
	return true;
}
function show(){
	if(!editorInDesignMode()) {
		return;
	}
	previewWin = window.open("previewSection.asp?matLang="+matLang,"Preview","scrollbars,toolbar,width=600,height=400")
}
function openTipsWin() {
	if(!editorInDesignMode()) {
		return false;
	}
	else
	{
		if(Check_Focus())
		{
		    window.open('addTip.asp','Tips','width=480,height=230');
		}
		else
		{
			alert("من فضلك ، ضع المؤشر فى محرر النصوص فى المكان الذى تريده ")
			//window.close();
		}
	}	
}
function openAyaWin() {
	    
	if(!editorInDesignMode()) {
		return false;
	}
	else
	{
		if(Check_Focus())
		{
		  window.open("/QuranFont/embedAya_popup.asp","InsertAya","width=600,height=320,dependent=yes")
		}
		else
		{
			alert("من فضلك ، ضع المؤشر فى محرر النصوص فى المكان الذى تريده ")
			//window.close();
		}
	}
}
function modRecord(){
	if (document.material.EditHTML.checked){
  		alert(" 'Edit HTML' من فضلك  أزل العلامة التي بجوار ");
  		return false;
	}
	if (matLang != "arb")
		document.material.content.value = charConv(idContent.document.body.innerHTML)
	else
		document.material.content.value = idContent.document.body.innerHTML
	return true;
}
function validate() {
	if(!validateEmpty(document.material.title, "يجب كتابة اسم الفصل")){
		return false;
	}
	if(!validateLength(document.material.summary, 300, " الوصف يجب الا يزيد عن 300 حرف")){
		return false;
	}
	if(!modRecord()) {
		return false;
	}
	return true;
}
function validateUrdy() {
	if(!validateUrdyEmpty(document.material.title_Obj, "يجب كتابة اسم الفصل")){
		return false;
	}
	setUrdyText();
	if(!modRecord()) {
		return false;
	}
	return true;
}
function validateEmpty(objText, msg) {
	if(trim(objText.value).length==0){
		window.alert(msg);
		objText.focus();
		return false;
	}
	return true;
}
function validateLength(objText, length, msg) {
	if(trim(objText.value).length > length){
		window.alert(msg);
		objText.focus();
		return false;
	}
	return true;
}
function validateUrdyEmpty(obj, msg) {
	if(trim(obj.NastaliqText) == ''){
		window.alert(msg);
		obj.focus();
		return false;
	}
	return true;
}
function setUrdyText() {
	document.material.title.value = document.material.title_Obj.NastaliqText;
}
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

