window.onload = jsFnOnLoad;

function jsFnOnLoad()
{
	if (document.getElementById)
	{
		aFakeLink = document.getElementById('gennewuser');
		if (aFakeLink != null)
		{
			aFakeLink.style.textDecoration = 'underline';
			aFakeLink.style.cursor = 'pointer';
			aFakeLink.onclick = function(){window.location = 'newuser.php';}
		}

		var aReferFriend = document.getElementById('ReferFriend');
		if (aReferFriend != null) aReferFriend.onsubmit = JSFnValidateReferFriend;
		
		aProductContent = document.getElementById('content_bottom');
		if (aProductContent != null)
		{
			var aDiv = document.getElementsByTagName("div");
			var aFirst = true;
			if (aDiv != null) 
			{
				for(aDivIndex=0; aDivIndex < aDiv.length; aDivIndex++)
				{
					if(aDiv[aDivIndex].className=='tab')
					{
						if(aFirst) aFirst = false;
						else aDiv[aDivIndex].style.display = 'none';
					}
				}
			}
		}
		
		/* Open external and gallery links in new window */		 
		aLinks = document.getElementsByTagName("a");
		for (aIndex = 0; aIndex < aLinks.length; aIndex++)
		{
			if ((aLinks[aIndex].href.indexOf('http://192.168.1.21/') == -1) && (aLinks[aIndex].href.indexOf('http://www.vanallengroup.com') == -1) && (aLinks[aIndex].href.indexOf('http://www.yachtcrewgroup.com') == -1))
			{
				aLinks[aIndex].target = '_blank';
			}
		}

		//*** Link confirm ***********************************************************************************************
		var aLink = document.getElementsByTagName("a");
 		if (aLink != null) 
		{
			for(aLinkIndex=0;aLinkIndex<aLink.length;aLinkIndex++)
			{
				if(aLink[aLinkIndex].className=='rem') aLink[aLinkIndex].onclick = JSFnRemoveClick;
				if(aLink[aLinkIndex].className=='clear') aLink[aLinkIndex].onclick = JSFnRemoveClick;
				if(aLink[aLinkIndex].className=='viewhtml') aLink[aLinkIndex].onclick = JSFnNewWindow;
			}
		}				
		//******************************************************************************************************************
	}
}

var aReferFriendRequiredFields = new Array ("YourName","Please enter your name to continue",
											"YourEmailAddress","Please enter your email addrss to continue",
											"FriendsName","Please enter your friends name to continue",
											"FriendsEmailAddress","Please enter your friends email address to continue");
function JSFnValidateReferFriend()
{
	return JSFnValidateForm(aReferFriendRequiredFields);
}

/*** Pop Up Window ***/
function JSFnNewWindow()
{
	var aWindow = window.open(this.href, 'VIewHTML', 'scrollbars=yes, menubar=no, resizeable=yes, toolbar=no, width=800px, height=800px')
	aWindow.focus();
	return false;
}
//********************************************************************************************************************************

/*** Validate Form ***/
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;
}
//********************************************************************************************************************************

/*** Remove Link ***/
function JSFnRemoveClick()
{
	var removed = confirm("Are you sure you want to remove this item?");

	return removed;
}
//********************************************************************************************************************************
