﻿//Ahmed Eid Salim - created : 1-5-2006
//this file include all common javascript functions



var browserType;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
   browserType= "gecko"
}
function Count(text,long) 

{

	var maxlength = new Number(long); // Change number to your max length.

	if (text.value.length > maxlength){

		text.value = text.value.substring(0,maxlength);

		alert(" فقط " + long + " حرف مسموح بها");

	}

}
function hide() {
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("realtooltip")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("realtooltip")');
  else
     document.poppedLayer =   
        eval('document.layers["realtooltip"]');
  document.poppedLayer.style.visibility = "hidden";
}

function show() {
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("realtooltip")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("realtooltip")');
  else
     document.poppedLayer = 
         eval('document.layers["realtooltip"]');
  document.poppedLayer.style.visibility = "visible";
}
function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i]
      if (elm.type == 'radio')
      {
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;
}
function OpenAudioWindow(id)
{
  window.open("/Channel/AudioStreaming.aspx?Show="+id+"","MyWindow3","height=450,width=470,top=0,left=0,scrollbars=yes,resizable=yes");
}
function OpenVideoWindow(id)
{
  window.open("/Channel/VideoStreaming.aspx?Show="+id+"","MyWindow4","height=450,width=470,top=0,left=0,scrollbars=yes,resizable=yes");
}
function OpenGeneralVideo(Path)
{
  window.open("/PlayGeneralVideo.aspx?Show="+Path+"","MyWindow4","height=450,width=470,top=0,left=0,scrollbars=yes,resizable=yes");
}
function OpenGeneralAudio(Path)
{
  window.open("/PlayGeneralAudio.aspx?Show="+Path+"","MyWindow4","height=450,width=470,top=0,left=0,scrollbars=yes,resizable=yes");
}
function OpenVideoLibrary()
{
  window.open("/admin/NewsVideo.aspx","MyWindow2","height=600,width=1000,top=0,left=0,dependent=yes,toolbar=yes,menubar=yes,status=yes,location=yes,scrollbars=yes,resizable=yes");
}
function OpenAudioLibrary()
{
  window.open("/admin/NewsAudio.aspx","MyWindow3","height=600,width=1000,top=0,left=0,dependent=yes,toolbar=yes,menubar=yes,status=yes,location=yes,scrollbars=yes,resizable=yes");
}
function OpenImageLibrary()
{
  window.open("/admin/NewsImages.aspx","MyWindow","height=600,width=800,top=0,left=0,scrollbars=yes,resizable=yes");
}
<!--
function GetDay(nDay)
{
	var Days = new Array("الأحد","الأثنين","الثلاثاء","الأربعاء",
	                     "الخميس","الجمعة","السبت");
	return Days[nDay]
}

function GetMonth(nMonth)
{
	var Months = new Array("يناير","فبراير","مارس","أبريل","مايو","يونيو",
	                       "يوليو","أغسطس","سبتمبر","أكتوبر","نوفمبر","ديسمبر");
	return Months[nMonth] 	  	 
}

function DateString()
{
	var Today = new Date();
	var suffix = "";
	//switch (Today.getDate())
	//{
	//	case 1:
	//	case 21:
	//	case 31: 
	//		suffix = "st"; break;
	//	case 2:
	//	case 22:
	//		suffix = "nd"; break;
	//	case 3:
	//	case 23:
	//		suffix = "rd"; break;
	//};

	var strDate = GetDay(Today.getDay()) + " " + Today.getDate();
	strDate += suffix + " " + GetMonth(Today.getMonth()) + " " + Today.getYear();
	return strDate
}
//-->
function Toggle_Div(div_id)
{
	if(document.getElementById)
	{
		var div = document.getElementById(div_id);
		if(div.style.display == "block" || div.style.display=='')
			{div.style.display = "none";}
		else
			{div.style.display = "block";}
	}
}
function Div_ShowHide(div_id,show_hide)
{
	if(show_hide==false)
		document.getElementById(div_id).style.display='none';
    else document.getElementById(div_id).style.display='block';
}
function Div_onLoad(div_id,show_hide)
{
	if(show_hide==false)
		document.getElementById(div_id).style.display='none';
}

function Href_PopUp(linkRef, opt_target) 
{
	if (!window.focus) return true;
	// get the link
	var href;
	if (typeof(linkRef) == 'string') href = linkRef;
	else href = linkRef.href;
	// Get the window name
	if (!opt_target) {opt_target = linkRef.target;}
	if (!opt_target) {opt_target = 'SelectParent';}
	// pop the window, bring to top/focus
	var newWin;
	newWin = window.open(href, opt_target,'width=900,height=650,resizable=1,toolbar=0,location=0,directories=0,addressbar=0,scrollbars=1,status=0,menubar=0,top=0,left=100,screenX=0,screenY=0');
	newWin.focus();
	return false;
}
function check_GridItemStyle(obj,index)
{
    var chkAll = window.event.srcElement; 
    var tbl = chkAll.parentNode.parentNode;
    if(obj.checked)
        ItemClassName = tbl.className;
    if (obj.checked)
    {
        obj.parentNode.parentNode.className=CheckEdItemClass;
    }else
        obj.parentNode.parentNode.className=GetGridItemStyle(index);
}
var CheckEdItemClass='Checkeditem';
var GridItemClass='griditem';
var AlternateGridItemClass='glist_ItemStyle';
function GetGridItemStyle(index)
{
    if(index%2!=0)
    {
        return GridItemClass;
    }else
        {return AlternateGridItemClass;}
}
function checkRowOfObject(obj,Index)
{
    if (obj.checked)
    {
        obj.parentNode.parentNode.className=CheckEdItemClass;
    }
    else
    {
       obj.parentNode.parentNode.className=GetGridItemStyle(Index);
    }
}
function SelectAllRows(CellNum,HasFooter,RowIndex)
{
   var chkAll = window.event.srcElement; 
   var tbl = chkAll.parentNode.parentNode.parentNode.parentNode;
   if (chkAll)
   {
        // if has footer loop to lenth - 1 *** else ***  loop to length
   	    if(HasFooter==true)
   	    {
            for(var i=1;i<tbl.rows.length-1;i++)
            {
                var chk = tbl.rows[i].cells[CellNum].firstChild;
                chk.checked=chkAll.checked;
                checkRowOfObject(chk,i);
            }
         }else
         {
            for(var i=1;i<tbl.rows.length;i++)
            {
                var chk = tbl.rows[i].cells[CellNum].firstChild;
                chk.checked=chkAll.checked;
                checkRowOfObject(chk,i);
            }
         }
   }
}
function Search_Div(div_id,LabelID)
{
	if(document.getElementById)
	{
		var div = document.getElementById(div_id);
		var Label = document.getElementById(LabelID);
		if(div.style.display == "block" || div.style.display=='')
		{
	
			div.style.display = "none";
			Label.value="Show Search";
			
		}
		else
		{
			div.style.display = "block";
			Label.value="Hide Search";
		}
	}
}

function EmptySearchTextValue(TextId,EmptyText)
{
	if(document.getElementById)
	{
		var TextBoxV = document.getElementById(TextId);
		var Text = EmptyText;
		if(TextBoxV.value == Text)
		{
	      TextBoxV.value="";
		}

	}
}

function SetSearchTextValue(TextId,EmptyText)
{
	if(document.getElementById)
	{
		var TextBoxV = document.getElementById(TextId);
		var Text = EmptyText;
	
		if(TextBoxV.value == "")
		{
	      TextBoxV.value=EmptyText;
		}
	}
}

// check nested grid
function SelectNestedGris(ParentID,_Checked)
{
	var frm = document.forms[0];
	ParentID=ParentID.substring(0,ParentID.length-12);
	for (i=0; i<frm.length; i++) 
	{
	    var elem = frm.elements[i];
		var chk2=elem.id.substring(0,elem.id.length-38);
		if(chk2==ParentID && elem.type=='checkbox')
		{
			elem.checked = _Checked;
		}
	}
}

// check parent to nested grid
function SelectParntToNestedGris(ChildID)
{
    var ChildID_tochecknonoSelection=ChildID.substring(0,ChildID.length-22);
    ChildID=ChildID.substring(0,ChildID.length-37);
	var ParentID=ChildID+'chkSelect01';
	var elem = document.getElementById(ParentID);
	if(elem.type=='checkbox')
	{
	    if(checkNoneSelectionToParent(ChildID_tochecknonoSelection))
		    {elem.checked = true;}
		else
		    {elem.checked = false;}
		
	}
}
// check the seletion of none to parent
function checkNoneSelectionToParent(ChildID)
{
    var Res=false;
	var frm = document.forms[0];
	for (i=0; i<frm.length; i++) 
	{
	    var elem = frm.elements[i];
	    var chk2=elem.id.substring(0,elem.id.length-22);
		if(chk2==ChildID && elem.type=='checkbox')
		{
			if(elem.checked){Res=true;break;}
		}
	}
	return Res;
}
// check All check boxes on form
function CheckUncheckAllCheckBoxes(_Checked)
{
	var frm = document.forms[0];
	for (i=0; i<frm.length; i++) 
	{
	    var elem = frm.elements[i];
		if(elem.type=='checkbox')
		{
			elem.checked = _Checked;
		}
	}
}