// JavaScript Document
function unhide(id){
	var i = document.getElementById(id);
	if(i.style.display == "none"){
		i.style.display = "block";
	}else{
		i.style.display = "none";
	}
}

function hide(id){
	unhide(id);
}

function toggleClassDisplay(id){
	$('#' + id).each(function() {
		if($(this).hasClass('hidden')){
			$(this).removeClass('hidden').addClass('shown');
			//console.debug('show hidden');
		} else if($(this).hasClass('shown')){
			$(this).removeClass('shown').addClass('hidden');
			//console.debug('hide other stuff');
		}
	});
}

function showClass(id){
	$('#' + id).each(function() {
		if($(this).hasClass('hidden')){
			$(this).removeClass('hidden').addClass('shown');
		}
	});
}

function hideClass(id){
	$('#' + id).each(function() {
		if($(this).hasClass('shown')){
			$(this).removeClass('shown').addClass('hidden');
		}
	});
}

function disable(id){
	// For disabling buttons (prevent double-click)
	// USAGE: <input type="button/submit" id="myButton" value="" onclick="disable(this);" />
	var element = document.getElementById(id);
	element.disabled = true;
}

function enable(id){
	var element = document.getElementById(id);
	element.disabled = false;
}

function openOverlay(id, w){
	var $div = $('#' + id);
	if(w<=0 || w==null){
		// Use the object's width.
		var width = $div.width();
	}else{
		// Set passed in width instead.
		$div.css({'width' : w});
		var width = w;
	}
		
	var pageWidth = window.innerWidth;
	var offset = (pageWidth - width)/2;
	var css = {
		'position' : 'fixed',
		'left' : offset + 'px',
		'top' : '100px',
		'display' : 'block',
		'z-index' : '1001'
	}
	$div.css(css);
	$('body').append('<div id="fade"></div>');
}

function closeOverlay(){
	$('#fade').remove();
	$('div.overlay:visible').hide();
}
