<!--

//NEWS TICKER
//HOME MADE - IT WILL WORK BUT NEEDS WORK!!!!
function displayNews(i,text) {
	var content=document.getElementById("ticker");
	var lgth=content.length;
	content.innerHTML=text.substring(0, i)+"_";
}

function news() {
	if(document.getElementById("ticker")) {
		var text=document.getElementById("ticker").innerHTML;
		for(var i=0; i<(text.length+1); i++) {
			setTimeout("displayNews('"+i+"','"+text+"')", 1000);
		}
	}
}


function imageSwap() {
	var links=document.getElementsByTagName("a");
	for(var i=0;  i<links.length; i++) {
		if(links[i].className=="thumbnail") {
			links[i].onclick=function() {
				var newImage=this.getAttribute("href");
				var oldImage=document.getElementById("large_image");
				oldImage.setAttribute("src", newImage);
				return false;
			}
		}
	}
}


// JavaScript Document

//ALLOWS EXTERNAL LINKS TO BE OPENED IN A NEW WINDOW WITHOUT THE USE OF TARGET ATTRIBUTE
//LOOPS THROUGH LINKS ON PAGE FINDS EXTERNAL LINKS AND ADDS TARGET//
function externalLinks() {
	//SETS DOMAIN OF SITE
	var domainName=document.domain;
	
	//FIND ALL LINKS ON THE CURRENT PAGE
	var externalLinks=document.getElementsByTagName("a");
	//LOOP THROUGH LINKS ARRAY
	for(var i=0; i<externalLinks.length; i++) {
		//GETS CONTENT OF 'HREF' ATTRIBUTE ON CLICKED LINK
		var attribute=externalLinks[i].getAttribute("href");
		
		//GET VALUE http IN 'HREF' **FOR MOZILLA&&
		var contains_http=attribute.indexOf("http");
		
		//GET VALUE domainName **FOR IE**
		var contains_domain=attribute.indexOf(domainName);
		
		//DOES CONTAIN AN 'http' OR DOES NOT CONTAIN domainName
		if(contains_http>-1 && contains_domain==-1) {
			//SET NEW ATTRIBUTE ON LINK
			externalLinks[i].setAttribute("target", "_blank");
		}
		
	}
	
}

//COLLAPSE ALL UL ELEMENTS WITHIN LI ELEMENT WITH CLASS OF 'expand'
function menuFunction() {

	//GET ALL LIs ON THE PAGE
	var listElements=document.getElementsByTagName("li");
	
	//CONDENSE MENU ON PAGE LOAD
	for(var i=0; i<listElements.length; i++) {
		
		//DOES LI HAVE THE CLASS WE WANT
		if (listElements[i].className=='expand') { 
		
			//GET THE UL WITHIN OUR LI
			var subCat=listElements[i].getElementsByTagName("ul");
			
			//HIDE IT
			subCat[0].style.display="none";
		
		}
		
	}
	
}

function menu() {
	
	//GET ALL LIs ON THE PAGE
	var listElements=document.getElementsByTagName("li");
	
	for(var i=0; i<listElements.length; i++) {
		
		//HAS THE SPAN ELEMENT WITHIN OUT LIST BEEN CLICKED
		if(listElements[i].firstChild) {
			listElements[i].firstChild.onclick=function() {
				
				//DOES THE PARENT (LI) OF OUR SPAN HAVE A CLASS NAME THAT WE WANT
				if(this.parentNode.className=="expand") {
					
					//GET UL FROM WITHIN OUR LIST ELEMENT AND OPEN CLOSE IT DEPENDING ON CURRENT STATE
					var subCat=this.parentNode.getElementsByTagName("ul");
					
					//IF UL IS ALREADY HIDDEN SHOW IT AND VISA VERSA
					if(subCat[0].style.display=="none") {
						subCat[0].style.display="block";
					}else{
						subCat[0].style.display="none";
					}
					
				}
				
			}
			
		}
		
	}
	
}

function liHeights() {

	if(!document.getElementsByTagName('ul'));
	
	var uls = document.getElementsByTagName('ul');
	
	var elementHeight = 0;
	
	for(var i=0; i<uls.length; i++) {
	
		if(uls[i].className == 'gallery_images') {
		
			var listElements = uls[i].getElementsByTagName('li');
			
			for(var x=0; x<listElements.length; x++) {
			
				if(listElements[x].offsetHeight > elementHeight) {
					
					elementHeight = listElements[x].offsetHeight;
					
				}
			
			}
			
			for(x=0; x<listElements.length; x++) {
			
				listElements[x].style.height=elementHeight + 'px';
			
			}
		
		}
	
	}

}

function homePageGrid() {

	if(!document.getElementsByTagName('div')) return false;
	
	var divs = document.getElementsByTagName('div');
	
	var elementHeight = 0;
	
	for(var i=0; i<divs.length; i++) {
	
		if(divs[i].className == 'product_boxed') {
		
			if(divs[i].offsetHeight > elementHeight) {
			
				elementHeight = divs[i].offsetHeight;
			
			}
		
		}
	
	}
	
	for(var i=0; i<divs.length; i++) {
	
		if(divs[i].className == 'product_boxed') {
	
			divs[i].style.height = elementHeight + 'px';
		
		}
	
	}

}

var lgth=0;
var newsitems = newsArticles;
var newslinks = newsLinks;

// ****  Do not alter below this line *****************************************
var ini=0; var st=0; var x=newsitems[0].length;
	
function newsclicker() {
	
	var temp=newsitems[ini].substring(0,st);
	var thislink=newslinks[ini];
	var thing = unescape(temp);
	
	var displaynews = document.getElementById('tickertextbox');
	
	displaynews.innerHTML="<a href=\""+thislink+"\">"+thing+"</a> ";
	
	if(st++==x) { 
		//Adjust timer for delay between messages
		st=0; setTimeout("newsclicker()",3000); ini++;
		if(ini==newsitems.length) ini=0; x=newsitems[ini].length; 
	} else {
		//adjust timer for "clicking speed" eg letter,letter,letter....
		setTimeout("newsclicker()",10);
	}
		
}

//EXECUTES ONLOAD FUNCTIONS
function loadfunctions() {
	imageSwap();
	externalLinks();
	menuFunction();
	menu();
	
}
//LOADS IN MULTIPLE FUNCTIONS ONLOAD
window.onload=loadfunctions;


// BIKEMAGIC COOKIE
function set_bikemagic() {
	var nextyear=new Date();
	nextyear.setFullYear(nextyear.getFullYear()+1);
	var cookies=document.cookie;
	var cookprod=cookies.indexOf("atchdregal=");
	if (cookprod==-1) { document.cookie="atchdregal=bikemagic;expires=" + nextyear.toGMTString(); } }

// FUNCTION REQUIRED FOR VALIDATION FUNCTIONS
function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x; }

// VALIDATES NON-FINANCE FORM
function MM_validateForm() {
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { 
		test=args[i+2]; val=MM_findObj(args[i]);
		if (val) { 
			nm=val.name; 
			if ((val=val.value)!="") {
				if (test.indexOf('isEmail')!=-1) { 
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) { 
						errors+='- '+nm+' must contain an e-mail address\n'; } } 
				else if (test!='R') {
					if (isNaN(val)) { 
						errors+='- '+nm+' must contain a number\n'; }
					if (test.indexOf('inRange') != -1) { 
						p=test.indexOf(':');
						min=test.substring(8,p); 
						max=test.substring(p+1);
						if (val<min || max<val) { 
							errors+='- '+nm+' must contain a number between '+min+' and '+max+'\n'; } } } }
		else if (test.charAt(0) == 'R') {
			errors += '- '+nm+'\n'; } } } 
	
	
	// CHECK CARD PAYMENT DETAILS
	// ENSURE USER ENTERED CARD TYPE
	if (document.finance_form.cardtype.value=='') { 
		errors+='- cardtype\n'; }
	// FULL EXPIRY DATE REQUIRED
	if ((document.finance_form.expmonth.value=='')||(document.finance_form.expyear.value=='')) { 
		errors+='- full expiry date\n'; }
	// ISSUE NO OR DATE REQUIRED FOR SWITCH/SOLO/ELECTRON
	/*
	if ((	(document.finance_form.cardtype.value=='Switch')	||
			(document.finance_form.cardtype.value=='Solo')	||
			(document.finance_form.cardtype.value=='Electron'))
			&&
			((document.finance_form.issueno.value=='')&&((document.finance_form.issmonth.value=='')||(document.finance_form.issyear.value=='')))	) { 
		errors+='- issue number or full issue date\n'; }
	*/
	// ENSURE USER ENTERED CARD NO
	if (document.finance_form.cardno.value=='') { 
		errors+='- card number\n'; }
	// ENSURE USER ENTERED CARD SECURITY CODE
	if (document.finance_form.security_code.value=='') { 
		errors+='- card security code\n'; }
	
	// AGREE TO TERMS AND CONDITIONS
	if (document.finance_form.agree.value=='N') { 
		errors+='\nYou must agree to All Terrain Cycle\'s Terms & Conditions before confirming your order.         \n'; }
	
	
	// SHOW ERRORS IF OCCURED
	if (errors) {
		alert('Please enter the following details before proceeding:            \n\n'+errors); }
	document.MM_returnValue = (errors == ''); }

// VALIDATES FINANCE FORM
function validateFinance() {
	// WORK OUT TIME AT CURRENT ADDRESS
	if (document.finance_form.Current_Months.value) { 
		var now_months=document.finance_form.Current_Months.value/12;
		var red=(document.finance_form.Current_Years.value/1)+now_months; }
	else if (document.finance_form.Current_Years.value) {
		var red=document.finance_form.Current_Years.value; }
	else {
		var red=0; }
	// WORK OUT TIME AT PREVIOUS ADDRESS
	if (document.finance_form.prev_mths1.value) { 
		var previous1=document.finance_form.prev_mths1.value/12;
		var green=document.finance_form.prev_yrs1.value/1+previous1+red; }
	else if (document.finance_form.prev_yrs1.value) {
		var green=document.finance_form.prev_yrs1.value+red; }
	else {
		var green=red+0; }
	// WORK OUT TIME AT 2 ADDRESSES AGO
	if (document.finance_form.prev_mths2.value) { 
		var prev_months2=document.finance_form.prev_mths2.value/12;
		var blue=(document.finance_form.prev_yrs2.value/1)+prev_months2+green; }
	else if (document.finance_form.prev_yrs2.value) {
		var blue=(document.finance_form.prev_yrs2.value)+green; }
	else {
		var blue=green+0; }
	
	var i,p,q,nm,test,num,min,max,errors='',args=validateFinance.arguments;
	for (i=0; i<(args.length-2); i+=3) { 
		test=args[i+2]; 
		val=MM_findObj(args[i]);

		if (val) { 
			nm=val.name; 
			if ((val=val.value)!="") {
				if (test.indexOf('isEmail')!=-1) { 
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) { 
						errors+='- '+nm+' must contain an e-mail address\n'; } } 
				else if (test!='R') {
					if (isNaN(val)) {
						errors+='- '+nm+' must contain a number\n'; }
					if (test.indexOf('inRange') != -1) { 
						p=test.indexOf(':');
						min=test.substring(8,p); 
						max=test.substring(p+1);
						if (val<min || max<val) { 
							errors+='- '+nm+' must contain a number between '+min+' and '+max+'\n'; } } } } 
			else if (test.charAt(0) == 'R') { 
				errors += '  - '+nm+' is required\n'; } } } 
	
	// NO TITLE
	if ((document.finance_form.Title[0].checked==false)&&(document.finance_form.Title[1].checked==false)&&(document.finance_form.Title[2].checked==false)&&(document.finance_form.Title[3].checked==false)&&(document.finance_form.Title[4].checked==false)) { 
		errors+='  - Title is required\n'; }
	// NO HOME STATUS
	if ((document.finance_form.Home_Status[0].checked==false)&&(document.finance_form.Home_Status[1].checked==false)&&(document.finance_form.Home_Status[2].checked==false)&&(document.finance_form.Home_Status[3].checked==false)) { 
		errors+='  - Home Status is required\n'; }
	// NO MARRIAGE STATUS
	if ((document.finance_form.Marriage_Status[0].checked==false)&&(document.finance_form.Marriage_Status[1].checked==false)&&(document.finance_form.Marriage_Status[2].checked==false)&&(document.finance_form.Marriage_Status[3].checked==false)&&(document.finance_form.Marriage_Status[4].checked==false)) { 
		errors+='  - Marriage Status is required\n'; }
	// NO EMPLOYMENT
	if ((document.finance_form.Employment_Details[0].checked==false)&&(document.finance_form.Employment_Details[1].checked==false)&&(document.finance_form.Employment_Details[2].checked==false)&&(document.finance_form.Employment_Details[3].checked==false)&&(document.finance_form.Employment_Details[4].checked==false)) { 
		errors+='  - Employment Status is required\n'; }
	// NEED MORE ADDRESSES SINCE NOT LIVED THERE FOR THREE YEARS
	if ((document.finance_form.Current_Years.value<3)&&(document.finance_form.prev_add.value=="")) { 
		errors+='  - Previous Address 1 is required\n'; }
	if ((document.finance_form.prev_add.value!="")&&(document.finance_form.prev_post.value=="")) { 
		errors+='  - Previous Postcode 1 is required\n'; }
	if ((document.finance_form.prev_add.value!="")&&(document.finance_form.prev_mths1.value=="")&&(document.finance_form.prev_yrs1.value=="")) { 
		errors+='  - Time at previous address 1 is required\n'; }
	if ((green<3)&&(document.finance_form.prev_add2.value=="")) { 
		errors+='  - Previous Address 2 is required\n'; }
	if ((document.finance_form.prev_add2.value!="")&&(document.finance_form.prev_post2.value=="")) { 
		errors+='  - Previous Postcode 2 is required\n'; }
	if ((document.finance_form.prev_add2.value!="")&&(document.finance_form.prev_mths2.value=="")&&(document.finance_form.prev_yrs2.value=="")) { 
		errors+='  - Time at previous address 2 is required\n'; }
	if ((blue<3)&&(document.finance_form.prev_add3.value=="")) { 
		errors+='  - Previous Address 3 is required\n'; }
	if ((document.finance_form.prev_add3.value!="")&&(document.finance_form.prev_post3.value=="")) { 
		errors+='  - Previous Postcode 3 is required\n'; }
	if ((document.finance_form.prev_add3.value!="")&&(document.finance_form.prev_mths3.value=="")&&(document.finance_form.prev_yrs3.value=="")) { 
  		errors+='  - Time at previous address 3 is required\n'; }
	// NEW DEPOSIT MUST BE EQUAL TO OR GREATER THAN REQUIRED DEPOSIT
	if (document.finance_form.New_Deposit.value<document.finance_form.Required_Deposit.value) {
		errors+='  - Your adjusted deposit cannot be smaller than the required deposit\n'; }
	
	// MUST ENTER CARD SECURITY IF ENTERED CARD TYPE
	if (document.finance_form.cardno.value!='') { 
		if (document.finance_form.security_code.value=='') {
			errors+='  - Credit card security code\n'; } }
			
	// IF DEPOSIT REQUIRED OR CHOSEN - MUST ENTER CHEQUE OR CREDIT CARD DETAILS
	if ((document.finance_form.pay_now_required.value=='1')&&(document.finance_form.Cheque.checked==false)&&(!document.finance_form.cardholder.value)) {
		errors+='\nFull credit card details or cheque payment required to cover deposit\n'; }
	
	// AGREE TO TERMS AND CONDITIONS
	if (document.finance_form.agree.value=='N') { 
		errors+='\nYou must agree to All Terrain Cycle\'s Terms & Conditions before confirming your order.           \n'; }
	
	
	// SHOW ERRORS IF OCCURED
	if (errors) {
		alert('Please amend the following error(s):\n\n'+errors); }
	document.MM_returnValue = (errors == ''); }
	
	
	function showEnlargement(filename) {
		
		if(!document.getElementById('largeone')) return false;
		
		var image = document.getElementById('largeone');
		
		var attr = image.setAttribute('href', filename);
		
		var newAtt = image.getAttribute('href');
		
		return false;
		
	}
	
	
//-->