/*
Company prices script 
Desc:	Scripts used in company prices section
Created: 09.05.2008 HP
*/

				// Compare two options within a list by VALUES
				function compareOptionValues(a, b) 
					{ 
					  // Radix 10: for numeric values
					  // Radix 36: for alphanumeric values
					  var sA = parseInt( a.value, 36 );  
					  var sB = parseInt( b.value, 36 );  
					  return sA - sB;
					}
				
				// Compare two options within a list by TEXT
				function compareOptionText(a, b) 
					{ 
					  // Radix 10: for numeric values
					  // Radix 36: for alphanumeric values
					  var sA = parseInt( a.text, 36 );  
					  var sB = parseInt( b.text, 36 );  
					  return sA - sB;
					}
				
				// Dual list move function
				function moveDualList( srcList, destList, moveAll ) 
					{ 
					// Do nothing if nothing is selected
					  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   )
					  {
						return;
					  }
					
					  newDestList = new Array( destList.options.length );
					  var len = 0;
					  for( len = 0; len < destList.options.length; len++ ) 
					  {
						if ( destList.options[ len ] != null )
						{
						  newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
						}
					  }
					  for( var i = 0; i < srcList.options.length; i++ ) 
					  { 
						if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
						{
						   // Statements to perform if option is selected
						   // Incorporate into new list
						   newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );
						   len++;
						}
					  }
					  // Sort out the new destination list
					  newDestList.sort( compareOptionValues );   // BY VALUES
					  //newDestList.sort( compareOptionText );   // BY TEXT
					  // Populate the destination with the items from the new array
					  for ( var j = 0; j < newDestList.length; j++ ) 
					  {
						if ( newDestList[ j ] != null )
						{
						  destList.options[ j ] = newDestList[ j ];
						}
					  }
					  // Erase source list selected elements
					  for( var i = srcList.options.length - 1; i >= 0; i-- ) 
					  { 
						if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
						{
						   // Erase Source
						   //srcList.options[i].value = "";
						   //srcList.options[i].text  = "";
						   srcList.options[i]       = null;
						}
					  }
					} // End of moveDualList()
				
				function selectAll()
					{
					  for( var i = 0; i < document.frmCompSearch.sproduct.options.length; i++ ) 
					  { 
						document.frmCompSearch.sproduct.options[i].selected = true;
					  }
					  for( var i = 0; i < document.frmCompSearch.sexpiry.options.length; i++ ) 
					  { 
						document.frmCompSearch.sexpiry.options[i].selected = true;
					  }
					//  for( var i = 0; i < document.frmCompSearch.scompany.options.length; i++ ) 
					 // { 
					//	document.frmCompSearch.scompany.options[i].selected = true;
					//  }
					}
				
					function toggle(tbl1,tbl2) {
							/* modified slightly compared to original website. Explicitly get element properties 06.05.2008 */
							var x1=document.getElementById(tbl1);
							var x2=document.getElementById(tbl2);
							
							 //alert(tbl2);
							
						  if (x1.style.display == "none") {
							x1.style.display = "";
							x2.style.display = "";
							x2.src = "/images/minus.gif";
						  } else {
							x1.style.display = "none";
							x2.style.display = "";
							x2.src = "/images/plus.gif";
						  }
						  //alert(x2.src);
						  return true;
						}
				
				//reset the check boxes on the company prices form. and collapse any expanded fields. 
				//Note: it does not clear what's in the fields within a section
				function resetBtn(formResults) {
				// DEBUGGING alert(formResults.chkProduct.checked);
					if (formResults.chkProduct.checked) {
						document.getElementById('productb').style.display = "none";
						document.getElementById('producta').style.display = "";
						formResults.chkProduct.checked = "";
					}
					if (formResults.chkExpiry.checked) {
						document.getElementById('expiryb').style.display = "none";
						document.getElementById('expirya').style.display = "";
						formResults.chkExpiry.checked = "";
					}
					/*if (formResults.chkCompany.checked) {
						companyb.style.display = "";
						companya.style.display = "none";
					} */
					if (formResults.chkDate.checked) {
						document.getElementById('dateb').style.display = "none";
						document.getElementById('datea').style.display = "";
						formResults.chkDate.checked = "";
					}
					if (formResults.chkPrice.checked) {
						document.getElementById('priceb').style.display = "none";
						document.getElementById('pricea').style.display = "";
						formResults.chkPrice.checked = "";
					}
					if (formResults.chkVolume.checked) {
						document.getElementById('volumeb').style.display = "none";
						document.getElementById('volumea').style.display = "";
						formResults.chkVolume.checked = "";
					}
					if (formResults.chkBuySell.checked) {
				
						document.getElementById('buysellb').style.display = "";
						document.getElementById('buysella').style.display = "none";
						formResults.chkBuySell.checked = "";
					}
					if (formResults.chkStatus.checked) {
						document.getElementById('statusb').style.display = "";
						document.getElementById('statusa').style.display = "none";
						formResults.chkStatus.checked = "";
					}
				}
