

<!--

//initialize global variables

function selectState(field,fieldState)
{
	// here if US and Canada fields are selected in field dropdown box
	// set index field of fieldState to point to 'choose One'
	// otherwise fieldState to ' ' (blank)
	if ( (field.options[field.selectedIndex].text.toUpperCase() == "UNITED STATES") || (field.options[field.selectedIndex].text.toUpperCase() == "CANADA") )
	{
		fieldState.selectedIndex = 1;
	}
	else
	{
		fieldState.selectedIndex = 0;
	}
}

function selectCountry(field,fieldCountry)
{
	// here US and Canada fields are selected 
	// based on the state value
	var state = field.options[field.selectedIndex].value
	var indexUS
	var indexCanada
		
	//get index value for US and Canada
	for (var count=0; count<fieldCountry.length; count++)
	{
		if (fieldCountry.options[count].text == "United States")
			indexUS = count;	

		if (fieldCountry.options[count].text == "Canada")
			indexCanada = count;	
	}
		
	switch(state)
	{
		case "":
			fieldCountry.selectedIndex = 0;
			break;
				
		case "AB": 
		case "BC":
		case "MB": 
		case "NB":
		case "NF": 
		case "NS":
		case "NT":
		case "ON":
		case "PE":
		case "QC":
		case "SK":
		case "YT":
			fieldCountry.selectedIndex = indexCanada;
			break;
				
		default:
			fieldCountry.selectedIndex = indexUS;	
	}
}


function upperMe(field) 
{
	field.value = field.value.toUpperCase()
}

function trim(strText) 
{ 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);
    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   return strText;
} 

function showWordCount()
{
	document.form.txtWordCountAbstract.value = countWords(document.form.txtAbstract, 250) 
}



function validateEmail(this_field) 
{
	//Author : P.Lau - 10/12/2001
	//purpose: Validate E-mail Adress
	//input Parameter: E-mail address
	//output Parameter:	boolean
	//
	//Requirements:
	//must have at least one '@'
	//must have at least one '.'
	//'a@b.c' cannot be less than 5 chars
	//has no more then 3 chars after last "."
	//has no "_" after the "@"
	
	if (this_field.value != "") 
	{
		var strCheck = this_field.value
		if (strCheck.indexOf("@")==-1 ||							
			strCheck.indexOf(".")==-1 ||							
			strCheck.length < 5 ||									
			strCheck.length - (strCheck.lastIndexOf(".")+1) > 3 ||	
			(strCheck.indexOf("_")-strCheck.indexOf("@") > 0))		
		{
			alert("Please enter valid Email Address.");
			this_field.focus();
			this_field.select();
			return false;
		}
	}
	return true;
}


function validatePassword(this_field_Email, this_field_Validate) 
{
	//Author : P.Lau - 10/12/2001
	//purpose: Validate password
	//input Parameter: password, password
	//output Parameter:	boolean

	Email = this_field_Email.value;
	Validate = this_field_Validate.value;

	if (Email != Validate) 
	{
		alert ("\nYou did not enter the same Email address twice. Please re-enter your Email address.");
		return false;
	}
	return true;
}

function cursorwait(){
	document.body.style.cursor='wait';
}

function cursordone() {
	document.body.style.cursor='auto';
}


// Hongmin Shu 3/10/2003 

function VerifyUploadMsg() 
{
	//Author : Hongmin Shu 3/10/2003
	//purpose: Pop-up box asking if they are sure they have uploaded all files
	//input Parameter: 
	//output Parameter:	boolean

	var bResultReturned
	bResultReturned = confirm("Have you uploaded all the files?")
		if (bResultReturned) 
		{
			cursorwait();
			return true
		}
		else 
		{
			return false
		}
}

function PopupWin(theURL, winName) {
	winFeatures = "status=yes,scrollbars=yes,resizable=yes,left=100,top=100";
	Popup = window.open(theURL,winName, winFeatures);
	
	Popup.focus();
}

function PopFullWin(theURL, winName) {
	winFeatures = "location=yes,titlebar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes,left=100,top=100";
	Popup = window.open(theURL,winName, winFeatures);
	
	Popup.focus();
}


//*****************************************************************
// 1/21/2004  from Letters to editor common.js file
//*****************************************************************
function validateRef(form) 
{
	//validation common between Ref & NoRef forms
	//if (validateFormCommon(form)) 	
	//{
		//reset word count in case it was manipulated with.
		showWordCount175()
		
		if (countWords(form.txtLetter,175) > 190)
		{
			alert("Word count exceeded maximum limit.")
			form.txtLetter.focus();
			return false;
		}
		if (countWords(form.txtLetter,175) < 4 || form.txtLetter.text == "")
		{
			alert('Please insert the text of the letter.')
			form.txtLetter.focus();
			return false;
		}

		//Dropdown list for Articles.
		//At the minimum one selection
		if (form.cboArticle.selectedIndex < 0 ) 
		{
			alert("Please select one article");
			form.cboArticle.focus();
			return false;
		}
	
		//Dropdown list for Articles.
		//At the minimum one to a max of three selection
		if (form.cboArticle.length > 0)
		{
			var count = 0;
			var maxList = form.cboArticle.length - 1
			for (var i=0; i<=maxList; i++)
			{
				if (form.cboArticle.options[i].selected)
				{
					count = count + 1
				}
			}
			if (count > 3)
			{
				alert("maximum of 3 articles allowed")
				form.cboArticle.focus();
				return false;		
			}
		}
		
		if ((form.optFigTable[1].checked || form.optFigTable[2].checked ) && trim(form.txtFigTable.value)=="" )
		{
			alert("Please enter a brief legend")
			form.txtFigTable.focus();
			return false;
		}
	
		
		return true;
	//}
	//else
	//{
	//	return false;
	//}
}
function cleanLegendBox()
{
	if (form.optFigTable[0].checked==true)
	{
		form.txtFigTable.value ="";
		form.optFigTable[0].focus();
	}	
}
function validateNoRef(form) 
{
	//validation common between Ref & NoRef forms
	//if (validateFormCommon(form)) 	
	//{
		//reset word count in case it was manipulated with.
		showWordCount400()

		//if (form.optResubmit[0].checked == false && trim(form.txtReSubmitID.value)=="")
		//{
		//	alert("Please reference previously submitted reference number");
		//	form.txtReSubmitID.focus();
		//	return false;
		//}

		//if (form.optResubmit[0].checked && trim(form.txtReSubmitID.value)!="")
		//{
		//	document.form.txtReSubmitID.value = "";
		//}

	
		if (form.txtLetterTitle.value == "") 
		{
			alert("Title of Letter is a required field.");
			form.txtLetterTitle.focus();
			return false;
		}

		if (countWords(form.txtLetter,400) > 450)
		{
			alert("Word count exceeded maximum limit.")
			form.txtLetter.focus();
			return false;
		}
		if (countWords(form.txtLetter,400) < 4 || form.txtLetter.text == "")
		{
			alert('Please insert the text of the letter.')
			form.txtLetter.focus();
			return false;
		}
		if ((form.optFigTable[1].checked || form.optFigTable[2].checked ) && trim(form.txtFigTable.value)=="" )
		{
			alert("Please enter a brief legend")
			form.txtFigTable.focus();
			return false;
		}
	
		if ( trim(form.txtFigTable.value)!="" )
		{
			if (form.optFigTable[1].checked==false && form.optFigTable[2].checked==false )
			{
				alert("Please check whether or not submitting a Figure or Table.")
				form.optFigTable[0].focus();
				return false;
			}
		}
		return true;
	//}
	//else
	//{
	//	return false;
	//}
}

function validateFormCommon(form) 
{
	//Common validation between Ref & NoRef forms
	
	if (form.txtAut1FName.value == "") 
	{
		alert("Please enter your First Name.");
		form.txtAut1FName.focus();
		return false;
	}

	if (form.txtAut1LName.value == "") 
	{
		alert("Please enter your Last Name.");
		form.txtAut1LName.focus();
		return false;
	}
	
	if (form.txtAut1Affil.value == "") 
	{
		alert("Affiliation is a required field.");
		form.txtAut1Affil.focus();
		return false;
	}
	
	if (form.txtAut1City.value == "") 
	{
		alert("City is a required field.");
		form.txtAut1City.focus();
		return false;
	}
	
	if (form.txtAut1PostalCode.value == "") 
	{	// Hongmin Shu 6/27/2003 US and Canada require the postal code for author one
		if (form.cboAut1Cntry.value == "United States" || form.cboAut1Cntry.value == "Canada")
			{ 
			alert("Postal Code is a required field.");
			form.txtAut1PostalCode.focus();
			return false;
			}
	}
	
	
	//need to validate here for drop down when USA is picked
	//state field for Author1 must be filled.
	if (form.cboAut1State.selectedIndex == 0 ) 
	{
	
		if (form.cboAut1Cntry.value == "United States" || form.cboAut1Cntry.value == "Canada")
		{
			alert("Please enter a state");
			form.cboAut1State.focus();
			return false;
		}
	}
	
	//need to validate here for drop down
	if (form.cboAut1Cntry.selectedIndex == 0) 
	{
		alert("\nYou must make a selection from the drop-down menu.");
		form.cboAut1Cntry.focus();
		return false;
	}
	
	// Hongmin Shu 7/21/2003 US and Canada require the postal code for author #2 and #3
	if (form.txtAut2PostalCode.value == "") 
	{	
		if (form.cboAut2Cntry.value == "United States" || form.cboAut2Cntry.value == "Canada")
			{ 
			alert("Postal Code is a required field.");
			form.txtAut2PostalCode.focus();
			return false;
			}
	}
	
	if (form.txtAut3PostalCode.value == "") 
	{	
		if (form.cboAut3Cntry.value == "United States" || form.cboAut3Cntry.value == "Canada")
			{ 
			alert("Postal Code is a required field.");
			form.txtAut3PostalCode.focus();
			return false;
			}
	}
	
	// end of the changes
	
	

	//if option button for the 2nd corresponding author is checked 
	//then validate appropriate fields below
	if ((form.optAutCorrFlag[1].checked) || 
		(form.txtAut2FName.value != "") ||
		(form.txtAut2LName.value != "") ) 
	{
		if (form.txtAut2FName.value == "") 
		{
			alert("Please enter First Name for corresponding author.");
			form.txtAut2FName.focus();
			return false;
		}
		if (form.txtAut2LName.value == "") 
		{
			alert("Please enter Last Name for corresponding author.");
			form.txtAut2LName.focus();
			return false;
		}
	}

	//if option button for the 3rd corresponding author is checked 
	//then validate appropriate fields below
	if ((form.optAutCorrFlag[2].checked) || 
		(form.txtAut3FName.value != "") ||
		(form.txtAut3LName.value != "") ) 
	{
		if (form.txtAut3FName.value == "") 
		{
			alert("Please enter First Name for corresponding author.");
			form.txtAut3FName.focus();
			return false;
		}
		if (form.txtAut3LName.value == "") 
		{
			alert("Please enter Last Name for corresponding author.");
			form.txtAut3LName.focus();
			return false;
		}
	}

	
	if (form.txtCorrStreetAddr1.value == "") 
	{
		alert("'Street Address' for corresponding author is a required field.");
		form.txtCorrStreetAddr1.focus();
		return false;
	}
	
	if (form.txtCorrCity.value == "") 
	{
		alert("'City' for corresponding author is a required field.");
		form.txtCorrCity.focus();
		return false;
	}
	
	if (form.txtCorrPostalCode.value == "") 
	{
		// Hongmin Shu 6/27/2003 US and Canada require postal code for corresponding author
		if (form.cboCorrCntry.value == "USA" || form.cboCorrCntry.value == "CAN")
		{
			alert("'Postal Code' for corresponding author is a required field.");
			form.txtCorrPostalCode.focus();
			return false;
		}
	}
	
	//need to validate here for drop down
	if (form.cboCorrCntry.selectedIndex == 0) 
	{
		alert("\nYou must make a selection from the drop-down menu.");
		form.cboCorrCntry.focus();
		return false;
	}
	

	//need to validate here for drop down when USA is picked
	//state field for Corresponding author must be filled.
	if (form.cboCorrCntry.selectedIndex > 0 ) 
	{
		var list = form.cboCorrCntry
		var listState = form.cboCorrState
		if (list.options[list.selectedIndex].value == 'USA' && listState.options[listState.selectedIndex].value == "")
		{
			alert("Please enter a state");
			form.cboCorrState.focus();
			return false;
		}
	}
	// 5/3/2004 --- check the Fax number
	if (isNaN(form.txtCorrFax.value) || form.txtCorrFax.value.indexOf("+") != -1)
	{
		alert("Please remove any symbols(+, -, etc.) from fax number fields.");
		form.txtCorrFax.focus();
		return false;
	}

	if (form.txtCorrEmail.value == "") 
	{
		alert("'E-mail Address' for corresponding author is a required field.");
		form.txtCorrEmail.focus();
		return false;
	}

	if (form.txtCorrEmail.value != "") 
	{
		var strCheck = form.txtCorrEmail.value
		if (!validateEmail(form.txtCorrEmail))
		{
			return false;
		}
	}
	
	if (form.txtCorrEmail.value != form.txtCorrEmailVerify.value) 
	{
		alert("Please check E-mail address.")
		form.txtCorrEmail.focus()
		return false;
	}

	if (form.txtCorrPhone.value == "") 
	{
		alert("'Phone number' for corresponding author is a required field.");
		form.txtCorrPhone.focus();
		return false;
	}

	//if (form.optConflict[0].checked && trim(form.txtDisclose.value)=="")
	//{
	//	alert("Please enter a disclosure")
	//	form.txtDisclose.value = trim(form.txtDisclose.value)
	//	return false;
	//}
	
	//if (form.chkLegendPost.checked && trim(form.txtFigTable.value)=="")
	//{
	//	alert("Please enter a brief legend")
	//	form.txtFigTable.value = trim(form.txtFigTable.value)
	//	form.txtFigTable.focus();
	//	return false;
	//}

	//if ((form.optFigTable[0].checked || form.optFigTable[1].checked ) && trim(form.txtFigTable.value)=="" )
	//{
	//	alert("Please enter a brief legend")
	//	form.txtFigTable.focus();
	//	return false;
	//}
	
	//if ( trim(form.txtFigTable.value)!="" )
	//{
	//	if (form.optFigTable[0].checked==false && form.optFigTable[1].checked==false )
	//	{
	//		alert("Please check whether or not submitting a Figure or Table.")
	//		form.optFigTable[0].focus();
	//		return false;
	//	}
	//}
	
	// Hongmin Shu 7/21/2003 make the Disclosure a required field
	if ( !form.optConflict[0].checked && !form.optConflict[1].checked)
	{
		alert("Disclosure is required. Please select either Yes or No.");
			form.optConflict[0].focus();
			return false;
	}
	

	if ( form.optConflict[0].checked && trim(form.txtDisclose.value)=="" )
	{
		alert("Please enter a disclosure.");
		form.optConflict[0].focus();
		return false;
	}


	return true;
}

function resetOptionFigTab()
{
	//reset option buttons and clear text
	document.form.optFigTable[0].checked = false;
	document.form.optFigTable[1].checked = false;
	document.form.chkLegendPost.checked = false;
	document.form.txtFigTable.value = "";
}

function showWordCount175()
{
	document.form.txtWordCount.value = countWords(document.form.txtLetter, 175) 
}

function showWordCount400()
{
	document.form.txtWordCount.value = countWords(document.form.txtLetter, 400) 
}


//----------------------End of actual code ---------------------



function validateNumber(iNum)
 {
 	//Author : Andre Barber 3/22/2003
	//purpose: Validate if valid number
	//input Parameter: 
	//output Parameter:	boolean
				var sValidNums = '0123456789';
				var temp;
				for (var i=0; i<iNum.length; i++)
					{
					temp = '' + iNum.substring(i, i+1);
					if (sValidNums.indexOf(temp) == '-1') return false;	
					}
				return true;
}

	// use this for generic child windows
	function childWindow(url)
	{	var childWindow=window.open(url,'childWindow','width=700,height=400,left=100,top=100,menubar,location,toolbar,resizable,scrollbars,status');
	childWindow.focus();
	}


	
// End -->