//*********************************************************
//window functions
//*********************************************************
function openNewWindow(link) 
{
  popupWin = window.open(link, 'popup', 'dependent,width=800,height=690,left=100,top=5,scrollbars=yes');
}

//*********************************************************
//layer functions
//*********************************************************
var stopTransition = false;
var version = 0;

if (navigator.appVersion.indexOf("MSIE")!=-1)
{
	temp=navigator.appVersion.split("MSIE")
	//version=parseFloat(temp[1])
	version=0
}

function highLink(link)
{
	if(document.getElementById('navball' + link))
	{
		document.getElementById('navball' + link).src="./WebContent/images/navballHigh1.gif";
	}
}

function unHighLink(link)
{
	if(document.getElementById('navball' + link))
	{
		document.getElementById('navball' + link).src="./WebContent/images/navball1.gif";
	}
}

function highControls()
{
	var splitURL = document.getElementById('controls').src.split('/');
	
	if(splitURL[splitURL.length - 1] == 'pause1.gif')
	{
		document.getElementById('controls').src="./WebContent/images/pause.gif";
	}
	else if(splitURL[splitURL.length - 1] == 'play1.gif')
	{
		document.getElementById('controls').src="./WebContent/images/play.gif";
	}
}

function unHighControls()
{
	var splitURL = document.getElementById('controls').src.split('/');
	
	if(splitURL[splitURL.length - 1] == 'pause.gif')
	{
		document.getElementById('controls').src="./WebContent/images/pause1.gif";
	}
	else if(splitURL[splitURL.length - 1] == 'play.gif')
	{
		document.getElementById('controls').src="./WebContent/images/play1.gif";
	}
}

function toggleControls()
{
	var splitURL = document.getElementById('controls').src.split('/');
	
	if(splitURL[splitURL.length - 1] == 'pause.gif' || splitURL[splitURL.length - 1] == 'pause1.gif')
	{
		stopTransition = true;
		document.getElementById('controls').src="./WebContent/images/play.gif";
	}
	else if(splitURL[splitURL.length - 1] == 'play.gif' || splitURL[splitURL.length - 1] == 'play1.gif')
	{
		stopTransition = false;	
		document.getElementById('controls').src="./WebContent/images/pause.gif";
	}
}

function loadTransition()
{
	if(version != 0)
	{
		setTimeout("sidePlug(0)", 1000);
	}
	else
	{
		setTimeout("sidePlug(0)", 0);
	}
	
}

function sidePlug(id)
{
	if(version != 0)
	{
		if(document.getElementById('sideBody' + id) && !stopTransition)
		{    	
			document.getElementById('transitionContainer').filters[0].Apply();	
					
			if(document.getElementById('sideBody' + id).style.display == 'none')
			{
				document.getElementById('sideBody' + id).style.display = 'inline';
				document.getElementById('sidePic' + id).style.display = 'none';
			}
			else
			{
				document.getElementById('sideBody' + id).style.display = 'none';
				document.getElementById('sidePic' + id).style.display = 'inline';
			}
			
			document.getElementById('transitionContainer').filters[0].Play();
		}
		
		setTimeout("sidePlug(0)", 7500);
	}
	else
	{
		document.getElementById('sideBody' + id).style.display = 'inline';
		document.getElementById('sidePic' + id).style.display = 'none';
		document.getElementById('controls').src='./WebContent/images/blank.gif';
	}
}

function alterTextArea(bulletValue)
{
	if(trim(bulletValue) == "")
	{
		document.getElementById('textArea').cols = 54;
	}
	else
	{
		document.getElementById('textArea').cols = 40;
	}
}

//*********************************************************
//data manipulation functions
//*********************************************************
function trim(str)
{ 
	return str.replace(/^\s+/,'').replace(/\s+$/,'');
}

//*********************************************************
//ajax functions
//*********************************************************

function getAction(action, htmlId)
{ 
	 new Ajax.Request
	 ('./WebContent/actions/' + action,   
	 {     method:'get'
	 ,     onSuccess: function(transport)
	                  {
						 new Ajax.Request
						 ('./WebContent/actions/dynamic-php.xml',   
						 {     method:'get'
						 ,     parameters: {
							      differentiator: Math.floor(Math.random()*50000)
							   }
						 
						 ,     onSuccess: function(transport)
						                  {
						                         var response = transport.responseXML;
						                         var nodes = response.getElementsByTagName('returnValue');

							 	 				 if(nodes.length > 0)
						 	 				 	 { 
						 	 				 	 	 var returnValue = nodes.item(0).firstChild.data;
													 document.getElementById(htmlId).innerHTML = returnValue;						 
												 }
						                  }
						 ,     onFailure: function()
										  {
										 		 alert("Problem encountered while running requested action!");
										  }
						 });
	                  }
	 ,     onFailure: function()
					  {
					 		 alert("Problem encountered while running requested action!");
					  }
	 });
}

function previousBlocks()
{
	var pageId = eval(window.document.contentForm.links);
	var blockIndex = eval(window.document.contentForm.blockIndex);
	
	var index = blockIndex.value;

	changeContentRequest(pageId.value, --index);
}

function nextBlocks()
{
	var pageId = eval(window.document.contentForm.links);
	var blockIndex = eval(window.document.contentForm.blockIndex);
	
	var index = blockIndex.value;

	changeContentRequest(pageId.value, ++index);
}

function changeBlocks()
{
		var pageId = eval(window.document.contentForm.links);
		
		changeContentRequest(pageId.value, 1);
}

function changeContentRequest(pageId, blockIndex)
{

		new Ajax.Request
		('./WebContent/actions/changeContent.php',   //url
		{     method:'get'
		,     parameters: 'pageId=' + pageId + '&blockIndex=' + blockIndex
		,     onSuccess: function()
		                 {
		                 	 new Ajax.Request
							 ('./WebContent/actions/changeContent-php.xml',   
							 {     method:'get'
							 ,     parameters: {
								      differentiator: Math.floor(Math.random()*50000)
								   }							 
							 ,     onSuccess: function(transport)
							                  {
							                         var response = transport.responseXML;
							                         var nodes = response.getElementsByTagName('returnValue');
							                         	
								 	 				 if(nodes.length > 0)
							 	 				 	 { 
							 	 				 	 	var returnValue = nodes.item(0).firstChild.data;
							 	 				 	 	 
														document.getElementById('changePageContent').innerHTML = returnValue;
														document.getElementById('errorsLeft').innerHTML = "";
													 }
													 //document.getElementById('errorsLeft').innerHTML = document.getElementById('changePageContent').innerHTML.substring(471, 571);
							                  }
							 ,     onFailure: function()
											  {
											 		 alert("Problem encountered while running requested action!");
											  }
							 });
		                 }
		 ,     onFailure: function()
						 {
						 	alert("Problem encountered while changing pages!");
						 }
		 });
}

function changeRightBlocks()
{
		var pageId = eval(window.document.rightContentForm.links);
		
		changeRightContentRequest(pageId.value);
}

function changeRightContentRequest(pageId)
{

		new Ajax.Request
		('./WebContent/actions/changeRightContent.php',   //url
		{     method:'get'
		,     parameters: 'pageId=' + pageId
		,     onSuccess: function()
		                 {
		                 	 new Ajax.Request
							 ('./WebContent/actions/changeRightContent-php.xml',   
							 {     method:'get'
							 ,     parameters: {
								      differentiator: Math.floor(Math.random()*50000)
								   }							 
							 ,     onSuccess: function(transport)
							                  {
							                         var response = transport.responseXML;
							                         var nodes = response.getElementsByTagName('returnValue');
							                         	
								 	 				 if(nodes.length > 0)
							 	 				 	 { 
							 	 				 	 	var returnValue = nodes.item(0).firstChild.data;
							 	 				 	 	 
														document.getElementById('changePageContent').innerHTML = returnValue;
														document.getElementById('errorsLeft').innerHTML = "";
													 }
													 //document.getElementById('errorsLeft').innerHTML = document.getElementById('changePageContent').innerHTML.substring(471, 571);
							                  }
							 ,     onFailure: function()
											  {
											 		 alert("Problem encountered while running requested action!");
											  }
							 });
		                 }
		 ,     onFailure: function()
						 {
						 	alert("Problem encountered while changing pages!");
						 }
		 });
}