window.onload = jsFnOnload;

function jsFnOnload()
{
	if (document.getElementById)
	{
		// Remove confirm
		var remove = document.getElementsByTagName("a");
 		if (remove != null) 
		{
			for(aremindex=0;aremindex<remove.length;aremindex++)
			{
				if(remove[aremindex].className=='rem') remove[aremindex].onclick = JSFnRemoveClick;
			}
		}
				
		var aContactForm = document.getElementById('contactform');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;
		
		// Close POPUP
		var aCloseNoRefreshPage = document.getElementById('CloseNoRefresh');
		if (aCloseNoRefreshPage != null) aCloseNoRefreshPage.onclick = JSFnCloseNoRefresh;
		//**************************************************************************************************************************************
		
		// LOCATION POPUP
		var aLocationLinks = document.getElementsByTagName("a");
		for (aLocationIndex = 0; aLocationIndex < aLocationLinks.length; aLocationIndex++)
		{
			if (aLocationLinks[aLocationIndex].className == 'loclink') aLocationLinks[aLocationIndex].onclick = JSFnNewWindowLocation;
		}
		//**************************************************************************************************************************************
		
	}
	
}

function JSFnRemoveClick()
{
	var removed = confirm("Are you sure you want to remove this item?");

	return removed;
}

function JSFnCheckAll()
{
	bIndex = 1;

	var inputs = window.document.getElementsByTagName('input');
	
	var aCheckedCount = 0;
	var aCheckboxesPresent = 0;
	
	// Loop through all input elements
	for(var i=0; i < inputs.length; i++)
	{
		if (inputs[i].type.toLowerCase() == 'checkbox') //if the element is a checkbox then check it
		{
			inputs[i].checked = true;
		}
	}
}

function JSFnUncheckAll()
{
	bIndex = 1;

	var inputs = window.document.getElementsByTagName('input');
	
	var aCheckedCount = 0;
	var aCheckboxesPresent = 0;
	
	// Loop through all input elements
	for(var i=0; i < inputs.length; i++)
	{
		if (inputs[i].type.toLowerCase() == 'checkbox') //if the element is a checkbox then check it
		{
			inputs[i].checked = false;
		}
	}
}

function CountCheck()
{
	var chkCnt = 0;
	var Frm = document.forms[0]; // or name where the first form is 0
	var dLen = Frm.length - 1;
	for (i=0;i<=dLen;i++)
	{
		if (Frm.type == 'checkbox') chkCnt++;
	}
} 

var aContactRequiredFields = new Array ("name","Please enter your name to continue");

function JSFnValidateContactForm()
{
	var aEmail = document.getElementById('email');
	var aTelephone = document.getElementById('telephone');

	if ((aEmail != null) && (aTelephone != null))
	{
		if ((aEmail.value == '') && (aTelephone.value == ''))
		{
			alert('You must provide either your telephone number or email address to continue.');
			return false;
		}
	}

	return JSFnValidateForm(aContactRequiredFields);
}

function JSFnValidateForm(aRequiredFields)
{
	for (aIndex = 0; aIndex < aRequiredFields.length; aIndex = aIndex + 2)
	{
		currElement = document.getElementById(aRequiredFields[aIndex]);
		if (currElement != null)
		{
			if  (   (   (currElement.type == 'text')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'password')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'checkbox')
				     && (currElement.checked == false))
				 || (   (currElement.type == 'file')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'textarea')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'select-one')
				     && (currElement.value == '')))
			{
				alert(aRequiredFields[aIndex + 1]);
				return false;
			}
			else if (currElement.type == 'radio')
			{
				aIndex = aIndex + 2;
				if (!currElement.checked)
				{
					currElement = document.getElementById(aRequiredFields[aIndex]);
					if ((currElement.type == 'radio') && (!currElement.checked))
					{
						alert(aRequiredFields[aIndex + 1]);
						return false;
					}
				}
			}
		}
	}
	return true;
}

/******************************************************************************************************************************************/
function JSFnNewWindowLocation()
{
	window.open(this.href, '','width=540px,height=200px,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
	return false;
}

/******************************************************************************************************************************************/
function JSFnCloseNoRefresh()
{
	window.close();
	return false;
}
