// JavaScript Document
function validate(name,address,daytel,evetel,email,comments) {
	if (document.getElementById(name).value == '') {
		window.alert("Please enter your name.");
		return false;
	}
	if ((document.getElementById(address).value == '') && (document.getElementById(daytel).value == '') && (document.getElementById(evetel).value == '') && (document.getElementById(email).value == '')) {
		window.alert("Please enter at least one of your contact details.");
		return false;
	}
	if (document.getElementById(email).value.length > 0) {
		return checkEmail(document.getElementById(email).value);
	}
	if (document.getElementById(comments).value == '') {
		window.alert("Please enter the details of your query or your comments.");
		return false;
	}
	return true;
}

function checkEmail(email) {
	//window.alert(email);
	invalidChars = " /:,;";
	if (email.length > 0){
	
		for (i=0; i<invalidChars.length; i++) {
			badChar=invalidChars.charAt(i);
			if(email.indexOf(badChar,0)>-1) {
				alert('Please enter a valid e-mail address');
				return false;
			}
		}
			
		atPos=email.indexOf("@",1);
		if(atPos==-1) {
			alert('Please enter a valid e-mail address');
			return false;
		}
				
		if(email.indexOf("@",atPos+1)!=-1) {
			alert('Please enter a valid e-mail address');
			return false;
		}
				
		periodPos = email.indexOf(".",atPos);
		if(periodPos == -1) {	
			alert('Please enter a valid e-mail address');
			return false;
		}
				
		if(periodPos + 3 > email.length) {
			alert('Please enter a valid e-mail address');
			return false;
		}
	}
	return true;
}

var searchVal = self.location.search;
if (searchVal.length > 1) {
	searchVal = searchVal.substring(1,searchVal.length);
} else {
	searchVal = null;
}

urlVals = new Array();
if (searchVal) {
	for (var i=0; i < searchVal.split("&").length; i++) {
		urlVals[i] = searchVal.split("&")[i];
	}
}
if (urlVals.length > 0) {
	quoteImgVal = urlVals[0];
	quoteImg = quoteImgVal.substring((quoteImgVal.indexOf("=")+1),quoteImgVal.length);
	quoteImg = unescape(quoteImg);
	quotePieces = quoteImg.split("+");
	quoteImg = quotePieces[0];
	for (var a=1; a < quotePieces.length; a++) {
		quoteImg += " " + quotePieces[a];
	}
	//window.alert(quoteImg);
} else {
	quoteImg = "";
}
function getQuoteImg() {
	document.getElementById('quotePic').innerHTML = '<img src="' + quoteImg + '" />';
	document.getElementById('quoteImage').value = quoteImg;
}