// JavaScript Document
function hoverImage(imgID, changeTo){
	if(document.getElementById(imgID)){
		document.getElementById(imgID).src = 'images/'+changeTo;
	}
}

function show_desc(desc){
	document.getElementById('login_to_desc').innerHTML = document.getElementById(desc+'_desc').innerHTML;
}

function showClientHelp(desc){
	document.getElementById('client-help').innerHTML = document.getElementById('desc-'+desc).innerHTML;
}

function valAccountForm(theField, theValue){
	switch(theField){
		case 'name':
		if(theValue != "" && theValue.length > 5){
			document.getElementById('imgval-'+theField).src='images/1_round_small.png';
			document.getElementById('formError').innerHTML = '';
		}
		else{
			document.getElementById('imgval-'+theField).src='images/0_round_small.png';
			document.getElementById('formError').innerHTML = 'Please provide your full name for registration.';
		}
		break;
		
		case 'address':
		if(theValue != "" && theValue.length > 8){
			document.getElementById('imgval-'+theField).src='images/1_round_small.png';
			document.getElementById('formError').innerHTML = '';
		}
		else{
			document.getElementById('imgval-'+theField).src='images/0_round_small.png';
			document.getElementById('formError').innerHTML = 'Please provide at least the first line of your address.';
		}
		break;
		
		case 'postcode':
		if(theValue != "" && theValue.length > 4){
			document.getElementById('imgval-'+theField).src='images/1_round_small.png';
			document.getElementById('formError').innerHTML = '';
		}
		else{
			document.getElementById('imgval-'+theField).src='images/0_round_small.png';
			document.getElementById('formError').innerHTML = 'Please provide your post code.';
		}
		break;
		
		case 'tel':
		case 'mob':
		theTel = document.getElementById('tel').value;
		theMob = document.getElementById('mob').value;
		if((theTel != "" || theMob != '') && (theTel.length > 10 | theMob.length > 10)){
			document.getElementById('imgval-tel').src='images/1_round_small.png';
			document.getElementById('imgval-mob').src='images/1_round_small.png';
			document.getElementById('formError').innerHTML = '';
		}
		else{
			document.getElementById('imgval-tel').src='images/0_round_small.png';
			document.getElementById('imgval-mob').src='images/0_round_small.png';
			document.getElementById('formError').innerHTML = 'At least one number is required. Telephone or Mobile. Please include area code.';
		}
		break;
		
		case 'email':
		if(theValue != "" && theValue.length > 4 && /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theValue)){
			document.getElementById('imgval-'+theField).src='images/1_round_small.png';
			document.getElementById('formError').innerHTML = '';
		}
		else{
			document.getElementById('imgval-'+theField).src='images/0_round_small.png';
			document.getElementById('formError').innerHTML = 'A valid email address is essential. Using an email address hosted on our servers is not recommended.';
		}
		break;
		
		case 'cemail':
		if(theValue != "" && theValue == document.getElementById('email').value){
			document.getElementById('imgval-'+theField).src='images/1_round_small.png';
			document.getElementById('formError').innerHTML = '';
		}
		else{
			document.getElementById('imgval-'+theField).src='images/0_round_small.png';
			document.getElementById('formError').innerHTML = 'Email addresses do not match.';
		}
		break;
		
		case 'npw':
		if(theValue != "" && theValue.length > 5){
			document.getElementById('imgval-'+theField).src='images/1_round_small.png';
			document.getElementById('formError').innerHTML = '';
		}
		else{
			document.getElementById('imgval-'+theField).src='images/0_round_small.png';
			document.getElementById('formError').innerHTML = 'Password must 6 characters or more.';
		}
		break;
		
		case 'cnpw':
		if(theValue != "" && theValue == document.getElementById('npw').value){
			document.getElementById('imgval-'+theField).src='images/1_round_small.png';
			document.getElementById('formError').innerHTML = '';
		}
		else{
			document.getElementById('imgval-'+theField).src='images/0_round_small.png';
			document.getElementById('formError').innerHTML = 'Passwords do not match.';
		}
		break;
	}
}
