// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function externalLinks() {
	if (!document.getElementsByTagName) return;
	
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
	}
}
window.onload = externalLinks;


function openSizedPopUp(PageName, Width, Height){
	new_window = window.open(PageName,"new_window","width="+Width+",height="+Height+",location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0,left=150,top=50,screenx=150,screeny=50"); 
	if (new_window.opener === null) { 
		new_window.opener = self; 
	} 
	new_window.focus();
}



function checkSearch(elem) {
	if (elem.length == 0 || elem.value == " ")
	{
		alert("Please enter a search term");
		return false;
	}
	else
		return true;
}
function isEmail(mailvalue) {
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; // valid
	if (!reg1.test(mailvalue) && reg2.test(mailvalue))
	{
		return (true);
	} else
	{
		return (false);
	}
}
function isEmpty(str){
  return (str == null) || (str.length == 0);
}
function frmCatalogRequest() {
	var email = document.getElementById("emailaddress")
	if (email) {
		if (isEmpty(email.value))
		{  	alert("Please enter an e-mail address.");
			email.focus()
			return false;
		} else
		{	if (isEmail(email.value)  != true)
			{	alert("Please enter a valid e-mail address.");
				email.focus()
				return false;
			}
		}
	}
	var firstname = document.getElementById("FirstName")
	if (firstname.value == "") {
		alert("Please enter your first name.");
		firstname.focus();
		firstname.select();
		return false;
	}
	var lastname = document.getElementById("LastName")
	if (lastname.value == "") {
		alert("Please enter your last name.");
		lastname.focus();
		lastname.select();
		return false;
	}
	var address = document.getElementById("Address1")
	if (address.value == "") {
		alert("Please enter your street address.");
		address.focus();
		address.select();
		return false;
	}
	var city = document.getElementById("City")
	if (city.value == "") {
		alert("Please enter your city.");
		city.focus();
		city.select();
		return false;
	}
	var state = document.getElementById("State")
	if (state.value == "") {
		alert("Please enter your state's initials.");
		state.focus();
		state.select();
		return false;
	}
	var zipcode = document.getElementById("Zip")
	if (zipcode.value == "") {
		alert("Please enter your zip code.");
		zipcode.focus();
		zipcode.select();
		return false;
	}
	return true;
}
