browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
	if (browserName == "Netscape" && browserVer >= 3) version = "n3";
	else if (browserName == "Microsoft Internet Explorer" && browserVer >= 3)
	version = "n3";
	else version = "n2";

var errorTextArray = new Array();
var errors = new Array();
var numErrors = 0;
var errorText = new String("");

//var ERROR_MISSING_EMAILLISTCATEGORYID = 0;
//errorTextArray[ERROR_MISSING_EMAILLISTCATEGORYID] = "How would you like to receive the new Design Guide?";

//var ERROR_MISSING_ICONICPANELSCATALOG = 1;
//errorTextArray[ERROR_MISSING_ICONICPANELSCATALOG] = "How would you like to receive the new Iconic Panels Catalog?";

var ERROR_MISSING_DOWNLOADORMAIL = 0;
errorTextArray[ERROR_MISSING_DOWNLOADORMAIL] = "Would you like to download documents or have them mailed to you?";

var ERROR_MISSING_MAILSELECTION = 9;
errorTextArray[ERROR_MISSING_MAILSELECTION] = "What would you like to have mailed to you?";

var ERROR_MISSING_PASSWORD = 100;
errorTextArray[ERROR_MISSING_PASSWORD] = "Your password";

var ERROR_MISSING_PASSWORD_CONFIRMATION = 101;
errorTextArray[ERROR_MISSING_PASSWORD_CONFIRMATION] = "Your password confirmation";

var ERROR_PASSWORDS_DO_NOT_MATCH = 102;
errorTextArray[ERROR_PASSWORDS_DO_NOT_MATCH] = "Your password and password confirmation do not match";

var ERROR_MISSING_DOWNLOADSELECTION = 10;
errorTextArray[ERROR_MISSING_DOWNLOADSELECTION] = "What would you like to download?";

var ERROR_MISSING_NAME = 1;
errorTextArray[ERROR_MISSING_NAME] = "Your Full Name";

var ERROR_MISSING_COMPANY = 2;
errorTextArray[ERROR_MISSING_COMPANY] = "Your Company";

var ERROR_MISSING_ADDRESS_1 = 3;
errorTextArray[ERROR_MISSING_ADDRESS_1] = "Your Street Address";

var ERROR_MISSING_CITY = 4;
errorTextArray[ERROR_MISSING_CITY] = "Your City";

var ERROR_MISSING_STATE = 5;
errorTextArray[ERROR_MISSING_STATE] = "Your State";

var ERROR_MISSING_ZIP = 6;
errorTextArray[ERROR_MISSING_ZIP] = "Your Zip";

var ERROR_MISSING_COUNTRY = 7;
errorTextArray[ERROR_MISSING_COUNTRY] = "Your Country";

var ERROR_INVALID_EMAILADDRESS = 8;
errorTextArray[ERROR_INVALID_EMAILADDRESS] = "A Valid E-mail Address";


function registerError(errorNumber)
{	
	errors[numErrors] = errorTextArray[errorNumber];
	
	numErrors++;
}

function trim(str)
{
	return str.replace(/^\s*|\s*$/g,"");
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function submitPage1()
{
	//if(trim(document.ordercatalogs.EmailListCategoryID.value) == ""){
	//	registerError(ERROR_MISSING_EMAILLISTCATEGORYID);
	//}
	
	//if(trim(document.ordercatalogs.IconicPanelsCatalog.value) == ""){
	//	registerError(ERROR_MISSING_ICONICPANELSCATALOG);
	//}
	
	if(getCheckedValue(document.ordercatalogs.DownloadOrMail) == ""){
		registerError(ERROR_MISSING_DOWNLOADORMAIL);
	}
	else {
		if(getCheckedValue(document.ordercatalogs.DownloadOrMail) == "Mail") {
			if(getCheckedValue(document.ordercatalogs["MailSelection[]"]) == ""){
				registerError(ERROR_MISSING_MAILSELECTION);
			}
		}
		else {
			if(getCheckedValue(document.ordercatalogs["DownloadSelection[]"]) == ""){
				registerError(ERROR_MISSING_DOWNLOADSELECTION);
			}
		}
	}	
	
	if(trim(document.ordercatalogs.Password.value) == ""){
		registerError(ERROR_MISSING_PASSWORD);
	}

	if(trim(document.ordercatalogs.PasswordConfirmation.value) == ""){
		registerError(ERROR_MISSING_PASSWORD_CONFIRMATION);
	}
	
	if ( (trim(document.ordercatalogs.PasswordConfirmation.value) != "") &&
	(trim(document.ordercatalogs.Password.value) != "") )
	{
		if (document.ordercatalogs.PasswordConfirmation.value != document.ordercatalogs.Password.value) registerError(ERROR_PASSWORDS_DO_NOT_MATCH);
	}



	if(trim(document.ordercatalogs.Name.value) == ""){
		registerError(ERROR_MISSING_NAME);
	}
	
	if(trim(document.ordercatalogs.Company.value) == ""){
		registerError(ERROR_MISSING_COMPANY);
	}
	
	if(trim(document.ordercatalogs.Address_1.value) == ""){
		registerError(ERROR_MISSING_ADDRESS_1);
	}
	
	if(trim(document.ordercatalogs.City.value) == ""){
		registerError(ERROR_MISSING_CITY);
	}
	
	if(trim(document.ordercatalogs.State.value) == ""){
		registerError(ERROR_MISSING_STATE);
	}
	
	if(trim(document.ordercatalogs.Zip.value) == ""){
		registerError(ERROR_MISSING_ZIP);
	}
	
	if(trim(document.ordercatalogs.Country.value) == ""){
		registerError(ERROR_MISSING_COUNTRY);
	}

	if(trim(document.ordercatalogs.EmailAddress.value) == ""){
		registerError(ERROR_INVALID_EMAILADDRESS);
	}

	else
	{
		atPos = document.ordercatalogs.EmailAddress.value.indexOf("@");
			
		if(atPos < 1)
		{
			registerError(ERROR_INVALID_EMAILADDRESS);
		}
		else
		{
			atPos = document.ordercatalogs.EmailAddress.value.indexOf(".", atPos + 2);
			if(atPos < 1 || (atPos == document.ordercatalogs.EmailAddress.value.length))
			{
				registerError(ERROR_INVALID_EMAILADDRESS);
			}
		}
	}
	
	if(numErrors > 0)
	{
		errorText = "You must enter the following information before submitting:\n";	

		for(i = 0; i < errors.length; i++)
		{
			errorText = errorText + "\t" + "\n" + errors[i];
		}
		
		alert(errorText);
		errors.length = 0;
		numErrors = 0;
		errorText = "";
	}
	else
	{
		document.ordercatalogs.submit();
	}
}

// manage radio/checkbox choices
// document.ordercatalogs.DownloadOrMail
// document.ordercatalogs.MailSelection
// document.ordercatalogs.DownloadSelection

function dgpEnableChoices(radioObj) {
	var radioLength = radioObj.length;
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].disabled= false;
	}
}

function dgpDisableChoices(radioObj) {
	var radioLength = radioObj.length;
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		radioObj[i].disabled= true;
	}
}

function dgpSelectType(type) {
	var radioObj = document.ordercatalogs.DownloadOrMail;
	var radioLength = radioObj.length;
	for(var i = 0; i < radioLength; i++) {
		if (radioObj[i].value == type) {
			radioObj[i].checked = true;
		}
		else {
			radioObj[i].checked = false;
		}
	}
	if (type=='Mail') {
		dgpEnableChoices(document.ordercatalogs["MailSelection[]"]);
		dgpDisableChoices(document.ordercatalogs["DownloadSelection[]"]);
	}
	else {
		dgpEnableChoices(document.ordercatalogs["DownloadSelection[]"]);
		dgpDisableChoices(document.ordercatalogs["MailSelection[]"]);
	}
	return "";
}



