// JavaScript Document
function validation(){
	var title = document.getElementById('title');
	var name = document.getElementById('name');
	var company = document.getElementById('company');
	var address = document.getElementById('address');
	var telephone = document.getElementById('telephone');
	var email = document.getElementById('email');
	var attention = document.getElementById('attention');
	var details = document.getElementById('details');
	var other = document.getElementById('other');
	var check = document.getElementById('check');
	if(isEmail(email, 'Please enter your email'))
	{
		if(isSelected(title, "Please fill this field"))
		{
			if(isEmpty(name, "Please fill this field"))
			{
				if(isEmpty(company, "Please fill this field"))
				{
					if(isEmpty(address, "Please fill this field"))
					{
						if(isEmpty(telephone, "Please fill this field"))
						{
							if(isEmpty(email, "Please fill this field"))
							{
								if(isSelected(attention, "Please fill this field"))
								{
									if(isEmpty(details, "Please fill this field"))
									{
										return true;
									}
								}
							}
						}
					}
				}
			}
			
		}
		
	}
	return false;
}
function isEmail(elem, message){
	var emailCnt = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/
	if(elem.value.match(emailCnt)){
		return true;
	}else{
		alert(message);
		elem.focus();
		return false;
	}
}
function validateAlert()
{
	var email = document.getElementById('email');
	var cemail = document.getElementById('cemail');
	var title = document.getElementById('title');
	var surname = document.getElementById('surname');
	var forename = document.getElementById('forename');
	var address1 = document.getElementById('address1');
	var address2 = document.getElementById('address2');
	var address3 = document.getElementById('address3');
	var address4 = document.getElementById('address4');
	var postcode = document.getElementById('postcode');
	var telephone = document.getElementById('telephone');
	if(isEmail(email, 'Please enter email'))
	{
		if(isEmail(cemail, 'Please enter email'))
		{
			if(email.value == cemail.value)
			{
				if(isSelected(title, "Please fill this field"))
				{
					if(isEmpty(surname, "Please fill this field"))
					{
						if(isEmpty(forename, "Please fill this field"))
						{
							if(isEmpty(address1, "Please fill this field"))
							{
								if(isEmpty(postcode, "Please fill this field"))
								{
									if(isEmpty(telephone, "Please fill this field"))
									{
										return true;
									}
								}
							}
						}
					}
				}
			}else{
			alert('Both Email addresses must be identical');
			}
		}
					
	}
	return false;
}
function isEmail(elem, message){
		var emailCnt = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z0-9]{2,4}$/
		if(elem.value.match(emailCnt)){
				return true;
		}else{
			alert(message)
			elem.focus();
			return false;
			}
	}
/*	Send email to a friend		*/
function formValidator(){
	var yourEmail = document.getElementById('yourEmail');
	var yourName = document.getElementById('yourName');
	var ReciepientEmail = document.getElementById('ReciepientEmail');
	var message = document.getElementById('message');

	if(emailValidator(yourEmail, "Please enter a valid email address")){
		if(isEmpty(yourName, "Please enter a name")){
			if(emailValidator(ReciepientEmail, "Please enter a valid email address")){
				return true;
			}
		}
	}
	return false;
}

function isSame(){
		if(document.getElementById('yourEmail').value == document.getElementById('ReciepientEmail').value){
			alert('Please provide correct email address');
			elem.focus();
		return false;
		}else{
			return true;
		}
}
function isMessage(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}
function isSelected(elem, helperMsg){
	if(elem.selectedIndex < 1){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}
/* Archive */
function setSearch(){
	var url = window.location.href.substring(0,window.location.href.indexOf('.asp')+4);
	if (document.getElementById("month").selectedIndex>0){
		month = document.getElementById("month").value;
		if (document.getElementById("year").selectedIndex>-1)
			year = document.getElementById("year").value;
		else
			year = document.getElementById("year").options[1].value;
	window.location.href=url+'?month=' + month +"&year=" + year;
	}else if (document.getElementById("year").selectedIndex>-1){
		year = document.getElementById("year").value;
		if (document.getElementById("month").selectedIndex>-1)
			month = document.getElementById("month").value;
		else
			month = document.getElementById("month").options[1].value;
	window.location.href=url+'?month=' + month +"&year=" + year;
	}
}