var XMLHttpRequestObject = false;

if( window.XMLHttpRequest ) {
	XMLHttpRequestObject = new XMLHttpRequest();
} else if ( window.ActiveXObject) {
	XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function getData( dataSource, divID ){
	if( XMLHttpRequestObject ) {
		var obj = document.getElementById(divID);
		XMLHttpRequestObject.open("GET", dataSource);
		
		XMLHttpRequestObject.onreadystatechange = function() {
			if( XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200 ) {
				obj.innerHTML = XMLHttpRequestObject.responseText;
			}
		}
		
		XMLHttpRequestObject.send(null);
	}
}

function deleteConfirm(stripID) {
 var agree = confirm('Are you sure you want to delete this comic?');
	if ( agree ){
		location.href = 'login.php?mode=delete&sid=' + stripID;
	}
}
	
function hideshow( id, action ) {
	if ( action == 'hide' ) {
		document.getElementById(id).style.display = 'none';
	} else {
		document.getElementById(id).style.display = 'block';
	}
}

function sidebarCollapse(id){
	var obj = document.getElementById(id);
	if( obj.style.display == 'none' ){
		var action = 'show';
		var link = 'hide';
		var groupClass = 'group';
	} else {
		var action = 'hide';
		var link = 'show';
		var groupClass = 'group_closed';
	}
	hideshow( id, action );
	var groupID = id + '_group';
	document.getElementById(groupID).className = groupClass;
	var linkID = id + '_showhide';
	document.getElementById(linkID).innerHTML = link;
}

function toggleVisibility(id,action) {
	var obj = document.getElementById(id);
	if ( action == 'off' ) {
		obj.style.visibility = 'hidden';
	} else {
		obj.style.visibility = 'visible';
	}
}

function tdbg( id ) {
	var radioid = 'radio' + id;
	var tdid = 'td' + id;
	if( document.getElementById(radioid).checked == true ) {
		document.getElementById(tdid).style.background='red';
	} else {
		document.getElementById(tdid).style.background='none';
	}
}

function reverseContentDisplay(d) {
	if( d.length < 1 ) { return; }
	if(document.getElementById(d).style.display == 'none') {
		document.getElementById(d).style.display = 'block'; 
	} else { 
		document.getElementById(d).style.display = 'none';
	}
}

function viewStrip(source,strip_id){
	document.getElementById('large_image').src = source;
	toggleVisibility('large_div','on');
	toggleVisibility('shade','on');
	location.href = '#top';
	sid = strip_id;
}

function closeStrip(){
	toggleVisibility('large_div','off');
	toggleVisibility('shade','off');
	document.getElementById('large_image').src = '';
	location.href = '#' + sid;
}

$(function(){
	$('#info_toggle').click(function(event){
		$('#extra_info').slideToggle(500);
		if( $(this).html() == 'Hide Info' ){
			$(this).html('Show Info');
		} else {
			$(this).html('Hide Info');
		}
		$(this).disableSelection();
		event.preventDefault();
	});
});