window.onload = function(){
	init();
}

function init(){
	
	
	if(document.login != null){
		document.login.username.focus();
	}
	document.getElementById('main-content').onclick = function(){
		
		hidePopups();
		
	}

/*popup calendar functonality*/
	if(document.getElementById('publish_date') != null){
	
		publishDate = document.getElementById('publish_date');
		publishDate.onclick = function(){
											displayCalendar('publish_date');
																						
										}
	}
	if(document.getElementById('expire_date') != null){
	
		expireDate = document.getElementById('expire_date');
		expireDate.onclick = function(){
											displayCalendar('expire_date');
										}
	}







/*library manager functionlaity*/


	if(document.getElementsByName('add_image') != null){

		imageElement = document.getElementsByName('add_image');
		if(imageElement[0] != null){
			imageElement[0].onclick = function(){		
													id = document.getElementById('add_image_id').value;
													setScriptToConnectTo("getImageLibrary.php");
													setImageId(id);												
													displayLibrary("image");									
										}
		}
	}	
	if(document.getElementsByName('add_story') != null){

		storyElement = document.getElementsByName('add_story');
		if(storyElement[0] != null){
			storyElement[0].onclick = function(){		
													id = document.getElementById('add_story_id').value;
													setScriptToConnectTo("getStoryLibrary.php");
													setImageId(id);												
													displayLibrary("story");									
										}
		}
	}
}


function removeSection(sectionToRemove){
		
	document.getElementById(sectionToRemove).style.display = "none;"
	document.getElementById(sectionToRemove).innerHTML = '';
}
/**

This function hides the calendar popups when you click elsewhere on the page
*/

function hidePopups(){
	
	popupElements = document.getElementsByName('popup');
	if(popupElements.length > 0){
		
		for(i = 0; i < popupElements.length; i++){
			
			if(popupElements[i].style.display == "block"){
				popupElements[i].style.display = "none";
			}
		}		
	}
}

				
				
				
