function checkAll(cbid) { 
	for (var i = 0; i < document.forms["browseproductsfrm"].elements.length; i++) { 
		document.forms["searchproductsfrm"].elements[i].checked = cbid.checked; 
	} 
}

function setaction(action) { 
	document.forms["searchproductsfrm"].elements["takeaction"].value = action;
}
			
function doSearch() {
	document.searchproductsfrm.page.value = 1; 
	setaction('newsearch');
	document.forms["searchproductsfrm"].submit();
}

function getShowAdvancedSearchOptionLink() {
	return document.getElementById('searchShowOptionPane');
}

function getHideAdvancedSearchOptionLink() {
	return document.getElementById('searchHideOptionPane');
}

function getAdvancedSearchOptionPane() {
	return document.getElementById('moreSearchOptionPane');
}

function showAdvancedSearchOptionPane() {

	// Step 1 : Switch the show adv. option link to hide adv. option
	getShowAdvancedSearchOptionLink().style.display = 'none';
	getHideAdvancedSearchOptionLink().style.display = 'inline';
	
	// Step 2 : Show the advanced option pane
	getAdvancedSearchOptionPane().style.display = 'inline';
	
} 

function hideAdvancedSearchOptionPane() {

	// Step 1 : Switch the show adv. option link to hide adv. option
	getShowAdvancedSearchOptionLink().style.display = 'inline';
	getHideAdvancedSearchOptionLink().style.display = 'none';
	
	// Step 2 : Show the advanced option pane
	getAdvancedSearchOptionPane().style.display = 'none';
	
}

function showCallForPricing() {
	
	var strMessage = document.getElementById("pricingMessage").innerHTML;
	var strPhone   = document.getElementById("pricingPhoneNumber").innerHTML;
	
	var uidHtml = 			'<table border="0"  width="500">';
	uidHtml = uidHtml + '	<tr>';
	uidHtml = uidHtml + '		<td style="text-align : center;" valign="top">';
	uidHtml = uidHtml + '			<div id="priceContent">';
	uidHtml = uidHtml + '				<h2>Please call for pricing</h2> <br />';
	uidHtml = uidHtml + '				<table border="0" cellspacing="3" cellpadding="3" width="100%">';
	uidHtml = uidHtml + '				<tr>';
	uidHtml = uidHtml + '				    <td class="msgContact">' + strMessage +'</td>';
	uidHtml = uidHtml + '				</tr>';
	uidHtml = uidHtml + '				<tr>';
	uidHtml = uidHtml + '				    <td class="phoneContact"><img src="templates/images/phone.jpg" />     <b>' + strPhone +'</b></td>';
	uidHtml = uidHtml + '				</tr>';
	uidHtml = uidHtml + '				<tr>';
	uidHtml = uidHtml + '				    <td align="center"><br />' +
											'<a class="btnOkContact" href="javascript:undarkBackground();">Ok</a></td>';
	uidHtml = uidHtml + '				</tr>';
	uidHtml = uidHtml + '				</table>';
	uidHtml = uidHtml + '			</div>';
	uidHtml = uidHtml + '		</td>';
	uidHtml = uidHtml + '	<tr>';
	uidHtml = uidHtml + '</table>';

	darkBackground();
	
	var infoBox = document.getElementById("InformationBox");
	infoBox.innerHTML = uidHtml;
	
	centerInfoBox();
	infoBox.style.display = 'block';
}

function showLargerPhoto(photo) {
	
	var uidHtml = 		'<table border="0"  width="500">';
	uidHtml = uidHtml + '	<tr>';
	uidHtml = uidHtml + '		<td style="text-align : center;" valign="top">';
	uidHtml = uidHtml + '			<center>' ;
	uidHtml = uidHtml + '				<a href="javascript:undarkBackground();">' ;
	uidHtml = uidHtml + '					Close<br />' ;
	uidHtml = uidHtml + '					<img src="'+ photo + '" style="border : 0px;" />';
	uidHtml = uidHtml + '				</a>' ;
	uidHtml = uidHtml + '			</center>' ;
	uidHtml = uidHtml + '		</td>';
	uidHtml = uidHtml + '	<tr>';
	uidHtml = uidHtml + '</table>';

	darkBackground();
	
	var infoBox = document.getElementById("InformationBox");
	infoBox.innerHTML = uidHtml;
	
	centerInfoBox();
	infoBox.style.display = 'block';
}

function initSearchForm( pharmaFieldsEnabled ) {
	
	$('#fieldProductName').keyup( function( event ) { handleSearchFormKeyUp( event ) } );
	$('#fieldProductID').keyup( function( event ) { handleSearchFormKeyUp( event ) } );
	
	if ( pharmaFieldsEnabled == true ) {
		$('#fieldPharmGenName').keyup( function( event ) { handleSearchFormKeyUp( event ) } );
		$('#fieldPharmNDCNumber').keyup( function( event ) { handleSearchFormKeyUp( event ) } );
	}
}

function handleSearchFormKeyUp( event ) {

	if ( event.keyCode == '13' ) {
		 	event.preventDefault();
		 	doSearch();
	 }

}
