// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

// email

//Check whole form function//

function checkWholeForm(myForm) {
    var why = "Please fill in your";
    
	
	if(isEmpty(myForm.name.value)){
		why += "\nname";
	}
	
	if(isEmpty(myForm.city.value)){
		why += "\ncity";
	}
	
	if(isEmpty(myForm.country.value)){
		why += "\ncountry";
	}
	
	if(isEmpty(myForm.zipcode.value)){
		why += "\nzipcode";
	}
	
	if(isEmpty(myForm.message.value)){
		why += "\nmessage";
	}
	
	if(checkDropdown(myForm.drop_down_title.selectedIndex)){
		why += "\ntitle";
	}
	
	if(checkDropdown(myForm.drop_down_topic.selectedIndex)){
		why += "\ntopic";
	}
	
	if(checkDropdown(myForm.first_dropdown.selectedIndex)){
		why += "\nproduct category";
	}
	
	why += checkEmail(myForm.email.value);

    
	if (why != "Please fill in your") {
       alert(why);
       return false;
    }

	
	document.myForm.submit();
	
	return true;
}


//end of check whole form//

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "\nPlease enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
	
	return error;    
}


// non-empty textbox

function isEmpty(strng) {
	
	if (strng.length == 0) {
		return true;
	}
		
	return false;
}


// valid selector from dropdown list

function checkDropdown(choice) {
    if (choice == 0) {
        return true;
    }    
	
    return false;
}    


