var n = 0;
var currValues = new Array();
var values  = new Array();
var textFields= new Array();



function populateFields() {

    for (i = 0; i< textFields.length; i++) {
        $(textFields[i][1]).value += ',' + $(textFields[i][0]).value

    }

}

function removeValue(element,valueToRemove) {
    e=$(element);
    e.value = e.value.replace(valueToRemove,"");
}
function addValue(element,valueToAdd) {

    e=$(element);

    e.value += ',' + valueToAdd;
}
function toggleTag(element,value,thisElem){

    s=$(element).value;
    if (s.search(value) == -1) {
         
         addValue(element,value);
         
         thisElem.className = thisElem.className.replace(/unlike/,'like');
         
    } else {

        removeValue(element,value);
        
        thisElem.className = thisElem.className.replace(/like/,'unlike'); 
        
    }
  
 
}

function startLoading(){
 window.loaded = false;
 window.setTimeout('showLoadingImage()', 1000);
}
function showLoadingImage() {

   var el = $("loading_box");
    if (el && !loaded) {
        el.innerHTML = '<img src="/images/loading.gif" height="12">';
        new Effect.Appear('loading_box');
    }
}

function stopLoading() {
        window.loaded = true;
        Element.hide('loading_box');
}
String.prototype.trim = function() {
	return this.replace( /^\s+|\s+$/, "" );
}

function selectAll(a) {
    var theForm = document.myForm;
    for (i=0; i<theForm.elements.length; i++) {
        if (theForm.elements[i].name=='contacts[]')
            theForm.elements[i].checked = a;
    }
}


function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
Ajax.Responders.register({
    onCreate : startLoading,
    onComplete : stopLoading
  });

