
function getText( nodeId )
{
	var node = document.getElementById( nodeId );
	if( node == null || node.firstChild == null )
		return null;
	return node.firstChild.nodeValue;
}

function updateText( nodeId , txt )
{
	var node = document.getElementById( nodeId );
	var txtNode = document.createTextNode( txt );
	if( node.childNodes.length > 0 )
		node.replaceChild( txtNode , node.firstChild );
	else
		node.appendChild( txtNode );
}

// Ensure we're working with a relatively standards compliant user agent
function isBrowserCompliant()
{
	return document.getElementById && document.createElement && document.createTextNode;
}

/**
* returns false if state already updated
*/
function updateState( node , className , nodeList , override )
{
	var curState = node.className;

	//prevent multiple mouseover handling when already handled
	if( curState == className )
		return false;
		
	//we can only update non selected states
	if( curState != "selected" || override )
	{
		var combinedClass = "";
		if( node.prevClassName != null && node.prevClassName.length > 0 )
			combinedClass += node.prevClassName + "-";
		if( className != null )
			combinedClass += className;
		node.className = combinedClass;
	}

	if( nodeList != null && className == "selected" )
	{
		//remove all other selected!
		for( var i=0 ; i < nodeList.length ; i++ )
		{
			//alert( nodeList[i] );
			if( nodeList[i] != node.id )
			{
				labelRef = document.getElementById( nodeList[i] );
				if( labelRef.className == "selected" )
				{
					if( labelRef.prevClassName != null )
						labelRef.className = labelRef.prevClassName
					else
						labelRef.className = null;
				}
			}

		}
	}
	return true;
}

var revertStore = new Object();
function updateDisplayItem( itemOb , fieldId , imgId  , tempShow )
{
	if( !isBrowserCompliant() )
		return;
	//START: update img
	if( itemOb.img != null )
	{
		var curImg = document.getElementById('baseimage');
		//check if change already taken place
		if( curImg.src != itemOb.img )
		{
			var newImg = curImg.cloneNode( true );
			newImg.src = itemOb.img;
			curImg.parentNode.replaceChild( newImg , curImg );
		}
	}
	//END: update img

	//START: update text
	if( itemOb.title != null )
	{
		var textField = document.getElementById(fieldId);
	
		//remove old children
		while( textField.childNodes.length > 0 )
			textField.removeChild( textField.childNodes[0] );
		
		if( itemOb.title != null && itemOb.title != "" )
		{
			/* Removed 21/2/07 AW - title no longer required on rollovers - #277
			var objNew = document.createElement('strong');
			objNew.appendChild(document.createTextNode( itemOb.title + ":" ));
		
			textField.appendChild( objNew );
			textField.appendChild(document.createTextNode(" "));
			*/
		}
		
		if( itemOb.desc != null )
		{
			//HACK: around entity escape problem 
			if( itemOb.desc.indexOf( "&" ) == -1 )
			{
				textField.appendChild(document.createTextNode( itemOb.desc ));
			}
			else
			{
				var objNew = document.createElement('span');
				objNew.innerHTML = itemOb.desc;
				textField.appendChild( objNew );
			}
		}
		
		if( itemOb.icon != null )
		{
			var objNew = document.createElement('img');
			objNew.src = itemOb.icon;
			
			if( itemOb.iconAlt != null )
				objNew.alt = itemOb.iconAlt;
			else
				objNew.alt = "";
			textField.appendChild( objNew );
		}
		
		if( itemOb.icon2 != null )
		{
			var objNew = document.createElement('img');
			objNew.src = itemOb.icon2;
			
			if( itemOb.iconAlt != null )
				objNew.alt = itemOb.iconAlt;
			else
				objNew.alt = "";
			textField.appendChild( objNew );
		}
		
		if( !tempShow )
			revertStore[ fieldId + "-" + imgId ] = itemOb;
	}
	//END: update txt

}

function revertTxt( fieldId , imgId )
{
	if( !isBrowserCompliant() )
		return;
		
	var key = fieldId + "-" + imgId;
	//alert( "revert:" + revertStore[ key ] );
	if( revertStore[ key ] == null )
		return;
	else
		updateDisplayItem( revertStore[ key ] , fieldId , imgId , false )
	//find current selected node and revert
}

function initWatchItems( watchItems )
{
	for( var i=0 ; i < watchItems.length ; i++ )
	{
		var item = document.getElementById( watchItems[i] );
		item.onchange = function()
		{
			return formChange( this );
		};
	}
}

function popupWin(url)
{
	window.open (url, "checkout","location=0,status=0,scrollbars=0,resizable=0,width=390,height=240");
}

function popupWinTerms(url)
{
 window.open (url, "terms","location=0,status=0,scrollbars=1,resizable=1,width=500,height=460");
}

function popupWinPrivacy(url)
{
 window.open (url, "privacy","location=0,status=0,scrollbars=0,resizable=0");
}