function FreshAir() {
	var sURL      = "http://b2b.aeslibrarysupplies.com.au/index.cfm";
	var sName     = "winPopup";
	var sFeatures = "status=yes,scrollbars=no,resizable=yes,width=780,height=560"
	window.open(sURL,sName,sFeatures);
}

function dispStatus(myMsg) {
	status=myMsg;
	return true;
}

function validateForm(form){
	var contactField = form.contact;
	var contactStr = trim(contactField.value,"both");
	var emailField = form.email;
	var emailStr = trim(emailField.value,"both");
	if(contactStr.length <= 1){
		alert("Please provide a valid contact name.");
		contactField.focus();
		contactField.select();
		return false;
	} else if (!emailCheck(emailStr)){
		alert("Please provide a valid email address.");
		emailField.focus();
		emailField.select();
		return false;
	}
	return true;
}

function emailFieldCheck(form) {
  var field = form.email;
  var str = field.value;
  if (emailCheck(str))
      return true;
    field.focus();
    field.select();
    return false;
}

function emailCheck(str) {
  if (window.RegExp) { //check if browser supports RegExp
    var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var reg1 = new RegExp(reg1str);
    var reg2 = new RegExp(reg2str);
    if (!reg1.test(str) && reg2.test(str))
      return true;
    return false;
  } else {
    if(str.indexOf("@") >= 0)
      return true;
    return false;
  }
}

function trim(arg,func) {
	var trimvalue = "";
	arglen = arg.length;
	if (arglen < 1) return trimvalue;
	if (func == "left" || func== "both") {
		i = 0; pos = -1;
		while (i < arglen) {
			if (arg.charCodeAt(i) != 32 &&
				!isNaN(arg.charCodeAt(i))) {
				pos = i; break;
			}
			i++;
		}
	}
	
	if (func == "right" || func== "both") {
		var lastpos = -1; i = arglen;
		while (i >= 0) {
			if (arg.charCodeAt(i) != 32 &&
				!isNaN(arg.charCodeAt(i))) {
				lastpos = i; break;
			}
			i--;
		}
	}
	
	if (func == "left") trimvalue = arg.substring(pos,arglen-1);
	if (func == "right") trimvalue = arg.substring(0,lastpos+1);
	if (func == "both") trimvalue = arg.substring(pos,lastpos + 1);
	return trimvalue;
}


