 function userExists(username){
        	if(username!="" && validateUsername(username)){
				$("#usr_spinner").css("display", "");
				$.ajax({
        			   type: "GET",
        			   url: "jsonProcess.php",
        			   dataType: 'json',
        			   data: "a=userExists&username="+username,
        			   success: function(response){
        							$("#usr_spinner").css("display", "none");
									if (response.result=="taken"){
        								/*$('#userExists').val('true');*/
        								/*$("#existing_usr").html($('#username').val());*/
        								/*$('#username').val("");*/
        								$('#username').focus();
        								$("#userAvailable").fadeOut(function(){
        									$("#userTaken").fadeIn();	
        								});
        								alert("The selected user is already taken. Please choose another one.");
        								$("#userTaken").val("true");
        								return true;
        									
        							}else{
        								$("#userTaken").fadeOut(function(){
        									$('#userAvailable').fadeIn();
        								});
        								$("#userTaken").val("false");
        								return false;
        							}
									
        						},
        				error: function(response){ 
        					alert("ERROR " + response.error);
							$("#usr_spinner").css("display", "none");
        					return false;		
        				}
        			});
        	}else{
        		$("#userAvailable").fadeOut();
        		$("#userTaken").fadeOut();	
        	}
        		
        		return false;

        	}


        	function checkFields(){
        		
				/* Nicolas */
				var uname = document.getElementById("user");

				
				if($("#name").val()==""){
        			alert("You must enter your First Name");
        			$("#name").focus();
        			return false;
        		}else if($("#lastname").val()==""){
        			alert("You must enter your Last Name");
        			$("#lastname").focus();
        			return false;
        		}else if($("#email").val()=="" || !isEmail($("#email").val())){
        			alert("You must enter a valid Email Address");
        			$("#email").focus();
        			return false;
        		}else if (isEmpty(uname)){
					alert("Please enter a username.");
					uname.select();
					return false;
				}else if (validateUsername(uname.value)!=true){
					alert("Please enter a valid username (letters, numbers, and underscores).");
					uname.select();
					return false;
				}else if($("#pass").val()==""){
        			alert("You must enter your password");
        			$("#pass").focus();
        			return false;
        		}else if($("#cpass").val()==""){
        			alert("You must confirm your password");
        			$("#cpass").focus();
        			return false;

        		}else if($("#pass").val()!=$("#cpass").val()){
        			alert("Passwords didn't match");
        			return false;
        		}else if($("#userExists").val()=="true"){
        			alert("The selected user is already taken. Please choose another one.");
        			return false;
        		}
				

				return true;
        	}

        	function isEmail(Mail) {
        		Mail=Mail.toLowerCase();
        		return (Mail.search(/^([a-z]+)([a-z0-9\-\_\.]{1,100})([a-z0-9]+)\@([a-z0-9]+)([a-z0-9\-\.]*)([a-z0-9]+)\.([a-z]{2,6})$/) != -1);
        	}

        	function susbscribeToNewsletter(){
        		var user_email = $("#subscribe-input").val();
        		if(isEmail(user_email)){
        			$.ajax({
        				 url:'api.php?a=Newsletter',
        				 method: 'POST',
        				 data:'email='+user_email,
        				 success: function (response){
        					if(response=='OK'){
        							alert("Congratulations! From now on you will receive our newsletter!");
        							$("#subscribe-input").val('');
        					}else{
    							if(response=='ERROR'){
    									alert("OOPS... There was an error. Please try again later");
    							}else if(response=='EXISTS'){
									alert("You are already subscribed to our newsletter");

    							}
    						}
        				}       			
        			});
        		}else{
        			alert('Please enter a valid email address!');
        		}
        	}
        	
        	
        	function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
    		{
    		  // the highlightStartTag and highlightEndTag parameters are optional
    		  if ((!highlightStartTag) || (!highlightEndTag)) {
    		    highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
    		    highlightEndTag = "</font>";
    		  }
    		  
    		  // find all occurences of the search term in the given text,
    		  // and add some "highlight" tags to them (we're not using a
    		  // regular expression search, because we want to filter out
    		  // matches that occur within HTML tags and script blocks, so
    		  // we have to do a little extra validation)
    		  var newText = "";
    		  var i = -1;
    		  var lcSearchTerm = searchTerm.toLowerCase();
    		  var lcBodyText = bodyText.toLowerCase();
    		    
    		  while (bodyText.length > 0) {
    		    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    		    if (i < 0) {
    		      newText += bodyText;
    		      bodyText = "";
    		    } else {
    		      // skip anything inside an HTML tag
    		      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
    		        // skip anything inside a <script> block
    		        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
    		          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
    		          bodyText = bodyText.substr(i + searchTerm.length);
    		          lcBodyText = bodyText.toLowerCase();
    		          i = -1;
    		        }
    		      }
    		    }
    		  }
    		  
    		  return newText;
    		}

    				

    		function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
    		{
    		  // if the treatAsPhrase parameter is true, then we should search for 
    		  // the entire phrase that was entered; otherwise, we will split the
    		  // search string so that each word is searched for and highlighted
    		  // individually
    		  if (treatAsPhrase) {
    		    searchArray = [searchText];
    		  } else {
    		    searchArray = searchText.split(" ");
    		  }
    		  
    		  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    		    if (warnOnFailure) {
    		      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    		    }
    		    return false;
    		  }
    		  
    		  var bodyText = document.body.innerHTML;
    		  for (var i = 0; i < searchArray.length; i++) {
    		    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
    		  }
    		  
    		  document.body.innerHTML = bodyText;
    		  return true;
    		}



    		function searchTerm(){
    			highlightSearchTerms($("#search-text").val(), false, true, "<font style='color:#666; background-color:#FFF;'>", "</font>");
    			return false;
    		}

			
			function isEmpty(fld) {
				var txt = fld.value.replace(/ /gi, "");
				emp = false;
				if (txt==""){
					emp = true;
					fld.select();
				}
				return emp;  
			}
			function validateUsername(fld) {
				var illegalChars = /\W/; // allow letters, numbers, and underscores
				
				if ((fld.length < 5) || (fld.length > 15)) {
					alert("The username is the wrong length.\n");
					return false;
				} else if (illegalChars.test(fld)) {
					alert("The username contains illegal characters.\n");
					return false;
				}else if(fld.search(" ")!=-1){
					alert("You can't use spaces in your username!.\n");
					return false;
				}
				return true;
			}
