var masterInstArray = new Array();
var errorHighlight="#cccc00";
var noErrorHighlight="#ffffff"; 

//Adds an new array element to master inistitution array and calls reset of Instituion display
function createInstInMaster(){
	var newPos=masterInstArray.length;
	masterInstArray[newPos]=new instStruct();
	createInstDisplay();
	addInstOnScreen(newPos,document.getElementById('txtAuthInstitution0').form);
}

//
function deleteInstInMaster(){
	if(masterInstArray.length>1){
		masterInstArray.splice(masterInstArray.length-1,1);	
		createInstDisplay();
		deleteInstOnScreen(document.getElementById('txtAuthInstitution0').form);
	}
	else{
		alert("You must have at least one institution");	
	}
}
//class structure of institution values
function instStruct(){
	this.divisionValue="";
	this.nameValue="";
	this.cityValue="";
	this.stateValue="";
	this.zipCodeValue="";
	this.countryValue="USA";
}
//creates and resets display of institution section of document.
function createInstDisplay(){
	var idx;
	var instDisplay=""
	var instDisplayDiv=document.getElementById("instDiv");
	
	//clear out old items
	while(instDisplayDiv.hasChildNodes()==true){
		instDisplayDiv.removeChild(instDisplayDiv.childNodes[0]);
	}
	//build up inner HTML
	for(idx=0; idx<masterInstArray.length; idx++){
		instDisplay+=createInstInput(idx);
	}
	//put in newly constructed div
	instDisplayDiv.innerHTML=instDisplay;
}

//creates on DIV/Table HTML setup for institute
function createInstInput(idx){
	var strHtml = "";
	var strInstInstruction = "";
	
	
		if (idx==0) {
			strInstInstruction = " - Please enter the school/institution of the Presenting Author."
		}
		else {
			strInstInstruction = "";
		}
	
		strHtml += "<div style='padding: 10px 0px;'><span style='font-weight: bold; color: #a13350;'>Institution #" + (idx + 1) + "</span>" + strInstInstruction + "</div>";		
		strHtml += "<div align='center' style='width: 100%;'> <!---BEGIN: container wrapper for each institution--->";
		strHtml += "<div style='display: block;'>";
		strHtml += "<div class='institution_label'>Name of Unit/Division/Center:<span class='required'>*</span></div>";
		strHtml += "<div align='left' class='institution_control'><input type='text' id='txtInstDivision" + idx + "' name='txtInstDivision" + idx + "' onChange='saveValue(&#39;divisionValue&#39;, " + idx + ",this.value)' value='" + masterInstArray[idx].divisionValue + "' size='32' maxlength='50'></div>";
		strHtml += "<div style='clear: both;'></div>";
		strHtml += "</div>";
		strHtml += "<div style='display: block;'>";
		strHtml += "<div class='institution_label'>Name of School/Institution:<span class='required'>*</span></div>";
		strHtml += "<div align='left' class='institution_control'><input type='text' id='txtInstName" + idx + "' name='txtInstName" + idx + "' onChange='updateInst(this)' value='" + masterInstArray[idx].nameValue + "'  size='32' maxlength='50'></div>";
		strHtml +=  "<div style='clear: both;'></div>";
		strHtml += "</div>";
		strHtml += "<div style='display: block;'>";
		strHtml += "<div class='institution_label'>City:<span class='required'>*</span></div>";
		strHtml += "<div align='left' class='institution_control'><input type='text' id='txtInstCity" + idx + "' name='txtInstCity" + idx + "' onChange='saveValue(&#39;cityValue&#39;, " + idx + ",this.value)' value='" + masterInstArray[idx].cityValue + "'  size='25' maxlength='25'></div>";
		strHtml += "<div style='clear: both;'></div>";
		strHtml += "</div>";
		strHtml += "<div style='display: block;'>";
		strHtml += "<div class='institution_label'>State or Provence:<br>(<span style='font-style: italic; font-size: .80em; '>If USA</span>)<span class='required'>*</span></div>";
		strHtml += "<div align='left' class='institution_control'><input type='text' id='txtInstState" + idx + "' name='txtInstState" + idx + "' onChange='saveValue(&#39;stateValue&#39;, " + idx + ",this.value)' value='" + masterInstArray[idx].stateValue + "'  size='10' maxlength='2'></div>";
		strHtml += "<div style='clear: both;'></div>";
		strHtml += "</div>";
		strHtml += "<div style='display: block;'>";
		strHtml += "<div class='institution_label'>Zip Code:<span class='required'>*</span></div>";
		strHtml += "<div align='left' class='institution_control'><input type='text' id='txtInstZipCode" + idx + "' name='txtInstZipCode" + idx + "' onChange='saveValue(&#39;zipCodeValue&#39;, " + idx + ",this.value)' value='" + masterInstArray[idx].zipCodeValue + "'  size='15' maxlength='10'></div>";
		strHtml += "<div style='clear: both;'></div>";
		strHtml += "</div>";
		strHtml += "<div style='display: block;'>";
		strHtml += "<div class='institution_label'>Country:<span class='required'>*</span></div>";
		strHtml += "<div align='left' class='institution_control'><input type='text' id='txtInstCountry" + idx + "' name='txtInstCountry" + idx + "' onChange='saveValue(&#39;countryValue&#39;, " + idx + ",this.value)' value='" + masterInstArray[idx].countryValue + "'  size='25' maxlength='25'></div>";
		strHtml +=  "<div style='clear: both;'></div>";
		strHtml += "</div>";
		strHtml +=  "</div> <!---END: container wrapper for each institution--->";
return strHtml;
}

//debug function that shows list of form elements in Element Index, Type, Name of element in JS alert
function showFormElementsList(formPtr){
var formElements='Index\tType\tName\n';
for(var loopI=0;loopI < formPtr.elements.length;loopI++){
            formElements+=loopI+'\t'+formPtr.elements[loopI].type+'\t'+formPtr.elements[loopI].name+'\n';
}
alert(formElements);
}

function createAuthInstOptions(){
//optional arugment for index of selected option value can be passed
	var idx;
	var optNode;
	var returnString="";
	var selected;

	returnString+="<option value=\"\">--- Select Institution ---</option> ";
	//populate new optios
	for(idx=0;idx<masterInstArray.length;idx++){
		selected="";
		if(typeof arguments[0]!="undefined"){
			if(arrAuthInstitutionValue[arguments[0]]==masterInstArray[idx].nameValue&&arrAuthInstitutionValue[arguments[0]]!=""){
				selected=" selected";													  
			}
		}
		returnString+='<option value="'+idx/*masterInstArray[idx].nameValue*/+'"'+selected+'>' +(idx + 1) + ' - ' +masterInstArray[idx].nameValue+'</option>';
	}
	return returnString;
}

var arrAuthInput = new Array(1);
var arrAuthLNameValue = new Array(1);
var arrAuthInitialsValue = new Array(1);
var arrAuthInstitutionValue = new Array(1);

arrAuthInput[0] = 0;
arrAuthLNameValue[0] = '';
arrAuthInitialsValue[0] = '';
arrAuthInstitutionValue[0] = '';

function saveAuthValue(ctlType, intId, strValue) {
	switch (ctlType)
	{
		case "AuthLName":
			arrAuthLNameValue[intId]=strValue;
			break;
		case "AuthInitials":
			arrAuthInitialsValue[intId]=strValue;
			break;
		case "AuthInstitution":
			arrAuthInstitutionValue[intId]=strValue;
			break;
		default : //;
	}
}


function addInput(strDiv) {
if (strDiv == 'auth')
	{
		arrAuthInput.push(arrAuthInput.length);
		arrAuthLNameValue.push("");
		arrAuthInitialsValue.push("");
		arrAuthInstitutionValue.push("");
	}
	else
	{
		//
	}
  
	display(strDiv);
}

function display(str) {
	var strDiv = str + 'Div';

	document.getElementById(strDiv).innerHTML="";
	
	if (str == 'inst')
	{
		for (i=1; i<masterArray.length; i++)
		{
			document.getElementById(strDiv).innerHTML+=createInput(str, masterArray[i]);
		}
	}
	else if (str == 'auth')
	{
		for (i=1; i<arrAuthInput.length; i++)
		{
			document.getElementById(strDiv).innerHTML+=createInput(str, arrAuthInput[i]);
		}
	}
	else
	{
		//
	}
}

function createInput(strDiv, id) {
	
	var strHtml = "";
	
	if (strDiv == 'auth')
	{
		strHtml =  "<div align='center' style='width: 100%;'> <!---BEGIN: container wrapper for each author--->";
		strHtml = strHtml + "<div style='display: block;'>";
		strHtml = strHtml + "<div style='position: relative; float: left; width: 20%;'>Author " + (id + 1) + "<span class='required'>*</span></div>";
		strHtml = strHtml + "<div style='position: relative; float: left; width: 30%;'><input type='text' id='txtAuthLName" + id + "' name='txtAuthLName" + id + "' onChange='saveAuthValue(&#39;AuthLName&#39;, " + id + ",this.value)' value='" + arrAuthLNameValue[id] + "'></div>";
		strHtml = strHtml + "<div style='position: relative; float: left; width: 10%;'><input type='text' id='txtAuthInitials" + id + "' name='txtAuthInitials" + id + "' onChange='saveAuthValue(&#39;AuthInitials&#39;, " + id + ",this.value)' value='" + arrAuthInitialsValue[id] + "' size='5' maxlength='2'></div>";
		strHtml = strHtml + "<div style='position: relative; float: left; width: 38%;'>";
		strHtml = strHtml + "<select id='txtAuthInstitution" + id + "' name='txtAuthInstitution" + id + "' onChange='saveAuthValue(&#39;AuthInstitution&#39;, " + id + ",this.value)'>";
		strHtml = strHtml + createAuthInstOptions(id);
		strHtml = strHtml + "</select>";
		strHtml = strHtml + "</div>";
		strHtml = strHtml + "<div style='clear: both;'></div>";
		strHtml = strHtml + "</div>";
		strHtml = strHtml + "</div> <!---END: container wrapper for each author--->";
	}
	
	return strHtml; 
}

function saveValue(structEl, arrPos, strValue) {
	//take in value, sturct element name to palace value in and array Postion of Master Inst Array 
	masterInstArray[arrPos][structEl]=strValue;
}
 
function deleteInput(strDiv) {
if (strDiv == 'auth')
	{
		if (arrAuthInput.length > 1) { 
			arrAuthInput.pop(); 
			arrAuthLNameValue.pop();
			arrAuthInitialsValue.pop();
			arrAuthInstitutionValue.pop();
		}
	}

	display(strDiv); 
}

function updateInst(instNamePtr){
	var arrPos=Number(instNamePtr.name.substr("txtInstName".length));
	
	//check input length is greater than 0 or error
	if(instNamePtr.value.length==0){
		instNamePtr.style.backgroundColor=errorHighlight
		alert("Error: The Institution must have have a name");
		return false;
	}
	else{
		instNamePtr.style.backgroundColor=noErrorHighlight;
	}

	//check if the postion is defined in master list
	if(typeof document.getElementById("txtAuthInstitution0").options[arrPos+1]=="undefined"){
		masterInstArray[arrPos].nameValue=instNamePtr.value;
		//create an option for each Auth Inst
		addInstOnScreen(arrPos,instNamePtr.form);
		
	}
	else{
			masterInstArray[arrPos].nameValue=instNamePtr.value;
		//if greater than 0 loop over each auth inst select and change values
			updateInstOnScreen(arrPos,instNamePtr.form);
	}
}

function updateInstOnScreen(arrPos,formPtr){
	var idx;
	
	for(idx=0;idx<formPtr.elements.length;idx++){
//alert (idx);
		if(formPtr.elements[idx].name.indexOf("txtAuthInstitution")>-1){
			formPtr.elements[idx].options[arrPos+1].value = arrPos; //masterInstArray[arrPos].nameValue;
			formPtr.elements[idx].options[arrPos+1].text='' + (arrPos+1) + ' - ' + masterInstArray[arrPos].nameValue;
			formPtr.elements[idx].onchange();
		}
	}
}

function addInstOnScreen(arrPos,formPtr){
	var idx;
	var optNode;
	
	for(idx=0;idx<formPtr.elements.length;idx++){
		if(formPtr.elements[idx].name.indexOf("txtAuthInstitution")>-1){
				optNode=document.createElement("option");
//				alert(arrPos); 
				optNode.value = arrPos; //masterInstArray[arrPos].nameValue;
				optNode.text='' + (arrPos+1) + ' - ' + masterInstArray[arrPos].nameValue;
				formPtr.elements[idx].appendChild(optNode);
		}
	}
}

function deleteInstOnScreen(formPtr){
	var idx;
	var optNode;
	
	for(idx=0;idx<formPtr.elements.length;idx++){
		if(formPtr.elements[idx].name.indexOf("txtAuthInstitution")>-1){
				if(formPtr.elements[idx].options[formPtr.elements[idx].options.length-1].selected==true){
					formPtr.elements[idx].options[0].selected=true;
				}
				formPtr.elements[idx].remove(formPtr.elements[idx].options.length-1);
		}
	}
}

function validateAndSubmitForm(formPtr){
	var	errorFlag=0;
	var	errorMsg='Please correct the following before submitting:\n';
	var idx;
	var states=new USStatesObject();
	
	//make sure abstract information is filled in
	if(checkTextNotFilledIn(formPtr.elements["txtAbstractTitle"])){
		errorFlag++;
		errorMsg+="Please fill in the abstract title.\n";
		formPtr.elements["txtAbstractTitle"].style.backgroundColor=errorHighlight;	
	}
	else{
		formPtr.elements["txtAbstractTitle"].style.backgroundColor=noErrorHighlight;	
	}
	if(checkTextNotFilledIn(formPtr.elements["txtAbstractBody"])){
		errorFlag++;
		errorMsg+="Please fill in the abstract body.\n";
		formPtr.elements["txtAbstractBody"].style.backgroundColor=errorHighlight;	
	}
	else{
		formPtr.elements["txtAbstractBody"].style.backgroundColor=noErrorHighlight;	
	}
	
	//at least One Keyword entered
	if(checkTextNotFilledIn(formPtr.elements["txtKeyword1"])){
		errorFlag++;
		errorMsg+="Please fill in at least one keyword.\n";
		formPtr.elements["txtKeyword1"].style.backgroundColor=errorHighlight;	
	}
	else{
		formPtr.elements["txtKeyword1"].style.backgroundColor=noErrorHighlight;	
	}
	

	//loop over master insituttion array to do check for instution fields correct
	for(idx=0;idx<masterInstArray.length;idx++){
		//check	Unit/Division/Center is filled in
		if(checkTextNotFilledIn(formPtr.elements["txtInstDivision"+idx])){
			errorFlag++;
			errorMsg+="Please fill in Unit/Division/Center for Institution #"+(idx+1)+".\n";
			formPtr.elements["txtInstDivision"+idx].style.backgroundColor=errorHighlight;	
		}
		else{
			formPtr.elements["txtInstDivision"+idx].style.backgroundColor=noErrorHighlight;	
		}
		//check	Institution Name is filled in
		if(checkTextNotFilledIn(formPtr.elements["txtInstName"+idx])){
			errorFlag++;
			errorMsg+="Please fill in Name for Institution #"+(idx+1)+".\n";
			formPtr.elements["txtInstName"+idx].style.backgroundColor=errorHighlight;	
		}
		else{
			formPtr.elements["txtInstName"+idx].style.backgroundColor=noErrorHighlight;	
		}
		//check	Institution City is filled in
		if(checkTextNotFilledIn(formPtr.elements["txtInstCity"+idx])){
			errorFlag++;
			errorMsg+="Please fill in City for Institution #"+(idx+1)+".\n";
			formPtr.elements["txtInstCity"+idx].style.backgroundColor=errorHighlight;	
		}
		else{
			formPtr.elements["txtInstCity"+idx].style.backgroundColor=noErrorHighlight;	
		}
		//check Institution State and Zip or Country is filled in
		//if country is not filled in make sure Zip is State are filled in or output error
		if(formPtr.elements["txtInstCountry"+idx].value=="USA"){
			//if state and zip filled in
			//ensure that state is alphabetical and uppercased
			formPtr.elements["txtInstState"+idx].value=formPtr.elements["txtInstState"+idx].value.toUpperCase();
			if(states.isStateAbbr(formPtr.elements["txtInstState"+idx].value)==false){
				errorFlag++;
				errorMsg+="Please fill in a 2 letter state abbreviation for Institution #"+(idx+1)+".\n";
				formPtr.elements["txtInstState"+idx].style.backgroundColor=errorHighlight;	
			}
			else{
				formPtr.elements["txtInstState"+idx].style.backgroundColor=noErrorHighlight;	
			}
			//ensure that zip is correctly entered
			if(formPtr.elements["txtInstZipCode"+idx].value.length>5&&formPtr.elements["txtInstZipCode"+idx].value.search(/\d{5}-\d{4}/)==-1){
				errorFlag++;
				errorMsg+="Please fill in the zip code with postal code formated '99999-9999' for Institution #"+(idx+1)+".\n";
				formPtr.elements["txtInstZipCode"+idx].style.backgroundColor=errorHighlight;	
			}
			else if(formPtr.elements["txtInstZipCode"+idx].value.search(/\d{5}/)==-1){
				errorFlag++;
				errorMsg+="Please fill in the 5 digit zip code for Institution #"+(idx+1)+".\n";
				formPtr.elements["txtInstZipCode"+idx].style.backgroundColor=errorHighlight;	
			}
			else{
				formPtr.elements["txtInstZipCode"+idx].style.backgroundColor=noErrorHighlight;
				if(formPtr.elements["txtInstZipCode"+idx].value.length==5){
					formPtr.elements["txtInstZipCode"+idx].value+="-0000";
					saveValue('zipCodeValue', idx,formPtr.elements["txtInstZipCode"+idx].value);
				}
			}
		}
		else if(checkTextNotFilledIn(formPtr.elements["txtInstCountry"+idx])==false){
				//make sure that state is not filled in if not USA
				if(checkTextNotFilledIn(formPtr.elements["txtInstState"+idx])==false){
					errorFlag++;
					errorMsg+="Please remove the state value for Institution #"+(idx+1)+".\n";
					formPtr.elements["txtInstState"+idx].style.backgroundColor=errorHighlight;	
				}
				else{
					formPtr.elements["txtInstState"+idx].value=formPtr.elements["txtInstState"+idx].value.toUpperCase();
					formPtr.elements["txtInstState"+idx].style.backgroundColor=noErrorHighlight;	
				}
				//make sure that postal code is filled in
				if(checkTextNotFilledIn(formPtr.elements["txtInstZipCode"+idx])){
					errorFlag++;
					errorMsg+="Please fill in the postal code in zip code field for Institution #"+(idx+1)+".\n";
					formPtr.elements["txtInstZipCode"+idx].style.backgroundColor=errorHighlight;	
				}
				else{
					formPtr.elements["txtInstZipCode"+idx].style.backgroundColor=noErrorHighlight;	
				}
		}
		else{
			//output error for and highlight all three elements as incorrect
			errorFlag++;
			errorMsg+="Please fill in the country for Institution #"+(idx+1)+". Enter 'USA' for the United States.\n";
			formPtr.elements["txtInstCountry"+idx].style.backgroundColor=errorHighlight;	
		}
	}
	//loop over author array to check author information has been entered correctly
	for(idx=0;idx<arrAuthInstitutionValue.length;idx++)
	{
		//check author last name
		if(checkTextNotFilledIn(formPtr.elements["txtAuthLName"+idx])){
			errorFlag++;
			errorMsg+="Please fill in the Last Name for Author #"+(idx+1)+".\n";
			formPtr.elements["txtAuthLName"+idx].style.backgroundColor=errorHighlight;	
		}
		else{
			formPtr.elements["txtAuthLName"+idx].style.backgroundColor=noErrorHighlight;	
		}
		
		//check author initials
		if(checkTextNotFilledIn(formPtr.elements["txtAuthInitials"+idx])){
			errorFlag++;
			errorMsg+="Please fill in the Initials for Author #"+(idx+1)+".\n";
			formPtr.elements["txtAuthInitials"+idx].style.backgroundColor=errorHighlight;	
		}
		else{
			formPtr.elements["txtAuthInitials"+idx].style.backgroundColor=noErrorHighlight;	
		}
		
		//check author institution
		if(checkSelectNotSelected(formPtr.elements["txtAuthInstitution"+idx])||formPtr.elements["txtAuthInstitution"+idx].options[formPtr.elements["txtAuthInstitution"+idx].selectedIndex].value==""){
			errorFlag++;
			errorMsg+="Please select a Institution for Author #"+(idx+1)+".\n";
			formPtr.elements["txtAuthInstitution"+idx].style.backgroundColor=errorHighlight;	
		}
		else{
				formPtr.elements["txtAuthInstitution"+idx].style.backgroundColor=noErrorHighlight;
		}
		
		//if first author 
		if(idx==0){
			//check telephone 
			if(formPtr.elements["txtAuthPhone"].value.search(/\b[\d-]+\b/)||-1&&formPtr.elements["txtAuthPhone"].value.search(/[^\d-]+/)>-1){
				errorFlag++;
				errorMsg+="Please fill in the telephone for Author #"+(idx+1)+" with only numbers and dashes.\n";
				formPtr.elements["txtAuthPhone"].style.backgroundColor=errorHighlight;	
			}
			else{
				formPtr.elements["txtAuthPhone"].style.backgroundColor=noErrorHighlight;	
			}

			//check email
			if(checkTextNotEmailAddress(formPtr.elements["txtAuthEmail"])){
				errorFlag++;
				errorMsg+="Please fill in the e-mail for Author #"+(idx+1)+".\n";
				formPtr.elements["txtAuthEmail"].style.backgroundColor=errorHighlight;	
			}
			else{
				formPtr.elements["txtAuthEmail"].style.backgroundColor=noErrorHighlight;	
			}
		}
	}
	
	//if YITA or Mentor Dinner must be radio buttons 1-3 not 0
	if(checkCheckBoxesNotSelected(formPtr.elements["chkIsYITA"])!=true&&formPtr.elements["optAuthStatus"][0].checked==true){
		errorFlag++;
		errorMsg+="You must be Trainee or Postdoc to submit for the YITA award.\n";
		formPtr.elements["chkIsYITA"].parentNode.style.backgroundColor=errorHighlight;	
	}
	else{
		formPtr.elements["chkIsYITA"].parentNode.style.backgroundColor=noErrorHighlight;	
	}
	
	//if mentor dinner 
	if(checkCheckBoxesNotSelected(formPtr.elements["chkWillAttendDinner"])!=true&&formPtr.elements["optAuthStatus"][0].checked==true){
		errorFlag++;
		errorMsg+="You must be Trainee or Postdoc to attend the Mentor's Dinner.\n";
		formPtr.elements["chkWillAttendDinner"].parentNode.style.backgroundColor=errorHighlight;	
	}
	else{
		formPtr.elements["chkWillAttendDinner"].parentNode.style.backgroundColor=noErrorHighlight;	
	}
	
	//if presenting in poster session - only for Invited speakers 
	if(checkCheckBoxesNotSelected(formPtr.elements["chkWillPresentPoster"])!=true&&checkCheckBoxesNotSelected(formPtr.elements["chkIsInvitedSpeaker"])==true){
		errorFlag++;
		errorMsg+="You must also check the 'I am presenting this abstract as an Invited Speaker' box in order to present in the Poster Session.\n";
		formPtr.elements["chkWillPresentPoster"].parentNode.style.backgroundColor=errorHighlight;	
	}
	else{
		formPtr.elements["chkWillPresentPoster"].parentNode.style.backgroundColor=noErrorHighlight;	
	}
	   errorFlat = 0;
 	if(errorFlag==0){
		formPtr.submit();
	}
	else{
		alert(errorMsg);
	}
}

function checkTextNotFilledIn(passedTextField) {
    if (passedTextField.value.length == 0) {
        return true;
    } else {
        return false;
    }
}

function checkSelectNotSelected(passedSelectField) {
    if (passedSelectField.options[0].selected) {
        return true;
    } else {
        return false;
    }
}

function checkTextNotEmailAddress(passedTextField) {
    if (passedTextField.value.search(/.+@.+/) == -1 ||
        passedTextField.value.indexOf(" ", 0) != -1) {
        return true;
    } else {
        return false;
    }
}

function checkCheckBoxesNotSelected(passedCheckBoxField) {
    if (passedCheckBoxField != null) {
        if (passedCheckBoxField.length != null) {
            var loopcount;
            for (loopcount = 0; loopcount < passedCheckBoxField.length; loopcount++) {
                if (passedCheckBoxField[loopcount].checked) {
                    return false;
                }
            }
        } else {
            if (passedCheckBoxField.checked) {
                return false;
            }
        }
    } else {
        if (passedCheckBoxField != null) {
            alert("checkCheckBoxesNotSelected was passed a null field");
        }
    }
    return true;
}


function USStatesObject(){
	function USStateObject(fName,abbr,sPFlag){
		this.fullName=fName.toUpperCase();
		this.abbreviation=abbr.toUpperCase();
		this.statePossessionFlag=sPFlag.toUpperCase();//S=state P=possession;
	}


	this.statesArray= new Array(
new USStateObject("ALABAMA","AL","S"),
new USStateObject("ALASKA","AK","S"),
new USStateObject("AMERICAN SAMOA","AS","P"),
new USStateObject("ARIZONA","AZ","S"),
new USStateObject("ARKANSAS","AR","S"),
new USStateObject("CALIFORNIA","CA","S"),
new USStateObject("COLORADO","CO","S"),
new USStateObject("CONNECTICUT","CT","S"),
new USStateObject("DELAWARE","DE","S"),
new USStateObject("DISTRICT OF COLUMBIA","DC","P"),
new USStateObject("FEDERATED STATES OF MICRONESIA","FM","P"),
new USStateObject("FLORIDA","FL","S"),
new USStateObject("GEORGIA","GA","S"),
new USStateObject("GUAM","GU","P"),
new USStateObject("HAWAII","HI","S"),
new USStateObject("IDAHO","ID","S"),
new USStateObject("ILLINOIS","IL","S"),
new USStateObject("INDIANA","IN","S"),
new USStateObject("IOWA","IA","S"),
new USStateObject("KANSAS","KS","S"),
new USStateObject("KENTUCKY","KY","S"),
new USStateObject("LOUISIANA","LA","S"),
new USStateObject("MAINE","ME","S"),
new USStateObject("MARSHALL ISLANDS","MH","P"),
new USStateObject("MARYLAND","MD","S"),
new USStateObject("MASSACHUSETTS","MA","S"),
new USStateObject("MICHIGAN","MI","S"),
new USStateObject("MINNESOTA","MN","S"),
new USStateObject("MISSISSIPPI","MS","S"),
new USStateObject("MISSOURI","MO","S"),
new USStateObject("MONTANA","MT","S"),
new USStateObject("NEBRASKA","NE","S"),
new USStateObject("NEVADA","NV","S"),
new USStateObject("NEW HAMPSHIRE","NH","S"),
new USStateObject("NEW JERSEY","NJ","S"),
new USStateObject("NEW MEXICO","NM","S"),
new USStateObject("NEW YORK","NY","S"),
new USStateObject("NORTH CAROLINA","NC","S"),
new USStateObject("NORTH DAKOTA","ND","S"),
new USStateObject("NORTHERN MARIANA ISLANDS","MP","P"),
new USStateObject("OHIO","OH","S"),
new USStateObject("OKLAHOMA","OK","S"),
new USStateObject("OREGON","OR","S"),
new USStateObject("PALAU","PW","P"),
new USStateObject("PENNSYLVANIA","PA","S"),
new USStateObject("PUERTO RICO","PR","P"),
new USStateObject("RHODE ISLAND","RI","S"),
new USStateObject("SOUTH CAROLINA","SC","S"),
new USStateObject("SOUTH DAKOTA","SD","S"),
new USStateObject("TENNESSEE","TN","S"),
new USStateObject("TEXAS","TX","S"),
new USStateObject("UTAH","UT","S"),
new USStateObject("VERMONT","VT","S"),
new USStateObject("VIRGIN ISLANDS","VI","P"),
new USStateObject("VIRGINIA","VA","S"),
new USStateObject("WASHINGTON","WA","S"),
new USStateObject("WEST VIRGINIA","WV","S"),
new USStateObject("WISCONSIN","WI","S"),
new USStateObject("WYOMING","WY","S"),

new USStateObject("Armed Forces Africa","AE","P"),
new USStateObject("Armed Forces Americas","AA","P"),
new USStateObject("Armed Forces Canada","AE","P"),
new USStateObject("Armed Forces Europe","AE","P"),
new USStateObject("Armed Forces Middle East","AE","P"),
new USStateObject("Armed Forces Pacific","AP","P")							
	);
	//checks if passed value is Two Upper Case Letters of State Possession Abbreviations if not returns false.
	this.isStateAbbr=function(valueToCheck){
		if(valueToCheck.search(/[A-Z]{2}/)==-1||valueToCheck.length!=2){
			return false;	
		}
		else{
			var idx;
			//go over abbreviations and compare value
			for(idx=0;idx<this.statesArray.length;idx++){
				if(this.statesArray[idx].abbreviation==valueToCheck){return true;}
			}
			return false;//if not found in array return false
		}
	}
}




function textAreaCount(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
}


function enablePosterCheckbox() {
	if (document.forms[0].chkWillPresentPoster.disabled == true) {
		document.forms[0].chkWillPresentPoster.disabled = false;
	}
	else {
		document.forms[0].chkWillPresentPoster.checked = false;
		document.forms[0].chkWillPresentPoster.disabled = true;
	}
}

