var xml_Http;
var message_type;
function unique(a){
   var r = new Array();
   o:for(var i = 0, n = a.length; i < n; i++)
   {
      for(var x = 0, y = r.length; x < y; x++)
      {
         if(r[x]==a[i]) continue o;
      }
      r[r.length] = a[i];
   }
   return r;
}
function SendQuickReply(touser){

	message_type = 'mail';

	if (document.getElementById('temp_subject').style.display = ''){
		subject = document.getElementById('temp_subject').value;
	} else {
		subject = document.getElementById('subject').value;
	}
	
	message = document.getElementById('message').value;
	message = message.replace(/\n/g, "<br />");

	document.getElementById('QuickReply').style.display = 'none';
	document.getElementById('sending_message').style.display = '';

	SendUpdates('send-quick-reply.php?touser='+touser+'&subject='+subject+'&message='+message);
}

function SetEmailNotify(){
	if (document.getElementById('email_notify').checked == false){
		SendUpdates('settings.php?setting=email_notify&value=0');
	} else {
		SendUpdates('settings.php?setting=email_notify&value=1');
	}
}
function UnblockUsers() {
	var selectedArray = new Array();
	var selObj = document.getElementById('Blocked');
	var i;
	var count = 0;
	for (i=0; i<selObj.options.length; i++) {
		if (selObj.options[i].selected) {
			selectedArray[count] = selObj.options[i].value;
			count++;
		}
	}
	if (selectedArray.length == 0){
		alert('No items selected.');
	} else {
		SendUpdates('unblockusers.php?unblockusers='+selectedArray.join(','));
		for (i = selObj.options.length - 1; i>=0; i--) {
			if (selObj.options[i].selected) {
				selObj.remove(i);
			}
		}
	}
}
function BlockUsers() {
	var blockedusers = new Array();
	var userindex = 0;
	if (document.getElementById('select_box') == undefined){
		alert('No items selected.');
	} else {
		if (document.forms['Account'].select_box.length == undefined && document.forms['Account'].select_box.checked){
			blockedusers[userindex] = document.forms['Account'].select_box.value;
			username = blockedusers[userindex].split(",");
			blockedusers[userindex] = username[1];
		} else {
			for(i=0; i<document.forms['Account'].select_box.length; i++){
				if(document.forms['Account'].select_box[i].checked){
					blockedusers[userindex] = document.forms['Account'].select_box[i].value;
					username = blockedusers[userindex].split(",");
					blockedusers[userindex] = username[1];
					userindex++;
				}
			}
		}
		if (blockedusers.length > 0){
			var answer = confirm("Are you sure you want to block these users?");
			if (answer){
				blockedusers = unique(blockedusers);
       			SendUpdates('blockusers.php?blockedusers='+blockedusers.join(','));
			}
		} else {
			alert("No items selected.");
		}
	}
}
function SendUpdates(url) {
	xml_Http=GetXml_HttpObject();
	if (xml_Http==null) {
  		alert ("Please upgrade to Internet Explorer 5 or later.");
 		return;
  	} 
	
	isbusy = 1;
	xml_Http.open("GET","http://www.freeflirtdating.com/account/"+url,true);
	xml_Http.onreadystatechange=state_Changed;
	xml_Http.send(null);
}

function state_Changed(){ 
	if (xml_Http.readyState==4 || xml_Http.readyState=="complete"){
		isbusy = 0;

		if (xml_Http.responseText == 0){
			if (message_type == 'mail'){
				document.getElementById('sending_message').style.display = 'none';
				document.getElementById('send_message_failure').style.display = '';
			}
		} else if (xml_Http.responseText == 1){
			if (message_type == 'mail'){
				document.getElementById('sending_message').style.display = 'none';
				document.getElementById('send_message_success').style.display = '';
			}
		} else if (xml_Http.responseText == "UsersBlocked"){
			alert('The selected users have been blocked.');
		}

 	}
}

function GetXml_HttpObject()
{
try
 {
 // Firefox, Opera 8.0+, Safari
 xml_Http=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xml_Http=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xml_Http=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xml_Http;
}
