window.onload = jsFnOnload;

function jsFnOnload()
{
	if (document.getElementById)
	{	
		var aScrollDiv = document.getElementById('content');
 		if (aScrollDiv != null) {	 
			JsFnConfigureScoll();
	  	}
	  	
	  	var aFlashDiv = document.getElementById('flash');
	  	if (aFlashDiv != null) {	 
			JSFnCreateFlash();
	  	}
	  	
		/* Associate logo's onclick event with home page */
		var logo = document.getElementById("logo");
 		if (logo != null) {
			logo.onclick = function() {
				window.location = 'index.php';
				return false;
			}
		}
		
		var menu = document.getElementById("topmenu");
 		if (menu != null) 
		{
			var lis = menu.getElementsByTagName("li");
			for(aliindex=0;aliindex<lis.length;aliindex++)
			{
				if(lis[aliindex].className=='level1')
				{
					lis[aliindex].onclick = JSFnMenuLiClick;
					
					lis[aliindex].onmouseover = JSFnMenuLiOver;
					lis[aliindex].onmouseout = JSFnMenuLiOut;
				}
			}
		}		
		
		var aDateDots = document.getElementById('datedots');
		if (aDateDots != null) 
		{
			JSFnHideDotInfo();
			JSFnPrepDateDots();
		}
		
		var aContactForm = document.getElementById('contactform');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;
		
		var aImageZoom = document.getElementById('largeimage');
		if (aImageZoom != null) aImageZoom.onclick = JSFnImageZoom;
	}
	
}

function JSFnPrepDateDots()
{
	var aDateDiv = document.getElementById("datedots");
	var aContent = document.getElementById("content");
	if (aDateDiv != null) 
	{
		var aImgs = aDateDiv.getElementsByTagName("img");
		for(aImgIndex = 0; aImgIndex < aImgs.length; aImgIndex++)
		{
			aImgs[aImgIndex].onclick = JSFnDateDotClick;
			aImgs[aImgIndex].style.cursor = 'pointer';
		}
				
		aNewParagraph = document.createElement("p");
		aNewParagraph.style.width = '180px'; 
		aNewParagraph.style.fontSize = '0.7em';
		aNewTextNode = document.createTextNode('Click a red dot on the map to see the tour information for that location.');
		aNewParagraph.appendChild(aNewTextNode);
		aContent.appendChild(aNewParagraph);	
	}
}

function JSFnDateDotClick()
{
	JSFnHideDotInfo(this.className);
}

function JSFnHideDotInfo(aTown)
{
	var menu = document.getElementById("content");
	if (menu != null) 
	{
		var aParas = menu.getElementsByTagName("p");
		for(aParaIndex = 0; aParaIndex < aParas.length; aParaIndex++)
		{
			if ((aParas[aParaIndex].className != aTown) && (aParas[aParaIndex].className != '')) 
			{
				aParas[aParaIndex].style.width = '180px'; 
				aParas[aParaIndex].style.fontSize = '0.7em';
				aParas[aParaIndex].style.display = 'none';
			}
			else if (aParas[aParaIndex].className != '') 
			{
			 	aParas[aParaIndex].style.width = '180px'; 
				aParas[aParaIndex].style.fontSize = '0.7em';
				aParas[aParaIndex].style.display = 'block';
			}
		}
		JsFnConfigureScoll();
	}
}

function JsFnConfigureScoll()
{
	aScrollDiv = document.getElementById('content');
	aScrollSpan= document.getElementById('container');

		

	aScrollDiv.style.height = 'auto';
	aRealHeight = aScrollDiv.offsetHeight;
	aScrollDiv.style.height = '646px';
	
	if (aRealHeight > 756)
	{		
		aScrollDiv.style.height = '606px';
		aScrollDiv.style.marginBottom = '40px';
		
		aScrollDiv.className = 'js';
		
		aNewParagraph = document.createElement("p");
		aNewParagraph.id = 'updownpara';
		aNewLink = document.createElement("a");
		aNewLink.href = '';
		aNewLink.onclick = JsFnScrollDown;
		aNewTextNode = document.createTextNode('down');
		aNewLink.appendChild(aNewTextNode);
		aNewParagraph.appendChild(aNewLink);
		
		aNewTextNode = document.createTextNode(' | ');
		aNewParagraph.appendChild(aNewTextNode);
		
		aNewLink = document.createElement("a");
		aNewLink.href = '';
		aNewLink.onclick = JsFnScrollUp;
		aNewTextNode = document.createTextNode('up');
		aNewLink.appendChild(aNewTextNode);
		aNewParagraph.appendChild(aNewLink);
		aScrollSpan.appendChild(aNewParagraph);	
	}
}

function JsFnScrollDown()
{
	aScrollDiv = document.getElementById('content');
	aScrollDiv.scrollTop += 600;
	return false;
}

function JsFnScrollUp()
{
	aScrollDiv = document.getElementById('content');
	aScrollDiv.scrollTop -= 600;
	return false;
}

function JSFnMenuLiOver()
{
	this.className = 'level1 hover';
}

function JSFnMenuLiOut()
{
	this.className = 'level1';
}

function JSFnMenuLiClick()
{
	window.location = this.childNodes[0].href;
	//alert(this.childNodes[0]);
}

function JSFnGoBack()
{
	history.go(-1);
}

function JSFnImageZoom()
{
	var aWindow = window.open(this.href, 'productbig', 'menubar=no, resizeable=no, toolbar=no, width=600px, height=600px')
	aWindow.focus();
	return false;
}

var aContactRequiredFields = new Array ("firstname","Please enter your name to continue","surname","Please enter your surname to continue");

function JSFnValidateContactForm()
{
	var aEmail = document.getElementById('email');
	var aTelephone = document.getElementById('telephone');
	var aMobile = document.getElementById('mobile');
	if ((aEmail != null) && (aTelephone != null) && (aMobile != null))
	{
		if ((aEmail.value == '') && (aTelephone.value == '') && (aMobile.value == ''))
		{
			alert('You must provide either your telephone/mobile 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 JSFnCreateFlash()
{
 	var aFlashDiv = document.getElementById('flash');
	var aFlashObject = document.getElementById('indexflash');
	
	aFlashData = aFlashObject.getAttribute("data");
	
 	aFlashDiv.removeChild(aFlashDiv.childNodes[0]);
 	
	aContent = '<object type="application/x-shockwave-flash" data="' + aFlashData + '" id="indexflash">\n';
	aContent += '<param name="movie" value="' + aFlashData + '" />\n';
	aContent += '<param name="wmode" value="transparent"></param>\n';
	aContent += '<param name="play" value="true"></param>\n';
	aContent += '<br />Your browser does not support Flash - please use the menu at the top of the page to navigate the site.';
	aContent += '</object>\n';
	
	aFlashDiv.innerHTML = aContent;
}