// JavaScript Document

//email-a-friend function
function emailPage(URLStr, left, top, width, height) {
/********************************************
DESCRIPTION: emails a friend
DATE ADDED: 10th November 2007
*********************************************/
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function emailPageCheck(emailOne, emailTwo) {
/********************************************
DESCRIPTION: email-a-page-to-a-friend check
DATE ADDED: 10th November 2007
*********************************************/

	if (!emailValid(emailOne)) {
		return false;
	}
	if (!emailValid(emailTwo)) {
		return false;
	}
	return true;
}

function emailValid(email) {
/********************************************
DESCRIPTION: email address validator
DATE ADDED: 10th November 2007
*********************************************/
	
	// email validation
	var field = email; // email field
  	var str = field.value; // email string
  	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid (doesnt validate emails with long tld, e.g. .name)
  	if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
		return true;
  	}
  	else {
		alert("Please enter a valid email address."); 
		field.focus();
		field.select();
		return false;
  	}
}

function deleteItem(ID) {
/********************************************
DESCRIPTION: updates action and submits page
DATE ADDED: 5th April 2007
DATE UPDATED: -
*********************************************/
	
	document.frm_item.a.value = 3; //delete
	document.frm_item.step.value = 1; //wizard start
	document.frm_item.remove.value = ID;
	if (confirm("You are about to delete this item.\n\nAre you sure you want to continue?")) {
		document.frm_item.submit();
	}
}

function doItem(action) {
/********************************************
DESCRIPTION: updates action and submits page
DATE ADDED: 5th April 2007
DATE UPDATED: -
*********************************************/
	
	document.frm_item.a.value = action;
	document.frm_item.step.value = 1;
	document.frm_item.submit();
}

function selectItem(pID, ID, nID, stepID) {
/********************************************
DESCRIPTION: updates action and submits page
DATE ADDED: 6th April 2007
DATE UPDATED: -
*********************************************/
	document.frm_item.prev_id.value = pID;
	document.frm_item.item_id.value = ID;
	document.frm_item.next_id.value = nID;
	document.frm_item.step.value = stepID;
	document.frm_item.submit();
}

function selectItemExtra(pID, ID, nID, stepID, extraID) {
/********************************************
DESCRIPTION: updates action and submits page
DATE ADDED: 6th April 2007
DATE UPDATED: -
*********************************************/
	document.frm_item.prev_id.value = pID;
	document.frm_item.item_id.value = ID;
	document.frm_item.next_id.value = nID;
	document.frm_item.step.value = stepID;
	document.frm_item.extra_id.value = extraID;
	document.frm_item.submit();
}

