var SendEmailWindow = null;
var strArticleURL;
var strDocumentTitle;
var blnShowError = false;

if (docDate == null)
	var docDate = "";
	
if (docDate == "none")
	var docDate = "";
	
if (id == null)
	var id = "";
	
window.onerror = stopAllErrors;

function stopAllErrors() 
{
	if (blnShowError)
		alert("Error: " + msg + "\n" + "URL: " + url + "\n" + "Line Number: " + lno);
		
	return true;
}

function trim(str)
{
	return str.replace(/^ *| *$/g,"");
}

function isValidEmail(strEmail)
{   
	var emailRegExp = /^.+\@.+\..+$/ ;
	return emailRegExp.test(strEmail);
}

function getMonthLength(nYear,nMonth)
{
	switch (nMonth)
	{
		case 0: case 2: case 4: case 6: case 7: case 9: case 11:
			return 31;
					
		case 3: case 5: case 8: case 10:
			return 30;
					
		case 1:	
			if (nYear % 4 == 0)
				return 29;
			else
				return 28;
			break
	}
}

function submitSearch(lang)
{
	var text;
	
	if (trim(document.getElementById("searchText").value) == ""
	|| document.getElementById("searchText").value == document.getElementById("searchText").defaultValue )
	{
		alert("الرجاء ادخال كلمة واحدة على الاقل");
		document.getElementById("searchText").value = "";
		document.getElementById("searchText").focus();
		return;
	}
	else
		if (document.all)
			text = escape(document.getElementById("searchText").value);
		else
			text = document.getElementById("searchText").value;
			
		document.location.href = "/topics/search.asp?cu_no=1&num=2&text=" + text + "&lng=" + lang;
}



function mEvent(objImg,evntType)
{
	var strSrcName; 
	
	switch (evntType)
	{
		case "over":
			var nLastIndexOf_DotChar = objImg.src.lastIndexOf(".");
			var strImgExt = objImg.src.substring(nLastIndexOf_DotChar,objImg.src.length);
			strSrcName = objImg.src.substring(0, nLastIndexOf_DotChar);
			objImg.src = strSrcName + "-over" + strImgExt;
			break;

		case "out":
			var astr = objImg.src.split("-over");
			objImg.src = astr[0] + astr[1];
			break;
	}
}
var temp;
function veiwDetail(detailId)
{
	Icon = 'icon'+detailId;
	
	//alert(temp + " temp first time")
	
	if((temp != undefined)&&(temp != detailId))
	{
		//alert(temp);
		document.all[temp].className = "hide";
		document.all[tempicon].src='/customer/images/arrowdown.gif'
	}
	
	if (document.all[detailId].className == "")
	{
		document.all[detailId].className = "hide";
		document.all[Icon].src="/customer/images/arrowdown.gif";
	}
	else
	{	
		temp = detailId;
		tempicon = 'icon'+detailId;
		document.all[detailId].className = "";
		document.all[Icon].src='/customer/images/arrowup.gif';
		
	}
	
}


function SendByEmail()
{
	if (SendEmailWindow != null)
		SendEmailWindow.focus();
	else
	{
		var height = 310;
		var width = 401;
		var top = window.screen.height/2 - height/2;
		var left = window.screen.width/2 - width/2;
		var strProperties = 
			"width=" + width + 
			",height=" + height + 
			",top=" + top + 
			",left=" + left + 
			",scrollbars=0";
		
		if (document.location.hash == "")
			strArticleURL = document.location.href;
		else
			strArticleURL = document.location.href.replace(document.location.hash,"");
				
		strDocumentTitle = document.title;
		SendEmailWindow = window.open("/Customer/templates/sendByEmail.htm","",strProperties);
	}
}


function SendFeedback()
{
	if (SendEmailWindow != null)
		SendEmailWindow.focus();
	else
	{
		var height = 375;
		var width = 420;
		var top = window.screen.height/2 - height/2;
		var left = window.screen.width/2 - width/2;
		var strProperties = 
			"width=" + width + 
			",height=" + height + 
			",top=" + top + 
			",left=" + left + 
			",scrollbars=0";
		
		if (document.location.hash == "")
			strArticleURL = document.location.href;
		else
			strArticleURL = document.location.href.replace(document.location.hash,"");
				
		strDocumentTitle = document.title;
		SendEmailWindow = window.open("/Customer/templates/SendFeedback.asp","",strProperties);
	}
}

function ValidateNewsItemSearch()
{
		if (document.NewsIemsSearch.MainSub.value == "")
		{
			
			alert("الرجاء إختيار موضوع رئيسي او فرعي");
			return false;
		}
		if((isNaN(document.NewsIemsSearch.MainSub.value)))
		{
			alert("الرجاء إختيار موضوع رئيسي او فرعي");
			return false;
		}
		
			if (document.NewsIemsSearch.MainSub.options[document.NewsIemsSearch.MainSub.selectedIndex].style.color == 'red')
			{
				document.getElementById("MainSubID").value = document.NewsIemsSearch.MainSub.options[document.NewsIemsSearch.MainSub.selectedIndex].value
				document.getElementById("subSubID").value = "*"
			}
			else
			{
				document.getElementById("MainSubID").value = "*"
				document.getElementById("subSubID").value = document.NewsIemsSearch.MainSub.options[document.NewsIemsSearch.MainSub.selectedIndex].value
			}
return true;
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
		if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
			{
			return null;
			}
		if ( start == -1 ) return null;
			var end = document.cookie.indexOf( ";", len );
		if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
	}//End Get_Cookie function.....
	
	

function getMultiMediaGalleryItems(ptype,plng,pfirst)
{
	var type;
	var lng;
	var strLink;
	type = ptype;
	lng  = plng;
	first = pfirst;
	strLink = "/topics/getMultiMediaGallery.asp?type=" + type + "&lng=" + lng + "&first="+ first;
	
	
	
	//alert(type);
	//alert(lng);
	//alert(strLink);
	 switch (type) {
		case 211: 
				document.getElementById("btnTop").className = "tabedButton";
				document.getElementById("btnNew").className = "untabedButton";
				document.getElementById("btnSports").className = "untabedButton";
				document.getElementById("btnCommunity").className = "untabedButton";
		break;
		case 212: 
				document.getElementById("btnTop").className = "untabedButton";
				document.getElementById("btnNew").className = "tabedButton";
				document.getElementById("btnSports").className = "untabedButton";
				document.getElementById("btnCommunity").className = "untabedButton";
		break;
		case 213: 
				document.getElementById("btnTop").className = "untabedButton";
				document.getElementById("btnNew").className = "untabedButton";
				document.getElementById("btnSports").className = "tabedButton";
				document.getElementById("btnCommunity").className = "untabedButton";
		break;
		case 214: 
				document.getElementById("btnTop").className = "untabedButton";
				document.getElementById("btnNew").className = "untabedButton";
				document.getElementById("btnSports").className = "untabedButton";
				document.getElementById("btnCommunity").className = "tabedButton";
		break;
		
		default: 
				document.getElementById("btnTop").className = "tabedButton";
				document.getElementById("btnNew").className = "untabedButton";
				document.getElementById("btnSports").className = "untabedButton";
				document.getElementById("btnCommunity").className = "untabedButton";
		
	}
	
	AnsReq=createRequestObject();
	AnsReq.open('get', strLink);
	AnsReq.onreadystatechange = getItems;
	AnsReq.send(null);
	
}

//begin the ajax function
function createRequestObject()
 {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}
//end the ajax function

function getItems()
{
      if(AnsReq.readyState == 4)
      {
           
			var HTMLSteam = new String();
            HTMLSteam = AnsReq.responseText ;             
            document.getElementById("TDGalleryItems").innerHTML = HTMLSteam;
			if(document.getElementById("firstPath").value != -1){
            document.QnocMV.SetVariable("MVPathvar", document.getElementById("firstPath").value);}
      }
      else
      {

      }
}

function search_submit(id)
{
//alert(id);

}

function Enlarge(lng)
{
window.open ("/topics/Enlarge.asp","Enlarge"+ lng +"","menubar=0,resizable=1,width=690,height=480"); 


}

function FlashPlayer(lng,Item_No)
{
var url;
url = "/topics/flashplayer.asp?Item_No=" + Item_No
window.open(url,"flashplayer"+ lng +"","menubar=0,resizable=0,width=477,height=430"); 
}
	


/* Mohammad Abdullah : Menu and Ticker functions 25-11-2008 */

function ShowSubMenu(DivId)
	{
		document.getElementById(DivId).style.display = "";
		document.getElementById("tr"+DivId).className = "OverMainClassMenu";
	}
function HideSubMenu(DivId)
	{
		document.getElementById(DivId).style.display = "none";
		document.getElementById("tr"+DivId).className = "";
	}
		
	function SelectClass(tt)
	{
		tt.className = "OverClassMenu";
	}
		
	function UnSelectClass(tt)
	{
		tt.className = "";
	}
	
	
	

function TickerPlay(type)
{
	var ticker = document.getElementById("marTicker")
	var TickerStatus = document.getElementById("TickerStatus").value
	switch(type)
	{
		case "pause_play":
			//ticker.stop();
			if(TickerStatus == "play")
			{
				ticker.stop();
				document.getElementById("TickerStatus").value = "pause";
				document.getElementById("imgPlayPause").src = "/customer/images/playBtn.gif";
				
			}
			else
			{
				ticker.start();
				document.getElementById("TickerStatus").value = "play";
				document.getElementById("imgPlayPause").src = "/customer/images/Pause.gif";
			}
		break ;
		
		case "Right":
			if(TickerStatus == "pause")
			{
				ticker.start();
				document.getElementById("TickerStatus").value = "play";
				document.getElementById("imgPlayPause").src = "/customer/images/Pause.gif";
			}
			ticker.direction ="right";
		break ;
		
		case "Left":
			if(TickerStatus == "pause")
			{
				ticker.start();
				document.getElementById("TickerStatus").value = "play";
				document.getElementById("imgPlayPause").src = "/customer/images/Pause.gif";
			}
			ticker.direction ="left";
		break ;
	}


}



/* Mohammad Abdullah : End menu and Ticker functions 25-11-2008 */

