//
// 		Common Javascript Functions
// 		(c) Copyright, 2008
// 		Batelco Jordan
//		mnuaimat@batelco.jo
//		June 2008
//
//  	Updates -<>- mnuaimat


function in_array(arr,p_val) {
	for(var i = 0; i < arr.length; i++) {
		if(arr[i] == p_val) {
			return true;
		}
	}
	return false;
}

function search_array(arr,p_val) {
	for(var i = 0; i < arr.length; i++) {
		if(arr[i] == p_val) {
			return i;
		}
	}
	return false;
}
 

function remove_element (arr,s){
for(var i = 0; i < arr.length; i++)
	if(s==arr[i]) arr.splice(i, 1);
	 
}



var Base64 = {

	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = Base64._utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

		}

		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = Base64._utf8_decode(output);

		return output;

	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}




	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, January 2006
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	

	
	var rectangleBorderWidth = 2;	// Used to set correct size of the rectangle with red dashed border
	var useRectangle = true;
	
	var autoScrollSpeed = 0;	// Autoscroll speed	- Higher = faster
	
	/* Don't change anything below here */
	
	
	var dragableElementsParentBox;
	var opera = navigator.appVersion.indexOf('Opera')>=0?true:false;
		
	var rectangleDiv = true;
	var insertionMarkerDiv = false;
	var mouse_x;
	var mouse_y;
	
	var el_x;
	var el_y;
		
	var dragDropTimer = -1;	// -1 = no drag, 0-9 = initialization in progress, 10 = dragging
	var dragObject = false;
	var dragObjectNextObj = false;
	var dragableObjectArray = new Array();
	var destinationObj = false;	
	var currentDest = false;
	var allowRectangleMove = true;
	var insertionMarkerLine;
	var dragDropMoveLayer;
	var autoScrollActive = false;
	var documentHeight = false;
	var documentScrollHeight = false;
	var dragableAreaWidth = false;
	
	function getTopPos(inputObj)
	{		
	  var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null){
	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
	  }
	  return returnValue;
	}
	
	function getLeftPos(inputObj)
	{
	  var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null){
	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
	  }
	  return returnValue;
	}
		
	function cancelSelectionEvent()
	{
		if(dragDropTimer>=0)return false;
		return true;
	}
	
	function getObjectFromPosition(x,y)
	{
		var height = dragObject.offsetHeight;
		var width = dragObject.offsetWidth;
		var indexCurrentDragObject=-5;
		for(var no=0;no<dragableObjectArray.length;no++){			
			ref = dragableObjectArray[no];			
			if(ref['obj']==dragObject)indexCurrentDragObject=no;
			if(no<dragableObjectArray.length-1 && dragableObjectArray[no+1]['obj']==dragObject)indexCurrentDragObject=no+1;
			if(ref['obj']==dragObject && useRectangle)continue;	
			if(x > ref['left'] && y>ref['top'] && x<(ref['left'] + (ref['width']/2)) && y<(ref['top'] + ref['height'])){
				if(!useRectangle && dragableObjectArray[no]['obj']==dragObject)return 'self';
				if(indexCurrentDragObject==(no-1))return 'self';
				return Array(dragableObjectArray[no],no);
			}
			
			if(x > (ref['left'] + (ref['width']/2)) && y>ref['top'] && x<(ref['left'] + ref['width']) && y<(ref['top'] + ref['height'])){
				if(no<dragableObjectArray.length-1){
					if(no==indexCurrentDragObject || (no==indexCurrentDragObject-1)){
						return 'self';
					}
					if(dragableObjectArray[no]['obj']!=dragObject){
						return Array(dragableObjectArray[no+1],no+1);
					}else{
						if(!useRectangle)return 'self';
						if(no<dragableObjectArray.length-2)return Array(dragableObjectArray[no+2],no+2);
					}
				}else{
					if(dragableObjectArray[dragableObjectArray.length-1]['obj']!=dragObject)return 'append';	
					
				}
			}
			if(no<dragableObjectArray.length-1){
				if(x > (ref['left'] + ref['width']) && y>ref['top'] && y<(ref['top'] + ref['height']) && y<dragableObjectArray[no+1]['top']){
					return Array(dragableObjectArray[no+1],no+1);
				}
			}
		}	
		if(x>ref['left'] && y>(ref['top'] + ref['height']))return 'append';				
		return false;	
	}
		
	function initDrag(e)
	{
		if(document.all)e = event;
		mouse_x = e.clientX;
		mouse_y = e.clientY;
		if(!documentScrollHeight)documentScrollHeight = document.documentElement.scrollHeight + 100;
		el_x = getLeftPos(this)/1;
		el_y = getTopPos(this)/1;
		dragObject = this;
		if(useRectangle){
			rectangleDiv.style.width = this.clientWidth - (rectangleBorderWidth*2) +'px';
			rectangleDiv.style.height = this.clientHeight - (rectangleBorderWidth*2) +'px';
			rectangleDiv.className = this.className;
		}else{
			insertionMarkerLine.style.width = '6px';
		}
		dragDropTimer = 0;
		dragObjectNextObj = false;
		if(this.nextSibling){
			dragObjectNextObj = this.nextSibling;
			if(!dragObjectNextObj.tagName)dragObjectNextObj = dragObjectNextObj.nextSibling;
		}
		initDragTimer();
		return false;
	}
	
	function initDragTimer()
	{
		if(dragDropTimer>=0 && dragDropTimer<10){
			dragDropTimer++;
			setTimeout('initDragTimer()',5);
			return;
		}
		if(dragDropTimer==10){
			
			if(useRectangle){
				dragObject.style.opacity = 0.5;
				dragObject.style.filter = 'alpha(opacity=50)';
				dragObject.style.cursor = 'default';
			}else{
				var newObject = dragObject.cloneNode(true);
				dragDropMoveLayer.appendChild(newObject);
			}
		}
	}
	
	
	function autoScroll(direction,yPos)
	{
		if(document.documentElement.scrollHeight>documentScrollHeight && direction>0)return;
		
		window.scrollBy(0,direction);
		
		if(direction<0){
			if(document.documentElement.scrollTop>0){
				mouse_y = mouse_y - direction;
				if(useRectangle){
					dragObject.style.top = (el_y - mouse_y + yPos) + 'px';
				}else{
					dragDropMoveLayer.style.top = (el_y - mouse_y + yPos) + 'px';
				}			
			}else{
				autoScrollActive = false;
			}
		}else{
			if(yPos>(documentHeight-50)){		

				mouse_y = mouse_y - direction;
				if(useRectangle){
					if(dragObject && dragObject.style)
						dragObject.style.top = (el_y - mouse_y + yPos) + 'px';
				}else{
					dragDropMoveLayer.style.top = (el_y - mouse_y + yPos) + 'px';
				}				
			}else{
				autoScrollActive = false;
			}
		}
		if(autoScrollActive)setTimeout('autoScroll('+direction+',' + yPos + ')',5);
	}
	
	function moveDragableElement(e)
	{
		if(document.all)e = event;

		if(dragDropTimer<10)return;
		if(!allowRectangleMove)return false;
		
		
		if(e.clientY<50 || e.clientY>(documentHeight-50)){
			if(e.clientY<50 && !autoScrollActive){
				autoScrollActive = true;
				autoScroll((autoScrollSpeed*-1),e.clientY);
			}
			
			if(e.clientY>(documentHeight-50) && document.documentElement.scrollHeight<=documentScrollHeight && !autoScrollActive){
				autoScrollActive = true;
				autoScroll(autoScrollSpeed,e.clientY);
			}
		}else{
			autoScrollActive = false;
		}
		if(useRectangle){			
			if(dragObject.style.position!='absolute'){
				dragObject.style.position = 'absolute';
				setTimeout('repositionDragObjectArray()',50);
			}
		}		
	
		if(useRectangle){
			rectangleDiv.style.display='block';
		}else{
			insertionMarkerDiv.style.display='block';	
			dragDropMoveLayer.style.display='block';	
		}
		
		if(useRectangle){
			dragObject.style.left = (el_x - mouse_x + e.clientX + Math.max(document.body.scrollLeft,document.documentElement.scrollLeft)) + 'px';
			dragObject.style.top = (el_y - mouse_y + e.clientY) + 'px';
		}else{
			dragDropMoveLayer.style.left = (el_x - mouse_x + e.clientX + Math.max(document.body.scrollLeft,document.documentElement.scrollLeft)) + 'px';
			dragDropMoveLayer.style.top = (el_y - mouse_y + e.clientY) + 'px';
		}
		dest = getObjectFromPosition(e.clientX+Math.max(document.body.scrollLeft,document.documentElement.scrollLeft),e.clientY+Math.max(document.body.scrollTop,document.documentElement.scrollTop));
		
		if(dest!==false && dest!='append' && dest!='self'){
			destinationObj = dest[0]; 
			
			if(currentDest!==destinationObj){
				currentDest = destinationObj;
				if(useRectangle){
					destinationObj['obj'].parentNode.insertBefore(rectangleDiv,destinationObj['obj']);
					repositionDragObjectArray();
				}else{
					if(dest[1]>0 && (dragableObjectArray[dest[1]-1]['obj'].offsetLeft + dragableObjectArray[dest[1]-1]['width'] + dragObject.offsetWidth) < dragableAreaWidth){
						insertionMarkerDiv.style.left = (getLeftPos(dragableObjectArray[dest[1]-1]['obj']) + dragableObjectArray[dest[1]-1]['width'] + 2) + 'px';
						insertionMarkerDiv.style.top = (getTopPos(dragableObjectArray[dest[1]-1]['obj']) - 2) + 'px';
						insertionMarkerLine.style.height = dragableObjectArray[dest[1]-1]['height'] + 'px';
					}else{					
						insertionMarkerDiv.style.left = (getLeftPos(destinationObj['obj']) - 8) + 'px';
						insertionMarkerDiv.style.top = (getTopPos(destinationObj['obj']) - 2) + 'px';
						insertionMarkerLine.style.height = destinationObj['height'] + 'px';
					}
					
					
				}
			}
		}
		
		if(dest=='self' || !dest){
			insertionMarkerDiv.style.display='none';
			destinationObj = dest;	
		}
		
		if(dest=='append'){
			if(useRectangle){
				dragableElementsParentBox.appendChild(rectangleDiv);
				dragableElementsParentBox.appendChild(document.getElementById('clear'));
			}else{
				var tmpRef = dragableObjectArray[dragableObjectArray.length-1];
				insertionMarkerDiv.style.left = (getLeftPos(tmpRef['obj']) + 2) + tmpRef['width'] + 'px';
				insertionMarkerDiv.style.top = (getTopPos(tmpRef['obj']) - 2) + 'px';
				insertionMarkerLine.style.height = tmpRef['height'] + 'px';	
			}
			destinationObj = dest;
			repositionDragObjectArray();
		}	
		
		if(useRectangle && !dest){
			destinationObj = currentDest;
		}
		
		allowRectangleMove = false;
		setTimeout('allowRectangleMove=true',50);
	}
	
	function stop_dragDropElement()
	{
		dragDropTimer = -1;
		
		if(destinationObj && destinationObj!='append' && destinationObj!='self'){
			destinationObj['obj'].parentNode.insertBefore(dragObject,destinationObj['obj']);
		}
		if(destinationObj=='append'){
			dragableElementsParentBox.appendChild(dragObject);
			dragableElementsParentBox.appendChild(document.getElementById('clear'));
		}
		
		if(dragObject && useRectangle){
			dragObject.style.opacity = 1;
			dragObject.style.filter = 'alpha(opacity=100)';
			dragObject.style.cursor = 'move';
			dragObject.style.position='static';
		}
		rectangleDiv.style.display='none';
		insertionMarkerDiv.style.display='none';
		dragObject = false;
		currentDest = false;
		resetObjectArray();
		destinationObj = false;
		if(dragDropMoveLayer){
			dragDropMoveLayer.style.display='none';
			dragDropMoveLayer.innerHTML='';
		}
		autoScrollActive = false;
		documentScrollHeight = document.documentElement.scrollHeight + 100;
		saveData();
	}
	
	function cancelEvent()
	{
		return false;
	}
	
	function repositionDragObjectArray()
	{
		for(var no=0;no<dragableObjectArray.length;no++){
			ref = dragableObjectArray[no];
			ref['left'] = getLeftPos(ref['obj']);
			ref['top'] = getTopPos(ref['obj']);			
		}	
		documentScrollHeight = document.documentElement.scrollHeight + 100;
		documentHeight = document.documentElement.clientHeight;
	}
	
	function resetObjectArray()
	{
		dragableObjectArray.length=0;
		var subDivs = dragableElementsParentBox.getElementsByTagName('*');
		var countEl = 0;

		for(var no=0;no<subDivs.length;no++){
			var attr = subDivs[no].getAttribute('dragableBox');
			if(opera)attr = subDivs[no].dragableBox;
			if(attr=='true'){
				var index = dragableObjectArray.length;
				dragableObjectArray[index] = new Array();
				ref = dragableObjectArray[index];
				ref['obj'] = subDivs[no];
				ref['width'] = subDivs[no].offsetWidth;
				ref['height'] = subDivs[no].offsetHeight;
				ref['left'] = getLeftPos(subDivs[no]);
				ref['top'] = getTopPos(subDivs[no]);
				ref['index'] = countEl;
				countEl++;
			}
		}	
	}
	
	/* The saveData function creates a string containing the ids of your dragable elements. 
	
	The format of this string is as follow
	
	id of item 1|id of item 2|id of item 3
	
	i.e. a semi colon separated list. The id is something you put in as "id" attribute of your dragable elements.
	
	*/
	
	function saveData()
	{
		var saveString = "";
		for(var no=0;no<dragableObjectArray.length;no++){
			if(saveString.length>0)saveString = saveString + '|';
			ref = dragableObjectArray[no];
			saveString = saveString + ref['obj'].id;
		}	
		//console.log(saveString);
		//alert(saveString);	// For demo only
		createCookie_exact_name("alarabalyawm_hp_box_sort",saveString,15);
		/* 	Put this item into a hidden form field and then submit the form 
		
		example:
		
		document.forms[0].itemOrder.value = saveString;
		document.forms[0].submit;
		
		On the server explode the values by use of server side script. Then update your database with the new item order
		
		*/
		
		
		
	}
	
	function resetArrangement(){
			createCookie_exact_name("alarabalyawm_hp_box_sort","",-3);
		}
	
	function initdragableElements()
	{
		dragableElementsParentBox = document.getElementById('dragableElementsParentBox');
		insertionMarkerDiv = document.getElementById('insertionMarker');
		insertionMarkerLine = document.getElementById('insertionMarkerLine');
		dragableAreaWidth = dragableElementsParentBox.offsetWidth;
		
		if(!useRectangle){
			dragDropMoveLayer = document.createElement('DIV');
			dragDropMoveLayer.id = 'dragDropMoveLayer';		
			document.body.appendChild(dragDropMoveLayer);	
		}
		
		var subDivs = dragableElementsParentBox.getElementsByTagName('*');
		var countEl = 0;
		for(var no=0;no<subDivs.length;no++){
			var attr = subDivs[no].getAttribute('dragableBox');
			if(opera)attr = subDivs[no].dragableBox;
			if(attr=='true'){
				subDivs[no].style.cursor='move';	
				subDivs[no].onmousedown = initDrag;
				
				var index = dragableObjectArray.length;
				dragableObjectArray[index] = new Array();
				ref = dragableObjectArray[index];
				ref['obj'] = subDivs[no];
				ref['width'] = subDivs[no].offsetWidth;
				ref['height'] = subDivs[no].offsetHeight;
				ref['left'] = getLeftPos(subDivs[no]);
				ref['top'] = getTopPos(subDivs[no]);
				ref['index'] = countEl;
				countEl++;
			}
		}
		
		/* Creating rectangel indicating where item will be dropped */
		rectangleDiv = document.createElement('DIV');
		rectangleDiv.id='rectangle';
		rectangleDiv.style.display='none';
		dragableElementsParentBox.appendChild(rectangleDiv);
		
		
		document.body.onmousemove = moveDragableElement;
		document.body.onmouseup = stop_dragDropElement;
		document.body.onselectstart = cancelSelectionEvent;
		document.body.ondragstart = cancelEvent;
		window.onresize = repositionDragObjectArray; 
		
		documentHeight = document.documentElement.clientHeight;
	}
	



cookieCounter = document.cookie.split(';').length;

var anim=null;
var flyingElement = null;
var fade = null;
var somethingIsMoving = false;
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

function move_to_list(ename,from_x,from_y,to_x,to_y) 
		{
			move(ename, from_x, from_y, to_x, to_y, 5, 0, styleSin, false, null,null);
		}

function js_add_to_fav(href,title,num){
	if(somethingIsMoving)
		return;
	somethingIsMoving = true;
	linkname = "add_fav_link"+num;
	if($element(linkname) != null){
	
	 
	 origX = getX($element(linkname));
	 origY = getY($element(linkname));
	 
	 
	 //$element(linkname).parentNode.removeChild($element(linkname));
	 document.getElementsByTagName("body")[0].appendChild($element(linkname));
	 $element(linkname).style.position = "absolute";
	 $element(linkname).style.top =  origY;
	 $element(linkname).style.left =  origX;
	
	 $element(linkname).style.zIndex = 400;
	 
  
	dtop = getY($element("fav_area"));  
 	dleft = getX($element("fav_area"))+$element("fav_area").offsetWidth-10;//go to the right corner of the td
	
	
	 
	 
	
	 
	if(IE6){
		
		move_to_list(linkname,origY,origX,dtop, dleft);
	} else {
		fade = Animator.apply($element(linkname), "top: "+dtop+"px;left:"+dleft+"px");
		fade.options.duration  = 500;
		fade.options.interval  = 5;
		//console.log(fade.inspect());
	 
	}
	flyingElement = $element(linkname);
	
	if(!IE6)
	fade.play(1);
		
		}
	// console.log("cookieCounter =  '"+cookieCounter+"'  " );
	for(var i=cookieCounter;i>0;i--){
		
			if(!cook)
				continue;
			rval  = Base64.decode(cook);
			
			if(!rval)
				continue;
				
			rval = rval.split("-=-=-=-");
			
			href2 = rval[0];
			title2 = rval[1]; 
			
			if(href2 == href && title2.length > 0){
				setTimeout("probeFavouritesArea()",500);
				return;}
			
	}
	
	var linkstr = href+"-=-=-=-"+title;
	linkstr = Base64.encode(linkstr);
	createCookie("fav",linkstr,30);
	
	
	setTimeout("probeFavouritesArea()",500);
	}
	
	
function js_trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function createCookie(name,value,days) {
	if(!days || days && days > 0){ // otherwise it would be deleting
		name += ++cookieCounter;
		name += "_"+current_issue_date;
		}
	name =  js_trim(name);
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function createCookie_exact_name(name,value,days) {
	
	name =  js_trim(name);
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	cookieCounter = document.cookie.split(';').length;
	createCookie(name,"",-1);
}

function probeFavouritesArea(){
	 
	if(!IE6){
		if(fade != null && fade.state != 1){
				setTimeout("probeFavouritesArea()",50);
				return;
			}
		}
		
    somethingIsMoving = false;
	if(flyingElement != null)
		flyingElement.style.visibility = "hidden";
	
	mystr = "<table border=0 cellspacing=3 cellpadding=3 dir='rtl' width='100%'>";
	cookiesArr = document.cookie.split(';');
	innerStr = "";
	cookiesArr.reverse();
	var validCookiesCounter = 0;
	for(var i in cookiesArr){
			cname = cookiesArr[i];
			cookie2 = cookiesArr[i].split("=");
			
			
			cookiename = js_trim(cookie2[0]);
			
			if(!cookiename.match("fav[0-9]*"))
				continue;
			
			
			cook = readCookie(cookiename);
			if(!cook)
				continue;
			rval  = Base64.decode(cook);
			if(!rval)
				continue;
				
			rval = rval.split("-=-=-=-");
			
			href = rval[0];
			title = rval[1];
			validCookiesCounter++;
			
			innerStr += "<tr id='"+cookiename+"_tr'><td nowrap style='width: 7px;' valign='top'><img width='7' height='6' border='0' src='images/sec_ico2.gif' style='margin-top: 4px;'/></td><td><a href='"+href+"'>"+title+"&nbsp;<a href='javascript:rem_click_fav(\""+cookiename+"\")' style='color: #FF0000;text-decoration: none'>حذف</a></td></tr>";
			}
	
	if(innerStr.length == 0){ // no cookies yet
			innerStr += "<tr><td>بامكانك اضافة اخبار وموضوعات الى هنا ، استخدم الرمز <img border='0'   src='images/pin_to_fav.gif'/></td></tr>";
			//$element("fav_title_area").innerHTML="<a class=\"box_clickable\" style=\"width: 69px;\" href=\"#\" id=\"main_box_close\">بامكانك اضافة اخبارك المفضلة هنا</a>";
			$("#fav_title_area").find(".box_clickable").html("بامكانك اضافة اخبارك المفضلة هنا");
		} else {
			innerStr += "<tr><td colspan=2 align='center'><a href='javascript:eraseAll();probeFavouritesArea();' style='text-decoration: underline'>حذف الكل</a></td></tr>";
			//$element("fav_title_area").innerHTML="<a class=\"box_clickable\" style=\"width: 69px;\" href=\"#\" id=\"main_box_close\">اخباري المفضلة</a>&nbsp;&nbsp;<sup><small>"+validCookiesCounter+"</small></sup>";
			$("#fav_title_area").find(".box_clickable").html("اخباري المفضلة&nbsp;&nbsp;<sup>"+validCookiesCounter+"</sup>");
			 
			}
		
	
	 
							 
	
	mystr += innerStr;
	mystr += "</table>";
	$element("fav_area").innerHTML = mystr;
	
 
 
	 
	}


function $element(n){
		return document.getElementById(n);
	}


function rem_click_fav(id){
	xcoll(id+"_tr");
	eraseCookie(id);
	probeFavouritesArea();
	}
	
	
function xcoll(eid){
			
		$("#"+eid).hide('slow');
		
	}

function getY( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}



function eraseAll(){
	cookiesArr = document.cookie.split(';');
	for(i in cookiesArr){ 
		cookie2 = cookiesArr[i].split("=");
		cookiename = cookie2[0];
		
		if(cookiename.match("fav[0-9]*")){
			eraseCookie(cookiename);
			
			}
		}
	}

//on each load of the page
function initalize(){
		if($element("fav_area") != null)	
			probeFavouritesArea();
		else
			setTimeout("initalize()",100);
	}
	
	













/*******************************************************************************************/
// Animation styles used in Magic /////////////////////////////////////////////

function styleLinear(x) { return x; }
function styleSin(x) { return Math.sin(x*Math.PI/2); }
function stylePulse(x) { return (Math.sin(x*2*Math.PI) + 1) / 2; }
function styleBounce(x) { return (x == 0) ? 0 : (((-Math.sin(x*25)/(x*25))+1)*(1-x))+x; }
function styleBounceLess(x) { return (x == 0) ? 0 : (((-Math.sin(x*15)/(x*15))+1)*(1-x))+x; }
function styleBounceMore(x) { return (x == 0) ? 0 : (((-Math.sin(x*35)/(x*35))+1)*(1-x))+x; }

// Magic Animation Core ///////////////////////////////////////////////////////

magic = new function ()
{
	this.effects = [];
	this.interval;
	this.frequency = 30;
	
	this.remove = function(effect)
	{
		var i = 0;
		while (i < this.effects.length) 
			if (this.effects[i] == effect) 
				this.effects.splice(i, 1);
			else i++;
				
		if (this.effects.length == 0) 
			window.clearInterval(this.interval);
	}
	
	this.tick = function()
	{
		for (var i=0; i<this.effects.length; i++)			
			this.effects[i].tick();
	}

	this.add = function(effect)
	{
		this.effects.push(effect);
		if (this.effects.length == 1)
			this.interval = window.setInterval(function() {magic.tick();}, this.frequency);	
	}
}


function effectObject(elementId, ticksToStart, speed, action, style, loop, coAction, endAction) 
{		
	this.elementId = elementId;
	this.ticksToStart = (ticksToStart == undefined) ? 0 : ticksToStart;
	this.speed = speed;
	this.now = 0;
	this.action = action;
	this.coAction = coAction;
	this.endAction = endAction;
	this.loop = (loop == undefined) ? false : loop;
	this.style = (style == undefined) ? styleSin : style;
	this.tick = function()
	{
		if (this.ticksToStart > 0)
		{
			this.ticksToStart--;
			return;
		}
		
		if (this.now > 100)
		{
			if (this.loop)
				this.now = 0;
			else
			{
				magic.remove(this);				
				if (this.endAction != undefined) 
					this.endAction();
			}
		}
		else
		{
			if (typeof elementId == 'string' && document.getElementById(elementId) == null)
			{
				magic.remove(this);
				return;
			}			
			this.action();
			
			if (this.coAction != undefined)
				this.coAction();
			
			this.now += this.speed;
			if (this.now > 100) this.now = 101;			
		}
	}
	
	magic.add(this);
}

// Magic Effects ///// 


function changeNumber(element, what, suffix, value1, value2, speed, ticksToStart, style, loop, coAction, endAction)
{
	action = function()
	{
		this.element.style[this.what] = Math.round(this.value1 + this.style(this.now/100)*(value2-value1)) + suffix;
	}
	effect = new effectObject(element, ticksToStart, speed, action, style, loop, coAction, endAction);
	effect.element = (typeof element == 'string') ? document.getElementById(element) : element;
	effect.what = what;
	effect.value1 = value1;
	effect.value2 = value2;
}

function fade(element, opacity1, opacity2, speed, ticksToStart, style, loop, coAction, endAction)
{
	action = function()
	{		
		this.element.style.opacity = this.opacity1 + this.style(this.now/100) * (this.opacity2-this.opacity1);
		this.element.style.filter = "alpha(opacity=" + this.element.style.opacity*100 + ")";
	}
	effect = new effectObject(element, ticksToStart, speed, action, style, loop, coAction, endAction);
	effect.element = (typeof element == 'string') ? document.getElementById(element) : element;
	effect.opacity1 = opacity1;
	effect.opacity2 = opacity2;
}

function move(element, top1, left1, top2, left2, speed, ticksToStart, style, loop, coAction, endAction)
{	
	changeNumber(element, "top", "px", top1, top2, speed, ticksToStart, style, loop, coAction, endAction);
	changeNumber(element, "left", "px", left1, left2, speed, ticksToStart, style, loop);
}

function scale(element, width1, height1, width2, height2, speed, ticksToStart, style, loop, coAction, endAction)
{
	changeNumber(element, "width", "px", width1, width2, speed, ticksToStart, style, loop, coAction, endAction);
	changeNumber(element, "height", "px", height1, height2, speed, ticksToStart, style, loop);
}

function morph(element1, element2, width1, height1, width2, height2, speed, ticksToStart, style, loop, coAction, endAction)
{
	scale(element1, width1, height1, width2, height2, speed, ticksToStart, style, loop, coAction, endAction);
	scale(element2, width1, height1, width2, height2, speed, ticksToStart, style, loop);
	fade(element1, 1, 0, speed, ticksToStart, style, loop);
	fade(element2, 0, 1, speed, ticksToStart, style, loop);
}




function image_text(idindex)
   {
	 var imagename = image[idindex];
	 //document.masterimage.src = "image/" + imagename;
	 var srcc = imagename;
	 blendimage('blenddiv','blendimage', srcc, 800);
   }
 

   
  function changecolor(idindex) {
		if(mytime != null)
			clearTimeout(mytime);
		var ids = "f" + (idindex);
		
		
		 
							$("#top_news_rasterize").html('<table  cellspacing="0" cellpadding="0" border="0" width="100%" style="height: 254px;"><tr><td width="370" align="left" valign="top"  id="new_style_td" style="width: 370px;height: 254px;"  ><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#330033" dir="ltr"><tr><td align="center" valign="middle"><a id="mainlink" href="#" style="padding:0;margin: 0"><div style="background-repeat: no-repeat; width: 350px; height: 200px;background-position: top left;border: 1px solid #000;" id="blenddiv"><img src="images/loadingAnimation.gif" name="masterimage" border="0"  style="cursor: pointer" id="blendimage" alt="" /></div></a></td><td  valign="top" style="width: 3px;background: url(images/mbox_border_right.gif) repeat-y center;"></td></tr><tr><td align="left" colspan="2" >&nbsp;</td></tr></table></td><td valign="top" style="padding-top: 20px;"><div id="slidetitle" style="text-align: justify;padding: 10px;" class="normal_text bold_text" ><a id="mainlink22" href="index.php" class="normal_text bold_text"></a></div><br /><div id="mainnewsid" style="text-align: justify;padding: 10px;" class="normal_text regular" > </div></td></tr></table>');
							
							$("#main_news_icons_table").find(".dc").removeClass("dc").addClass("dd");
 							
							$("#mainnewsid").html(sumtext[idindex-1]); 
							$("#slidetitle").html("<a href='"+links[idindex-1]+"' id='mainlink22'>"+slidtitel[idindex-1]+"</a>"); 
							
 							var newxtid = ((idindex + 1) % (document.getElementById("main_news_icons_table").rows.length+1));
 							var this_image = idindex - 1;
							//image_text(this_image);
							var imagename = image[this_image];
							var srcc = imagename;
							 
							
							
							 
							
							
							
							var ids = "f" + (idindex);
 							document.getElementById(ids).className = "dc";
							
							if(idindex == 1 ){
									document.getElementById(ids).style.borderTop = "none";
									 
								}
						if( idindex == links.length ){
									 
									document.getElementById(ids).style.borderBottom = "none";
								}
							
							
					/*		for(i=0;i<links.length;i++)	
								$("#f"+i).css("border-right","1px solid #000000")
								
							$("td#f"+idindex).css("border-right","1px solid #FF0000");*/
							
							 
							if(newxtid == 0)
							newxtid  = 1;
							 mytime = setTimeout("changecolor(" + (newxtid) + ")", 10000); 
							
							
							
							$("#new_style_td").html(
												   	'<table border=0 cellpadding=0 cellspacing=0 wdith="100%"><tr><td><div style="position: relative"><div id="mbox_caption" style="z-index:1; position: absolute; top: 231px; filter:alpha(opacity=50);width: 370px; height: 26px;font-family:Tahoma,Arial, Helvetica, sans-serif; font-size:10px; vertical-align: middle;-moz-opacity:.50;opacity:.50;left: 0px;text-align: center;overflow: hidden;background-color: #000000;color: #FFFFFF"   >  </div><a href="#"  id="photo_link"><img width=370 height=256 src="'+srcc+'" id="blendimage" style="border-top: none;border-bottom: none"  border=0 /></div></td></tr></table>'
												   );
							if(mnews_captions[idindex-1] != null && mnews_captions[idindex-1].length > 0)
								$("#mbox_caption").html(mnews_captions[idindex-1]);
							else 
								$("#mbox_caption").html(slidtitel[idindex-1]);
								//$("#mbox_caption").css("display","none");
							
							$("#photo_link").attr("href",links[idindex-1]);
						 	$("#blendimage").attr("alt",slidtitel[idindex-1]);
							$("#blendimage").attr("title",slidtitel[idindex-1]);
							

 	

		     
}

	 function set_thum_image(imindex)
	   {
	    
	     imindex = imindex - 1;
	     var imagethum = "image" + (imindex+1);
		 
	    document.getElementById(imagethum).src = image_thum[imindex+1];
	   
	   }
	   
function blendimage(divid, imageid, imagefile, millisec) { 
    var speed = Math.round(millisec / 100); 
    var timer = 0;  
 
	
      
    //set the current image as background 
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")"; 
     
    //make image transparent 
   // changeOpac(0, imageid); 
     
    //make new image 
	document.getElementById(imageid).src = imagefile; 
    

    //fade in image 
    for(i = 0; i <= 100; i++) { 
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed)); 
        timer++; 
    }  
} 



function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
/*function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}*/

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

 

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}



var clockID = 0;

function UpdateClock() {
		if(clockID) {
			clearTimeout(clockID);
			clockID  = 0;
		}
		
		var tDate = new Date();
		if($("#theClock"))
		$("#theClock").html( "" 
					   + tDate.getHours() + ":" 
					   + tDate.getMinutes() + ":" 
					   + tDate.getSeconds()
					   );
		
		clockID = setTimeout("UpdateClock()", 1000);
}


function checkMySection(formObj, chkValue) {
	var len = Number(formObj.length);
	for (var i=0;i<len;i++) {
		if (formObj.elements[i].type == "checkbox") {
			if (formObj.elements[i].id == "sub_sections") {
				formObj.elements[i].checked = chkValue;
			}
		}
	}
}

var closedBoxesArray = new Array;
var deletedBoxesArray = new Array;
var bCtr =  0 ;
var dCtr =  0 ;
c_closed_boxes = readCookie("closed_boxes");
						  
						   if(c_closed_boxes != null){
							   		cArr  = c_closed_boxes.split("|");
									for(j in cArr){
										if(js_trim(cArr[j]) != "")
										closedBoxesArray[bCtr++]=cArr[j];
										}
							   }

c_deleted_boxes = readCookie("deleted_boxes");
						  
						   if(c_deleted_boxes != null){
							   		dArr  = c_deleted_boxes.split("|");
									for(j in dArr){
										if(js_trim(dArr[j]) != "")
										deletedBoxesArray[dCtr++]=dArr[j];
										}
							   }



function prepare_serialize(ar){
		for(j in closedBoxesArray){
			jst = closedBoxesArray[j];
			if(typeof(jst)== "undefined"){
					 closedBoxesArray.splice(j, 1);
				}
			}
		 
		createCookie_exact_name("closed_boxes",closedBoxesArray.join("|"),365)
	} 

function prepare_serialize_del(ar){
		for(j in deletedBoxesArray){
			jst = deletedBoxesArray[j];
			if(typeof(jst)== "undefined"){
					 closedBoxesArray.splice(j, 1);
				}
			}
//		console.log(deletedBoxesArray);
		createCookie_exact_name("deleted_boxes",deletedBoxesArray.join("|"),365)
	}

$(document).ready(
				  	function(){
						
						  
					   
						
							$("a")
								.filter(".box_clickable")
									.click(function(event){
												event.preventDefault();
												 
												$(this).css("cursor","pointer");
												bArea = $(this).parents(".box_container").find(".box_area");
												bArea.toggle();
												//console.log("id = "  + $(this).parents(".box_container").attr("id"));
												if(bArea.css("display")=="none"){ 
												 
														if($(this).parents(".box_container").attr("id")!=null){
															tid = $(this).parents(".box_container").attr("id");
														 
														 	if(!in_array(closedBoxesArray,tid))
															 	closedBoxesArray[closedBoxesArray.length]=tid;
															prepare_serialize(closedBoxesArray);
														 	
														}
														
													} else {
												 
														if($(this).parents(".box_container").attr("id")!=null){
															tid = $(this).parents(".box_container").attr("id");
														 	if(in_array(closedBoxesArray,tid)){
																 remove_element(closedBoxesArray,tid);
														 	prepare_serialize(closedBoxesArray);
															}
														}
														
														}
												
													getMaxDragListLength();		 
												
													})
								.end()
								.filter(".main_menu_link")
									.hover(
										   function(){
												$(this).parents(".main_menu").removeClass("main_menu").addClass("main_menu_hover");
											 
											
													},
											function(){
												$(this).parents(".main_menu_hover").removeClass("main_menu_hover").addClass("main_menu");		
														})
								.end()
								
						
						for(j in closedBoxesArray){
								tid = closedBoxesArray[j];
								//console.log($("#"+tid));
								$("#"+tid).find(".box_area").hide();
							}
						/*for(k in deletedBoxesArray){
								did = deletedBoxesArray[k];
								$("#"+did).find("table");
							}*/
						//$("a.fav_link").css("display","none");
						existingFavs  = new Array;
						cookiecccCounter = 0;
						for(var i=cookieCounter*2;i>0;i--){
							cook = readCookie("fav"+i);
						 
							if(!cook)
								continue;
							rval  = Base64.decode(cook);
							if(!rval)
								continue;
								
							rval = rval.split("-=-=-=-");
							
							href2 = rval[0];
							title2 = rval[1];
							existingFavs[cookiecccCounter++] = href2;
							
							
						
					   }


						$("a.fav_link").each(function(){
													  	
														for(j in existingFavs){	
															cLink = existingFavs[j];
															aLink =  $(this).attr('href');
															
															
															exactLink = aLink.substr('javascript:js_add_to_fav("'.length);
															exactLink  = exactLink.substr(0,exactLink.indexOf('"'));
															if(exactLink == cLink )
																$(this).css("display","none");
															
														}
													  });
						
						lbcounter = 0;
					 
						while($("a.lightbox"+lbcounter).length>0){
								 
								$("a.lightbox"+lbcounter).lightBox();
								lbcounter++;
							}
						if(lbcounter == 0)
							 $("a.lightbox1").lightBox();
						
					/*	$("a.lightbox0").lightBox();
						*/
						$("a.top_drop_handler").toggle(
													   
															
														function(){
															$(".alarabalyawm_slide_down_checkboxes").each(function(){$(this).attr("checked",true)});
																											for(j in deletedBoxesArray){
																												dn = deletedBoxesArray[j];
																																																		
																													if($("#"+dn+"_checkbox").length > 0  ){
																														$("#"+dn+"_checkbox").attr("checked",false);	
																														}
																												}
																							if($.browser.msie)
																										$(".top_banner_holder").css({display:	"none"});					
																							$(".top_drop_container").animate({ 
																										top:	'0px',
																										opacity: 0.8 
																										 
																									  }, 800  );	
																							
															},
															function(){
																
														   $(".top_drop_container").animate({ 
																								top:	'-248px',
																								opacity: 0.4 
																								 
																							  }, 800 ,function(){
																								  if($.browser.msie)
																								  		$(".top_banner_holder").css({display:	""})
																								  });
														   
														   }
															);
						
						
						 
						if(IE6)
							$(".horiz_div").css("padding-top","3px");
												
						UpdateClock();
						
						
						 
						getMaxDragListLength();
						 
						initalize();
						
						$(".box_container").hover(function(){
																$(this).find(".box_delete_handler").animate({
																									  opacity: 1.0   
																									   });
																					   },
													function(){
																$(this).find(".box_delete_handler").animate({
																									  opacity: 0   
																									   });			
																									});
						//$("li.most_2").click();
						//$("li.most_1").click();
						if($("#TabbedPanels1").length > 0)
							setTimeout("for(j=0;j<=2;j++){TabbedPanels1.showPanel(j);}TabbedPanels1.showPanel(0);",1000);

						
						$("#sections_save_options").click(function(){
							deletedBoxesArray.length = 0;
							 $('.sections_checkbox_selector :checkbox').each(function(){
																					 if($(this).attr("checked") == false)
																						deletedBoxesArray.push($(this).val());
																					  });
							 //console.log(deletedBoxesArray);
							 createCookie_exact_name("deleted_boxes",deletedBoxesArray.join("|"),365);
							 window.location.reload();
								
 																		});
						
						$("#sections_cancel_options").click(function(){
															$("a.top_drop_handler").click();
																   }); 
						
						/*$('a.Show_Page_Setup').click(function(){
								$('#BannerDiv').css("visibility","hidden");
														});   */
						
						
						$("#sections_reset_options").click(function(){
															cookies_arr = document.cookie.split(";");
															for(co in cookies_arr){
																	co2 = cookies_arr[co].split("=")[0];
																	if(co2 != "PHPSESSID")
																		createCookie(co2,"",-1);
																	
																}
														 	 window.location.reload();	
																	});
						
						
						}
				  );

function delete_box(title2){
		title = title2.substring(title2.indexOf("_")+1);
		$(".box_clickable").each(function(){
										  if($(this).html() == title){
											  	var thisnode = $(this);
												
											  	$(this).parents("div.box_container").fadeOut("slow",function(){
																								did=thisnode.parents("div.box_container").attr("id");
																							 
																								if(!in_array(deletedBoxesArray,did)){
																									deletedBoxesArray[deletedBoxesArray.length]=did;
																									prepare_serialize_del(deletedBoxesArray);
																									}
																								
																								thisnode.parents("li").remove();
																								getMaxDragListLength();
																								 
																								 });
												
											  }
										  });
		 
	}

function getMaxDragListLength(){
		vmax = 0;
		maxelements = 0;
		minelements = 2000;
		telem = null; // tallest element
		selem = null; // shortest elements
		
		$("ul.draglist").each(function(){
								$(this).css("padding-bottom","30px");
								
								if($(this)	.children().size() < minelements){ // get ul with leasst il's 
									minelements = $(this)	.children().size();
									
									selem = $(this);
									
									}
									
								if($(this)	.children().size() > maxelements){ // get ul with most il's 
									maxelements = $(this).children().size();
									
									telem = $(this);
									
									}
									   
							 
								
								 
							});
		if(telem != null && selem != null){ // set the max height to the shortest ul , so that they all the same
			 
			selem.css("padding-bottom",(((telem.attr("scrollHeight")-selem.attr("scrollHeight")))+30)+"px");
			}
		 
						
	}


 
$(window).error(function(){
  return true;
});


 

var current_issue_date = '2010-09-09'; 