function create_XMLHttpRequest()
{
	if (window.XMLHttpRequest)
	{
		return new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		return false;
		/*
		document.getElementById('p_status').innerHTML =
		'Status: Cound not create XmlHttpRequest Object.' +
		'Consider upgrading your browser.';
		*/
	}
}

function xml_get_field(xmldoc, field_name)
{
	var xml_array = xmldoc.getElementsByTagName(field_name);

	if( xml_array.length > 0 )
	{
		if( xml_array[0].firstChild != null )
		{

			// If the client is using mozilla, we fetch the xml element differently as Mozilla has a bug not allowing more than 4096 chars in each element.
			if( true == isMoz() )
			{
				return xml_array[0].textContent;
			}
			else
			{
				return xml_array[0].firstChild.nodeValue;
			}
		}
		else
		{
			return "";
		}
	}
	else
	{
		return "";
	}
}


// Hide the div's with the class 'javascript_hide', used for buttons when javascript is enabled and the functions can use ajax.
function hide_javascript_divs()
{
	var div_elements = document.getElementsByTagName('div');

	for (i=0; i<div_elements.length; i++)
	{
		if (div_elements[i].className == 'javascript_hide')
		{
			div_elements[i].style.display = "none";
		}
	}
}


function hide_javascript_trs()
{
	var div_elements = document.getElementsByTagName('tr');

	for (i=0; i<div_elements.length; i++)
	{
		if (div_elements[i].className == 'javascript_hide')
		{
			div_elements[i].style.display = "none";
		}
	}
}

init_functions[init_functions.length] = "hide_javascript_divs();";
init_functions[init_functions.length] = "hide_javascript_trs();";

function open_window(url,name,rw,rh)
{

	if ( screen.width ) {
		xMax = screen.width;
		yMax = screen.height;
	} else {
		if (document.layers) {
			xMax = window.outerWidth; yMax = window.outerHeight;
		} else {
			xMax = 640; yMax=480;
		}
	}

	rw+=40;
	rh+=60;

	xMax-=20;
	yMax-=120;

	w=(rw<xMax)?rw:xMax;
	h=(rh<yMax)?rh:yMax;

	xOffset = (xMax - w)/2;
	yOffset = (yMax - h)/2;

	features='width='+w+
			',height='+h+
			',screenX='+xOffset+
			',screenY='+yOffset+
			',left='+xOffset+
			',top='+yOffset+
			',directories=no'+
			',location=no'+
			',menubar=yes'+
			',scrollbars=yes'+
			',status=no'+
			',toolbar=no'+
			',resizable=yes'+
			',alwaysRaised=yes';

	myWind=window.open(url,name,features);
}

function open_window_inside(url, name, inside)
{

	if( navigator.appName == "Netscape" )
	{
		// Mozilla/Firefox
		x = window.screenX;
		y = window.screenY;
		window_width = window.innerWidth;
		window_height = window.innerHeight;
	}
	else
	{

		if( navigator.appName == "Microsoft Internet Explorer")
		{
			// IE
			x = window.screenLeft;
			y = window.screenTop;
			window_width = document.body.clientWidth;
			window_height = document.body.clientHeight;
		}
		else
		{
			x = 0;
			y = 0;
			window_width = document.body.clientWidth;
			window_height = 600;
		}
	}

	offsetX = x + inside;
	offsetY = y + inside;

	width = window_width -  ( 2 * inside );
	height = window_height -  ( 2 * inside );

	features='width='+width+
			',height='+height+
			',screenX='+offsetX+
			',screenY='+offsetY+
			',left='+offsetX+
			',top='+offsetY+
			',directories=yes'+
			',location=yes'+
			',menubar=yes'+
			',scrollbars=yes'+
			',status=yes'+
			',toolbar=yes'+
			',resizable=yes'+
			',alwaysRaised=yes';

//	alert(features)

	myWind=window.open(url,name,features);
}

function more_images_display(max_images)
{
	more_images = more_images + 1;
	if( more_images < max_images )
	{
		max_images = more_images;
	}

	for( i=0; i<max_images; i++ )
	{
		var tr_display = document.getElementById('title_' + i);
		if( tr_display.className == 'javascript_hide' )
		{
			tr_display.style.display = "";
		}

		var tr_display = document.getElementById('file_' + i);
		if( tr_display.className == 'javascript_hide' )
		{
			tr_display.style.display = "";
		}

		var tr_display = document.getElementById('hr_' + i);
		if( tr_display.className == 'javascript_hide' )
		{
			tr_display.style.display = "";
		}
	}
}


function child_details_display(max_child, MAX_NUM_CHILD)
{
	// Hides all first
	for( i=1; i<=MAX_NUM_CHILD; i++ )
	{

		// The HR
		child = document.getElementById('child_' + i + '_hr');
		child.className = 'javascript_hide';
		child.style.display = 'none';

		// The name
		child = document.getElementById('child_' + i + '_name');
		child.className = 'javascript_hide';
		child.style.display = 'none';

		// The File
		child = document.getElementById('child_' + i + '_age');
		child.className = 'javascript_hide';
		child.style.display = 'none';

	}

	for( i=1; i<=max_child; i++ )
	{
		var tr_display = document.getElementById('child_' + i + '_hr');
		if( tr_display.className == 'javascript_hide' )
		{
			tr_display.style.display = "";
		}

		var tr_display = document.getElementById('child_' + i + '_name');
		if( tr_display.className == 'javascript_hide' )
		{
			tr_display.style.display = "";
		}

		var tr_display = document.getElementById('child_' + i + '_age');
		if( tr_display.className == 'javascript_hide' )
		{
			tr_display.style.display = "";
		}
	}
}

function rating_checkboxs(field, allow_unchecking)
{
	var f = field.form;

	// Only allow turning off of fields if another is selected OR you allow the checked one to be unchecked.
	if( field.checked == true || allow_unchecking == false )
	{
		for( var num=0; num<f.elements[field.name].length; num++ )
		{
			if( f.elements[field.name][num].value == field.value)
			{
				f.elements[field.name][num].checked = true;
			}

			else
			{
				f.elements[field.name][num].checked = false;
			}
		}
	}
}



//
// AJAX to delete watchlist items
//
var watchlist_ajax = create_XMLHttpRequest();

function watchlist_delete(watchlist_delete_url, watchlist_item)
{
	// Url must have content.
	if( watchlist_delete_url.length > 0 )
	{
		//alert( watchlist_ajax.readyState );
		if( watchlist_ajax.readyState == 4 || watchlist_ajax.readyState == 0 )
		{
			// Send data to Delete the watchlist item
			watchlist_ajax.open("GET", watchlist_delete_url, true);
			watchlist_ajax.onreadystatechange = function() { watchlist_remove_item(watchlist_item); };
			watchlist_ajax.send(null);
		}
	}
}

function watchlist_remove_item( watchlist_item )
{
	if( watchlist_ajax.readyState == 4 )
	{
		// Response code was 200, OK!
		if( watchlist_ajax.status == 200 )
		{
			// Delete the three rows of a watchlist item
			for( row=1; row<=3; row++)
			{
				row_id = watchlist_item + "_" + row;

				var watchlist_row = document.getElementById( row_id );

				// The starting colour of the background (row_even colour)
				watchlist_row.currentRGB = [248, 248, 248];

				// Fade Row Background
				doFadeMem(watchlist_row, watchlist_row.currentRGB, [255, 255, 255], 20, 3, 1.3 );

				// Fade the Text between the Links in the second cell of the first row
				if( row == 1 )
				{
					doFadeMem(watchlist_row.childNodes[1], [0, 0, 0], [255, 255, 255], 20, 3, 1.3 );
				}

				if( row == 2 )
				{
					// Fade the Text in the second cell of the second row
					doFadeMem(watchlist_row.childNodes[1], [0, 0, 0], [255, 255, 255], 20, 3, 1.3 );
				}

				// Check if the row has more than 1 cell
				if( watchlist_row.childNodes.length > 1 )
				{
					// Get an array of the links in second td cell
					var watchlist_links = watchlist_row.childNodes[1].getElementsByTagName("a");

					// Fade the link
					for( i=0; i<watchlist_links.length; i++ )
					{
						watchlist_links[i].currentRGB = [0, 0, 0];
						doFadeMem(watchlist_links[i], watchlist_links[i].currentRGB, [255,255,255], 20, 3, 1.3 );
					}
				}
			}
		}
	}
}

function doFadeMem(elem, startRGB, endRGB, steps, intervals, powr)
{
	//Fader with Memory by www.hesido.com
	if (elem.fadeMemInt)
	{
		window.clearInterval(elem.fadeMemInt);
	}

	var actStep = 0;

	elem.fadeMemInt = window.setInterval(
		function() {
			elem.currentRGB = [
				easeInOut(startRGB[0], endRGB[0], steps, actStep, powr),
				easeInOut(startRGB[1], endRGB[1], steps, actStep, powr),
				easeInOut(startRGB[2], endRGB[2], steps, actStep, powr)
				];
			if( elem.tagName == "TR" )
			{
				elem.style.backgroundColor = "rgb(" + elem.currentRGB[0] + "," + elem.currentRGB[1] + "," + elem.currentRGB[2] + ")";
			}
			else
			{
				elem.style.color = "rgb(" + elem.currentRGB[0] + "," + elem.currentRGB[1] + "," + elem.currentRGB[2] + ")";
			}
			actStep++;
			if (actStep > steps)
			{
				window.clearInterval(elem.fadeMemInt);
				elem.style.display = 'none';
			}
		}
		, intervals)
}

function easeInOut( minValue, maxValue, totalSteps, actualStep, powr )
{
	//Generic Animation Step Value Generator By www.hesido.com
	var delta = maxValue - minValue;
	var stepp = minValue + (Math.pow( ((1 / totalSteps) * actualStep), powr) * delta);
	return Math.ceil(stepp)
}

/**
 * Returns TRUE/FALSE if the browser is Mozilla or not.
 *
 */

function isMoz()
{
	// Set the default value to false.
	var moz = false;

	if ( !document.layers )
	{
		// Is the browser Konquerer.
		konq = ( navigator.userAgent.indexOf( 'Konqueror' ) != -1 );

		// Is the browser Safari?
		saf = ( navigator.userAgent.indexOf( 'Safari' ) != -1 );

		// Is the browser Mozilla?
		moz = ( navigator.userAgent.indexOf( 'Gecko' ) != -1 && !saf && !konq);
	}

	return moz;
}

// http://textsnippets.com/posts/show/686
function getElementsByClassName(oElm, strTagName, strClassName)
{
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++)
	{
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className))
		{
			arrReturnElements.push(oElement);
		}
	}

	return (arrReturnElements)
}