

function lookup(inputString, formtype) {
		
    if(inputString.length == 0) {
        // Hide the suggestion box.
        $('#'+formtype).hide();
    } else {
        $.post("/pals/ajax_interface.php", {queryString: ""+inputString+"",vAjax: ""+formtype+""}, function(data){
            if(data.length >0) {
                $('#'+formtype).show();
                $('#auto'+formtype+'List').html(data);
            }
        });
    }
} // lookup

function fill(thisValue, thisId, formtype) {
    $('#inputString').val(thisValue);
    $('#vId').val(thisId);
	setTimeout("$('#"+formtype+"').hide();", 500);	
}
// JavaScript Document

function emotions(id, nid, formtype) {
	document.getElementById(formtype+nid).innerHTML = formtype+"ing...";
	
	$.post("/pals/ajax_interface.php", {uid: ""+id+"",nid: ""+nid+"",vAjax: formtype}, function(data){   
            if(data.length >0) {
				setTimeout("this.window.location = '/pals/profile.php'", 400);	
            }else{
				document.getElementById(formtype+nid).innerHTML = "Error: "+formtype+" Failed! :[";
				 setTimeout("this.window.location = '/pals/profile.php'", 1200);	
			};
    });
}

function smile(id, nid, formtype) {
	document.getElementById(formtype+nid).innerHTML = formtype+" back...";
	
	jQuery.post("/pals/ajax_interface.php", {uid: ""+id+"",nid: ""+nid+"",vAjax: ""+formtype+""}, function(data){   
            if(data.length >0) {
            //document.getElementById('smile'+nid).innerHTML = data
				setTimeout("this.window.location = '/pals/profile.php'", 1200);	
            }else{
				document.getElementById('smile'+nid).innerHTML = "Error: Failed! :[";
				 setTimeout("this.window.location = '/pals/profile.php'", 1200);	
			};
    });
	
}

function updateMood(newMood)
{
	
if(newMood==""){newMood = ".";};

jQuery.post("/pals/ajax_interface.php", {newMood: newMood});


}

function swaptext(){ 

var box = document.getElementById("inputStringM");
store = box.value;
document.getElementById("inputStringM").value="Updating ...";
setTimeout("document.getElementById(\"inputStringM\").value=store;",1200);
}


//maximum number of allowed checked boxes 
var maxChecks=10 

function setTopFriends(form,obj ,value,id)
{
var checkCount=0;

  for (var n=0; n < form.elements.length; n++) {
     
      if(form.elements[n].checked == true){checkCount=checkCount+1}
  }
  
  if(checkCount>maxChecks){
  alert('you may only choose up to '+maxChecks+' options') 
  obj.checked = false
  }else
  {
	  if(obj.checked){ 
	  	jQuery.post("/pals/ajax_interface.php", {addfriendID: value});
	  }else{ 
	  	jQuery.post("/pals/ajax_interface.php", {subfriendID: value});
	  } 
  }

} 

