function findObj(n, d) { //v4.0
  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;
}

function validateOrder(objForm){
	if(objForm.Title.value==""){
		objForm.Title.focus();
		alert("Please select your title.");
		return false;
	}
	if(objForm.FirstName.value==""){
		objForm.FirstName.focus();
		alert("Please enter your first name.");
		return false;
	}
	if(objForm.LastName.value==""){
		objForm.LastName.focus();
		alert("Please enter your surname.");
		return false;
	}
	if(objForm.ContactPhone.value==""){
		objForm.ContactPhone.focus();
		alert("Please select a contact phone number.");
		return false;
	}
	if(objForm.Email.value==""){
		objForm.Email.focus();
		alert("Please enter your email");
		return false;
	}
	if(!checkemail(objForm.Email.value)){
		objForm.Email.focus();
		return false;
	}
	if(objForm.DeliveryAddress.value==""){
		objForm.DeliveryAddress.focus();
		alert("Please enter your address.");
		return false;
	}
	if(objForm.DeliveryState.value==""){
		objForm.DeliveryState.focus();
		alert("Please select your state.");
		return false;
	}
	if(objForm.DeliveryPostcode.value==""){
		objForm.DeliveryPostcode.focus();
		alert("Please enter your postcode.");
		return false;
	}
}

function validateRequestForm(objForm){
	if(objForm.Title.value==""){
		objForm.Title.focus();
		alert("Please select your title.");
		return false;
	}
	if(objForm.FirstName.value==""){
		objForm.FirstName.focus();
		alert("Please enter your first name.");
		return false;
	}
	if(objForm.LastName.value==""){
		objForm.LastName.focus();
		alert("Please enter your surname.");
		return false;
	}
	if(objForm.Email.value==""){
		objForm.Email.focus();
		alert("Please enter your email");
		return false;
	}
	if(!checkemail(objForm.Email.value)){
		objForm.Email.focus();
		return false;
	}
	if(objForm.Message.value==""){
		objForm.Message.focus();
		alert("Please enter your message");
		return false;
	}
}

function validateMemorial(objForm){
	if(objForm.title.value==""){
		objForm.title.focus();
		alert("Please enter your pets name.");
		return false;
	}
	/*
	if(objForm.birthdate.value==""){
		objForm.birthdate.focus();
		alert("Please enter your pets date of birth.");
		return false;
	}
	if(objForm.deceased.value==""){
		objForm.deceased.focus();
		alert("Please enter your pets date of passing.");
		return false;
	}*/
	if(objForm.message.value==""){
		objForm.message.focus();
		alert("Please enter a personal message.");
		return false;
	}
	if(checkWordSpaces(objForm.message.value)>200){
		objForm.message.focus();
		alert("Please tell us in 200 words or less.");
		return false;		
	}
	if(objForm.upimage.value==""){
		alert("Please upload an image of your pet.");
		return false;
	}
}

function validateReminder(objForm){
	if(objForm.Email.value==""){
		objForm.Email.focus();
		alert("Please enter your email");
		return false;
	}
	if(!checkemail(objForm.Email.value)){
		objForm.Email.focus();
		return false;
	}
}

function checkemail(strEmail){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(strEmail)){
		return true;
	}else{
		alert("Please enter a valid email address");
		return false;
	}
}

function checkWordSpaces(string){
	var spaceCount = 0;
	for(var i=1; i<string.length; i++){
		if(string.charAt(i)==" " || string.charAt(i)=="\r"){
			spaceCount += 1;
		}
	}
	return(spaceCount + 1);
}

var newwindow = '';
function newPopup(theURL,width,height,scrollbars) {
	x = (640 - width)/2, y = (480 - height)/2;

    if (screen) {
        y = (screen.availHeight - height)/2;
        x = (screen.availWidth - width)/2;
    }
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = theURL;
	}
	else {
		newwindow=window.open(theURL,'newWin','width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',scrollbars='+scrollbars+',status=no,resizable=no');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}