/*Globals*/
var DOMType = ""; //For browser specific checks
var teir2 = false; //False == The teir isn't opened yet.
var teir3 = false; //False == The teir isn't opened yet.
var teir4 = false; //False == The teir isn't opened yet.
var waiting = false; //Is there an Ajax call in progress?


// this function is needed to work around a bug in IE related to element attributes
function hasClass(obj) {var result = false;if (obj.getAttributeNode("class") != null) {result = obj.getAttributeNode("class").value;}return result;}

//Zebra stripes for tables!//Thanks! http://www.alistapart.com/d/stripedtables/script.txt
function stripe(id) {var even = false;
var evenColor = arguments[1] ? arguments[1] : "#663333";
var oddColor = arguments[2] ? arguments[2] : "#996666";
var table = document.getElementById(id);
if (! table) { return; }
var tbodies = table.getElementsByTagName("tbody");
for (var h = 0; h < tbodies.length; h++) {
var trs = tbodies[h].getElementsByTagName("tr");
for (var i = 0; i < trs.length; i++) {
if (! hasClass(trs[i]) &&
! trs[i].style.backgroundColor) {
var tds = trs[i].getElementsByTagName("td");
for (var j = 0; j < tds.length; j++) {
var mytd = tds[j];
if (! hasClass(mytd) &&
! mytd.style.backgroundColor) {
mytd.style.backgroundColor =
even ? evenColor : oddColor;
}}}even =  ! even;}}}

function confirmSubmit()
{
var agree=confirm("Are you sure you wish to continue?");
if (agree)
	return true ;
else
	return false ;
}

function confirmDelete()
{
var agree=confirm("Are you sure you wish to delete this?");
if (agree)
	return true ;
else
	return false ;
}

function popUp(URL, imgWidth, imgHeight) {
imgWidth = imgWidth + 15;
imgHeight = imgHeight + 15;
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=1,statusbar=1,menubar=0,resizable=1,width=' + imgWidth + ',height=' + imgHeight + ',left = 50,top = 50');");
}

function popUpRestrict(URL, imgWidth, imgHeight) {
imgWidth = imgWidth + 15;
imgHeight = imgHeight + 15;
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=' + imgWidth + ',height=' + imgHeight + ',left = 50,top = 50');");
}


function detectDOM(){ //ah the joys of browser specifics
	if (document.layers){
		DOMType = "layers";
	}
	else if (document.all){
		DOMType = "all";
	}
	else if (document.getElementById){
		DOMType = "EBI";
	}
}


/*Ajax Handlers Below This Line*/
//
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

function newAlbum(object){
	var theObjectValue = object.value;
	if (theObjectValue == "new"){
		document.getElementById('newAlbumDiv').innerHTML = "<input type='text' name='album' value='Album Name' />";
	}else{
		document.getElementById('newAlbumDiv').innerHTML = "";
	}
}

function deleteEvent(){
	if (confirmDelete()){
		$("#formAction").attr("value", "deleteEvent");
		$("#theEditForm").submit();
	}
}

/*jQuery Goodies*/
	/*
	* jGrow 0.2
	* 08.02.2008
	* 0.2 release: 04.03.2008
	*/
(function($) {
	$.fn.jGrow = function(options) {
		var opts = $.extend({}, $.fn.jGrow.defaults, options);
		return this.each(function() {
			$(this).css({ overflow: "hidden" }).bind("keypress", function() {
				$this = $(this);
				var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
				if(o.rows == 0 && (this.scrollHeight > this.clientHeight)) {
					this.rows += 1;
				} else if((this.rows <= o.rows) && (this.scrollHeight > this.clientHeight)) {
					this.rows += 1;
				} else if(o.rows != 0 && this.rows > o.rows) {
					$this.css({ overflow: "auto" });
				}
				$this.html();
			});
		});
	}
	$.fn.jGrow.defaults = { rows: 0 };
})(jQuery);