// PANEL AJAX INTERACTION FUNCTIONS

function livePostBreech(tgt_form, tgt_action, livePanel, loadPanel, errorPanel, set_size)
{
	if	(document.getElementById(tgt_form))	
	{	
		// Populate field values
		var frm_fields = createFormQuery(tgt_form);
		// End of the above
		
		// POST form data
		ajaxUpdate(false , tgt_action, { params:frm_fields, meth:"post", async:true, startfunc:"livePanelGrooming('"+livePanel+"', '"+loadPanel+"', '"+errorPanel+"', false, 'setScene', '"+set_size+"')", endfunc:"livePanelGrooming('"+livePanel+"', '"+loadPanel+"', '"+errorPanel+"', req.responseText, 'shootScene', '"+set_size+"');", errorfunc:"", noauthfunc:"" });
		// End of the above
	}
}

// Set and send an AJAX job
function liveRequestBreech(getCommands, livePanel, loadPanel, errorPanel, set_size)
{ ajaxUpdate(false , "index.php?", { params:getCommands, meth:"get", async:true, startfunc:"livePanelGrooming('"+livePanel+"', '"+loadPanel+"', '"+errorPanel+"', false, 'setScene', '"+set_size+"')", endfunc:"livePanelGrooming('"+livePanel+"', '"+loadPanel+"', '"+errorPanel+"', req.responseText, 'shootScene', '"+set_size+"');", errorfunc:"", noauthfunc:"" }); } 
// End of the above

window.sceneSetting = new Array();

// Set the panels for either loading or loading AJAX command results
function livePanelGrooming(livePanel, loadPanel, errorPanel, content, action, set_size)
{ 
	if		(action && action == 'setScene')
	{
		if 	(set_size)
		{
			window.sceneSetting['width'] 	= document.getElementById(livePanel).offsetWidth;
			window.sceneSetting['height'] 	= document.getElementById(livePanel).offsetHeight;
		}
		
		if	(loadPanel)
		{
			if	(document.getElementById(loadPanel)) { document.getElementById(loadPanel).style.display = ''; }
			if	(document.getElementById(livePanel)) { document.getElementById(livePanel).style.display = 'none'; }
			
			if 	(set_size == 'loading' || set_size == 'all')
			{ document.getElementById(loadPanel).style.height = window.sceneSetting['height']; }
		}
	}
	else if	(action && action == 'shootScene' && content)
	{	
		if	(document.getElementById(loadPanel)) { document.getElementById(loadPanel).style.display = 'none'; }
		if	(document.getElementById(livePanel)) 
		{ 
			// Populate live panel with content
			document.getElementById(livePanel).innerHTML = content;	
			// End of the above
			
			// Detect and execute embedded JS
			var responseContents = document.getElementById(livePanel).getElementsByTagName("script");
			
			if	(responseContents)
			{ 
				for (var i = 0; i < responseContents.length; i++)
				{ eval(responseContents[i].innerHTML); }
			}
			// End of the above
			
			// Show the live panel with new content added
			document.getElementById(livePanel).style.display = ''; 
			// End of the above
			
			if 	(set_size && set_size == 'all' || set_size && set_size == 'panel')
			{ document.getElementById(livePanel).style.width = window.sceneSetting['width']; } 
		}
	}
	else if	(action && action == 'shootScene' && !content)
	{
		if	(document.getElementById(loadPanel)) { document.getElementById(loadPanel).style.display = 'none'; }
		if	(document.getElementById(errorPanel)) { document.getElementById(errorPanel).style.display = ''; }
	}
}
// End of the above

// END OF THE ABOVE

	window.sliderRecord = new Array();

	function sliderControl(tgt_id, tgt_width, per_start, per_end, slide_time)
	{
		var direction;
		var difference;
		
		if		(per_end < per_start)
		{ direction = 'neg'; difference = slide_time/(per_start-per_end); }
		else if	(per_end > per_start)
		{ direction = 'pos'; difference = slide_time/(per_end-per_start); }
	
		clearInterval(window.sliderRecord[tgt_id]); window.sliderRecord[tgt_id] = setInterval("realiseSlider('"+tgt_id+"', '"+direction+"', '"+tgt_width+"', '"+per_start+"', '"+per_end+"', '"+difference+"')", 10);
	}

	function realiseSlider(tgt_id, direction, start_width, start_value, end_value, difference)
	{
		var width_end	= (Math.floor(start_width)/100)*Math.floor(end_value);
		var width_inc	= (Math.floor(start_width)/100)*difference;
		var pixel_cur 	= Math.floor(document.getElementById(tgt_id).offsetWidth);
		
		if	(direction == 'pos' && pixel_cur < width_end)
		{  
			if	((pixel_cur+width_inc) < start_width)
			{ document.getElementById(tgt_id).style.width = (pixel_cur+width_inc); }
			else
			{ clearInterval(window.sliderRecord[tgt_id]); document.getElementById(tgt_id).style.width = start_width; }
		}
		else if	(direction == 'pos')
		{ document.getElementById(tgt_id).style.width = width_end; clearInterval(window.sliderRecord[tgt_id]); }
		else if	(direction == 'neg' && pixel_cur > width_end)
		{ 
			if	((pixel_cur-width_inc) > 0)
			{ document.getElementById(tgt_id).style.width = (pixel_cur-width_inc); }
			else
			{ clearInterval(window.sliderRecord[tgt_id]); document.getElementById(tgt_id).style.width = 0; }
		}
		else if	(direction == 'neg')
		{ document.getElementById(tgt_id).style.width = '0'; clearInterval(window.sliderRecord[tgt_id]); }
	}
// MISC FUNCTIONS

	function switchHref(tgt_id, nw_href)
	{
		if	(document.getElementById(tgt_id))
		{ document.getElementById(tgt_id).href = nw_href; }
	}

	// Switch image function
	function switchSrc(tgt_id, tgt_src, nw_src, tgt_group)
	{	
		if	(tgt_id && document.getElementById(tgt_id))
		{
			if	(!window.imgRecord)
			{ window.imgRecord = new Array(); }
			
			if	(tgt_group && window.imgRecord[tgt_group])
			{ 
				switchSrc(window.imgRecord[tgt_group]['id'], false, window.imgRecord[tgt_group]['src'], ''); 
				
				if (tgt_src)
				{
					window.imgRecord[tgt_group] = new Array();
					window.imgRecord[tgt_group]['id']	= tgt_id;
					window.imgRecord[tgt_group]['src']	= tgt_src;
				}
			}
			else if (tgt_group)
			{ 
				if (tgt_src)
				{
					window.imgRecord[tgt_group] = new Array();
					window.imgRecord[tgt_group]['id']	= tgt_id;
					window.imgRecord[tgt_group]['src']	= tgt_src;
				}
			}
			
			if	(document.getElementById(tgt_id))
			{ document.getElementById(tgt_id).src = nw_src; }
		}
		else if (!tgt_id) 
		{	
			if	(tgt_group && window.imgRecord[tgt_group])
			{ switchSrc(window.imgRecord[tgt_group]['id'], false, window.imgRecord[tgt_group]['src'], ''); }
		}
	}
	// End of the above

	function managePopUps(tgt_window, tgt_width, tgt_height, tgt_url, scrl_bars)
	{ 
		if	(!tgt_width)
		{ tgt_width = '150'; }
	
		if	(!tgt_height)
		{ tgt_height = '250'; }
	
		if	(!window.activePopups)
		{ window.activePopups = new Array(); }
		
		// Create popup and populate popup registry
		if		(tgt_url)
		{ window.activePopups[tgt_window] = window.open(tgt_url, tgt_window,"location=1,status=0,resizable=1,scrollbars="+scrl_bars+",width="+tgt_width+",height="+tgt_height); }
		else
		{ alert('No target URL entered, window could not be opened'); }
		// End of the above
	} 
	
	function clearPopUps()
	{
		if	(window.activePopups)
		{
			for (var i in window.activePopups)
			{ window.activePopups[i].close(); } 
		}
	}
	
	function divManage(tgt_id, tgt_action, tgt_group)
	{
		if	(!window.divRecord)
		{ window.divRecord = new Array(); }
		
		if	(tgt_action == 'hide')
		{ var action = 'none'; var counter_action = 'show'; }
		else if (tgt_action == 'show')
		{ var action = ''; var counter_action = 'hide'; }
		else if (tgt_action == 'minimize')
		{  var action = 'hidden'; var action_size = '40px'; var counter_action = 'maximize'; }
		else if (tgt_action == 'maximize')
		{ var action = 'visible'; var action_size = '100%'; var counter_action = 'minimize'; }
		else if	(tgt_action == 'toggle')
		{
			if	(document.getElementById(tgt_id))
			{
				if	(document.getElementById(tgt_id).style.display == 'none')
				{ document.getElementById(tgt_id).style.display = ''; }
				else
				{ document.getElementById(tgt_id).style.display = 'none'; }
			}
		}
		
		if	(tgt_id && document.getElementById(tgt_id) && tgt_action != 'toggle')
		{	
			if	(tgt_group && window.divRecord[tgt_group])
			{ divManage(window.divRecord[tgt_group], counter_action, ''); window.divRecord[tgt_group] = tgt_id; }
			else if (tgt_group)

			{ window.divRecord[tgt_group] = tgt_id; }
			
			if		(tgt_action == 'show' || tgt_action == 'hide')
			{ document.getElementById(tgt_id).style.display = action; }
			else if (tgt_action == 'minimize' || tgt_action == 'maximize')
			{ document.getElementById(tgt_id).style.overflow = action; document.getElementById(tgt_id).style.width = action_size; }
		}
		else if (!tgt_id && tgt_action != 'toggle') 
		{	
			if	(tgt_group && window.divRecord[tgt_group])
			{ divManage(window.divRecord[tgt_group], counter_action, false); }
		}
	}
	
	function whichBrs() 
	{
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'Star Office';
	if (agt.indexOf("webtv") != -1) return 'WebTV';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie") != -1) return 'IE';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	if (agt.indexOf('\/') != -1) {
	if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
	return navigator.userAgent.substr(0,agt.indexOf('\/'));}
	else return 'Netscape';} else if (agt.indexOf(' ') != -1)
	return navigator.userAgent.substr(0,agt.indexOf(' '));
	else return navigator.userAgent;
	}

	window.browserType = whichBrs();

// END OF MISC FUNCTIONS