function submitform(submitpage) {
	if(submitpage == 1){
		document.getElementById('NewpagE').innerHTML = '<input type=hidden name="Home" value="yes">';
	}else if(submitpage == 2){
		document.getElementById('NewpagE').innerHTML = '<input type=hidden name="ExhexhibitorList" value="yes">';
	}else if(submitpage == 3){
		document.getElementById('NewpagE').innerHTML = '<input type=hidden name="ExhexhibitorRepsList" value="yes">';
	}else if(submitpage == 4){
		document.getElementById('NewpagE').innerHTML = '<input type=hidden name="QuickReportMain" value="yes">';
	}else if(submitpage == 5){
		document.getElementById('NewpagE').innerHTML = '<input type=hidden name="SearchMain" value="yes">';
	}
	document.myform.submit();
}

function enableBoothNumber(radio) {
	//alert(radio.value);
	if (radio.value != "Reps") {
		document.searchForm.booth.value = '';
		document.searchForm.booth.disabled = false;
	} else {
		document.searchForm.booth.value = 'disabled';
		document.searchForm.booth.disabled = true;
	}
}

function updateLabel(row1, row2, row3, i, length) {
	// get the value of the Current Drop Down List Selection
	//	alert();
	var match = 'false';
	var Booth1 = 'false';
	var Booth2 = 'false';
	var Booth3 = 'false';
	var Booth4 = 'false';
	var Boothseq = 'false';
	var num, mandatoryfields;

	// Check that booth numbers are selected in order
	if (document.getElementById('Row'+i).selectedIndex > 13 && document.getElementById('Row'+i).selectedIndex < 18) {
		for(num = 0; num < length; num++) {
			if (document.getElementById('Row'+num).selectedIndex == 13) {
				Booth1 = 'true';
			}
			if (document.getElementById('Row'+num).selectedIndex == 14) {
				Booth2 = 'true';
			}
			if (document.getElementById('Row'+num).selectedIndex == 15) {
				Booth3 = 'true';
			}
			if (document.getElementById('Row'+num).selectedIndex == 16) {
				Booth4 = 'true';
			}
		}

		if (document.getElementById('Row'+i).selectedIndex == 14) {
			if (Booth1 == 'true') {
				Boothseq = 'true';
			}
		} else if (document.getElementById('Row'+i).selectedIndex == 15) {
			if (Booth1 == 'true' && Booth2 == 'true') {
				Boothseq = 'true';
			}
		} else if (document.getElementById('Row'+i).selectedIndex == 16) {
			if (Booth1 == 'true' && Booth2 == 'true' && Booth3 == 'true') {
				Boothseq = 'true';
			}
		} else if (document.getElementById('Row'+i).selectedIndex == 17) {
			if (Booth1 == 'true' && Booth2 == 'true' && Booth3 == 'true' && Booth4 == 'true') {
				Boothseq = 'true';
			}
		}	
	} else {
		Boothseq = 'true';
	}

	if (Boothseq == 'true') {
		Value1 = document.getElementById('Row'+i).options[document.getElementById('Row'+i).selectedIndex].value;
		
		if (Value1) {
			for (num = 0; (num < length) && match != 'true'; num++) {
				// get the value of other drop down menus value
				Value2 = document.getElementById('Row'+num).options[document.getElementById('Row'+num).selectedIndex].value;

				// If match is found
				if ((Value1 == Value2) && num != i) {
					match = 'true';	
				}
			}
			// go to original value, to remove the increment of last for loop
			num = num - 1;
		}
		
		// Change label name
		if(match == 'true') {
			content= document.getElementById('TableHeading'+num).innerHTML;
			Duplicate = "The same Option was selected at row: "+content+"\nWould you like to use this current row for the table header: "+Value1+"\nPress OK to use the value\nPress Cancel to use the previous value";
			if(confirm(Duplicate)) {
				// assign the value to label
				document.getElementById('TableHeading'+i).innerHTML = Value1;
				// clear the duplicate value
				document.getElementById('TableHeading'+num).innerHTML = '';
				document.getElementById('Row'+num).selectedIndex = 0;

				//Fill in the value in the sample data
				if (row1) {
					// Fill in the value int he sample data
					tempstr1 = row1.split("^");
					// Check for null values
					if (tempstr1[i] == "" || tempstr1[i] == 'undefined') {
						tempstr1[i] = "&nbsp;"
					}

					if (row2) {
						tempstr2 = row2.split("^");
						if (tempstr2[i] == "" || tempstr2[i] == 'undefined') {
							tempstr2[i] = "&nbsp;"
						}
					}
					if (row3) {
						tempstr3 = row3.split("^");
						if (tempstr3[i] == "" || tempstr3[i] == 'undefined') {
							tempstr3[i] = "&nbsp;"
						}
					}
		
					// check if value exists in other rows, if it does erase it
					if (document.getElementById('Row'+i).selectedIndex > 0) {
						for (num2 = 1; num2 < document.getElementById('Row1').length; num2++) {
							// Gets the value from the drop down list to use to locate label names
							Val = document.getElementById('Row1').options[num2].value;
							if (document.getElementById('lbl_'+Val+'1').innerHTML == tempstr1[num]) {
								document.getElementById('lbl_'+Val+'1').innerHTML = "&nbsp;";	
							}
							if(typeof( window["lbl_" + Val + "2" ] ) != 'undefined') {
								if (document.getElementById('lbl_'+Val+'2').innerHTML == tempstr2[num]) {
									document.getElementById('lbl_'+Val+'2').innerHTML = "&nbsp;";	
								}
							}
							if(typeof( window["lbl_" + Val + "3" ] ) != 'undefined') {
								if (document.getElementById('lbl_'+Val+'3').innerHTML == tempstr3[num]) {
									document.getElementById('lbl_'+Val+'3').innerHTML = "&nbsp;";	
								}
							}
						}

						// Assign Values
						document.getElementById('lbl_'+Value1+'1').innerHTML = tempstr1[i];
						if (row2) {
							document.getElementById('lbl_'+Value1+'2').innerHTML = tempstr2[i];
						}
						if (row3) {
							document.getElementById('lbl_'+Value1+'3').innerHTML = tempstr3[i];
						}
					}

				} // if row1
			} else {
				// clear the values
				document.getElementById('TableHeading'+i).innerHTML = '';
				document.getElementById('Row'+i).selectedIndex = 0;
				
			}
		} else {
			if(Value1) {
				// fill in value in the label
				document.getElementById('TableHeading'+i).innerHTML = Value1;
			} else {
				document.getElementById('TableHeading'+i).innerHTML = '';
			}

			if (row1) {
				// Fill in the value int he sample data
				tempstr1 = row1.split("^");
				// Check for null values
				if (tempstr1[i] == "" || tempstr1[i] == 'undefined') {
					tempstr1[i] = "&nbsp;"
				}

				if (row2) {
					tempstr2 = row2.split("^");
					if (tempstr2[i] == "" || tempstr2[i] == 'undefined') {
						tempstr2[i] = "&nbsp;"
					}
				}
				if (row3) {
					tempstr3 = row3.split("^");
					if (tempstr3[i] == "" || tempstr3[i] == 'undefined') {
						tempstr3[i] = "&nbsp;"
					}
				}
				
				// check if value exists in other rows, if it does erase it
				for (num = 1; num < document.getElementById('Row1').length; num++) {
					Val = document.getElementById('Row1').options[num].value;
					if (document.getElementById('lbl_'+Val+'1').innerHTML == tempstr1[i]) {
						document.getElementById('lbl_'+Val+'1').innerHTML = "&nbsp;";	
					}
					if (document.getElementById('lbl_'+Val+'2').innerHTML == tempstr2[i]) {
						document.getElementById('lbl_'+Val+'2').innerHTML = "&nbsp;";	
					}
					if (document.getElementById('lbl_'+Val+'3').innerHTML == tempstr3[i]) {
						document.getElementById('lbl_'+Val+'3').innerHTML = "&nbsp;";	
					}
				}

				// Assign Values
				if (document.getElementById('Row'+i).selectedIndex > 0) {
					if (row1) {
						document.getElementById('lbl_'+Value1+'1').innerHTML = tempstr1[i];
					} else {
						document.getElementById('lbl_'+Value1+'1').innerHTML = '';
					}
					if (row2) {
						document.getElementById('lbl_'+Value1+'2').innerHTML = tempstr2[i];
					} else {
						document.getElementById('lbl_'+Value1+'2').innerHTML = '';
					}
					if (row3) {
						document.getElementById('lbl_'+Value1+'3').innerHTML = tempstr3[i];
					} else {
						document.getElementById('lbl_'+Value1+'3').innerHTML = '';
					}
				} 
			} // if row1
		} // else

		mandatoryfields = 0;
		// Check if mandatory fields have been selected
		for (num = 0; (num < length); num++) {
			// get the value of other drop down menus value
			if (document.getElementById('Row'+num).selectedIndex > 0) {
				Value2 = document.getElementById('Row'+num).options[document.getElementById('Row'+num).selectedIndex].value;
			} else {
				Value2 = "";
			}

			// If match is found
			if (Value2 == "Company") {
				mandatoryfields = mandatoryfields + 1;
			}
			if (Value2 == "First Name") {
				mandatoryfields = mandatoryfields + 1;
			}
			if (Value2 == "Last Name") {
				mandatoryfields = mandatoryfields + 1;
			}
		}

		// disable / enable button if all fiels are selected
		if (mandatoryfields == 3) {
			document.getElementById('Continue').disabled = false;
		} else {
			document.getElementById('Continue').disabled = true;
		}
	} else {
		alert('Booth # must be selected in sequence');
		// clear the values
		document.getElementById('TableHeading'+i).innerHTML = '';
		document.getElementById('Row'+i).selectedIndex = 0;
		return (true);
	} // END if booth sequence if
}

function trim(theForm) {
	return theForm.replace(/^\s+|\s+$/, '');
}

function updatefield(Value, Findex, DBindex, count) {

	var Error = '';
	var Lbl = '';
	var Lbl2 = ''
	var Ahref = '';
		
	Lbl2 = "1lbl_data" + Findex + count + "good";
	Lbl = "1lbl_data" + Findex + count;
	Txt = "txt_data" + Findex + count;
	Ahref = "a_data" + Findex + count;

	// trim leading and trailing spaces
	Value = trim(Value);


	if ((DBindex >= 0 && DBindex < 6) || DBindex == 14 || DBindex == 15) { // Rest
		var IllegalChars = /[A-Za-z0-9 ._&-\-®()\/\\+=@#]/;
		var Illegal = 'false';

		// check for illegal characters
		for(i=0; i < Value.length; i++) {
			if(!Value.charAt(i).match(IllegalChars)) {
				Illegal = 'true';
			}
		}

		if(DBindex == 0) {
			if(Illegal == 'true') {
				Error = "Field contains illegal characters";
			} else if (Value != "") {
				// get number of rows
				var oRows = document.getElementById('TableFinalValues').getElementsByTagName('tr');
				var iRowCount = oRows.length;

				var Value = Value.replace(/[&]/, '&amp;');
				// check if duplicate company name exists in the table
				for(i = 0; i < iRowCount; i++) {
					// if label 1 exists
					if(typeof( window["1lbl_data" + Findex + i ] ) != 'undefined') {
						if((document.getElementById("1lbl_data" + Findex + i).innerHTML == Value) && count != i) {
							Error = "Duplicate filename found in the file, please modify";
						}
					}
					// if label 3 exists
					if(typeof( window["3lbl_data" + Findex + i ] ) != 'undefined') {
						if((document.getElementById("3lbl_data" + Findex + i).innerHTML == Value) && count != i) {
							Error = "Duplicate filename found in the file, please modify";
						}
					}
				}

				// Check also for duplicate company names in database
				alert('start');
				// retrieve value from hidden textfield, and split into an array
				companiestemp = document.getElementById('DBCompanies').value;
				companies  = companiestemp.split("^^");
				companiestemp = '';

				for(i = 0; i < companies.length; i++) {
					// if label 1 exists
					if(typeof( window["1lbl_data" + Findex + count ] ) != 'undefined') {
						//alert(document.getElementById("3lbl_data" + Findex + count).innerHTML );
						if((document.getElementById("1lbl_data" + Findex + count).innerHTML == companies[i+1])) {
							alert('found');
							Error = "Duplicate filename found in the database, please modify";
						}
					}
					// if label 3 exists
					if(typeof( window["3lbl_data" + Findex + count ] ) != 'undefined') {
						//alert(document.getElementById("3lbl_data" + Findex + count).innerHTML );
						if((document.getElementById("3lbl_data" + Findex + count).innerHTML == companies[i+1])) {
							alert('found');
							Error = "Duplicate filename found in the database, please modify";
						}
					}

				}
			
				alert('end');
			} else {
				Error = "Company Name can not be empty"; 	
			}
		} else {
			if(Illegal == 'true') {
				Error = "Field contains illegal characters";
			} 
		}

	} else if(DBindex == 6) { // Postal Code
		var stripped = Value.replace(/[ ]/g, ''); 
		stripped = stripped.toUpperCase();
		var Illegal = 'false'
		var illegalChars= /[A-Za-z0-9]/;

		// check for illegal characters
		for(i=0; i < stripped.length; i++) {
			if(!stripped.charAt(i).match(illegalChars)) {
				Illegal = 'true';
			}
		}
		
		if(Illegal == 'true') {
			Error = "Field contains illegal characters";
		} else {
			// length of american zip code
			if (stripped.length >=3 && stripped.length <= 5) {
				var Zip = /[0-9]/;
				for(i=0; i < stripped.length; i++) {
					if(!stripped.charAt(i).match(Zip)) {
						Error = "Zip code is the wrong value";
					}
				}
			// length of canadian postal code
			} else if (stripped.length == 6) {
				var Filter = /[A-Za-z][0-9][A-Za-z][0-9][A-Za-z][0-9]/;
				var Filter2 = /[A-Za-z][0-9][A-Za-z][0-9][A-Za-z][A-Za-z]/;
				if (!Filter.test(stripped) && !Filter2.test(stripped)){
					Error += "Postal Code is the wrong type ex.X0X 0X0..";
				}
				Value = stripped.substring(0,3) + " " + stripped.substring(3,6);
			} else if(stripped.length == 0) {
				// leave blank for empty field
			} else {
				Error += "Field is the wrong length";
			}
		}

		
	} else if(DBindex == 7 || DBindex == 10) { // Phone and fax
		var stripped = Value.replace(/[\(\)\.\-\ ]/g, '');     
		var Illegal = 'false'
		var illegalChars= /[0-9]/ ;

		for(i=0; i < stripped.length; i++) {
			if(!stripped.charAt(i).match(illegalChars)) {
				Illegal = 'true';
			}
		}

		if ((Illegal == 'true') && stripped != "") {
			Error += "The field contains illegal characters";
		} else if ((!(stripped.length == 10)) && stripped != "") {
			Error += "The field is the wrong length. ex. XXX-XXX-XXXX";
		}
		if(stripped != "") {
			Value = "(" + stripped.substring(0,3)+") " + stripped.substring(3,6) + "-" + stripped.substring(6,10);
		} else {
			Value = "";
		}
	} else if(DBindex == 16) { // Email
		var tfld = trim(Value);
		var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

		if ((!emailFilter.test(tfld)) && Value != "") {      
			Error += "Please enter a valid email address";
		} else if ((Value.match(illegalChars)) && Value != "") {
			Error += "The email address contains illegal characters";
		} 

	} else if( DBindex == 33) { // max Regs
		var illegalChars= /[0-9]/ ;
		for(i=0; i < Value.length; i++) {
			if(!Value.charAt(i).match(illegalChars)) {
				Error = "Integers allowed only";
			}
		}
	} else {
		Error += "Site Error. Please contact your systems administrator.";
	}

	if(Error) {
		alert(Error);
		document.getElementById(Txt).focus();
	} else {
		document.getElementById(Txt).style.display = 'none';

		document.getElementById(Ahref).style.color= 'blue';
		document.getElementById(Ahref).style.display = 'none';

		document.getElementById(Lbl2).innerHTML = Value;
		document.getElementById(Lbl2).style.display = 'block';
		
		// decrease the error counter
		document.getElementById('ErrorCounter').value = document.getElementById('ErrorCounter').value - 1;
	}

	// disable / enable the button field
	if (document.getElementById('ErrorCounter').value == 0) {
		document.getElementById('FinalUpload').disabled = false;
	} else {
		document.getElementById('FinalUpload').disabled = true;
	}
}
