// JavaScript Document
function calculateSumOffset(idItem, offsetName)
{
	var totalOffset = 0;
	var item = eval('idItem');
	do
	{
		totalOffset += eval('item.'+offsetName);
		item = eval('item.offsetParent');
	} while (item != null);
	return totalOffset;
}

function open_calendar_window(mode)
{
window.open("includes/calendar_popup.php?mode="+mode,"calendar","width=276,height=230,top=200,left=560,scrollbars=no");
}

function open_color_window(mode)
{
window.open("color_picker.php?mode="+mode,"color","width=191,height=121,top=300,left=500,scrollbars=no");
}

function image_preview(file_name)
{
window.open("image_preview.php?file_name="+file_name,"img_preview","width=500,height=410,top=100,left=250,scrollbars=yes;resize=yes");
}

function video_preview(file_name)
{
window.open("video_preview.php?file_name="+file_name,"vid_preview","width=500,height=380,top=100,left=250,scrollbars=yes;resize=yes");
}

function color1_color(color)
{
frm.color1.value=color;
color1_preview.bgColor=color;
}

function color2_color(color)
{
frm.color2.value=color;
color2_preview.bgColor=color;
}

function header_text_color(color)
{
frm.header_color.value=color;
header_color_preview.bgColor=color;
}

function normal_text_color(color)
{
frm.normal_color.value=color;
normal_color_preview.bgColor=color;
}

function error_text_color(color)
{
frm.error_color.value=color;
error_color_preview.bgColor=color;
}

function focus_text_color(color)
{
frm.focus_color.value=color;
focus_color_preview.bgColor=color;
}

function link_text_color(color)
{
frm.link_color.value=color;
link_color_preview.bgColor=color;
}

function link_text_over_color(color)
{
frm.link_over_color.value=color;
link_over_color_preview.bgColor=color;
}


function start_date(d)
{
split_date="";
split_date=d.split("-");

frm.start_date.value=split_date[1]+"-"+split_date[2]+"-"+split_date[0];
}

function end_date(d)
{
split_date="";
split_date=d.split("-");

frm.end_date.value=split_date[1]+"-"+split_date[2]+"-"+split_date[0];
}


function delete_catalog(id,parent_id,level)
{
	return_confirm=confirm("Are you sure that you want to delete this catalog and all included items?");
	if(return_confirm==true)
	window.location="our_catalog.php?id="+id+"&parent_id="+parent_id+"&level="+level+"&delete_catalog=1";
}

function delete_item(id,parent_id,level)
{
	return_confirm=confirm("Are you sure that you want to delete this item?");
	if(return_confirm==true)
	window.location="catalog_items.php?id="+id+"&parent_id="+parent_id+"&level="+level+"&delete_item=1";
}

function delete_module_category(module_name,id)
{
	return_confirm=confirm("Are you sure that you want to delete this category?");
	if(return_confirm==true)
	window.location="modules_management.php?id="+id+"&delete_category=1&module_name="+module_name;
}

function delete_folder(id)
{
	return_confirm=confirm("Are you sure that you want to delete this folder, All subjects under this folder will be unspecified?");
	if(return_confirm==true)
	window.location="folders.php?id="+id+"&delete_folder=1";
}

function delete_message_board(id)
{
	return_confirm=confirm("Are you sure that you want to delete this folder, All subjects under this folder will be deleted?");
	if(return_confirm==true)
	window.location="main_board.php?id="+id+"&delete_folder=1";
}

function users_confirmation()
{
	if(frm.process1.value==1)
	{
		confirm_msg="Are you sure that you want to ACTIVATE the selected user/s?"
	}
	else
	if(frm.process1.value==2)
	{
		confirm_msg="Are you sure that you want to DEACTIVATE the selected user/s?"
	}
	else
	if(frm.process1.value==3)
	{
		confirm_msg="Are you sure that you want to DELETE the selected user/s?"
	}
	else
	{
		confirm_msg="";
	}	
	if(confirm_msg!="")
	{
		return_confirm=confirm(confirm_msg);
		if(return_confirm==true)
		return true;
		else
		return false;
	}	
	else
	{
		return true;
	}
	
}

function generate_upload(loop)
{
if(loop<=0)
frm.upload_num.value=1;
else
frm.upload_num.value=loop;

if(loop>0)
{
i=0;
upload_contents="";
upload_contents=upload_contents+"<table width=100% border=0  cellpadding=0 cellspacing=0 >";
for(i=0;i<loop;i++)
{
upload_contents=upload_contents+"<tr><td><table width=100% border=0 cellpadding=0 cellspacing=0><tr> ";
upload_contents=upload_contents+"<td><input name=image"+i+" type=file size=55></td></tr></table></td></tr>";
}
upload_contents=upload_contents+"</table>";
uploads.innerHTML=upload_contents;
}
}

function auto_jump_1()
{
if(frm.phone1.value.length==3)
	frm.phone2.focus();
}
function auto_jump_2()
{
if(frm.phone2.value.length==3)
	frm.phone3.focus();
}
function auto_jump_3()
{
if(frm.fax1.value.length==3)
	frm.fax2.focus();
}
function auto_jump_4()
{
if(frm.fax2.value.length==3)
	frm.fax3.focus();
}


function check_other()
{
if(frm.message_folder.value=="")
{
folder_contents="";
folder_contents=folder_contents+"<table cellspacing=0 cellpadding=0 border=0 align=left>";
folder_contents=folder_contents+"<tr><td class=normal_text><b>Folder Name:</b></td>";
folder_contents=folder_contents+"<td align=left style=padding-left:5><input type=text name=folder_name></td></tr></table>";
new_folder_description_title.innerHTML="<b>Folder Description:</b>";
new_folder_description.innerHTML="<textarea cols=72  rows=5  style=height:40 name=folder_description ></textarea>";
new_folder.innerHTML=folder_contents;
}
else
{
new_folder.innerHTML="";
new_folder_description_title.innerHTML="";
new_folder_description.innerHTML="";
}
}

function select_all_users()
{
if(frm.to.options[0].selected==true)
	{
		for(i=1;i<frm.to.length;i++)
			{
				if(frm.to.options[i].value!="")
					{
						frm.to.options[i].selected=true;
					}	
			}
	}
}

function select_all_folders()
{
if(frm.folders.options[1].selected==true)
	{
		frm.folders.options[1].selected=false;
		for(i=2;i<frm.folders.length;i++)
			{
				if(frm.folders.options[i].value!="")
					{
						frm.folders.options[i].selected=true;
					}	
			}
	}
}

function generate_slideshow(loop)
{
if(loop==0)
frm.upload_num.value=1;
else
frm.upload_num.value=loop;

if(loop>0)
{
i=0;
upload_contents="";
upload_contents=upload_contents+"<table width=100% border=0  cellpadding=0 cellspacing=0 >";
for(i=0;i<loop;i++)
{
upload_contents=upload_contents+"<tr>";
upload_contents=upload_contents+"<td class=normal_text>اسم الصورة:</td>";
upload_contents=upload_contents+"<td><input name=image"+i+" type=file size=36></td>";
upload_contents=upload_contents+"</tr>";
upload_contents=upload_contents+"<tr>";
upload_contents=upload_contents+"<td class=normal_text>الوصف:</td>";
upload_contents=upload_contents+"<td><textarea name=description"+i+" cols=48 style=height:40></textarea></td>";
upload_contents=upload_contents+"</tr>";
}
upload_contents=upload_contents+"</table>";
uploads.innerHTML=upload_contents;
}
}
function clear_intro_text()
{
if(frm.keywords_idntify.value=="") 
	{
		frm.keywords.value="";
		frm.keywords_idntify.value=1;
	}
}

function calculateSumOffset(idItem, offsetName)
{
	var totalOffset = 0;
	var item = eval('idItem');
	do
	{
		totalOffset += eval('item.'+offsetName);
		item = eval('item.offsetParent');
	} while (item != null);
	return totalOffset;
}

function CreateControl(DivID, CLSID, ObjectID, WIDTH, HEIGHT, URL)
{
  var d = document.getElementById(DivID);
  contents="";
  contents=contents+"<object classid='"+CLSID+"' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' id='"+ObjectID+"' width='"+WIDTH+"' height='"+HEIGHT+"'>";
  contents=contents+"<param name='allowScriptAccess' value='sameDomain' />";
  contents=contents+"<param name='movie' value='"+URL+"' />";
  contents=contents+"<param name='loop' value='false' />";
  contents=contents+"<param name='menu' value='false' />";
  contents=contents+"<param name='quality' value='high' />";
  contents=contents+"<param name='wmode' value='transparent' />";
  contents=contents+"<param name='bgcolor' value='#ffffff' />";
  contents=contents+"<embed src='"+URL+"' loop='false' menu='false' quality='high' wmode='transparent' bgcolor='#ffffff'  width='"+WIDTH+"' height='"+HEIGHT+"' name='"+ObjectID+"' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
  contents=contents+"</object>";
      
  d.innerHTML =contents;
}



function intPart(floatNum)
{
if (floatNum< -0.0000001){
return Math.ceil(floatNum-0.0000001)
}
return Math.floor(floatNum+0.0000001) 
}


function gethmon(m){

if(m==1){
return "محرم"
}
if(m==2){
return "صفر"
}
if(m==3){
return "ربيع الاول"
}
if(m==4){
return "ربيع الثاني"
}
if(m==5){
return "جمادى الاول"
}
if(m==6){
return "جمادى الثاني"
}
if(m==7){
return "رجب"
}
if(m==8){
return "شعبان"
}
if(m==9){
return "رمضان"
}
if(m==10){
return "شوال"
}
if(m==11){
return "ذو القعده"
}
if(m==12){
return "ذو الحجه"
}

}




function get_hijri_date(current_date) {
split_date=current_date.split("-");

d=parseInt(split_date[2])
m=parseInt(split_date[1])
y=parseInt(split_date[0])
if ((y>1582)||((y==1582)&&(m>10))||((y==1582)&&(m==10)&&(d>14))) 
{
jd=intPart((1461*(y+4800+intPart((m-14)/12)))/4)+intPart((367*(m-2-12*(intPart((m-14)/12))))/12)-
intPart( (3* (intPart( (y+4900+ intPart( (m-14)/12) )/100) ) ) /4)+d-32075
} else 
{
jd = 367*y-intPart((7*(y+5001+intPart((m-9)/7)))/4)+intPart((275*m)/9)+d+1729777
}
l=jd-1948440+10632
n=intPart((l-1)/10631)
l=l-10631*n+354
j=(intPart((10985-l)/5316))*(intPart((50*l)/17719))+(intPart(l/5670))*(intPart((43*l)/15238))
l=l-(intPart((30-j)/15))*(intPart((17719*j)/50))-(intPart(j/16))*(intPart((15238*j)/43))+29
m=intPart((24*l)/709)
d=l-intPart((709*m)/24)
y=30*n+j-30

h_date=d+" "+gethmon(m)+" "+y;
return h_date;
}

function generate_choices(loop)
{
	if(loop<=0)
		frm.choices_count.value=1;
	else
		frm.choices_count.value=loop;
	
	if(loop>0)
	{
		document.frm.hidden_created.value=loop;
		i=0;
		choices_contents="";
		choices_contents=choices_contents+"<table width=100% border=0  cellpadding=0 cellspacing=0 >";
		for(i=0;i<loop;i++)
		{
			choices_contents=choices_contents+"<tr><td class=normal_text width=15% align=left style='padding-left:10;'> الخيار "+(i+1)+"</td><td><input name=choice_"+i+" type=text size=46></td></tr>";
		}
		choices_contents=choices_contents+"</table>";
		choices.innerHTML=choices_contents;
	}
}

function collect_choices(id)
{
 	if(document.frm.document.getElementById(id).checked==true)
		frm.hidden_choices.value=parseInt(frm.hidden_choices.value)-1;
	else
	if(document.frm.document.getElementById(id).checked==false)
		frm.hidden_choices.value=parseInt(frm.hidden_choices.value)+1;
}
