function openWindow(url) {
  popupWin = window.open(url, 'remote', 'resizable,titlebars=yes,scrollbars=1,top=75,left=100,width=500,height=400')
}

function is_email(input)
{
    re = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    return re.test(input);
}

function validateEml(f) {
    //  Will check for @, period after @ and text in between
		var e1 = f.email.value;
		var e2 = f.x_email2.value;
    if (e1=="")
      {  return false;  }

    var in_space = e1.indexOf(" ");
    if (in_space != -1)
      { alert ("Email address should contain no spaces and be of the format jdoe\@aol.com");
           f.email.focus();
           return false;  }
    var len = e1.length;
    var alpha = e1.indexOf("@");
    var last_alpha = e1.lastIndexOf("@");
	var invalid;

    if (alpha != last_alpha)
       {  alert ("Please check your email address, it should contain only one @ and be of the format jdoe\@aol.com");
          f.email.focus();
           return false; }

    // No @, in first position, or name too short
    if (alpha == -1 || alpha == 0 || len<6 )
       {  alert ("Please check your email address, it should contain an @ and be of the format jdoe\@aol.com");
           f.email.focus();
           return false; }

     var last_p = e1.lastIndexOf(".");
          // Be sure period at least two spaces after @, but not last char.
     if (last_p - alpha < 2 || last_p == (len - 1) )
        {  alert ("Please check your email address, it should contain a period after the @ and be of the format jdoe\@aol.com");
           f.email.focus();
            return false; }

		// check for a value in both fields.
		//if (e1 == '' || e2 == '') {
		//	alert('Please enter your email address twice.');
		//	f.x_email2.focus();
		//	return false;
		//}

		// check for spaces
		if (f.email.value.indexOf(invalid) > -1) {
			alert("Sorry, spaces are not allowed.");
			f.email.focus();
			return false;
		} else {
			if (e1 != e2) {
			alert ("You did not enter the same email address twice. Please re-enter your email.");
			f.x_email2.focus();
			return false;
			}
		}

     return true;
   }

function formCheck(formobj){

	// name of mandatory fields
	var fieldRequired = Array("first_name","last_name","company_name","job_title","phone","email","address","city","state","zip","verificationcode");
	// field description to appear in the dialog box
	var fieldDescription = Array("First Name","Last Name","Company Name","Job Title","Phone","Email","Address","City","State/Province","Postal/Zip Code","Security Verification Code");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			if (obj.type == null){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				continue;
			}

			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
	
}
