function share_obj(t) 
{
  $('lb').style.display='block'; 
  $('share').style.display='block';
  new Ajax.Autocompleter("ac", "acc", "include/ajaxscripts/get-friends-info.php", {paramName: "input", minChars: 2, indicator: 'indicator1', updateElement: updateInput});
}

function autoSearch() 
{
  $('temp_alert').hide();
  new Ajax.Autocompleter("as", "ashd", "include/ajaxscripts/get-groups-auto-complete.php", {paramName: "q", minChars: 2, indicator: 'indicator1'});
}

function autoSearchGK() 
{
  $('temp_alert').hide();
  new Ajax.Autocompleter("as", "ashd", "include/ajaxscripts/get-groups-auto-complete.php", {paramName: "qgk", minChars: 2, indicator: 'indicator1'});
}

function toggleCategories() 
{
  var hiddenCategories = $('left-nav').select('ul.finder li.hidden'); 
	for (i = 0; i < hiddenCategories.length; i++) {
	   hiddenCategories[i].toggle();
	}   
  	  
  if ($('more-category-label').innerHTML == 'more') {
    $('more-category-label').innerHTML = 'less';
    $('more-category-label').style.background = "url('../img/icons/Arrow-Up-Disabled-16.gif') right no-repeat";
   /* $('more-category-label').hover(function() {
      $('more-category-label').style.color = '#333';
      $('more-category-label').style.background = "url('../img/icons/Arrow-Up-Enabled-16.gif') right no-repeat";
    }); */
  } else {
    $('more-category-label').innerHTML = 'more';
    $('more-category-label').style.background = "url('../img/icons/Arrow-Down-Disabled-16.gif') right no-repeat";
    /* $('more-category-label').hover(function() {
      $('more-category-label').style.color = '#333';
      $('more-category-label').style.background = "url('../img/icons/Arrow-Down-Enabled-16.gif') right no-repeat";
    }); */
  } 
}

/* search buttons */
function submit_search()
{
  var sform = $('hsearchform');
  var sformInput = $('sq-small');
  if(sformInput.value!=""){
    sform.submit();
  }else{
    sform.focus();
  }
  
  return;
}

function share_hide(t) {
  $('lb').hide();
  $('share').hide();
}

function helpDialogBox(t){
      
    var x = Event.pointerX(event);
    var y = Event.pointerY(event);
    var option = {};
    option['class'] = "small-dialog-box";
    var dialogBox = new Element('div', option );
    dialogBox.innerHTML = '<img src="../img/indicator.gif" /><br />Loading...';
    dialogBox.setStyle({
      left: x +'px',
      top: y + 'px'
    });
    
    new Element.insert('body', dialogBox);
    /*
    new Ajax.Request('<?= $CONFIG['baseurl']; ?>/include/ajaxscripts/help', {
      parameters: {
        id: t,
        key: '<?= cp_key_prepare('include/ajaxscripts/help'); ?>'
      },
      onSuccess: function (transport) {
        $('').innerHTML = 'Unsubscribe';
        new Insertion.Top('myTopicList', '<li id="page-' + id + '-subscribed" class="current new"><a class="subscriptions" href="<?= $CONFIG['baseurl']; ?>/page/' + id + '">' + name + '</a></li>');
      }
    });
    */
}

function getCapsLockState(e,loc) 
{
    
  if (e.keyCode) { //IE
    var keynum = e.keyCode;
  } else if (e.which) { // Netscape/Firefox/Opera
    var keynum = e.which;
  }

  // get shift status
  var shift_status = false;
  if (e.shiftKey) {
    shift_status = e.shiftKey;
  } else if (e.modifiers) {
    shift_status = !!(e.modifiers & 4);
  }
   
  //shift_status is true if the shift key is pressed
  if (((keynum >= 65 && keynum <= 90) && !shift_status) || 
  ((keynum >= 97 && keynum <= 122) && shift_status)) {
    //show warning
    $(loc).show();
  } else {
    //hide warning
    $(loc).hide();
  }
}

function calendar_until_change(dd) {
  if (dd.value > 1) t = getStyle('form-repeat','display');
  else t = 'none';
  document.getElementById('form-until').style.display = t;
}
function calendar_add_until_change(dd, i) {
  if (dd.value > 1) t = getStyle('row1','display');
  else t = 'none';
  document.getElementById('until'+i).style.display = t;
}

function getStyle(el,styleProp) {
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function hearts_click(i, s) {
  hearts_clicked = 1;
  hearts_update(i, s, 1);
  return false;
}
function hearts_update(i, s, direct) {
  var l, r;
  if (!hearts_clicked || direct) {
    document.forms[0].hearts.value = i;
    if (s == 1) document.forms[0].hearts.value -= 0.5;
    for (j = 1; j < 6; j++) {
      l = "/styles/heart_big_left_on.gif";
      r = "/styles/heart_big_right_on.gif";
      if (i < j) {
        l = "/styles/heart_big_left_off.gif";
        r = "/styles/heart_big_right_off.gif";
      } else if (i == j) { 
        if (s == 1) {
          r = "/styles/heart_big_right_off.gif";
        }
      }
      document.getElementById('heartsl'+j).src = l;
      document.getElementById('heartsr'+j).src = r;
    }
  }
}
function p_toggle(id) {
  if (document.getElementById(id).style.display == 'block') {
    document.getElementById(id).style.display = 'none';
  } else {
    document.getElementById(id).style.display = 'block';
  }
  return false;
}
function polls_edit_updatetype(dd) {
  if (dd.value > 1) t = getStyle('form-poll_edit_add-type','display');
  else t = 'none';
  for (i = 1; i <= 5; i++) {
    document.getElementById('form-poll_edit_add-option'+i).style.display = t;
  }
}
var quicksearch_sto = 'brandnew';
function swap_divs(a, b) {
  document.getElementById(b).style.display = 'block';
  document.getElementById(a).style.display = 'none'; 
  return false;
}
function tag_add() {
  xajax_tag_change(-1, document.getElementById('quicksearch').value, 4, tag_allowuser);
  document.getElementById('tagsel').scrollTop = 0;
  document.getElementById('quicksearch').disabled = false;
}
function tag_check(that, id) {
  document.getElementById('tag_ind').style.visibility = 'visible';
  if (that.checked) {
    document.getElementById('tagsel_hidden').value = id;
    that.checked = false;
    xajax_tag_change(id, document.getElementById('quicksearch').value, 1, tag_allowuser);
  } else {
    document.getElementById('quicksearch').disabled = false;
    document.getElementById('tagsel_hidden').value = 0;
    xajax_tag_change(id, document.getElementById('quicksearch').value, 2, tag_allowuser);
  }
  document.getElementById('tagsel').scrollTop = 0;
}
function tag_change(that,timer) {
  if (quicksearch_sto != document.getElementById('quicksearch').value) {
    quicksearch_sto = document.getElementById('quicksearch').value;
    document.getElementById('tag_ind').style.visibility = 'visible';
    xajax_tag_change(document.getElementById('tagsel_hidden').value, document.getElementById('quicksearch').value, 3, tag_allowuser);
    document.getElementById('tagsel').scrollTop = 0;
  }
  if (timer) setTimeout('tag_change(0,true);', 1000);
  return false;
}
function tag_onkeydown(e) {
  if (e.keyCode == 13 && tag_quicksearch_hasfocus) return false;
}
function tag_init(a) {
  tag_quicksearch_hasfocus = false;
  tag_allowuser = a;
  document.onkeydown = tag_onkeydown;
  setTimeout('tag_change(0,true);', 1000);
}


/* set star rating and update an input with value */ 
function setRating(rating, starElement, inputElement, msgElement) 
{
  $(starElement).style.width = rating * 20 + '%';
  $(inputElement).value = rating;
  
  if (rating == 1) 
  {
    $(msgElement).style.background = '#fdd';
    $(msgElement).style.border = '1px solid #b66';
    $(msgElement).innerHTML = 'Poor';
  }
  else if (rating == 2) 
  {
    $(msgElement).style.background = '#ffd';
    $(msgElement).style.border = '1px solid #bb6';
    $(msgElement).innerHTML = 'Fair';
  }
  else if (rating == 3) 
  {
    $(msgElement).style.background = '#f4f9fe';
    $(msgElement).style.border = '1px solid #c8e2fc';
    $(msgElement).innerHTML = 'Good';
  }
  else if (rating == 4) 
  {
    $(msgElement).style.background = '#dfd';
    $(msgElement).style.border = '1px solid #6b6';
    $(msgElement).innerHTML = 'Excellent';
  }
  else if (rating == 5) 
  {
    $(msgElement).style.background = '#8f8';
    $(msgElement).style.border = '1px solid #6b6';
    $(msgElement).innerHTML = 'Phenomenal';
  } 
  else 
  {
    $(msgElement).style.background = '#fdd';
    $(msgElement).style.border = '1px solid #b66';
    $(msgElement).innerHTML = 'Error Registering Rating';
  }
}

function popup(url, name, set)
{
  var newWindow, size;

  if (set = 'sm') {
    size = 'height=100,width=600';
  } 
   
  if (set = 'med') {
    size = 'height=200,width=600';
  } 
  
  if (set = 'lg') {
    size = 'height=300,width=600';
  }
  
  if (set = 'full') {
		size = 'height=480,width=600,resizable=1,scrollbars=1,location=1';
  } else {
		if (!size) {
	    size = 'height=200,width=600';
	  }
	  
		size = size + ',resizable=false,toolbar=false,location=false,menubar=false';
	}

  newWindow = window.open(url, 'name', size);
  if (window.focus) {
    newWindow.focus();
  }
} 

/* functions used for dynamic forms (central nav) */
function in_array( needle, haystack )
{
  for( var i = 0; i < haystack.length; i++ )
  {
    if( needle == haystack[i] ) return true;
  }
  return false;
}
