var http = createRequestObject();
function createRequestObject(){
	var request_;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer" || typeof ActiveXObject != "undefined" ){
		request_ = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_ = new XMLHttpRequest();
	}
	if (!request_) {
		alert('you browser dosn`t support AJAX Please update your browser');
		return false;
	}
	return request_;
}
function addFriends(username,meuser,encriptData,userFullName){
	document.getElementById('hrfAddFriends').href="#";
	invite(username,meuser,encriptData);
	sendPvMsgFromInvite(userFullName,meuser);
}
function addFriendsNew(){
	row = document.getElementById("AddFriendsFlag").value ;
	username = document.getElementById("userName").value ;
	meuser = document.getElementById("sendMeuser"+row).value ;
	encriptData = document.getElementById("encryptData"+row).value ;
	userFullName = document.getElementById("name"+row).value ;

	document.getElementById('hrfAddFriends').disabled= true;
	if (meuser != username){
		invite(username,meuser,encriptData);
		//sendPvMsgFromInvite(userFullName,meuser);
	}else{
		alert ("لا يمكنك ارسال هذه الدعوة او الهمسة");
	}
}
function addFriendsPopup(){
	document.getElementById("addFriendsPopup").style.display= 'block';
	document.getElementById("addFriendsPopup").style.visibility = "visible" ;
	document.getElementById("txtAddFriends").value = "";
	document.getElementById("txtAddFriends").focus();
	__toBeShowSelects('hide');
}
var friends_sbox ;
function addFriendsPopupNew(row){
	name = document.getElementById("name"+row).value;

	if (document.getElementById("UID")){
		if (document.getElementById("UID").value == document.getElementById("sendMeuser"+row).value){return ;}
	}
	if (document.getElementById("abused"+row)){
		if (document.getElementById("abused"+row).value == 1){return ;}
	}
	userId = document.getElementById("sendMeuser"+row).value ;
	
	document.getElementById("AddFriendsFlag").value = row ;
	var addFriendsBox = "<div  style=\"width: 530px; direction: rtl;background: #ffffff\">"+
							"<div class=\"blubg pad5\">"+
							"<div class=\"fltrit\"><strong>أضف صديقاً</strong>"+
			                   "</div><div class=\"fltlft\">"+
			                                "<a href=\"javascript:closeAddFriends();\"> X اغلاق </a>  "+
			                  " </div></div>"+
						"<div id=\"newPlacement\" class=\"brdr\"><div align=\"center\"><br/><br/><br/><img src=\""+imagesPath+"loading_bigger.gif\" alt=\"\" /><br/><br/><br/></div></div><div class=\"brdr\" id=\"MsgsPopupForInvite\" style=\"display:none;\">"+
							"<iframe id=\"iframe"+userId+"\" src=\""+domainName+"request/PopupTemplates/FriendRequest.htm?id="+userId+"&from=userList&rowId="+row+"\" frameborder=\"0\" width=\"520\" height=\"320\" style=\"visibility: visible;\"></iframe></div></div>";

	friends_sbox = new ShadowBox(addFriendsBox, { transHoldTime:550 , maxOpacity: 70 });
	friends_sbox.show();
	
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		//document.getElementById("iframe"+userId).src=document.getElementById("iframe"+userId).src;
		document.getElementById("iframe"+userId).contentWindow.location.reload(true);
	}
}
function closeAddFriends(){
	friends_sbox.hide();
}
function sendPvMsgFromInvite(sendFrom,sendMeuser){
	from = sendFrom ;
	sbody = document.getElementById("txtAddFriends").value ;
	if(sbody != ""){
		var meuser = sendMeuser ;
		strMsg = sbody ;
		for (i=0;i<strMsg.length;i++){
			strMsg = handleText(strMsg);
		}
		document.getElementById("MsgsPopupForInvite").style.display = "none";
		document.getElementById("newPlacement").style.display = "";
		//AJAXGet(domainName+"request/sendPvtMsgs.htm?to="+meuser+"&text="+strMsg+"&mm="+Math.random(),completePvtMsg,false,true);
	}else{
		closeAddFriends();
	}
}
function completePvtMsg(sText){
	document.getElementById("newPlacement").style.display = "none";
	document.getElementById("MsgsPopupForInvite").style.display = "";
	if (sText == "0"){
		alert("لم يتم ارسال همستك");
		document.getElementById("txtAddFriends").value = "";
	}else if (sText != '1'){
		alert(sText);
		closeAddFriends();
	}else{
		closeAddFriends();
	}
}
var sendHamsah;
function sendPvtMsgPopup(){
	if (document.getElementById("UID")){
		if (document.getElementById("UID").value == document.getElementById("sendMeuser").value){
			return ;
		}
	}
	var textFriendsHamsah = document.getElementById("hamsahForCreator").innerHTML ;
	var friendsImagesHamsah = document.getElementById("userImageAvater").innerHTML ;
	var UserData = document.getElementById("senderForCreatorData").innerHTML;
	var addFriendsBoxHamsah = "<div align=\"center\" style=\"width: 530px; direction: rtl;background: #ffffff\">"+
							"<div class=\"blubg pad5\">"+
							"<div class=\"fltrit\"><strong>أرسل همسة</strong>"+
			                   "</div><div class=\"fltlft\">"+
			                                "<a href=\"javascript:closeSendPvtMsg();\"> X اغلاق </a>  "+
			                  " </div></div>"+
						"<div id=\"newPlacement\" class=\"brdr\" style=\"display:none;\"><div align=\"center\"><br/><br/><br/><img src=\""+imagesPath+"loading_bigger.gif\" alt=\"\" /><br/><br/><br/></div></div><div class=\"brdr\" id=\"MsgsPopupForInvite\" >"+
							"<table style=\"border-collapse: collapse; line-height:25px\" border=\"0\" cellpadding=\"4\" width=\"500px\" cellspacing=\"4\">"+
								"<tr>"+
									"<td colspan=\"2\">"+textFriendsHamsah+"</td>"+
								"</tr>"+
								"<tr>"+
									"<td>"+
									"<textarea name=\"descriptionM\" id=\"descriptionM\" cols=\"60\" rows=\"7\"></textarea></td>"+UserData+
									"<td valign=\"top\" align=\"center\">"+friendsImagesHamsah+"</td>"+
								"</tr>"+
								"<tr>"+
									"<td colspan=\"2\">"+

									"<input type=\"button\" value=\"إرسال\" id=\"hrfPvtMsg\" onclick=\"sendPvtMsg();\" class=\"btns\" />"+
									"<input type=\"button\" value=\"إلغاء\" class=\"btns\" onclick=\"closeSendPvtMsg();\" /> </td>"+
								"</tr></table></div></div><script> setTimeout('document.getElementById(\"descriptionM\").focus()',1000); </script>";

	sendHamsah = new ShadowBox(addFriendsBoxHamsah, { transHoldTime:500 , maxOpacity: 70 ,marginLeft:"30px"});
	sendHamsah.show();
}
function closeSendPvtMsg(){
	sendHamsah.hide();
}
function sendPvtMsg(){
	document.getElementById('hrfPvtMsg').disabled = true;
	from = _("sendFrom").value;
	sbody = _("descriptionM").value;
	sbody = trim(sbody);
	if(sbody == ""){
		alert("الرجاء ادخال نص الرسالة");
		document.getElementById("descriptionM").focus();
		document.getElementById('hrfPvtMsg').disabled = false;
	}else{
		var meuser = _("sendMeuser").value;
		strMsg = sbody ;
		for (i=0;i<strMsg.length;i++){
			strMsg = handleText(strMsg);
		}
		document.getElementById("MsgsPopupForInvite").style.display = "none";
		document.getElementById("newPlacement").style.display = "";
		AJAXGet(domainName+"request/sendPvtMsgs.htm?to="+meuser+"&text="+strMsg+"&mm="+Math.random(),completefunction,false,true)	;
	}

}
function completefunction(sText){
	document.getElementById("newPlacement").style.display = "none";
	document.getElementById("MsgsPopupForInvite").style.display = "";
	if (sText == "0"){
		alert("لم يتم ارسال همستك");
		document.getElementById("descriptionM").value="";
		document.getElementById('hrfPvtMsg').disabled = false;
	}else if (sText != '1'){
		alert(sText);
		closeSendPvtMsg();
	}else{
		closeSendPvtMsg();
	}
}
function openBlockPopup(){
	document.getElementById("blockPopup").style.display= 'block';
	document.getElementById("blockPopup").style.visibility = "visible" ;
	__toBeShowSelects('hide');
}
function closeBlockPopup(){
	document.getElementById("blockPopup").style.display= 'none';
	document.getElementById("blockPopup").style.visibility = "hidden" ;
	__toBeShowSelects('show');
}
function BlockUser(username,meuser,encriptData){
   document.getElementById('hrfBlock').href='#';
   http.open('get', domainName+'denyUser.htm?userId='+username+'&rejectedUserId='+meuser+'&m='+encriptData+'&mm='+Math.floor(1000000*Math.random()));
   http.onreadystatechange = handleInfoBlock;
   http.send(null);
}
function handleInfoBlock(){
	if(http.readyState == 1 || http.readyState == 2 || http.readyState == 3 ){
		document.getElementById("deny").innerHTML = 'الرجاء الانتظار ...';
	}
	if(http.readyState == 4){
		if(http.status == 200 ){
			var response = http.responseText;
			document.getElementById("deny").innerHTML = response;
		}
	}
	closeBlockPopup();
}
var abuseObj;
function openAbusePopup(){
	var textFriendsAbuse = "نحن نعمل على توفير بيئة آمنة لكافة أصحاب مكتوب، <br/>	الرجاء كتابة سبب التبليغ ونعدك بمتابعة الموضوع بأقصى سرعة لاتخاذ الإجراء المناسب";
	var abuseFunction = document.getElementById("spanFunction").innerHTML ;
	var friendsImagesHamsah = document.getElementById("userImageAvater").innerHTML ;
	
	forumId = typeof(arguments[0]) != 'undefined' ? arguments[0] : '';

	var abuseHTML = "<div align=\"center\" style=\"width: 530px; direction: rtl;background: #ffffff\">"+
							"<div class=\"blubg pad5\">"+
							"<div class=\"fltrit\"><strong>أبلغ عن اساءة</strong>"+
			                   "</div><div class=\"fltlft\">"+
			                                "<a href=\"javascript:closeAbusePopup();\"> X اغلاق </a>  "+
			                  " </div></div>"+
						"<div class=\"brdr\">"+
							"<table style=\"border-collapse: collapse; line-height:25px\" border=\"0\" cellpadding=\"4\" width=\"500px\" cellspacing=\"4\">"+
								"<tr>"+
									"<td colspan=\"2\">"+textFriendsAbuse+"</td>"+
								"</tr>"+
								"<tr>"+
									"<td>"+
									"<textarea name=\"txtAbuse\" id=\"txtAbuse\" cols=\"60\" rows=\"7\"></textarea></td>"+
									"<td valign=\"top\" align=\"center\">"+friendsImagesHamsah+"</td>"+
								"</tr>"+
								"<tr>"+
									"<td colspan=\"2\">"+

									"<input type=\"button\" value=\"أبلغ\" id=\"hrfAbuse\" onclick=\"abuseUserSpamForum('"+abuseFunction+"','"+forumId+"');\" class=\"btns\" />"+
									"<input type=\"button\" value=\"إلغاء\" class=\"btns\" onclick=\"closeAbusePopup();\" /> </td>"+
								"</tr></table></div></div><script> setTimeout('document.getElementById(\"txtAbuse\").focus()',1000); </script>";

	abuseObj = new ShadowBox(abuseHTML, { transHoldTime:500 , maxOpacity: 70});
	abuseObj.show();
}
function closeAbusePopup(){
	abuseObj.hide();
}
function abuseUserSpam(reported){
	msg = document.getElementById('txtAbuse').value ;
	document.getElementById('hrfAbuse').disabled= true;
	msg = trim(msg);
	if(msg == ''){
		alert("الرجاء كتابة سبب التبليغ");
		document.getElementById('hrfAbuse').disabled= false;
		document.getElementById('txtAbuse').focus();
	}else{
		strMsg = msg ;
		for (i=0;i<strMsg.length;i++){
			strMsg = handleText(strMsg);
		}
		AJAXGet(domainName+"request/reportSpam.php?reported="+reported+"&msg="+strMsg,AbusedSpamHandler,false,true);
	}
}
function abuseUserSpamForum(reported,forumId){
	msg = document.getElementById('txtAbuse').value ;
	document.getElementById('hrfAbuse').disabled= true;
	groupId = document.getElementById('groupId').value ;
	//forumId = document.getElementById('forumId').value ;
	forumId = forumId != 'undefined' && forumId != ''  ? forumId : document.getElementById('forumId').value;

	msg = trim(msg);
	if(msg == ''){
		alert("الرجاء كتابة سبب التبليغ");
		document.getElementById('hrfAbuse').disabled= false;
		document.getElementById("txtAbuse").focus();
	}else{
		strMsg = msg ;
		for (i=0;i<strMsg.length;i++){
			strMsg = handleText(strMsg);
		}

		AJAXGet(domainName+"request/group/reportForumSpam.htm?gId="+groupId+"&fId="+forumId+"&msg="+strMsg,AbusedSpamHandler,false,true);
	}
}
function AbusedSpamHandler(sText){
	if(sText == 1){
		var response = "<center>تم ارسال تبليغ  </center>";

		if (document.getElementById("AbusedUser") != undefined){
			document.getElementById("AbusedUser").innerHTML = response;
		}
	}else{
		alert(sText);
	}
	closeAbusePopup();
}
function AbusedSpamHandler2(sText){
	if(sText == "1"){
		document.getElementById("AbusedUser").innerHTML = "تم ارسال تبليغ";
	}
	closeAbusePopup();
}
var sendHamsah ;
function sendPvtMsgPopupNew(row){
	if (document.getElementById("UID")){
		if (document.getElementById("UID").value == document.getElementById("sendMeuser"+row).value){return ;}
	}
	if (document.getElementById("allow"+row)){
		if (document.getElementById("allow"+row).value == 0){
			return ;
		}
	}
	if (document.getElementById("abused"+row)){
		if (document.getElementById("abused"+row).value == 1){
			return ;
		}
	}
	var userId = _("sendMeuser"+row).value;
	document.getElementById("pvtMsgFlag").value = row ;
	var source = domainName+"request/PopupTemplates/privateMessage.htm?id="+userId+"&from=userList&rowId="+row ;
	var addFriendsBoxHamsah = "<div  style=\"width: 530px; direction: rtl;background: #ffffff\">"+
							"<div class=\"blubg pad5\">"+
							"<div class=\"fltrit\"><strong>أرسل همسة</strong>"+
			                   "</div><div class=\"fltlft\">"+
			                                "<a href=\"javascript:closeSendPvtMsgNew();\"> X اغلاق </a>  "+
			                  " </div></div>"+
						"<div id=\"newPlacement\" class=\"brdr\"><div align=\"center\"><br/><br/><br/><img src=\""+imagesPath+"loading_bigger.gif\" alt=\"\" /><br/><br/><br/></div></div><div class=\"brdr\" id=\"MsgsPopupForInvite\" style=\"display:none;\">"+
							"<iframe name=\"iframe"+userId+"\" id=\"iframe"+userId+"\" src=\""+source+"\" frameborder=\"0\" width=\"520\" height=\"320\" style=\"visibility: visible;\"></iframe></div></div>";
	sendHamsah = new ShadowBox(addFriendsBoxHamsah, { transHoldTime:530 , maxOpacity: 70 ,marginLeft : "30px",width:" 530px"});
	sendHamsah.show();
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		document.getElementById("iframe"+userId).contentWindow.location.reload(true);
	}

}
function closeSendPvtMsgNew(){
	sendHamsah.hide();
}
function sendPvtMsgNew(){
	document.getElementById('hrfPvtMsgNew').disabled= true;
	row = document.getElementById("pvtMsgFlag").value ;
	from = _("sendFrom"+row).value;
	sbody = _("descriptionMNew").value;
	if(sbody == ""){
		alert("الرجاء ادخال نص الرسالة");
		document.getElementById("descriptionMNew").focus();
		document.getElementById('hrfPvtMsgNew').href='javascript:sendPvtMsgNew()';
	}else{
		var meuser = _("sendMeuser"+row).value;
		strMsg = sbody ;
		for (i=0;i<strMsg.length;i++){
			strMsg = handleText(strMsg);
		}
		document.getElementById("MsgsPopupForInvite").style.display = "none";
		document.getElementById("newPlacement").style.display = "";
		AJAXGet(domainName+"request/sendPvtMsgs.htm?to="+meuser+"&text="+strMsg+"&mm="+Math.random(),completefunctionNew,false,true)	;
	}
}
function completefunctionNew(sText){
	document.getElementById("newPlacement").style.display = "none";
	document.getElementById("MsgsPopupForInvite").style.display = "";
	if (sText == "0"){
		alert("لم يتم ارسال همستك");
		document.getElementById("descriptionMNew").value="";
		document.getElementById('hrfPvtMsgNew').disabled=false;
	}else if (sText != '1' && sText != ''){
		alert(sText);
		closeSendPvtMsgNew();
	}else{
		closeSendPvtMsgNew();
	}
}
function abuseUserSpamNew(){
	msg = document.getElementById('txtAbuseNew').value ;
	document.getElementById('hrfAbuseNew').disabled= true;

	groupId = document.getElementById('groupId').value ;
	forumId = document.getElementById('forumId').value ;

	row = document.getElementById("abuseFlag").value ;
	reported = document.getElementById("sendMeuser"+row).value ;

	commentId = document.getElementById("commentId"+row).value ;
	msg = trim(msg);
	if (msg == ''){
		alert("الرجاء كتابة سبب التبليغ");
		document.getElementById('hrfAbuseNew').disabled= false;
	}else{
		strMsg = msg ;
		for (i=0;i<strMsg.length;i++){
			strMsg = handleText(strMsg);
		}
		AJAXGet(domainName+"request/group/reportForumCommentsSpam.htm?gId="+groupId+"&fId="+forumId+"&commentId="+commentId+"&reported="+reported+"&msg="+strMsg,AbusedSpamHandlerNew,false,true);
	}
}
function AbusedSpamHandlerNew(sText){
	if(sText == "1"){
		row = document.getElementById("abuseFlag").value ;
	    document.getElementById("AbusedUserTag"+row).innerHTML = "تم ارسال تبليغ";
	}else{
		alert (sText);
	}
	closeAbusePopupNew();
}
function closeAbusePopupNew(){
	abuseObj.hide();
}
function openAbusePopupNew(row){
	document.getElementById("abuseFlag").value = row ;
	var textFriendsAbuse = "نحن نعمل على توفير بيئة آمنة لكافة أصحاب مكتوب، <br/>	الرجاء كتابة سبب التبليغ ونعدك بمتابعة الموضوع بأقصى سرعة لاتخاذ الإجراء المناسب";
	var friendsImagesHamsah = document.getElementById("friendsImages"+row).innerHTML ;
	var abuseHTML = "<div align=\"center\" style=\"width: 530px; direction: rtl;background: #ffffff\">"+
							"<div class=\"blubg pad5\">"+
							"<div class=\"fltrit\"><strong>أبلغ عن اساءة</strong>"+
			                   "</div><div class=\"fltlft\">"+
			                                "<a href=\"javascript:closeAbusePopupNew();\"> X اغلاق </a>  "+
			                  " </div></div>"+
						"<div class=\"brdr\">"+
							"<table style=\"border-collapse: collapse; line-height:25px\" border=\"0\" cellpadding=\"4\" width=\"500px\" cellspacing=\"4\">"+
								"<tr>"+
									"<td colspan=\"2\">"+textFriendsAbuse+"</td>"+
								"</tr>"+
								"<tr>"+
									"<td>"+
									"<textarea name=\"txtAbuse\" id=\"txtAbuseNew\" cols=\"60\" rows=\"7\"></textarea></td>"+
									"<td valign=\"top\" align=\"center\">"+friendsImagesHamsah+"</td>"+
								"</tr>"+
								"<tr>"+
									"<td colspan=\"2\">"+

									"<input type=\"button\" value=\"أبلغ\" id=\"hrfAbuseNew\" onclick=\"abuseUserSpamNew();\" class=\"btns\" />"+
									"<input type=\"button\" value=\"إلغاء\" class=\"btns\" onclick=\"closeAbusePopupNew();\" /> </td>"+
								"</tr></table></div></div><script> setTimeout('document.getElementById(\"txtAbuseNew\").focus()',1000); </script>";

	abuseObj = new ShadowBox(abuseHTML, { transHoldTime:500 , maxOpacity: 70});
	abuseObj.show();
}
function invite(invitor,invited,m) {
	if (invitor == invited){
		return ;
	}
	document.getElementById("MsgsPopupForInvite").style.display = "none";
	document.getElementById("newPlacement").style.display = "";
	http.open('get', domainName+'request/sendInvitation.htm?invitor='+invitor+'&invited='+invited+'&m='+m+'&mm='+Math.floor(1000000*Math.random()));
	http.onreadystatechange = handleInfo;
	http.send(null);
}
function handleInfo(){
	if(http.readyState == 4){
		if(http.status == 200 ){
			var responseInvite = http.responseText;
			var counter = document.getElementById("AddFriendsFlag").value ;
			if (responseInvite != 'لا يمكنك ارسال الدعوة'){
				document.getElementById('invite'+counter).innerHTML = responseInvite;
				document.getElementById('hrfAddFriends').disabled= false;
			}else{
				alert ("لا يمكنك ارسال الدعوة");
			}
		}
	}
	closeAddFriends();
}