function get(id){
	return document.getElementById(id);
}

Array.prototype.indexOf = function(search){
	for(var i=0; i<this.length; i++){
		if(this[i]==search)
			return i;
	}
	
	return -1;
}


Object.prototype.isBlank = function(){
	if(this=='&nbsp;' || (this.length==1 && this.charCodeAt(0)==160))
		return true;
	else
		return this.match(/^\s*$/);
}

Object.prototype.validDate = function(){
	var parts = this.split('/');
	
	if(parts.length < 2 || parts.length > 3 || !parts[0].match(/^\d+$/) || !parts[1].match(/^\d+$/) || parts[0] > 12 || parts[1] > 31 || (parts.length > 2 && !parts[2].match(/^\d+$/)))
		return false;
		
	return true;
}

Object.prototype.escapeQuotes = function(){
	return this.replace(/"/g, '&quot;');
}


// IE does not recognize this when used on an Object created by document.createElement 
// haven't found a work-around yet... T_T
// MORE IE lameness! =/
Object.prototype.getElementById = function(id){ 			
	return getElementById(this, id);
}

function getElementById(obj, id){
	if(obj.getElementsByTagName && obj.getAttribute){
		var tags = obj.getElementsByTagName("*");
		for(var i=0; i<tags.length; i++)
			if(tags[i].getAttribute("id") == id)
				return tags[i];
	}
}



// IE is retarded and doesn't support Object.prototype to be used on Form type object, so we have this dumb code
Object.prototype.addHiddenInput = function(name, value){
	return addHiddenInput(this, name, value);
}

function addHiddenInput(form, name, value){
	var elm 	= document.createElement('input');

	elm.type	= 'hidden';
	elm.name  	= name;
	elm.value	= value;

	form.appendChild(elm);
}

function tabOver(elm){
	var div = elm.childNodes[0];
	
	if(div.className=='teacherTab')
		div.className = 'teacherTabOver';
	else if(div.className=='teacherTabOver')
		div.className = 'teacherTab';
}

function getRadioValue(obj){
	for(var i=0; i<obj.length; i++)
		if(obj[i].checked)
			return obj[i].value;
			
	return false;
}

function setRadioValue(obj, value){
	for(var i=0; i<obj.length; i++)
		if(obj[i].value==value)
			obj[i].checked = true;
}

function getElementsByClassName(className, tag, elm){
	var regex 			= new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag 			= tag || "*";
	var elm 			= elm || document;
	var elements 		= (tag == "*" && elm.all) ? elm.all : elm.getElementsByTagName(tag);
	var returnElements 	= [];
	
	for(var i=0; i<elements.length; i++)
		if(elements[i].className.match(regex))
			returnElements.push(elements[i]);
	
	return returnElements;
}

function addOnload(func){
	if(window.addEventListener)
		window.addEventListener('load', func, false);
	else if(window.attachEvent)
		window.attachEvent('onload', func);
	else if(document.getElementById)
		window.onload = func;
}
