function moveOver()  
	{      

		var boxLength = document.choiceForm.choiceBox.length;
		var selectedItem = document.choiceForm.available.selectedIndex;
		var selectedText = document.choiceForm.available.options[selectedItem].text;
		var selectedValue = document.choiceForm.available.options[selectedItem].value;
		
			var selectedIndex = selectedValue.indexOf("&");

			var selectedValueSub=selectedValue.substr(0, selectedIndex);
			var i;
			var isNew = true;
		
			if (boxLength != 0) {
				for (i = 0; i < boxLength; i++) {
					thisitem = document.choiceForm.choiceBox.options[i].text;

					thisvalue = document.choiceForm.choiceBox.options[i].value;


					var thisvalueindex = thisvalue.indexOf("&");

					var thisvaluesub = thisvalue.substr(0, thisvalueindex);
					
					if (thisvaluesub == selectedValueSub) {
						alert(selectedText + " " + document.forms[0].LSelExist.value + " " + thisitem);
						isNew = false;
						break;
    	  			}					
   				}
			} 
			if (isNew) {
				// First remove the end of list item from the selected list.
				var eolText = document.choiceForm.choiceBox.options[document.choiceForm.choiceBox.options.length - 1].text;
				var eolValue = document.choiceForm.choiceBox.options[document.choiceForm.choiceBox.options.length - 1].value;
				document.choiceForm.choiceBox.options[document.choiceForm.choiceBox.options.length - 1] = null;
				newoption = new Option(selectedText, selectedValue, false, false);
				document.choiceForm.choiceBox.options[boxLength-1] = newoption;
				newOpt = new Option(eolText, eolValue);
				document.choiceForm.choiceBox.options[boxLength] = newOpt;
			}
			document.choiceForm.available.selectedIndex=-1;

	}
	function removeMe() {
		var boxLength = document.choiceForm.choiceBox.length;
		arrSelected = new Array();
		var count = 0;
		for (i = 0; i < boxLength-1; i++) {
			if (document.choiceForm.choiceBox.options[i].selected) {
				arrSelected[count] = document.choiceForm.choiceBox.options[i].value;
			}
			count++;
		}
		var x;
		for (i = 0; i < boxLength-1; i++) {
			for (x = 0; x < arrSelected.length; x++) {
				if (document.choiceForm.choiceBox.options[i].value == arrSelected[x]) {
					document.choiceForm.choiceBox.options[i] = null;
 			  	}
			}
			boxLength = document.choiceForm.choiceBox.length;
   		}
	}
	
	function searchBasic(){
		var str = document.forms[0].elements['JSearch'].value.toLowerCase(); 
		if(str<='') {
			return;
		} 
		var j = 0; 
		var sel = document.forms[0].elements['available']; 
		for(var i=0;i<sel.options.length;i++){
			var curItem = sel.options[i].text;
			var startSearchAt=0;
			var strLen=str.length;
			if( curItem.charAt(0)=='('){
				startSearchAt=1;
			}
			else{
				startSearchAt=0;
			} 
			if(curItem.substr(startSearchAt, strLen).toLowerCase() == str) {
			   sel.options[i].selected=true;
			   return;
			}
		}
	}
function setCasY(){
  for (i=0;i<document.choiceForm.choiceBox.length;i++)
  {
     document.choiceForm.choiceBox.options[i].selected = false;
  }
  for (i=0;i<document.choiceForm.choiceBox.length-1;i++)
  {
     document.choiceForm.choiceBox.options[i].selected = true;
  }
  	document.forms[0].action="chempick.jsp?sort=Y"; 
	document.forms[0].submit();	
}

function setCasN(){
  for (i=0;i<document.choiceForm.choiceBox.length;i++)
  {
     document.choiceForm.choiceBox.options[i].selected = false;
  }

  for (i=0;i<document.choiceForm.choiceBox.length-1;i++)
  {
     document.choiceForm.choiceBox.options[i].selected = true;
  }
  	document.forms[0].action="chempick.jsp"; 
	document.forms[0].submit();
}
 
function chemInfo(){ 
	if(document.forms[0].available.selectedIndex >-1)
	{
		var list=document.forms[0].available;
		var selectedValue = list.options[list.selectedIndex].value;
	
		if(selectedValue.lastIndexOf("&chem4=")>-1) {
		
			var selectedValueIndex = selectedValue.lastIndexOf("&");
				
			var selectedChem = selectedValue.substr(0, selectedValueIndex);
				
			var infoPage = "cheminfo.jsp?chem=" + selectedValue;
		}
		else{
			var infoPage = "cheminfo.jsp?chem=" + selectedValue;
		}
			var features = "toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=650,height=500";
			newWindow = window.open(infoPage, "ChemInfo", features);
	}
	else
	{
		alert(document.forms[0].LSelChemical.value);
	}			
}
 
function chemInfoSelected(){
	if(document.forms[0].choiceBox.selectedIndex >-1)
	{
		var list=document.forms[0].choiceBox;
		var selectedValue = list.options[list.selectedIndex].value;
	
		if(selectedValue.lastIndexOf("&chem4=")>-1) {
			var selectedValueIndex = selectedValue.lastIndexOf("&");
			var selectedChem = selectedValue.substr(0, selectedValueIndex);
			 
			var infoPage = "cheminfo.jsp?chem=" + selectedValue;

		}
		else{
			var infoPage = "cheminfo.jsp?chem=" + selectedValue;
		}
			var features = "toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=650,height=500";
			newWindow = window.open(infoPage, "ChemInfo", features);
	}
	else
	{
		alert(document.forms[0].LSelChemical.value);
	}			
}

function makeSelected(){
  for (i=0;i<document.choiceForm.choiceBox.length;i++)
  {
  	document.choiceForm.choiceBox.options[i].selected = false;
  }
  for (i=0;i<document.choiceForm.choiceBox.length-1;i++)
  {
     document.choiceForm.choiceBox.options[i].selected = true;
  }
}

function chemExpInfo(chemurl){

		var infoPage = "cheminfo.jsp?chem=" + chemurl;

		var features = "toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=650,height=500";
		newWindow = window.open(infoPage, "ChemInfo", features);
}


function checkIDLHQty(fieldName, idlhName, selectName, mllrWtName) 
{
	// First check if exposure qty is a valid number
	if (isNaN(fieldName.value)) {
		alert(document.Exposures.warning_select.value);
		return;
	}
}

function processDown() 
{
	var selected = document.Cartridges.available.selectedIndex;
	if (selected >= 0) {
		var item =document.Cartridges.available.options[selected].text;
		var val = document.Cartridges.available.options[selected].value;
		//alert("processDown()\nselected = " + selected + "\nitem = " + item + "\nvalue = " + val);
		if (val != "eol") {
			document.Cartridges.SelectedCartridge.value=item;
			document.Cartridges.SelectedCartridgeValue.value=val;
		}
	}
}
function navButton(url){
	window.location.href=url;
}
function generalSubmit(url){

	document.forms[0].action=url; 
	document.forms[0].submit();
}

function formButton(url){

	if(document.forms[0].formname.value=="exposures") {
		var elementArray = document.forms[0].elements;
		var validForm = true;
		var validRange = true;
		
		for (i = 0; i < elementArray.length; i++) {
			if (document.forms[0].elements[i].type == "text") {
				if (document.forms[0].elements[i].name.substring(0,3) == "Exp") {
					if ( isNaN(document.forms[0].elements[i].value)) {
							document.forms[0].elements[i].value =0;
 	                      
						}
					if (document.forms[0].elements[i].value != "") {
						var fValue = parseFloat(document.forms[0].elements[i].value);
 	                   if ( isNaN(fValue)) {
 	                       document.forms[0].elements[i].value =0;
						}
 	                   if (fValue < 0.00001 || fValue > 999999.99999) {
 	                       document.forms[0].elements[i].value =0;
						}
					}
					
				}
			}       
		}
		if (validForm && validRange) {
			document.forms[0].action=url; 
			document.forms[0].submit();
		}
		else if (!validForm) {
			alert(document.Exposures.warning_select.value);
		}
		else if (!validRange) {
			alert(document.Exposures.warning_outofrange.value);
		}
	
	}	
	
	if(document.forms[0].formname.value=="productreduction") {

		var elementArray = document.forms[0].elements;
		var validForm = true;
		var validRange = true;
		for (i = 0; i < elementArray.length; i++) {
						
			if (document.forms[0].elements[i].name.substring(0,7) == "REDUCED") {

				for (var j=0;j<document.forms[0].elements[i].length;j++){
  					
					document.forms[0].elements[i].options[j].selected = false;

				}
			}
		}
		document.forms[0].submit();	
	}	
} 

function chemPickSubmit(url){




  for (i=0;i<document.choiceForm.choiceBox.length;i++)
  {
     document.choiceForm.choiceBox.options[i].selected = false;
  }

  for (i=0;i<document.choiceForm.choiceBox.length-1;i++)
  {
     document.choiceForm.choiceBox.options[i].selected = true;
  }


  
  if(document.forms[0].choiceBox.selectedIndex <0){

	 var URL = url;  
 	 if (URL == "chemsearch.jsp"){
 		document.forms[0].action=url; 
    	document.forms[0].submit();

	 }
	 else if (URL == "genhazard.jsp"){

		document.forms[0].action=url; 
    	document.forms[0].submit();

	 }
	 else if (URL == "chempick.jsp"){
 
		document.forms[0].action=url; 
    	document.forms[0].submit();

	 }
	 else{	
		alert(document.forms[0].LContRequired.value);
  	 }
  }
  else{ 
  
    document.forms[0].action=url; 
    document.forms[0].submit();
  }
 
}




function submitChems()
{

	 for (i=0;i<document.choiceForm.choiceBox.length;i++)
  	{
   		document.choiceForm.choiceBox.options[i].selected = false;
  	}
	 for (i=0;i<document.choiceForm.choiceBox.length-1;i++)
  	{
   		document.choiceForm.choiceBox.options[i].selected = true;
  	}
	if(document.forms[0].choiceBox.selectedIndex <0){
		alert(document.forms[0].LContRequired.value);
		return false;
	}
	return true;
}		

function showHelp(helpurl){
		var helpPage = "help.jsp?page=" + helpurl;
		var features = "toolbar=1,location=0,status=0,menubar=1,scrollbars=1,resizable=1,width=600,height=250";
		newWindow = window.open(helpPage, "ChemInfo", features);
}	

function showPage(openPage)
{
	var features = "toolbar=1,location=0,status=0,menubar=1,scrollbars=1,resizable=1,width=800,height=450";
	newWindow = window.open(openPage, "newFrame", features);
}

function checkExp()
{
	var elementArray = document.forms[0].elements;
	var validForm = true;
	var validRange = true;
	for (i = 0; i < elementArray.length; i++) {
		if (document.forms[0].elements[i].type == "text") {
			if (document.forms[0].elements[i].name.substring(0,3) == "Exp") {
				if ( isNaN(document.forms[0].elements[i].value)) {
                        validForm = false;
					}
				if (document.forms[0].elements[i].value != "") {
					var fValue = parseFloat(document.forms[0].elements[i].value);
                    if ( isNaN(fValue)) {
                        validForm = false;
					}
                    if (fValue < 0.00001 || fValue > 999999.99999) {
                        validRange = false;
					}
				}
				else {
					validForm = false;
				}
			}
		}
	}
	if (validForm && validRange) {
		return true;
	}
	else if (!validForm) {
		alert(document.Exposures.warning_select.value);
		return false;
	}
	else if (!validRange) {
		alert(document.Exposures.warning_select.value);
		return false;
	}
}


function checkChemicalTypeSelection(chemType) {
	if(chemType == "S"){
		if(confirm(document.forms[0].tagLStanChemWarn.value))
		{
			window.location.href="chempick.jsp";
		}
		else{
			document.forms[0].ChemType[1].checked = "1";
		}
	}
	
	if(chemType == "U"){
		if(document.choiceForm.choiceBox.length>1){
			if(confirm(document.forms[0].tagLUserChemWarn.value))
			{
				window.location.href="userchemical.jsp";
			}
			else{
				document.forms[0].ChemType[0].checked = "1";
			}
		}
		else{
			window.location.href="userchemical.jsp";
		}
	}	
}

function checkEnv()
{
	var validForm = true;
	var validRange = true;

	if ( isNaN(document.forms[0].ENV_ATM.value)) {
    	validForm = false;
	}
	if (document.forms[0].ENV_ATM.value != "") {
		var fValue = parseFloat(document.forms[0].ENV_ATM.value);
        if ( isNaN(fValue)) {
   			validForm = false;
		}
        if (fValue < 0.8 || fValue > 1.2) {
        	validRange = false;
		}
	}
	else {
		validForm = false;
	}
			
	if (validForm && validRange) {
		return true;
	}
	else {
		alert("Atmospheric Pressure (ATM) must be in the rage of .8 to 1.2");
		return false;
	}
}

function checkHumidity()
{
	var validForm = true;
	var validRange = true;
	if (document.forms[0].ENV_HUMIDITY.value==">65%") {
		var helpPage = "help.jsp?page=2/USA/CSRV/ENV_HUMIDITY2.html";
		var features = "toolbar=1,location=0,status=0,menubar=1,scrollbars=1,resizable=1,width=600,height=250";
		newWindow = window.open(helpPage, "Humidity", features);
	}
	
}

function checkCorrFactor()
{
	var elementArray = document.forms[0].elements;
	var validForm = true;
	var validRange = true;
	for (i = 0; i < elementArray.length; i++) {
		if (document.forms[0].elements[i].type == "text") {
			if (document.forms[0].elements[i].name.substring(0,3) == "Exp") {
				if ( isNaN(document.forms[0].elements[i].value)) {
                        validForm = false;
					}
				if (document.forms[0].elements[i].value != "") {
					var fValue = parseFloat(document.forms[0].elements[i].value);
                    if ( isNaN(fValue)) {
                        validForm = false;
					}
                    if (fValue < 1 || fValue > 100) {
                        validRange = false;
					}
				}
				else {
					validForm = false;
				}
			}
		}
	}
	if (validForm && validRange) {
		return true;
	}
	else {
		alert("Correction factors must be in the range 1-100.");
		return false;
	}
}

function userChemInfo(){
		var infoPage = "usercheminfo.jsp";
		var features = "toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=650,height=500";
		newWindow = window.open(infoPage, "ChemInfo", features);
}

function checkUserCorrFactor()
{
	var validForm = true;
	var validRange = true;
	if ( isNaN(document.forms[0].usercorr.value)) {
		validForm = false;
	}
	if (document.forms[0].usercorr.value != "") {
		var fValue = parseFloat(document.forms[0].usercorr.value);
        if ( isNaN(fValue)) {
 	       validForm = false;
		}
        if (fValue < 1 || fValue > 100) {
           validRange = false;
		}
	}
	else {
		validForm = false;
	}
	if (validForm && validRange) {
		return true;
	}
	else {
		alert("Correction factors must be in the range 1-100.");
		return false;
	}
}

function checkCart()
{
	if (document.forms[0].SelectedCartridgeValue.value == "Undefined") {
	alert("Please select a cartridge");
		return false;
	}

	else {
		return true;
	}
}

function verifyEmail()
{
	if(confirm(document.forms[0].LEmVerifyMsg.value))
			{
				document.forms[0].submit();
			}

}
function showAudit(sArg)    
{

	var infoPage = "audit.jsp?var=" + sArg;	
	var features = "toolbar=1,location=0,status=0,menubar=1,scrollbars=1,resizable=1,width=650,height=450";
	var dt = new Date();
	auditWindow = window.open(infoPage, "auditFrame", features);

}

function newSession(url){
	document.forms[0].formname.value="newsession";
	document.forms[0].action=url;
	document.forms[0].submit();
} 


function cancelUserProfile(url){
	document.forms[0].formname.value="cancelUserProfile";
	document.forms[0].action=url;
	document.forms[0].submit();
}


function selectProduct(){
	document.forms[0].submit();
}

function flagSubmitProfile(labeltext){
	if(confirm(labeltext))
	{
		alert("hello");
		document.forms[0].submit();
		alert("hello2");
	}
}
function deleteSession(sessionid, sessionname){
	if(confirm(document.forms[0].LSessionDel.value + sessionname))
	{
		document.forms[0].formname.value="deletesession";
		document.forms[0].sessionid.value=sessionid;
		document.forms[0].submit();
	}
}
function retrieveSession(sessionid, sessionname, sessiondesc){
		document.forms[0].formname.value="retrievesession";
		document.forms[0].sessionid.value=sessionid;
		document.forms[0].sessionname.value=sessionname;
		document.forms[0].sessiondesc.value=sessiondesc;
		document.forms[0].action="genhazard.jsp";
		document.forms[0].submit();
}

function changeChems(){ 
		document.forms[0].formname.value="changechems";
		document.forms[0].action="chempick.jsp";
		document.forms[0].submit();
}
function previousSubmit(url){
		document.forms[0].formname.value="previoussubmit";
		document.forms[0].action=url; 
		document.forms[0].submit();
}

function selectHelpPage(){
	document.forms[0].submit();
}

function selectRegulation(){
	document.forms[0].submit();
}

function saveHelpText(url){ 
	document.forms[0].formname.value="helptextsave";
	document.forms[0].action=url; 
	document.forms[0].submit(); 
}

function searchLabelText(){ 
		document.forms[0].formname.value="searchlabeltext";
		document.forms[0].action="labeltranslation.jsp";
		document.forms[0].submit();
}

function saveLabelText(){   
		document.forms[0].formname.value="savelabeltext";
		document.forms[0].action="labeltranslation.jsp";
		document.forms[0].submit();
}

function clearAllBoxes(){ 
		document.forms[0].formname.value="clearallboxes";
		document.forms[0].action="labeltranslation.jsp";
		document.forms[0].submit();
}

function performCleanUp(){   
		document.forms[0].formname.value="integritycleanup";
		document.forms[0].action="integrity.jsp";
		document.forms[0].submit();
}

function checkIntegrity(){   
		document.forms[0].formname.value="integrityshow";
		document.forms[0].action="integrity.jsp";
		document.forms[0].submit();
}
 

function uploadDataTopDown(url){
	document.forms[0].formname.value="uploaddata1"; 
	document.forms[0].action=url;
	document.forms[0].submit();
}

function uploadDataBottomUp(url){
	document.forms[0].formname.value="uploaddata2";
	document.forms[0].action=url;
	document.forms[0].submit();
}

function contactUs(url){   
	var techPage = url;
	var features = "toolbar=1,location=1,status=1,menubar=1,scrollbars=1,resizable=1,width=650,height=500";
	newWindow = window.open(techPage, "ContactUs", features);
}
