function compareFields(field_1,field_2,name)
{
	if((field_1.value != "") || (field_2.value != ""))
	{
		if(field_1.value === field_2.value){
			return true;
		}
		else 
		{
			alert("Current \""+name+"'s\" do not match!");
			field_1.value = "";
			field_2.value = "";
			return false;
		}
	}
	else 
	{
		alert(name+" fields must not be empty!");
		return false;
	}
}

function setFocus(aField) {
	document.forms[0][aField].focus();
}

function isAnEmailAddress(aTextField) {
	// 1+@3+ [or x@x.x] is as close as we will test
	if (document.forms[0][aTextField].value.length<5) {
		alert("Please enter a correct Email Address!");
		return false;
	} else if (document.forms[0][aTextField].value.indexOf("@") < 1) {
		alert("Please enter a correct Email Address!");
		return false;
	} else if (document.forms[0][aTextField].value.length - document.forms[0][aTextField].value.indexOf("@") < 4) {
		alert("Please enter a correct Email Address!");
		return false;
	} else { 
		return true; 
	}
}
function isblank(s){
	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if((c != ' ') && (c != '\n') && (c != '')) return false;
	}
	return true;
}
function verify(f){
	var msg;
	var empty_fields = "";
	var errors = "";
	
	for(var i = 0; i < f.length; i++){
		var e = f.elements[i];
		if(((e.type == "text") || (e.type == "textarea") || (e.type == "password"))&& !e.optional){
			if((e.value == null) || (e.value == "") || isblank(e.value)){
				empty_fields += "\n         " + e.name;
				continue;
			} 
		}
		
		if(e.type == "select-one" && !e.optional)
		{
			check_selection(e);
		}
	}
	
	if(!empty_fields && !errors) return true;
	
	msg = "__________________________________________________________\n\n"
	msg +="The form was not submitted because of the following error(s).\n";
	msg +="Please correct these error(s) and re-submit.\n"
	msg +="__________________________________________________________\n\n"
	
	if(empty_fields){
		msg += "- The following required field(s) are empty:"
				+ empty_fields.toUpperCase() + "\n";
	}
	msg += errors;
	alert(msg);
	return false;
}

function check_selection(field)
{
	title = field.value;
	if(title == "CHOOSE AN ITEM")
	{
		alert("You must choose a "+field.name+"!");
		return false;
	}
											
}
	
function calculate(num,price,field)
{
	document.forms[0].elements['total_price_'+field].value = "$"+(price * num).toLocaleString();
}

function calcprice()
{
	// total = (playerslots x per slot) x how many months
	// discount price = total x discout percent
	// grandtotal = (total - discount price) + other options
	/*******************************************************/
	// FEILDS: 
	// paymentplan, server_type, playerslots, 
	// web_hosting, total_price, game
	/*******************************************************/
	
	//f = document.forms["config_server"];
	paymentplan = document.forms["config_server"].paymentplan.value; // lists: discount number, string value
	server_type = document.forms["config_server"].server_type.value; // string: public or private
	playerslots = document.forms["config_server"].playerslots.value; // int: minimum number of players on server
	web_hosting = document.forms["config_server"].web_hosting.value;  // int: 1 or 0
	game        = document.forms["config_server"].game.value;        // list: game title, public per slot price, private per slot price

	plan_values = paymentplan.split(',');    // convert the paymentplan value to an array to pull from
	discount_percent = plan_values[0];       // the first value in the array is the percent discount
	discount_descr = plan_values[1];         // the second value is the description of the discount
	descr_array = discount_descr.split(' '); // we convert to an array so that we can pull the total months
	total_months = descr_array[0];           // total months to charge for
	
	game_values = game.split(',');                // convert the game value to an array to pull from
	game_title = game_values[0];             // the first value in the array is the name of the game
	public_price = game_values[1];           // the second value in the array is the public per slot price
	private_price = game_values[2];          // the third value in the array is the private per slot price

	per_slot = (server_type == "public" ? public_price : private_price);
	
	//alert(playerslots);
	//return false;
	total = ( playerslots *  per_slot) * total_months;
	discount_price = total * discount_percent;
	grandtotal = (total - discount_price) + (web_hosting == 1 ? 5 : 0);
	//grandtotal = total;
	
	document.forms["config_server"].total_price.value = grandtotal.toLocaleString();
}

function calcpromo()
{
	web_hosting = document.config_server.web_hosting.value;
	pprice = 40.00 + (web_hosting == 1 ? 5.00 : 0.00);
	grandtotal = pprice;
	document.config_server.promo_price.value = grandtotal.toLocaleString();
}