	function moveLang()
	{
		var xLang_id = document.forms[0].fldlanguage_id;
		var xReading = document.forms[0].fldreading;
		var xSpeech = document.forms[0].fldspeach;
		var xWriting = document.forms[0].fldwriting;
		
		var xLangs = document.forms[0]['fldlangs[]'];
		
		
		if (xLang_id.selectedIndex > -1 && xReading.selectedIndex > -1 && xWriting.selectedIndex > -1 && xSpeech.selectedIndex > -1 )
		{
			var i =0;
			var myVal = xLang_id.options[xLang_id.selectedIndex].value;
			myVal +='-' + xReading.options[xReading.selectedIndex].value;
			myVal +='-' + xSpeech.options[xSpeech.selectedIndex].value;
			myVal +='-' + xWriting.options[xWriting.selectedIndex].value;
			

			while (i<xLangs.length)
			{
				
				if (xLangs.options[i].value.substr(0, xLangs.options[i].value.length - xLangs.options[i].value.replace(/^(.*?)\-/,'').length-1, xLangs.options[i].value)==xLang_id.options[xLang_id.selectedIndex].value)
					return;
				i++;
			}			
			var myText = xLang_id.options[xLang_id.selectedIndex].text;
			myText +=' - ' + xReading.options[xReading.selectedIndex].text;
			myText +=' - ' + xSpeech.options[xSpeech.selectedIndex].text;
			myText +=' - ' + xWriting.options[xWriting.selectedIndex].text;
			
			xLangs.options[xLangs.length]=new Option(myText, myVal);
		}
	
	}
	function deleteLang()
	{
		var xLangs = document.forms[0]['fldlangs[]'];
		xLangs.remove(xLangs.selectedIndex);
	}
	
	
	// notification 
	
	 notificationsDir= true;
	curWinLeft = 0;
	openedChats= new Array();
	openedChatsCount=0;
	postedBefore = false;
	commentText='';
    var viewNotif = true;
	function updateNotifSettings(value)
	{	  
		var x = new ajaxObject('ajax/set_notif.php');
		x.addParam('id', value);		
	//	x.onSuccess(function(response){document.form1.fldphone2.value=response;});
	//	x.onError(function(err){setTimeout(updateSubMenum , 1000)})
		x.send('post');
	}
	
	function showNotifications()
    {
			$("#notifNumber").css("display","none");
			$("#notifications").slideToggle("slow");		
			//$("#notifNumberid").css("display","block");
			ajaxCallUrl("ajax/notifications_setThemRead.php");
		
    }
/*    function hideNotifications()
    {
            document.getElementById('notifications').className='min';
    }
    function showHideNotifications()
    {
        if (notificationsDir)
        {
            showNotifications()
        }
        else
        {
            hideNotifications()
        }
		
        notificationsDir = !notificationsDir;
    }
*/    
	function notificationsNum()
    {
	   if(viewNotif==true)
		{
			notificationsFetch();
			setTimeout('notificationsNum()', 8000);
			viewNotif=false;
		}
		else
		{		
			var prevNotificationsNum=document.getElementById('notifNumber').innerHTML;
			var x = new ajaxObject("ajax/notifications_num.php");
			x.onSuccess	(
				function(response, arr)
				{
					//alert(response);
					if (!isNaN(response))
					{
						if (parseInt(response)>parseInt(prevNotificationsNum))
						{					
							notificationsFetch();
						}
						
						if (parseInt(response)>0)
							$("#notifNumber").css("display","inline");
						else
							$("#notifNumber").css("display","none");
						document.getElementById('notifNumber').innerHTML=response;
						
						
						
						//anyChatsToOpen();
						setTimeout('notificationsNum()', 8000);
					}
				}
						);
			x.onError	(
				function()
				{
				//		document.getElementById('notifNumber').innerHTML='!';
				//		document.getElementById('notifNumber').style.background='#EFCDA6';
						setTimeout('notifNumber()', 8000);
				}
						);
			x.send('get');
		}		
	
    }
    function notificationsFetch()
    {
		var x = new ajaxObject("ajax/notifications_fetch.php");
		x.addParam('root', root);
		x.onSuccess	(
				function(response)
				{					
					var xx = document.getElementById('fetchedNotifications');
					xx.innerHTML = response;
					//var newElem = document.createElement("DIV");
					//newElem.innerHTML=response;	
					//xx.replaceChild(newElem,xx.firstChild);
					//xx.insertBefore(newElem, xx.firstChild);
					
				}
					);
		x.send('get');
    }
	
	
	
	// end notifications
	
	
	
	// chat

	function openChatWin(id)
	{
		var opened=false;
		for (var j in openedChats)
			if (openedChats[j]==id)
				opened = true;
		if (!opened)
		{
			var a = document.createElement('DIV');
			a.id='chatWith'+id;
			a.className='chatWin';
			a.style.left= curWinLeft+'px';
			a.style.display= 'none';
			openedChats[openedChatsCount++]=id;
			currentKey=1;
			lastKey=1;
			a.innerHTML="<img onclick='destroyChatWin("+id+")' class='pointer right' src='"+root+"icons/cancel__.png' /> <img class='pointer right' onclick='$(&#34;#putChatHere"+id+"&#34;).toggle(&#34;slow&#34;)' src='"+root+"icons/eye__.png' /><img class='left bordered' height='50' src='"+root+"user/avatar.php?id="+id+"'><div id='cUserInfo"+id+"' class='chatUserInfo'></div><span class='chatUserInfo' id='progress"+id+"'><img src='"+root+"images/loader.gif'></span><br class='clear'/><div class='putChatHere' id='putChatHere"+id+"'><img src='"+root+"images/loader.gif' /></div></div><textarea onkeydown='lastKey=currentKey; currentKey=event.keyCode; if(currentKey==13 && lastKey!=16) {sendChatWin("+id+");}' id='chatText"+id+"' onkeyup='if(!isArabic(this.value)) this.style.direction=\"ltr\"; else this.style.direction=\"rtl\";' class='chatText'></textarea>";
			document.body.appendChild(a);
			$('#chatWith'+id).fadeIn('slow');
			curWinLeft+=250;
			getChatUserInfo(id);
			getRecentChats(id, 1);
		}
	}


	function destroyChatWin(id)
	{
	
		var Node1 = document.body; 
		var len = Node1.childNodes.length;
		$('#chatWith'+id).fadeOut('slow', function(){$('#chatWith'+id).remove();
			var j=0;
			for(var i = 0; i < len; i++)
			{
				if (Node1.childNodes[i]!= null)
				if (Node1.childNodes[i].className=='chatWin')
				{
					Node1.childNodes[i].style.left=(j++)*250+'px';
					
				}
			}
		});
		for(var j in openedChats)
		if (openedChats[j]==id)
		{
			openedChatsCount--;
			openedChats.splice(j,1);
			ajaxCallUrl("ajax/chat_setRead.php", {'id':id});
			curWinLeft-=250;
		}
		
	}

	function getRecentChats(id, type)
	{
		var x = new ajaxObject("ajax/chat_getRecent.php");
		if(!type)
			type=1;
		x.addParam('id', id);
		x.addParam('type', type);
		x.rePass('type', type);
		x.onError	(
				function()
				{
					document.getElementById('putChatHere'+id).innerHTML = 'حدث مشكلة أثناء جلب المحادثة';
				}
					);
		x.onSuccess	(
				function(response,arr)
				{
					if (arr['type']==1)
						document.getElementById('putChatHere'+id).innerHTML = response;
					else
					if (arr['type']==2)
					{
						document.getElementById('pastChats'+id).innerHTML = response;
						document.getElementById('pastChats'+id).className = "";
					}
					document.getElementById('putChatHere'+id).scrollTop = document.getElementById('putChatHere'+id).scrollHeight;
					checkChatWith(id);
				}
					);

        x.send('get');
	}
	function sendChatWin(id)
	{
		var x = new ajaxObject("ajax/chat_send.php");
		document.getElementById('progress'+id).innerHTML = '<img src="'+root+'images/loader.gif" />';
		var val = document.getElementById('chatText'+id).value;
		//val = encodeURI(val);
		//val = urlencode(val);
		x.addParam('text', val);
		x.addParam('to', id);
		x.rePass('id', id);
		document.getElementById('chatText'+id).disabled=true;
		x.onSuccess	(
			function(response, arr)
			{
				var elem = document.getElementById('putChatHere' + arr['id']);
				var x = document.createElement("div");
				x.innerHTML = (document.getElementById('chatText'+arr['id']).value).replace(/</g,'&lt;').replace(/\n/g, '<br />');
				if (isArabic(x.innerHTML))
				{
					x.align='right';
					x.dir = 'rtl';
				}
				else
				{
					x.align='left';
					x.dir = 'ltr';
				}
				
				x.className = 'green';
				//elem.insertBefore(x, elem.firstChild);
				$('#putChatHere' + arr['id']).append(x);
				elem.scrollTop = elem.scrollHeight;


				if(!isNaN(response))
					document.getElementById('chatText'+arr['id']).value='';
				document.getElementById('progress'+id).innerHTML = '';
				document.getElementById('chatText'+arr['id']).disabled=false;				
				document.getElementById('chatText'+arr['id']).focus();
			}
					);
		x.onError	(
			function(error, arr)
			{
				document.getElementById('progress'+id).innerHTML = '<img src="'+root+'images/inputError.png" />';
				document.getElementById('chatText'+arr['id']).disabled=false;
			}
					);
        x.send('post');
	}
    function anyChatsToOpen()
    {
        var xmlhttp=GetXmlHttpObject();
        var url=root+"ajax/chat_anyToOpen.php";
		
		url=url+"?sid="+Math.random();
		
		for(var j in openedChats)
			url += '&o[]='+openedChats[j];
        xmlhttp.onreadystatechange= function ()
		{
			if (xmlhttp.readyState==4 && xmlhttp.responseText!='')
			{
//				alert(xmlhttp.responseText);
				if (!isNaN(xmlhttp.responseText))
					openChatWin(xmlhttp.responseText);
			}
		};
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    function checkChatWith(id)
    {
		var x = new ajaxObject("ajax/chat_checkWith.php");
		x.addParam('id', id, true);
		
        x.onSuccess	(
			function(response, arr)
			{
				if (response!='')
				{
					var elem = document.getElementById('putChatHere' + arr['id']);
					var x = document.createElement("span");
					x.innerHTML = response;
					//elem.insertBefore(x, elem.firstChild);
					$('#putChatHere' + arr['id']).append(x);
					elem.scrollTop = elem.scrollHeight;
				}
				for(var j in openedChats)
					if (arr['id']== openedChats[j])
						setTimeout('checkChatWith('+arr['id']+')', 4000);
				
			}
		
					);
		x.onError	(
			function (error, arr)
			{
				setTimeout('checkChatWith('+arr['id']+')', 4000);
			}
					);
        x.send('get');
    }
	function getChatUserInfo(id)
	{
		var x = new ajaxObject('ajax/chat_getUserInfo.php');
		x.addParam('id', id);
		
		x.onSuccess	(
			function (response)
			{
				document.getElementById('cUserInfo'+id).innerHTML = response;
				document.getElementById('progress'+id).innerHTML = '';
			}
					);		
		x.send('get');
		
	}
    
    function ajaxSendRequest(id)
    {
		var x = new ajaxObject("ajax/friendship_sendRequest.php");
		var oldText = document.getElementById('sendRequest'+id).innerHTML;
		document.getElementById('sendRequest'+id).innerHTML= "<img src='"+root+"images/loader.gif'>";
		
		x.addParam('id', id);
		x.onSuccess	(
			function(response)
			{
				document.getElementById('sendRequest'+id).innerHTML=response;
				ajaxMoreFriendshipSuggestions();
				setTimeout(function(){$('#suggestElem'+id).fadeOut(2000)}, 8000);
			}
					);
		x.onError	(
			function(error)
			{
				document.getElementById('sendRequest'+id).innerHTML='<span class="red">حدثت مشكلة ما .. يمكنك معاودة المحاولة لاحقاً</span>';
			}
					);
        x.send('get');
    }
    function ajaxConfirmFriendship(id, state)
    {
		var x = new ajaxObject("ajax/friendship_confirm.php");
		document.getElementById('confirm'+id).innerHTML= "<img src='../images/loader.gif'>";
		x.addParam('id', id);
		x.addParam('state', state);
		x.onSuccess	(
			function (response, arr)
			{
				$('#confirm'+id).html(response);
				ajaxMoreFriendshipSuggestions();
				
				setTimeout(function(){$('#confirm'+id).parent().fadeOut(2000)}, 10000);
			}
					);
		x.onError	(
			function(error)
			{
				alert(error);
			}
					);
        x.send('get');
    }
    function ajaxMoreFriendshipSuggestions()
    {
	
		var x = new ajaxObject("ajax/friendship_moreSuggestions.php");
		//document.getElementById('confirm'+id).innerHTML= "<img src='../images/loader.gif'>";
		
		x.onSuccess	(
			function (response)
			{
				document.getElementById('suggestionsArea').innerHTML+=response;
			}
					);
        x.send('get');
    }
    function blackListSuggest(id)
    {
	
		var x = new ajaxObject("ajax/friendship_blackListSuggest.php");
		x.addParam('id', id);
		document.getElementById('suggestElem'+id).innerHTML= "<img src='../images/loader.gif'>";
		x.onSuccess	(
			function (response)
			{
				
				document.getElementById('suggestElem'+id).innerHTML=response;
				ajaxMoreFriendshipSuggestions();
				setTimeout(function(){$('#suggestElem'+id).fadeOut(2000)}, 8000);
			}
					);
        x.send('get');
    }

	
	function searchForUser(name)
	{
		if (isEmpty(name))
			return;
		var userSearch = new ajaxObject("ajax/search_user.php");
		userSearch.addParam('name', name);			
		userSearch.onSuccess	(
			function (response)
			{
				document.getElementById('searchResultsHere').innerHTML = response;
			}
					);
		
		userSearch.send("get");
	}
	function deleteFriendShip(id)
	{
		var x = new ajaxObject("ajax/friendship_delete.php");
		x.addParam('id', id);
		x.onSuccess	(
			function (response)
			{
				document.getElementById('toDelete'+id).innerHTML = response;
			}
					);
		x.send('get');
	}
	function postOnWall(id, text)
	{
		if (isEmpty(text) || postedBefore==true)
			return;
			
		var x = new ajaxObject("ajax/user_postOnWall.php");
		x.addParam('text', text);
		x.addParam('id', id);
		x.addParam('token', document.wall.walltoken.value);
		document.wall.walltoken.value = '';
		
		$('#postSomeThing').html('<img src="'+root+'images/loader.gif" />');
		$('#postSomeThing').attr({'class': 'camera'});
		x.onSuccess	(
			function(response, arr)
			{
				$('.totalUserViews').prepend(response);
				
				$('#postSomeThing').html('تمت الإضافة تعليقك بنجاح');
				$('#postSomeThing').attr({'class': 'notice'});
				postedBefore = true;
				window.location.href ='#table';
			}
					);
		x.onError	(
			function(error, arr)
			{
				alert(error);
			}
					);
        x.send('post');
	}
	function deleteWallPost(id)
	{
		var x = new ajaxObject("ajax/user_deleteWallPost.php");
		x.addParam('id', id);
		x.send('get');
	}
	function addTaskComment(id)
	{
		jAlert('<textarea onkeyup="updateCommentText(this)" ></textarea>', 'اترك تعليقك', function(x){insertTaskComment(id, commentText)});
	
	}
	function updateCommentText(elem)
	{
		commentText=elem.value;
	}
	function insertTaskComment(id, text)
	{
		if (isEmpty(text))
			return;
		var x = new ajaxObject("ajax/todo_insertcomment.php");
		x.addParam('id', id);
		x.addParam('text', text);
		x.onError(
			function(err){
				setTimeout(function () {insertTaskComment(id, text)}, 1000);
			});
		x.send('post');
	}
	function changeTaskStatus(elem, id, withMail)
	{
		
		var x = new ajaxObject("ajax/todo_changestatus.php");
		elem.src = '../../images/loader.gif';
		x.addParam('id', id);
		if (withMail)
			x.addParam('withMail', 1);
		x.onError(
			function(err){
				setTimeout(function () {changeTaskStatus(elem)}, 1000);
			});
		x.onSuccess(
			function (response)
			{
				elem.src = response;
			});
		x.send('post');
	
	}
	function ask_changeTaskStatus(elem, id)
	{
		jConfirm('هل ترغب بإرسال إيميل إلى باقي الأعضاء لتنبيههم عن تغيير حالة المهمة؟', 'إيميل', function(choice){changeTaskStatus(elem, id, choice)});
	}
	function letus_replyToCan(thisForm)
	{
		var elem, i, submitElem;
		
		var fastModal = thisForm.parentNode;
		var x = new ajaxObject("ajax/replyToCan.php");
		for(i=0; i<thisForm.elements.length; i++)
		{
			elem = thisForm.elements[i];
			if ((elem.type!='radio')||(elem.type=='radio' && elem.checked==true))
			x.addParam(elem.name, elem.value);
			
			if (elem.type=='submit')
				submitElem = elem;
		}
		submitElem.disabled = true;
		
		x.onSuccess(
			function(response){
				setTimeout(function(){
					hideProgressingBar();
					$('.simplemodal-close').click();
					jAlert('Proccess Done Successfully');
				}
				, 1);
				fastModal.innerHTML = response;
			
			}
		)
		x.onError(
			function(err){
				alert(err);
			}
		)
		x.send('POST')
	
	}
	function letus_repCan(thisForm)
	{
		var elem, i, submitElem;
		
		var fastModal = thisForm.parentNode;
		var x = new ajaxObject("ajax/repCan.php");
		for(i=0; i<thisForm.elements.length; i++)
		{
			elem = thisForm.elements[i];
			
			if ((elem.type!='radio')||(elem.type=='radio' && elem.checked==true))
				x.addParam(elem.name, elem.value);
			//alert(elem.name+ " --> "+ elem.value);
			if (elem.type=='submit')
				submitElem = elem;
		}
		submitElem.disabled = true;
		
		x.onSuccess(
			function(response){
				setTimeout(function(){
					hideProgressingBar();
					$('.simplemodal-close').click();
					jAlert('Proccess Done Successfully');
				}
				, 1);
				fastModal.innerHTML = response;
			
			}
		)
		x.onError(
			function(err){
				alert(err);
			}
		)
		x.send('POST')
	
	}
	function ccc(thisForm)
	{
		var elem, submitElem;
		var x = new ajaxObject("ajax/replyToCan_preview.php");
		for(i=0; i<thisForm.elements.length; i++)
		{
			elem = thisForm.elements[i];
			if ((elem.type!='radio')||(elem.type=='radio' && elem.checked==true))
				x.addParam(elem.name, elem.value);
			
			if (elem.type=='submit')
				submitElem = elem;
		}
		submitElem.disabled = true;
		
		x.onSuccess(
			function(response){
				
				$('#blacy-modal-data').html(response);
				//$('#blacy-modal-title').html('test test');
				hideProgressingBar();
			
			}
		)
		x.onError(
			function(err){
				alert(err);
			}
		)
		x.send('POST')
	}
	
