//JQ
$(document).ready(function() {
						   
	
	// Delete Confirmatin Link
	$('.deleteConfirm').click(function() {
		var link = $(this).attr('href');
	
		$('<div><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>This will be permanently deleted and cannot be recovered. Are you sure?</div>').dialog({
			title: $(this).attr('title'),
			resizable: false,
			modal : true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				'Delete': function() {
				$(this).dialog('close').remove();
				location.replace(link);
			},
			'Cancel': function() {
				$(this).dialog('close').remove();
				return false;
			}
		}
	});
	
	return false;
	});


	

	//toggle
	$('.gameList').find('.details').hide().end().find('h2').click(function() {
		$(this).next().slideToggle(1000);
		$(this).children(".arrow").toggle();
	});
		
	$('#OPsystem_id').change(function(){
		var system_id = "system_id="+$("select#OPsystem_id").val(); 
		//alert (dataString);return false;  
		$.ajax({  
			type: "POST",  
			url: "/inc/getOpenGames.php",  
			dataType: 'html',
			data: system_id,  
			beforeSend: function(){
				$('#openGamesQ').html("<center><br /><br /><br /><img src='http://mydndgame.com/img/load.gif' alt='Loading...' /></center>");
			},
			success: function(html) {  
				$('#openGamesQ').html(html);  
				$('.gameList').find('.details').hide().end().find('h2').click(function() {
					$(this).next().slideToggle(1000);
					$(this).children(".arrow").toggle();
				});
			},
			error: function(){
				$('#openGamesQ').html("An error has occurred.");
			}			
		});
	});
	
	$('#Csystem_id').change(function(){
		var system_id = "system_id="+$("select#Csystem_id").val(); 
		//alert (dataString);return false;  
		$.ajax({  
			type: "POST",  
			url: "/inc/getCampaigns.php",  
			dataType: 'html',
			data: system_id,  
			beforeSend: function(){
				$('#campaignsQ').html("<center><br /><br /><br /><img src='http://mydndgame.com/img/load.gif' alt='Loading...' /></center>");
			},
			success: function(html) {  
				$('#campaignsQ').html(html);  
				$('.gameList').find('.details').hide().end().find('h2').click(function() {
					$(this).next().slideToggle(1000);
					$(this).children(".arrow").toggle();
				});
			},
			error: function(){
				$('#campaignsQ').html("An error has occurred.");
			}			
		});
	});
	
	$('#MyCsystem_id').click(function(){
		var my = "my="+$("input#my").val(); 
		$.ajax({  
			type: "POST",  
			url: "/inc/getCampaigns.php",  
			dataType: 'html',
			data: my,  
			beforeSend: function(){
				$('#campaignsQ').html("<center><br /><br /><br /><img src='http://mydndgame.com/img/load.gif' alt='Loading...' /></center>");
			},
			success: function(html) {  
				$('#campaignsQ').html(html);  
				$('.gameList').find('.details').hide().end().find('h2').click(function() {
					$(this).next().slideToggle(1000);
					$(this).children(".arrow").toggle();
				});
			},
			error: function(){
				$('#campaignsQ').html("An error has occurred.");
			}			
		});
	});
	
	$('#Chsystem_id').change(function(){
		var system_id = "system_id="+$("select#Chsystem_id").val(); 
		//alert (dataString);return false;  
		$.ajax({  
			type: "POST",  
			url: "/inc/getCharacters.php",  
			dataType: 'html',
			data: system_id,  
			beforeSend: function(){
				$('#charactersQ').html("<center><br /><br /><br /><img src='http://mydndgame.com/img/load.gif' alt='Loading...' /></center>");
			},
			success: function(html) {  
				$('#charactersQ').html(html);  
				$('.gameList').find('.details').hide().end().find('h2').click(function() {
					$(this).next().slideToggle(1000);
					$(this).children(".arrow").toggle();
				});
			},
			error: function(){
				$('#charactersQ').html("An error has occurred.");
			}			
		});
	});
	
	$('#MyChsystem_id').click(function(){
		var my = "my="+$("input#my").val(); 
		$.ajax({  
			type: "POST",  
			url: "/inc/getCharacters.php",  
			dataType: 'html',
			data: my,  
			beforeSend: function(){
				$('#charactersQ').html("<center><br /><br /><br /><img src='http://mydndgame.com/img/load.gif' alt='Loading...' /></center>");
			},
			success: function(html) {  
				$('#charactersQ').html(html);  
				$('.gameList').find('.details').hide().end().find('h2').click(function() {
					$(this).next().slideToggle(1000);
					$(this).children(".arrow").toggle();
				});
			},
			error: function(){
				$('#charactersQ').html("An error has occurred.");
			}			
		});
	});



	$('#userInfo li.headlink,#nav1 li.headlink').hover(
		function() { $('ul', this).slideToggle('fast'); },
		function() { $('ul', this).slideToggle('fast'); 
	});

	$("#sortMain,#sidebar").sortable({
		placeholder: 'ui-state-highlight',
		axis: 'y',
		cursor: 'move',
		revert: true
	});
	
	$("div#ui-tabs-13 div#messageBoard .inside a").click(function(){
		alert ('Yes');return false;  
	});


	//&section=board&func=topic&ID=240
});



//Toggle Divs

function toggleDiv(div)
{
	var option=[div];

	for(var i=0; i<option.length; i++)
	{ 
		obj=document.getElementById(option[i]);
		
		if ((option[i]==div) && !(obj.style.display=="block"))
		{
			obj.style.display="block"; 			
		}
		else
		{
			obj.style.display="none"; 
		}
	}
}
//------------------------

//Disable input fields

function clearField()
{
	document.wikiForm.newCat.value='';
	document.wikiForm.child.disabled=true;
}


function clearGroup(obj)
{
	for ( var i = 0; i < obj.length; i++ )
	{
		obj[i].checked = false;
	}
	document.wikiForm.child.disabled=false;
}

//------------------------

//Show tabs on sheets
function toggle(ID) 
{
	state = 'block';
	document.getElementById(ID).style.display = state;
} 

//Hide tabs on sheets
function hide(ID) 
{
	state = 'none';
	document.getElementById(ID).style.display = state;
} 
//------------------------

// Checks if the passed input's value is nothing.
function isEmptyText(theField)
{
	// Copy the value so changes can be made..
	var theValue = theField.value;

	// Strip whitespace off the left side.
	while (theValue.length > 0 && (theValue.charAt(0) == ' ' || theValue.charAt(0) == '\t'))
		theValue = theValue.substring(1, theValue.length);
	// Strip whitespace off the right side.
	while (theValue.length > 0 && (theValue.charAt(theValue.length - 1) == ' ' || theValue.charAt(theValue.length - 1) == '\t'))
		theValue = theValue.substring(0, theValue.length - 1);

	if (theValue == '')
		return true;
	else
		return false;
}