var loaded;
var TimeOutNum = 0;
loaded = 0;

function show(idname)
{
  ns4 = (document.layers) ? 1:0;
  ie4 = (document.all) ? 1:0;
  
  if(!ns4)
  {
    if (document.getElementById)
    {
      var bxNM = document.getElementById(idname);
      bxNM.style.visibility = "visible";
    }
    else if (ns4)
    {
      document[idname].visibility = "show";   
    }
    else if (ie4)
    {
      document.all[idname].style.visibility = "visible";  
    }
  }
};

function hide(idname)
{
  ns4 = (document.layers) ? 1:0;
  ie4 = (document.all) ? 1:0; 

  if(!ns4)
  {
    if (document.getElementById)
    {
      var bxNM = document.getElementById(idname);
      bxNM.style.visibility = "hidden";
    }
    else if (ns4)
    {
      document[idname].visibility = "hide";
    }
    else if (ie4)
    {
      document.all[idname].style.visibility = "hidden";
    }
  }
};

function hideAll()
{
  clearTimeout(TimeOutNum);
  hide('navTest');
};

var TimeOutNum = 0;

loaded = 0;

function SetTimer()
{
  TimeOutNum = setTimeout("hideAll();",600);
};


/************************************************************************/

var arrdays = new Array(11);

function init()
{
	arrdays[0] = 31;
	arrdays[1] = 28;
	arrdays[2] = 31;
	arrdays[3] = 30;
	arrdays[4] = 31;
	arrdays[5] = 30;
	arrdays[6] = 31;
	arrdays[7] = 31;
	arrdays[8] = 30;
	arrdays[9] = 31;
	arrdays[10] = 30;
	arrdays[11] = 31;
}

/********* Main Navigation **********/

var homeOn = new Image();
var homeOff = new Image();
var servicesOn = new Image();
var servicesOff = new Image();
var aboutOn = new Image();
var aboutOff = new Image();
var newsOn = new Image();
var newsOff = new Image();
var casestudiesOn = new Image();
var casestudiesOff = new Image();
var membersOn = new Image();
var membersOff = new Image();
var contactOn = new Image();
var contactOff = new Image();
var globalnetworkOn = new Image();
var globalnetworkOff = new Image();

function setPicky(imageName, image, imagePath)
{
	if (image.src == '')
	{
		image.src = imagePath;
	}
	document.images[imageName].src = image.src;
}

function winPop(pageToLoad, winName, width, height, center, scroll, control)
{
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center))
    {
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    args = "width=" + width + ","
    + "height=" + height + ","
    + "location=0,"
    + "menubar=0,"
    + "resizable=" + control + ","
    + "scrollbars="+scroll+", "
    + "status=1,"
    + "titlebar=0,"
    + "toolbar=1,"
    + "hotkeys=0,"
    + "screenx=" + xposition + ","  //NN Only
    + "screeny=" + yposition + ","  //NN Only
    + "left=" + xposition + ","     //IE Only
    + "top=" + yposition;           //IE Only

    window.open(pageToLoad,winName,args );
}



function addOptionToSelectbox(pBox,pOptionValue,pOptionText)
{
    var iOptions = pBox.options.length;
    pBox.options[iOptions] = new Option(pOptionText,pOptionValue);
}

function clearSelectbox(pBox)
{
    var iOptions = pBox.options.length;
    for (var ii = iOptions; ii>=0; ii--)
    {
        pBox.options[ii] = null;
    }
}

function NumberOfChar(str,character)
{
	var ii, charCount;
	charCount = 0;
	for (ii=0; ii < str.length;ii++)
	{
		var cc = str.charAt(ii);
		if (cc == character)
		{
			charCount = charCount + 1;
		}
	}
	return charCount;
}

function validEmail(str)
{
	var bool;
	bool = true;
	if (str.length < 6)
	{
		bool = false;
		alert("Email address has too few characters.");
	}
	if ((bool) && ((NumberOfChar(str,'@')==0)||(NumberOfChar(str,'@')>1)))
	{
		bool = false;
		alert("Email address contains the wrong number of @'s.");
	}
	if ((bool) && (NumberOfChar(str,'.')==0))
	{
		bool = false;
		alert("Email address must contain at least one '.'.");
	}
	if ((bool) && (NumberOfChar(str,' ')!=0))
	{
		bool = false;
		alert("Email address must not contain any spaces.");
	}
	return bool;
}

function validYear(pYear)
{
	var bValid = true;

	if (IsNaturalNumber(pYear))
	{
		var thisYear, thisDate;
		thisDate = new Date();
		thisYear = thisDate.getFullYear();

		if (pYear.length != 4)
		{
			bValid = false;
			alert("The year has an incorrect amount of characters.  It musy be entered as 4 digits i.e. 1972");
		}
		else
		{
			if (pYear > thisYear)
			{
				bValid = false;
				alert("Your year of birth must be in the past");
			}
			else if (pYear < 1900)
			{
				bValid = false;
				alert("Your year of birth must be after 1900");
			}
		}
	}
	else
	{
		alert("Your year of birth must be a 4 digit number i.e. 1972");
		bValid = false;
	}

	return bValid;
}

function IsNaturalNumber(pValue)
{
    var iLength = pValue.length;
    var ii 		= 0;
    var cc;
    var bValid = true;

    while (ii < iLength)
    {
        cc = pValue.charAt(ii);
        if (!((cc >= '0') && (cc <= '9')))
        {
            bValid 	= false;
            ii 		= iLength;
        }
        else
        {
        	ii = ii + 1;
        }
    }

	return bValid;
}

function CheckMinimumLength(pMinLength,pStr)
{
	var bValid = true;

	if (pStr.length < pMinLength)
	{
		bValid = false;
	}

	return bValid;
}