var ps_themeurl = "http://www.normaleating.com/forum/Themes/Permutations";

var plusImg = new Image();
	plusImg.src = ps_themeurl+"/images/plus.gif"
	
var minusImg = new Image();
	minusImg.src = ps_themeurl+"/images/minus.gif"

function hidePart(_partId, _imgId) 
{
	var thisPart = document.getElementById(_partId);
	var thisImg = document.getElementById(_imgId);
	thisPart.style.display = "none";
	thisImg.src = plusImg.src;
	CreateCookie('hide'+_partId, 1);
//	document.cookie = 'hide'+_partId+'=1;';
//	alert('document.cookie: '+ document.cookie);	
}
	
function showPart(_partId, _imgId) 
{
	var thisPart = document.getElementById( _partId );
	var thisImg = document.getElementById( _imgId );
	thisPart.style.display = "";
	thisImg.src = minusImg.src;
	CreateCookie('hide'+_partId, 0);
//	document.cookie = 'hide'+_partId+'=0;';
//	alert('document.cookie: '+ document.cookie);	
}

function reDisplay(_partId, _imgId) 
{
	var thisPart = document.getElementById(_partId);
	var thisImg = document.getElementById(_imgId);
	if ( thisPart.style.display == "none")
		showPart(_partId, _imgId);
	else
		hidePart(_partId, _imgId);
}

function restoreAll(n_parts, part_stub, icon_stub)
{
	for (c = 1; c <= n_parts; c++) 
	{	
		hide = ReadCookie('hide'+part_stub+c);	
		if (hide == 1)
		{
//			alert('hiding - hide: '+hide);
			document.getElementById(part_stub+c).style.display = "none";
			document.getElementById(icon_stub+c).src = plusImg.src;
		}
		else
		{
//			alert('showing - hide: '+hide);
			document.getElementById(part_stub+c).style.display = "";
			document.getElementById(icon_stub+c).src = minusImg.src;		
		}
	}
}

function hideAll(n_parts, part_stub, icon_stub) 
{
	for (c = 1; c <= n_parts; c++) 
		hidePart(part_stub+c, icon_stub+c);
}

function showAll(n_parts, part_stub, icon_stub) 
{
	for (c = 1; c <= n_parts; c++) 
		showPart(part_stub+c, icon_stub+c);
}

function CreateCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function ReadCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i=0; i < ca.length; i++)
	{
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function EraseCookie(name)
{
	CreateCookie(name,"",-1);
}

function Validate( itemQty )
{
	var re_nbr = /^([0-9]){1,4}$/;
	var re_spc = /^(\s){1,4}$/;
	
//	alert( 'itemQty: ' + itemQty.value );	
	
	if ( itemQty.value != null && itemQty.value.length != 0 && !re_nbr.test( itemQty.value ) && !re_spc.test( itemQty.value ) )
	{
		alert( "You entered: " + itemQty.value + "\n\nPlease enter only numbers." );
		itemQty.focus();
		itemQty.select();
	}	
}


