<!--
//tyre form submit
function tyresubmit(dd) {
	for (x=dd; x<4; x++) {
		document.forms['tyresearchform'].elements[x].value='';
	}
	document.forms['tyresearchform'].submit();
}

// Links in new window
$(document).ready(function(){
	$('A[rel="_blank"]').each(function(){
	   $(this).attr('target', '_blank');
	   $(this).attr('title', 'External link opens in a new window.');
	});
});

//TO SHOW TERMS AND CONDITIONS
function termspop(div,action) {
	if (action=='show') {
		document.getElementById(div).style.display = 'block';
	} else {	
		document.getElementById(div).style.display = 'none';
	}
}

// TO CHECK BASIC FORM COMPLPETION
//function to check each field
function checkfield(field,mand,mini,maxi,reg,type) {
	field=document.getElementById(field);
	if (mand || field.value != '') {
		if (field.length < mini || field.length > maxi || !reg.test(field.value))	{
			var message;
			if(type=='email') message='You must type a valid email address!';
			else if(type=='captcha') message='Please copy the captcha code exactly as it appears in the box!';
			else message='The '+field.id+' must be '+mini+'-'+maxi+' '+type+' characters!';
			alert(message);
			field.focus();
			return false;
		}	
	}
	return true;
}

//main function for whole user form
function checkuserform(loc) {
	//check username
	var reg = /^[A-Za-z0-9_\-]{3,15}$/;
	if (!checkfield('user',true,3,15,reg,'alphanumeric')) return false;

	//check password
	var pass = document.getElementById('pass');
	var pass2 = document.getElementById('pass2');
	if (!checkfield('pass',true,3,15,reg,'alphanumeric')) return false;
	else if (pass.value != pass2.value)	{
		alert('The passwords entered do not match!');
		pass2.focus();
		return false;
	}

	//check email
	var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!checkfield('email',true,6,35,reg,'email')) return false;
	
	var email = document.getElementById('email');
	var emailconfirm = document.getElementById('emailconfirm');
	if (email.value != emailconfirm.value)	{
		alert('The emails entered do not match!');
		email.focus();
		return false;
	}

	//check firstname
	var reg = /^[A-Za-z]{3,15}$/;
	if (!checkfield('firstname',true,3,25,reg,'alphabetic')) return false;

	//check lastname
	if (!checkfield('lastname',true,3,25,reg,'alphabetic')) return false;

	//check telephone
	var reg = /^[0-9 ]{11,12}$/;
	if (!checkfield('tel',true,11,12,reg,'numeric')) return false;

	//check address
	var reg = /^[A-Za-z0-9\/, -]{5,50}$/;
	if (!checkfield('address1',true,5,50,reg,'alphanumeric')) return false;
	if (!checkfield('address2',false,5,50,reg,'alphanumeric')) return false;
	if (!checkfield('town',true,5,50,reg,'alphabetic')) return false;
	if (!checkfield('county',false,5,50,reg,'alphabetic')) return false;
	var reg = /^[A-Za-z0-9 ]{6,8}$/;
	if (!checkfield('postcode',true,6,8,reg,'alphanumeric')) return false;

	if (loc=="reg") {
		if (!document.getElementById('is18').checked) {
			alert('Sorry, but you must be at least 18 to join.');
			return false;
		}
		if (!document.getElementById('conditions').checked) {
			alert('Please read and agree to the terms and conditions before signing up.');
			return false;
		}	
	}
	//check captcha
	var reg = /^[A-Za-z0-9]{4}$/;
	if (!checkfield('captcha_code',true,4,4,reg,'captcha')) return false;

	return true;
}

$(document).ready(function() {
	
		
	//open info
	var fieldopen = new Array();
	fieldopen['width'] = false;
	fieldopen['profile'] = false;
	fieldopen['size'] = false;
	fieldopen['speed'] = false;
	
	var fields = new Array('width','profile','size','speed');
		
	//function to writch between open and closed
	function openclose(thisfield){
		if (fieldopen[thisfield]) {
			$('#guide'+thisfield+'text').hide('fast');
			fieldopen[thisfield] = false;
		} else {
			for (var i=0; i<4; i++) {
				$('#guide'+fields[i]+'text').hide('fast');
				fieldopen[fields[i]] = false;
			}
			$('#guide'+thisfield+'text').show('fast');
			fieldopen[thisfield] = true;
		}
	}
	
	//width
	$('#guidewidthtext').hide(); 
	$('#guidewidthinfo, #width_pic').click(function() {
	  openclose('width');
	}); 
	
	//profile				   
	$('#guideprofiletext').hide(); 
	$('#guideprofileinfo, #profile_pic').click(function() {
		openclose('profile');
	}); 

	//size					   
	$('#guidesizetext').hide(); 
	$('#guidesizeinfo, #size_pic').click(function() {
		openclose('size');
	}); 

	//speed					   
	$('#guidespeedtext').hide(); 
	$('#guidespeedinfo, #speed_pic').click(function() {
		openclose('speed');
	}); 

		
	//external links
	 if (!document.getElementsByTagName) return; 
	 var anchors = document.getElementsByTagName("a"); 
	 for (var i=0; i<anchors.length; i++) { 
	   var anchor = anchors[i]; 
	   if (anchor.getAttribute("href") && 
		   anchor.getAttribute("rel") == "external") 
		 anchor.target = "_blank"; 
	 } 

	//show hourglass cursor on auto submit
	$('#widthsel, #profilesel, #sizesel, a.x').change(function() {
		$('body').css('cursor', 'wait'); 
	})
 
});

//-->
