function inc(filename)
	{
	var head = document.getElementsByTagName('head').item(0);
	var js = document.createElement('script');
 	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', "/scripts/" + filename);
	head.appendChild(js)
	}

function thickbox()
	{	
	inc("jquery-1.1.3.1.js")
	inc("thickbox-3.1.js")
	}
	
function thickbox2()
	{
	inc("thickbox-3.1.js")
	}

//Start Up On Load Events
function startup()
	{
	input_btn()
	if(document.getElementById("userlogin"))document.getElementById("userlogin").focus()
	cms_menu()
	}
	
function cursor_sniff(fobj)
	{
	if (document.all){fobj.cursor="hand"}
	else{fobj.cursor="pointer"}
	}
	
//Caravan Finder Tours
function CF_movie(src,w,h)
	{
	document.write ('<object id="cftour" type="application/x-shockwave-flash" data="'+src+'" width="'+w+'" height="'+h+'">')
	document.write ('<param name="movie" value="'+src+'"/>')
	document.write ('<param name="wmode" value="transparent"/>')
	document.write ('</object>') 
	}
	
function compare_filter(num)
	{
	//Reset table
	document.getElementById("msg_response").style.display="none"
	document.getElementById("tblcolnum").value=0
		
	//Do Filter
	k		= 0;
	navRoot = document.getElementById("model_comparison")
	$(".filter_selected").removeClass("filter_selected");
	$("#filter_"+num).addClass("filter_selected");
	for (i=0;i<navRoot.childNodes.length;i++) 
			{
			node = navRoot.childNodes[i];
			
			$('.'+node.title).hide();
			$('#check_'+node.title).attr("checked","")
			
			if (node.className==eval('"'+num.toString()+'berth"') || num==0)
				{
				node.style.display="block";
				k++;
				if(k<5)
					{$('.'+node.title).show();$('#check_'+node.title).attr("checked","checked");$('#tblcolnum').val(k)}
				}
			else
				{
				node.style.display="none"
				}
			}
	
	}
	
//Find a Retailer
function find_retailer(fm)
	{
	mt=true;
	if(fm.pc.value=='Enter a location'){mt=false;alert("You must enter the first part of your post code");fm.pc.focus();return mt}
	checker(fm.pc,"You must enter the first part of your post code");
	return mt;	
	}
	
function search_for(fm)
	{
	mt=true;
	if(fm.search_box.value.length<3){mt=false;vmessage(fm.search_box,"Your search query must be at least three letters")}
	return mt;	
	}

//Input Button Hover
function input_btn()
	{
	var inp = document.getElementsByTagName("INPUT")
	for (i=0;i<inp.length;i++){if (inp[i].className=="ebtn"){inp[i].onmouseover=function(){cursor_sniff(this.style)}}}		
	}
	
// Form Validation
function checker(fobj,msg)
	{if(fobj.value=="" && mt==true)vmessage(fobj,msg)}
	
function vmessage(fobj,msg)
	{alert(msg);fobj.focus();mt=false}
	
function email(fobj)
	{
	var emailStr=fobj.value;var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)!£$%^&*()+='#~?<>@,;:\\\\\\\"\\.\\[\\]";var validChars="\[^\\s" + specialChars + "\]";var quotedUser="(\"[^\"]*\")";var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+';var word="(" + atom + "|" + quotedUser + ")";var userPat=new RegExp("^" + word + "(\\." + word + ")*$");var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");var matchArray=emailStr.match(emailPat)
	if ((matchArray==null) && mt==true){vmessage(fobj,"Email address seems incorrect (check @ and .'s)")}
	if (mt==true){var user=matchArray [1];var domain=matchArray [2];if (user.match(userPat)==null)vmessage(fobj,"The username doesn't seem to be valid.")}
	if (mt==true){var IPArray=domain.match(ipDomainPat);if (IPArray!=null){for (var j=1;j<=4;j++){if (IPArray[j]>255)vmessage(fobj,"Destination IP address is invalid!")}}}
	if (mt==true){var domainArray=domain.match(domainPat);if (domainArray==null)vmessage(fobj,"The domain name doesn't seem to be valid.")}
	if (mt==true){var atomPat=new RegExp(atom,"g");var domArr=domain.match(atomPat);var len=domArr.length;if(domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4)vmessage(fobj,"The address must end in a two,three or four letter domain")}
	if ((len<2) && mt==true)vmessage(fobj,"This address is missing a hostname!");
	}
	
function checker_select(fobj,msg,stval)
	{if(fobj.options[fobj.selectedIndex].text==stval && mt==true)vmessage(fobj,msg)}
		
//Newsletter
function sign_up(fm)
	{
	mt=true;
	checker(fm.fname,"You must enter your first name please");
	checker(fm.lname,"You must enter your last name please");
	checker(fm.add_1,"You must enter the firstline of the your address please");
	checker(fm.postcode,"You must enter your post code please");
	email(fm.email);
	checker(fm.tel,"You must enter a daytime telephone please");
	checker(fm.captcha,"Please enter the security code");
	return mt;
	}

function tab_format()
	{
	var navRoot = document.getElementById("pageview")
	if (navRoot)
		{
		//LI event handler
		for (i=0; i<navRoot.childNodes.length;i++) 
			{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") 
				{
				node.onmouseover= function(){cursor_sniff(this.style)}							
				node.onclick	= function(){reset_tabs(navRoot);tab = format_tab(this.innerHTML);change_tab(tab,'block');this.className+="over"}	
				}				
			}
		}
	}
	
function format_tab(a)
	{a=a.toLowerCase().split("'");b=a[0].split(" ");c=b[0].toString();return c}
	
function change_tab(tab,style)
	{e=eval('document.getElementById("'+tab+'")');e.style.display=style}
	
function reset_tabs(navRoot)
	{for (i=0; i<navRoot.childNodes.length;i++){node = navRoot.childNodes[i];if(node.nodeName=="LI"){node.className=node.className.replace("over", "");tab=format_tab(node.innerHTML);change_tab(tab,'none')}}}
	
window.onload = startup