function ajaxFunction()
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  return xmlHttp;
}
  
  

function ajax_checkusername(){
	
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	  document.getElementById("ajax_username").innerHTML = 'BLAH!';
	  if (response == '1'){
		document.getElementById("ajax_username").innerHTML = 'This username IS Available';
		document.getElementById("submitbutton").disabled = false;
		}else{
		document.getElementById("ajax_username").innerHTML = 'This username IS NOT Available';
		document.getElementById("submitbutton").disabled = true;
		}
      }
    }
	
  var username = document.getElementById("userscreenname").value;
  var url = 'ajax/ajax_functions.php?f=checkusername&u=' + username;
 
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function ajax_checkzipcode(){
	
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  if (response == '1'){
		document.getElementById("ajax_zipcode").innerHTML = 'This Zip Code IS Valid';
		document.getElementById("submitbutton").disabled = false;
		}else{
		document.getElementById("ajax_zipcode").innerHTML = 'This Zip Code IS NOT Valid';
		document.getElementById("submitbutton").disabled = true;
		}
      }
    }
	
  var username = document.getElementById("zip").value;
  var url = 'ajax/ajax_functions.php?f=checkzipcode&z=' + username;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function ajax_set_default_photo(){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	   var response = xmlHttp.responseText;
	  var rarray = new Array;
	  rarray = response.split('|');
	  var sf = rarray[0];
	  var text = rarray[1];
	  var photo = rarray[2];
	  
	  
	  if (sf == 1){
	  
		cancel_edit();
		document.getElementById("ajax_return").innerHTML = text;
		var headersrc = 'classes/phpthumb/phpThumb.php?src=' + photo + '&w=48&h=48&zc=1';
		document.getElementById("headerprofpic").src = headersrc;
		var smallsrc = 'classes/phpthumb/phpThumb.php?src=' + photo + '&w=19&h=19&zc=1';
		document.getElementById("browse_image").src = smallsrc;
		
	   }else{
		
		document.getElementById("ajax_return").innerHTML = text;
		   
	   }
	  
      }
    }
	
	if(undefined===window.clickedslot){
		document.getElementById("ajax_return").innerHTML = 'You did not select a new photo';
		//alert (clickedslot);
	}else{
	   // alert (clickedslot);
		  
		  var url = 'ajax/ajax_functions.php?f=changedefaultphoto&uid='+ userid +'&s=' + clickedslot;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			return false;
	}

  
}

function crush_member(memberto,memberfrom, keepred, idkeepred){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	   document.getElementById("ajax_return").innerHTML = response;
	   
	   if (keepred == 1){
		   
			document.getElementById(idkeepred).setAttribute('class', 'faves active');
			document.getElementById(idkeepred).setAttribute('className', 'faves active');
		   
	   }
	  
      }
    }
	

		  
		  var url = 'ajax/ajax_functions.php?f=sendcrush&to='+ memberto +'&from=' + memberfrom;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			return false;
	

  
}

function mark_read(crushid){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	   document.getElementById("ajax_return").innerHTML = response;
	   var idkeepred = 'rowcrush' + crushid;
	   document.getElementById(idkeepred).setAttribute('class', 'message_wrap clearfix');
	   document.getElementById(idkeepred).setAttribute('className', 'message_wrap clearfix');
	   //alert (nummsg);
	   var newnum = nummsg - 1;
	   //alert (newnum);
	   if (newnum == 0){
	   document.getElementById("nummsg").innerHTML = '';
	   }
	   if (newnum == 1){
		document.getElementById("nummsg").innerHTML = newnum + ' NEW CRUSH';
	   }
		if (newnum > 1){
		document.getElementById("nummsg").innerHTML = newnum + ' NEW CRUSHES';
	   }
	  
		nummsg = newnum;
		//alert (nummsg);
      }
    }
	

		  
		  var url = 'ajax/ajax_functions.php?f=markcrushread&crushid=' + crushid;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			return false;
	

  
}

function ajax_update_bio(memberid){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  var rarray = new Array;
	  rarray = response.split('|');
	  var sf = rarray[0];
	  var text = rarray[1];
	  var tagline = rarray[2];
	  
	  
	  if (sf == 1){
	  
		cancel_edit();
		document.getElementById("ajax_return").innerHTML = text;
		document.getElementById("usertagline").innerHTML = tagline;
		
	   }else{
		
		document.getElementById("ajax_return").innerHTML = text;
		   
	   }
	  
      }
    }
	
		var tag1 = document.getElementById("tagline").value;
		var tag = tag1.replace('&','%26');

		  
		  var url = 'ajax/ajax_functions.php?f=updatetagline&uid='+ memberid +'&tag=' + tag;
			xmlHttp.open("POST",url,true);
			xmlHttp.send(null);
			return false;
	

  
}

function remove_fave(membername,memberid,membertoremove){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	   document.getElementById("ajax_return").innerHTML = response;
	   window.location.reload();
	  
      }
    }
	
	
	if(confirm('Are you sure you want to remove ' + membername)){
		

		  
		  var url = 'ajax/ajax_functions.php?f=removefave&uid='+ memberid +'&remove=' + membertoremove;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			return false;
	
			}else{
				
			return false;
		
			}

  
}

function add_fave(memberid,membertoremove,refresh){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	   document.getElementById("ajax_return").innerHTML = response;
	   
	   if (refresh == 1){
		   
		   }else{
				window.location.reload();
		   }
      }
    }
	
	
	
		

		  
		  var url = 'ajax/ajax_functions.php?f=addfave&uid='+ memberid +'&add=' + membertoremove;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			return false;
	
			

  
}

function add_view(memberid,membertoremove){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	   //document.getElementById("ajax_return").innerHTML = response;
	   
	   
      }
    }
	
	
	
		

		  
		  var url = 'ajax/ajax_functions.php?f=addview&uid='+ memberid +'&add=' + membertoremove;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			return false;
	
			

  
}

function resetpassword(){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	   document.getElementById("ajax_return").innerHTML = response;
	   document.getElementById("usernamer").value = '';
		document.getElementById("emailr").value = '';
	  
      }
    }
	
	
	
		var uname = document.getElementById("usernamer").value;
		var email = document.getElementById("emailr").value;

		  
		  var url = 'ajax/ajax_functions.php?f=resetpassword&uname='+ uname +'&email=' + email;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			return false;
	
			

  
}

function cancelaccount(userid){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	  if (response == '1'){
			window.location = 'http://www.crushme.com/alert.html?alert=cancel';
		  }else{
			window.location = 'http://www.crushme.com/index.html?error=' + response;  
		  }
	  
      }
    }
	
	
	

		  
		  var url = 'ajax/ajax_functions.php?f=cancelaccount&uid='+ userid;
			xmlHttp.open("POST",url,true);
			xmlHttp.send(null);
			return false;
	
			

  
}

function setuserrole(type, userid){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	   //document.getElementById("ajax_return").innerHTML = response;
	  if (type == 'private'){
		window.location = 'http://www.crushme.com/alert.html?alert=private';
		}
	  
	  if (type == 'public'){
		window.location = 'http://www.crushme.com/alert.html?alert=public';
		}
	   
	  
      }
    }
	
	
	
		

		  
		  var url = 'ajax/ajax_functions.php?f=setuserrole&type=' + type + '&uid=' + userid;
			xmlHttp.open("POST",url,true);
			xmlHttp.send(null);
			return false;
	
			

  
}

function delete_crush(deleteid){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	   document.getElementById("ajax_return").innerHTML = response;
	   window.location.reload();
	  
      }
    }
	
	
	
		

		  
		  var url = 'ajax/ajax_functions.php?f=deletecrush&delete=' + deleteid;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			return false;
	
			

  
}

function delete_message(deleteid){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	   document.getElementById("ajax_return").innerHTML = response;
	   window.location.reload();
	  
      }
    }
	
	
	
		

		  
		  var url = 'ajax/ajax_functions.php?f=deletemsg&delete=' + deleteid;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			return false;
	
			

  
}

function do_spam(spamid){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	   document.getElementById("ajax_return").innerHTML = response;
	   window.location.reload();
	  
      }
    }
	
	
	
		

		  
		  var url = 'ajax/ajax_functions.php?f=spammsg&spam=' + spamid;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			return false;
	
			

  
}

function do_spam_profile(userid,sentby){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	   document.getElementById("ajax_return").innerHTML = response;
	   //window.location.reload();
	  
      }
    }
	
	
	
		

		  
		  var url = 'ajax/ajax_functions.php?f=spamprof&spam=' + userid + '&by=' + sentby;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			return false;
	
			

  
}

function deletepic(userid,slot){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	  if (response == 'Picture Deleted'){
		  
				window.location.reload();
		  }else{
			  
				document.getElementById("ajax_return").innerHTML = response;
		  }
	   
	   
	   
	  
      }
    }
	
	
	
		

		  
		  var url = 'ajax/ajax_functions.php?f=deletepic&uid=' + userid + '&slot=' + slot;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			return false;
	
			

  
}

function sendmessage(isreply){
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  
	   document.getElementById("ajax_return").innerHTML = response;
	   document.getElementById("send_message").value = '';
	   if (isreply == 1){
		hidereply();
	   }
      }
    }
	
	
	if (isreply == 1){
		var thread = document.getElementById("mid").value;
	}
	
		var msg = document.getElementById("send_message").value;
		var mto = document.getElementById("memberto").value;
		var mfr = document.getElementById("memberfrom").value;
		  
		  var url = 'ajax/ajax_functions.php?f=sendmessage&msg=' + msg + '&mto=' + mto + '&mfr=' + mfr + '&isreply=' + thread;
			xmlHttp.open("POST",url,true);
			xmlHttp.send(null);
			return false;
	
			

  
}

