function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '');
}
function validateForm(frm){
	if (!trim(frm["contactperson"].value)) {
		alert("Please insert the contact person.");
		frm["contactperson"].focus();
		return false;
	}
	if (!trim(frm["email"].value)) {
		alert("Please insert your email.");
		frm["email"].focus();
		return false;
	}else if(!isEmail(frm["email"].value)){
		alert("Please make sure your email is entered in this format. (eg. name@company.com).");
		frm["email"].focus();
		return false;
	}
	if (trim(frm["alt_email"].value) && !isEmail(frm["alt_email"].value)) {
		alert("You chose to enter an alternate email, but it is not in a valid format. (eg. name@company.com)");
		frm["alt_email"].focus();
		return false;
	}
	if(frm.country.options[frm.country.selectedIndex].value == ''){
		alert("Please select your country.");
		return false;
	}
    var pfields = 'nnn';
    var phone = [ frm["pcc"].value, frm["pac"].value, frm["pno"].value ];
    for (var i = 0, n = pfields.length; i < n; i++) {
        if (trim(phone[i])) {
            pfields = pfields.split('');
            pfields[i] = 'y';
            pfields = pfields.join('');
        }
    }
    if (pfields != 'nnn' && pfields != 'yyy') {
        alert('Please fill in all phone fields.');
        return false;
    }
    return true;
}

function isEmail(argvalue) {
  if (argvalue.indexOf(" ") != -1)
    return false;
  else if (argvalue.indexOf("@") == -1)
    return false;
  else if (argvalue.indexOf("@") == 0)
    return false;
  else if (argvalue.indexOf("@") == (argvalue.length-1))
    return false;

  if (argvalue.indexOf(".") == -1)
    return false;
  else if (argvalue.indexOf(".") == 0)
    return false;
  else if (argvalue.charAt(argvalue.length-1) == ".") {
    return false;
  }

  return true;

}

function stateupd() {
	with (document.frmDld){
		if ((country.options[country.selectedIndex].value != 222) && (state.options[state.selectedIndex].value != 'Non US')){
			country.selectedIndex=226;
		}
	}
}

function countryupd() {
	with (document.frmDld){
		if ((country.options[country.selectedIndex].value != 222) && (state.options[state.selectedIndex].value != 'Non US')){
			state.selectedIndex='Non US';
		}
	}
}
