function changePhoto(objectId,image){
	objectId.style.backgroundImage = image;
}

function showFolder(folderName,toDoAction) {
	form = document.getElementById("welcomeForm");	
	form.toDoAction.value =toDoAction;
	form.folder_to_display.value = folderName;
	form.submit();
}
function toInbox(folderName,action) {
	document.compose.toDoAction.value = action;
	document.compose.folder_to_display.value = folderName;
	document.compose.submit();
}
function sendto(Action) {
	form = document.getElementById("welcomeForm");
	form.toDoAction.value = Action;
	form.submit();
}
function goToTemplates(toDoAction){
	form = document.getElementById("welcomeForm");
	form.toDoAction.value  = toDoAction;
	form.submit();
}
function sendFriendShipRequest(username,toDoAction,action) {
	//regexp=/^[\w-]+(\.[\w-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$/;
	regexp=/^[A-Za-z][A-Za-z0-9._-]*@[A-Za-z0-9][A-Za-z0-9._-]*\.[A-Za-z0-9][A-Za-z0-9._-]+$/;
	//regexp2=/^[\w-]+(\.[\w-]+)*/;
	regexp2=/^[A-Za-z][A-Za-z0-9._-]*$/;
	textField = document.getElementById("sendFriendship");
	if (textField.value==""){
		alert("يرجى كتابة اسم صديقك الذي تود إرسال طلب له");
		textField.focus();
		return;
	}else{
		if (regexp.test(textField.value)||regexp2.test(textField.value)){
			var friendName=textField.value;
			var temp = new Array();
			temp = friendName.split('@');		
			if (temp.length>1){
				if (temp[1]!="spacetoon.com"){
					alert("لا يمكنك إرسال دعوة إلا إلى عضو من نادي سبيستون....");
					textField.focus();
					return;
				}
			}
			friendName=temp[0];
			if(temp[0].toLowerCase() == username.toLowerCase()){
				alert('لايمكنك إرسال دعوة إلى نفسك');
				textField.focus();
				return;
			} 
			textField.value=temp[0];
			form = document.getElementById("botomForm");
			form.action=action;
			form.toDoAction.value = toDoAction ;
			form.friend_request_to.value =temp[0];
			form.submit();
			return;
		}else{
			alert(" عنوان بريد خاطئ "+textField.value+"\n");
			return;
		}	
	}
}
function doSubmit(toDoAction) {
	form = document.getElementById("contactsForm");
	form.toDoAction.value  = toDoAction;
	form.submit();
}

function handleMessage(todo){
	if(todo == 'block&report'){
		if(confirm('هل أنت متأكد من أنك لا ترغب في استقبال أي رسالة من هذا الشخص بعد الآن؟')){
		document.displaymessage.toDoAction.value = todo ;
		document.displaymessage.submit();
		}
	}
	else{
		document.displaymessage.toDoAction.value = todo ;
		document.displaymessage.submit();
	}
}
function display_pref(){
	form = document.getElementById("prefForm");
	//form.toDoAction.value =  "editProfile";
	form.submit();
}
function display_contacts() {
	form = document.getElementById("contactsForm");
	//    form.toDoAction.value  = toDoAction;
	form.submit();
}
function editProfile(){
	form = document.getElementById("profileForm");
	//form.toDoAction.value =  "editProfile";
	form.submit();
}
function EditContacts(){
		win = window.open("addressbook.html",'addressbook','height=500,width=400,menubar=no,status=no,toolbar=no,scrollbars=yes');
	}

	function send(action){
	  document.preview.toDoAction.value = action;
	  document.preview.submit();
	}

	function returnToCompose(action){
	  document.preview.toDoAction.value = action;
	  document.preview.submit();
	}

	function savePreferences(){
	  var oEditor = FCKeditorAPI.GetInstance('signature') ;
	  // Get the Editor Area DOM (Document object).
	  var oDOM = oEditor.EditorDocument ; 
	  var iLength ;
	  // The are two diffent ways to get the text (without HTML markups).
	  // It is browser specific.
	  if ( document.all ){ // If Internet Explorer.{
		  iLength = oDOM.body.innerText.length ;
	  }
	  else // If Gecko.
	  {
		  var r = oDOM.createRange() ;
		  r.selectNodeContents( oDOM.body ) ;
		  iLength = r.toString().length ;
	  }
	  if (iLength > 400)
	  {
		  alert("لا يسمح لك بإدخال أكثر من 400 حرف ضمن التوقيع الخاص بك.");
		  return;
	  }
	  document.preferences.toDoAction.value = "savePreferences";
	  document.preferences.submit();
	}

	function attach(todo){
		var to=document.getElementById("message_to");
		var error=checkEmail(to.value);
		if(error==""){
					document.compose.toDoAction.value = todo;
					document.compose.submit();
		}else{		
		alert(error);
		}
	}

	function attachReportImges(todo){
		document.sendReport.toDoAction.value = todo;
		document.sendReport.submit();
		
	}

	function attachTemplate(todo){
		var to=document.getElementById("message_to");
		var error=checkEmail(to.value);
		if(error==""){
					document.composeTemplate.toDoAction.value = todo;
					document.composeTemplate.submit();
		}else{		
		alert(error);
		}
	}

	function whichButton(event,constant){
		if(event.keyCode == 13){
			return;
		}else{
			return;
		}
	}
	
      // drawPercentBar()
      // Written by Matthew Harvey (matt AT unlikelywords DOT com)
      // (http://www.unlikelywords.com/html-morsels/)
      // Distributed under the Creative Commons
      // "Attribution-NonCommercial-ShareAlike 2.0" License
      // (http://creativecommons.org/licenses/by-nc-sa/2.0/)
      function drawPercentBar(width, percent, color, background)
      {
        var pixels = width * (percent / 100);
        if (!background) { background = "none"; }

        document.write("<div style=\"position: relative;top:10px; left:15px;font-size:16px;"+
		"background-color: "
        + background + ";border-style: solid;"+"border-width: 1px;"+
			"height: 24px; " +
			"border-top-color: #fff;"+
			"border-left-color: #fff;"+
		"border-bottom-color: #000;" +
		"border-right-color: #000;  width: "
        + width + "px\">");
        document.write("<div style=\"height: 24px; width: " + pixels + "px; background-color: "
        + color + ";\"></div>");
        document.write("<div style=\"position: absolute; text-align: center; padding-top: .25em; width: "
        + width + "px; top: 0; left: 0\">" + percent + "%</div>");
        document.write("</div>");
      }
		window.onload=function(){
			Nifty("div.mbox","transparent");
			Nifty("div.pollrounded","transparent");
			Nifty("div#hold","transparent");
			Nifty("div#games","transparent");
			Nifty("div.mainBoxes","transparent");
		}
		function Trim(TRIM_VALUE){
			if(TRIM_VALUE.length < 1){
			return"";
			}
			TRIM_VALUE = RTrim(TRIM_VALUE);
			TRIM_VALUE = LTrim(TRIM_VALUE);
			if(TRIM_VALUE==""){
			return "";
			}
			else{
			return TRIM_VALUE;
			}
			} //End Function

			function RTrim(VALUE){
			var w_space = String.fromCharCode(32);
			var v_length = VALUE.length;
			var strTemp = "";
			if(v_length < 0){
			return"";
			}
			var iTemp = v_length -1;

			while(iTemp > -1){
			if(VALUE.charAt(iTemp) == w_space){
			}
			else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
			}
			iTemp = iTemp-1;

			} //End While
			return strTemp;

			} //End Function

			function LTrim(VALUE){
			var w_space = String.fromCharCode(32);
			if(v_length < 1){
			return"";
			}
			var v_length = VALUE.length;
			var strTemp = "";

			var iTemp = 0;

			while(iTemp < v_length){
			if(VALUE.charAt(iTemp) == w_space){
			}
			else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
			}
			iTemp = iTemp + 1;
			} //End While
			return strTemp;
			} //End Function


