function in_array(needle,haystack,strict){
 var strict=!!strict;
 for( var key in haystack){
  if((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)){
   return true;
  }
 }

 return false;
}

var PROTOTYPE_LOADED=typeof Prototype == 'object';
var MOOTOOLS_LOADED=typeof MooTools == 'object';

function setActiveStyleSheet(title,user_id){
 var i,a,main,current;
 var titles=['blue','gray','green','white','orange'];
 for(i=0;(a=document.getElementsByTagName("link")[i]);i++){
  if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")
    && in_array(a.getAttribute("title"),titles)){
   if(!a.disabled)
    current=a.getAttribute('title') + 'theme';
   a.disabled=true;
   if(a.getAttribute("title") + 'theme' == title)
    a.disabled=false;
  }
 }
 var classes=['l','row1_','row2_','quoteclass_','border_','H','','menu_bg_','STH_menu_bg_',
   'overlay'];
 var elements;
 for( var i=0;cls=classes[i],i < classes.length;++i){
  elements=$$('.' + cls + current);
  for( var j=0;el=elements[j],j < elements.length;++j){
   if(PROTOTYPE_LOADED){
    Element.removeClassName(el,cls + current);
    Element.addClassName(el,cls + title);
   }else if(MOOTOOLS_LOADED){
    Element.removeClass(el,cls + current);
    Element.addClass(el,cls + title);
   }
  }
 }
 var request='/changeTheme.php?t=' + title + '&u=' + user_id;
 if(PROTOTYPE_LOADED)
  new Ajax.Request(request);
 else if(MOOTOOLS_LOADED)
  new Request({
   url :request
  }).send();
}
function FindDateFilter(start,end,url,form){
 var extra='?';
 var action=url || 'find.php';
 var form=form || document.form1;
 if(action.indexOf('?') > -1)
  extra='';
 if(start && !start.disabled && start.value)
  extra+='&start=' + start.value;
 if(end && !end.disabled && end.value)
  extra+='&end=' + end.value;
 form.action=action + extra;
 form.submit();
}
function stretchBody(){
 var H=0;
 with(document){
  if(window.innerHeight)
   H=window.innerHeight;
  else if(document.documentElement && documentElement.clientHeight)
   H=documentElement.clientHeight;
  else
   H=body.offsetHeight;
 }
 try{
  if($('stretchBody').disabled)
   return;
 }catch(e){}
 var con=$('auto_content');
 if(!con)
  return;
 if (PROTOTYPE_LOADED){
  Element.setStyle(con,{
   paddingBottom: '5px'
  });
 }else if (MOOTOOLS_LOADED){
  con.setStyle('padding-bottom', 5);
 }
 var bdH = 0;
 var body=$('body')?$('body'):$$('body')[0];
 var footer='foo_info';
 if(PROTOTYPE_LOADED){
  bdH=Element.getDimensions(body).height;
  bdH+=Element.getDimensions(footer).height;
 }else if(MOOTOOLS_LOADED){
  bdH=parseInt(body.getSize().y);
  bdH+=parseInt($(footer).getSize().y);
 }else{
  return;
 }
 if(bdH < H){
  var btPad=H - bdH;
  if (PROTOTYPE_LOADED){
   Element.setStyle(con,{
    paddingBottom: btPad + 'px'
   });
  }else if (MOOTOOLS_LOADED){
   con.setStyle('padding-bottom', btPad);
  }
 }
}
function toggleLogin_ForgetPasswordForms(){
 var lfs=$$('.login_area');
 if(PROTOTYPE_LOADED)
  lfs.each(Element.toggle);
 else if(MOOTOOLS_LOADED)
  lfs.each( function(lf){
   lf.setStyle('display','none' == lf.getStyle('display')?'block':'none')
  });
}

function switchSearchField_active(field,defaultText){
 if(field.value==defaultText)field.value='';
 if(PROTOTYPE_LOADED){
  Element.addClassName(field,'active');
 }else if(MOOTOOLS_LOADED){
  Element.addClass(field,'active');
 }
}
function switchSearchField_notactive(field,defaultText){
 if(field.value==''){
  field.value=defaultText;
  if(PROTOTYPE_LOADED){
   Element.removeClassName(field,'active');
  }else if(MOOTOOLS_LOADED){
   Element.removeClass(field,'active');
  }
 }
}
