function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}
function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

function ajaxObject(url, callbackFunction) {
  var that=this;      
  this.updating = false;
  this.abort = function() {
    if (that.updating) {
      that.updating=false;
      that.AJAX.abort();
      that.AJAX=null;
    }
  }
  this.update = function(passData,postMethod) { 
    if (that.updating) { return false; }
    that.AJAX = null;                          
    if (window.XMLHttpRequest) {              
      that.AJAX=new XMLHttpRequest();              
    } else {                                  
      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
    }                                             
    if (that.AJAX==null) {                             
      return false;                               
    } else {
      that.AJAX.onreadystatechange = function() {  
        if (that.AJAX.readyState==4) {             
          that.updating=false;                
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
          that.AJAX=null;                                         
        }                                                      
      }                                                        
      that.updating = new Date();                              
      if (/post/i.test(postMethod)) {
        var uri=urlCall+'?'+that.updating.getTime();
        that.AJAX.open("POST", uri, true);
        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        that.AJAX.setRequestHeader("Content-Length", passData.length);
        that.AJAX.send(passData);
      } else {
        var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime()); 
        that.AJAX.open("GET", uri, true);                             
        that.AJAX.send(null);                                         
      }              
      return true;                                             
    }                                                                           
  }
  var urlCall = url;        
  this.callback = callbackFunction || function () { };
}
function insertbbcode(field, v, tagadd, tagclose, buttonname, name) { 
    var newname = buttonname+"*";
	if (eval(v)%2 == 0) { 
		eval("window."+name+".value = newname;"); 
		var myValue = tagadd; 
	} else { 
		eval("window."+name+".value = buttonname;"); 
		var myValue = tagclose;
	} 
	eval(v+"++;"); 
	//IE support
	if (document.selection) {
		field.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (field.selectionStart || field.selectionStart == '0') {
		var startPos = field.selectionStart;
		var endPos = field.selectionEnd;
		field.value = field.value.substring(0, startPos)
		+ myValue
		+ field.value.substring(endPos, field.value.length);
	} else {
		field.value += myValue;
	}
}

function hidebox(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}
function showbox(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = '';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = '';
		}
		else { // IE 4
			document.all.id.style.display = '';
		}
	}
}
function startUploads(){
    document.getElementById('upload_processs').style.visibility = 'visible';
    return true;
}
function startUploadb(){
    document.getElementById('upload_processb').style.visibility = 'visible';
    return true;
}

function stopUploads(success){
      var result = '';
      if (success == 1){
         document.getElementById('results').innerHTML =
           '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
      }
      else {
         document.getElementById('results').innerHTML = 
           '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
      }
      document.getElementById('upload_processs').style.visibility = 'hidden';
      return true;   
}
function stopUploadb(success){
      var result = '';
      if (success == 1){
         document.getElementById('resultb').innerHTML =
           '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
      }
      else {
         document.getElementById('resultb').innerHTML = 
           '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
      }
      document.getElementById('upload_processb').style.visibility = 'hidden';
      return true;   
}
function toggleLayer(whichLayer){var elem,vis;if(document.getElementById)
elem=document.getElementById(whichLayer);else if(document.all)
elem=document.all[whichLayer];else if(document.layers)
elem=document.layers[whichLayer];vis=elem.style;if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
vis.display=(elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';vis.display=(vis.display==''||vis.display=='block')?'none':'block';}
function kH(e) {
	var code;
	
	if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	
	if(code==13)
	{
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
		return false;
	}else{
		return true;
	}
}
function catchenter (evt) {
	return kH(evt);
}
var W3CDOM = (document.createElement && document.getElementsByTagName);
function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='/gfx/browse.png';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}
function doyay(yayhash){
	if (window.XMLHttpRequest){
	  window["y_"+yayhash]=new XMLHttpRequest();
	}else{
	  window["y_"+yayhash]=new ActiveXObject('Microsoft.XMLHTTP');
	}
	window["y_"+yayhash].onreadystatechange=function(){
		if (window["y_"+yayhash].readyState==4 && window["y_"+yayhash].status==200){
	    $('#yay_'+yayhash).html(window["y_"+yayhash].responseText);
	  }
	}
	window["y_"+yayhash].open('GET','/ext/yay.php?h='+yayhash,true);
	window["y_"+yayhash].send();
}
function BarUpdate(){
	if (window.XMLHttpRequest){
	  barupd=new XMLHttpRequest();
	}else{
	  barupd=new ActiveXObject('Microsoft.XMLHTTP');
	}
	barupd.onreadystatechange=function(){
		if (barupd.readyState==4 && barupd.status==200 && barupd.responseText == 'LOGOUT'){
			top.location.href='/';
	  } else if (barupd.readyState==4 && barupd.status==200){
	    $('#barwrap').html(barupd.responseText);
	  }
	}
	barupd.open('GET','/ext/bars.php',true);
	barupd.send();
}
function FetchModule(whatfile,whereid){
	if (window.XMLHttpRequest){
	  window["m_"+whereid]=new XMLHttpRequest();
	}else{
	  window["m_"+whereid]=new ActiveXObject('Microsoft.XMLHTTP');
	}
	window["m_"+whereid].onreadystatechange=function(){
		if (window["m_"+whereid].readyState==4 && window["m_"+whereid].status==200){
	    $('#'+whereid).html(window["m_"+whereid].responseText);
	  }
	}
	window["m_"+whereid].open('GET','/ext/'+whatfile+'.php',true);
	window["m_"+whereid].send();
}
