// JavaScript Document

function getPublicationFolder(number, reframe)
{
	if (reframe !=null) {
		showEditor(reframe);
	}
	var pathToFile = "/~ecoagric/functions/cms_publications.php?ajax=listPublicationFolderContents&folder="+number;
	ajaxGetContents('innerHTML',pathToFile, 'publicationFrame');
}

function getPublicationFolders()
{
	var pathToFile = "/~ecoagric/functions/cms_publications.php?ajax=getPublicationFolders";
	ajaxGetContents('innerHTML',pathToFile, 'publicationFrame');
}

function deletePublication(id, folder)
{
	var check = confirm("Are you sure that you would like to delete this publication? This action cannot be undone and if any pages manually reference this document (i.e. a link to the document was added directly into the code of a page) the link will be broken.\r\nAlso, if this is a draft it will delete the original object as well unless it is deleted through the 'Content Admin' section by person with publishing rights.");	
	if (check)
	{
		var pathToFile = "/~ecoagric/functions/cms_publications.php?ajax=deletePublication&publicationID="+id;
		var returnValue = ajaxGetContents('javascript',pathToFile, 'publicationFrame');	
	}
}

function editPublication(id)
{
	var pathToFile = "/~ecoagric/cms/publications_edit.php?id="+id;
	var returnValue = ajaxGetContents('innerHTML',pathToFile, 'publicationManage');	
}

function addPublicationFolder()
{
	var check = confirm('Please be careful about adding new folders. Once a folder has been created it cannot be deleted, so please be judicious in your folder management. \r\n\r\nIf you would still like to create a new folder, select OK.');
	if (check)
	{
		var name = prompt("Please provide a UNIQUE name for the folder. (do not include special characters)");
		while (name==''){prompt("You must provide a UNIQUE name for the folder. (do not include special characters)");};
		var pathToFile = "/~ecoagric/functions/cms_publications.php?ajax=addPublicationFolder&folderName="+name;
		var returnValue = ajaxGetContents('javascript',pathToFile, 'publicationFrame');	
		getPublicationFolders();
	}
}

function publishPublication(id)
{
	var pathToFile = "/~ecoagric/functions/cms_publications.php?ajax=publishPublication&pubID="+id;
	ajaxGetContents('javascript',pathToFile, 'none');
}

function addNewAuthorOrg()
{
	var theObj = document.getElementById('author1');
	var counter = 1;
	while (theObj)
	{
		counter++;
		theObj=document.getElementById('author'+counter);
	};
	//now we know what the last one was, build the new layer
	var theHtml = '<input type="text" name="author'+counter+'" id="author'+counter+'" class="inputStretch" style="width:40%" /> , <input name="org'+counter+'"  id="org'+counter+'"type="text" class="inputStretch" style="width:40%" /> <img src="/~ecoagric/images/cms/icons/tiny_del_misc.jpg" alt="Delete This Author, Org" width="15" height="15" align="absmiddle" onclick="deleteNewAuthorOrg('+counter+')" />';
	
	
	var parentObj = document.getElementById('authorBox');
	var newdiv = document.createElement('div');
	var divIdName = 'authorOrg'+counter;
	newdiv.setAttribute('id',divIdName);
	newdiv.innerHTML = theHtml;
	parentObj.appendChild(newdiv);
	
	//now focus
	document.getElementById('author'+counter).focus();
}

function deleteNewAuthorOrg(id)
{
	var theDiv = document.getElementById('authorOrg'+id);
	//erase existing values so the system ignores it later
	document.getElementById('author'+id).value='';
	document.getElementById('org'+id).value='';
	theDiv.className='hidetext';
}

function addNewReadmore()
{
	var theObj = document.getElementById('readmore1');
	var counter = 1;
	while (theObj)
	{
		counter++;
		theObj=document.getElementById('readmore'+counter);
	};
	//now we know what the last one was, build the new layer
	var theHtml = '<input type="text" name="readmore'+counter+'" id="readmore'+counter+'" class="inputStretch" style="width:40%" value="Read More" /> at <input name="readurl'+counter+'" type="text" class="inputStretch" id="readurl'+counter+'" style="width:40%" value="http://" /> <img src="/~ecoagric/images/cms/icons/tiny_del_misc.jpg" alt="Delete This Read More Field" title="Delete This Read More Field" width="15" height="15" align="absmiddle" onclick="deleteReadmore('+counter+')" />'
	
	
	parentObj = document.getElementById('readmoreBox');
	var newdiv = document.createElement('div');
	var divIdName = 'readmoreDiv'+counter;
	newdiv.setAttribute('id',divIdName);
	newdiv.innerHTML = theHtml;
	parentObj.appendChild(newdiv);
	
	//now focus
	document.getElementById('readmore'+counter).focus();
}

function deleteReadmore(id)
{
	var theDiv = document.getElementById('readmoreDiv'+id);
	//erase existing values so the system ignores it later
	document.getElementById('readmore'+id).value='';
	document.getElementById('readurl'+id).value='';
	theDiv.className='hidetext';
}

function checkSpotlight(number)
{
	var pathToFile = "/~ecoagric/functions/cms_publications.php?ajax=checkSpotlight&spotlight="+number;
	var returnValue = ajaxGetContents('javascript',pathToFile, 'none');	
}

function checkRecommended()
{
	if (document.getElementById('recommended').checked==false){return true;}
	else 
	{
		var pathToFile = "/~ecoagric/functions/cms_publications.php?ajax=checkRecommended";
		var returnValue = ajaxGetContents('javascript',pathToFile, 'none');
	}
}

function unrecommendPopup()
{
	var checkRecommend = confirm('Recommending this document will push you over the total number of recommended documents that are permitted.\n\nIf you would still like to recommend this document, click OK and you will be able to unrecommend some existing documents, otherwise click cancel)'); 
	if (!checkRecommend){
		document.getElementById('recommended').checked=false;
		} 
	else {
		if (popupMenu != null){popupMenu.close();};
		document.getElementById('recommended').checked=false; 
		popupMenu = popUpWinCMS ('/~ecoagric/cms/popup_unrecommend.php', "popRecommend", 410, 410, ''); 
		if (popupMenu) {popupMenu.focus();} 
		else {
			alert('Error: While Launching New Window...\\nYour browser maybe blocking up Popup windows.\\n\\nPlease check your Popup Blocker Settings');
			};
		};
}

function recommendPopup()
{
	if (popupMenu != null){popupMenu.close();};
	popupMenu = popUpWinCMS ('/~ecoagric/cms/popup_recommend.php', "popRecommend", 410, 410, ''); 
	if (popupMenu) {popupMenu.focus();} 
	else {
		alert('Error: While Launching New Window...\\nYour browser maybe blocking up Popup windows.\\n\\nPlease check your Popup Blocker Settings');
	};
}