// JavaScript Document

//the show/hide windows

var shown = [];

function showChecked(id){
	if(this.checked == true){
		var div = document.getElementById(id);
		div.style.display='block';
	} else {
		var div = document.getElementById(id);
		div.style.display='none';
	}
}

function showPointerDiv(type) {
	//make sure array key has been defined - if not = false
	if(window.shown[type] == undefined){
		shown[type] = false;	
	}
	if(!shown[type]){
		var div = document.getElementById(type);
		div.style.display='block';
		shown[type] = true
	} else {
		hidePointerDiv(type);
	}
}
function hidePointerDiv(type){
	var div = document.getElementById(type);
	div.style.display='none';
	shown[type] = false;
}

function popUp(theURL,winName,features) {
  window.open(theURL,winName,features);
}

/*links functions*/
function selectAll(id){
	document.getElementById(id).focus();
	document.getElementById(id).select();
}
function maxChars(m_chars, id){
	if(document.getElementById(id).length > m_chars){
		alert("shit!")
	}
}

/* forum functions*/
function setReadOnly(id){
	document.getElementById(id).readOnly=true;
}
function unsetReadOnly(id){
	document.getElementById(id).readOnly=false;
}
function addFrownie(post, key){
	document.forum_post.elements[post].value += " "+key+" ";
	/*document.forum_post.elements[post].focus();*/
	return;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
// sort function - ascending (case-insensitive)
function sortAsc(r1, r2) {
    var v1 = r1.optText.toLowerCase();
    var v2 = r2.optText.toLowerCase();
    if (v1 > v2) return(1);
    if (v1 < v2) return(-1);
    return(0);
}

function jumpToURL(surl) {
	window.location.href = surl;
}

/*	HIDE SHOW	*/

function hideShow(hide, show){
	
	this.hide = new Array(true, hide);
	this.show = new Array(false, show);
	
	this.swap = function(){
		if(this.hide[0]){
			this.showIt(this.hide);
			this.hideIt(this.show);
			this.hide[0] = false;
			this.show[0] = true;
		} else {
			this.showIt(this.show);
			this.hideIt(this.hide);
			this.hide[0] = true;
			this.show[0] = false;
		}
	}
	this.hideIt = function(type){
		var hide = document.getElementById(type[1]);
		hide.style.display = "none";
	}
	this.showIt = function(type){
		var hide = document.getElementById(type[1]);
		hide.style.display = "block";
	}
}

/*	GREY OUT	*/

function greyOut(){
	
	this.onoff = false;
	this.form_id = 0;
	this.oldColor = "";
	this.newColor = "#222222";
	this.oldTextColor = "";
	this.newTextColor = "#323232";
	
	
	this.setForm = function($form_id){
		this.form_id = $form_id;
	}
	
	this.grey = function($form_id){
		this.setForm($form_id);
		if(this.onoff){
			this.onoff = false;
			this.disableGreyOut();
		} else {
			this.onoff = true;
			this.enableGreyOut();	
		}
	}
	
	/*define the functions*/
	this.enableGreyOut = function() {
		var $theForm = document.forms[this.form_id];
		
		for($i=0; $i<$theForm.elements.length; $i++){
			if($theForm.elements[$i].type == "text" || $theForm.elements[$i].type == "textarea" || $theForm.elements[$i].type == "submit"){
				this.oldColor = $theForm.elements[$i].style.backgroundColor;
				$theForm.elements[$i].style.backgroundColor = this.newColor;
				$theForm.elements[$i].disabled = 'disabled';
			}
			this.oldTextColor = $theForm.elements[$i].style.color;
			$theForm.elements[$i].style.color = this.newTextColor;
		}
	}
	this.disableGreyOut = function() {
		var $theForm = document.forms[this.form_id];
		for($i=0; $i<$theForm.elements.length; $i++){
			if($theForm.elements[$i].type == "text" || $theForm.elements[$i].type == "textarea" || $theForm.elements[$i].type == "submit"){
				this.newColor = $theForm.elements[$i].style.backgroundColor;
				$theForm.elements[$i].style.backgroundColor = this.oldColor;
				$theForm.elements[$i].disabled = '';
			}
			this.newTextColor = $theForm.elements[$i].style.color;
			$theForm.elements[$i].style.color = this.oldTextColor;
		}
	}
}