var ROOTURL="http://www.bigedd.com/";

function roll_over(image_id,change_to) {
   var this_img=document.getElementById(image_id);
   this_img.src=ROOTURL+change_to;
}
function post_form($form_id){document.getElementById($form_id).submit();}
function add_event($object,$type,$fn){ 
   if($object.attachEvent){ 
      $object['e'+$type+$fn] = $fn; 
      $object[$type+$fn] = function(){$object['e'+$type+$fn]( window.event );} 
      $object.attachEvent( 'on'+$type, $object[$type+$fn] ); 
   }else{
      $object.addEventListener($type,$fn,false); 
   }
}
function remove_event($object,$type,$fn){
   if($object.detachEvent){
      $object.detachEvent('on'+$type,$object[$type+$fn]);
      $object[$type+$fn]=null;
   }else{
      $object.removeEventListener($type,$fn,false);
   }
} 
function elements_with_class($elem,$tag_name,$class_name){
   var $arr_elems=($tag_name=="*" && document.all)? document.all : $elem.getElementsByTagName($tag_name);
   var $found = new Array();
   for($i=0;$i<$arr_elems.length;$i++){  
      if($arr_elems[$i].className==$class_name) $found.push($arr_elems[$i]);
   }
   return ($found);
}
function http_location($filename){
   window.location=$filename;
}
function confirm_action($message,$url) {
	var $answer=confirm($message);
	if($answer)window.location($url);
}
function picture_window($url,$width,$height,$window) {
   window.open($url+'&width='+$width+'&height='+$height,$window,"width="+$width+",height="+$height+",scrollbars=no,left=100,top=100");
}
function external_links(){
   if (!document.getElementsByTagName) return;
   var anchors = document.getElementsByTagName("a");
   for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")anchor.target = "_blank";
   }
}

function view_info_panel($id){
   $panel=document.getElementById($id);
	 if(!$panel)return false;
	 if($panel.style.display=='none' || !$panel.style.display){
	    $panel.style.display='block';
	 }else{
	    $panel.style.display='none';
	 }
}


function chop_text($textarea){
   $maxlen=$textarea.getAttribute("maxlength");
	 $curlen=$textarea.value.length;
	 if($curlen>$maxlen) {
	    $textarea.value=$textarea.value.substring(0,$maxlen);
   }
	 $left=$maxlen-$curlen;
	 if($left<0) { $left=0; }
	 document.getElementById("count").firstChild.nodeValue=$left;
	 document.getElementById("maxleft").firstChild.nodeValue='left';
}


function ajax_edd_search(){
   $keyword=document.getElementById('searchfor').value;
   $url=ROOTURL+'inc/ajax/edd_search.php?keyword='+$keyword;
   ajax_do(ajax_init(),$url,show_search_results,'GET');
}

function show_search_results($xh_obj){
   $response=$xh_obj.responseText;

	 $profiles=$response.split(',');

   $black=elements_with_class(document,"*",'black highlight');
	 for($i=0;$i<$black.length;$i++){ $black[$i].className='black'; }

   $purple=elements_with_class(document,"*",'purple highlight');
	 for($i=0;$i<$purple.length;$i++){ $purple[$i].className='purple'; }
	 
   $green=elements_with_class(document,"*",'green highlight');
	 for($i=0;$i<$green.length;$i++){ $green[$i].className='green'; }
	 
   $grey=elements_with_class(document,"*",'grey highlight');
	 for($i=0;$i<$grey.length;$i++){ $grey[$i].className='grey'; }
	 
	 if($response=='none'){
	    document.getElementById('searchresultbox').style.display='block';
      document.getElementById('searchresultbox').firstChild.nodeValue='No results found';
			document.getElementById('searchresultbox').style.color='#FF0000';
	    return false;
	 }
	 
	 
   for($i=0;$i<$profiles.length;$i++){
	    $li=document.getElementById('playeringrid'+$profiles[$i]);
	    $li.className=$li.className+' highlight';
	 }
	 $results=$profiles.length;
	 document.getElementById('searchresultbox').style.display='block';
	 document.getElementById('searchresultbox').firstChild.nodeValue=$results+' result(s) found. The search matches are highlighted with red borders in the grid.';
	 document.getElementById('searchresultbox').style.color='#87c540';
	 
}
