function set_combo2(comboname,option) {
	for (var i=0; i < comboname.options.length; i++) {
		if (comboname.options[i].value == option) {
			comboname.options[i].selected = true;
			return true;
		}
	}

}//end set_combo2


function createRequest()
{
	var request = null;
	try 
	{
		request = new XMLHttpRequest();
	} 
	catch (trymicrosoft) 
	{
		try 
		{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (othermicrosoft) 
		{
			try 
			{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (failed) 
			{
				request = null;
			}
		}
	}

	if (request == null)
		alert("Your browser doesn't support AJAX requests, did you disable Javascript?")
	else
	{
		return request;
	}
}


var request_searchByLetter = createRequest();
var request_searchByDrug = createRequest();
var request_catlistings = createRequest();
var request_ProductDisplay = createRequest();
var request_CategoryDisplay = createRequest();

function getGlobalCart()
{

	window.location="http://www.testcountry.com/cart.html";


}


function addToCart(frm)
{
//alert (frm.name);

//frm.marc.parentNode.removeChild(close_cart);

var qty = frm.qty.value; // qty to be added

 if (isNaN(parseInt(qty))) { // Non-numeric qty entered. Abort.

  alert("Quantity must be a numeric value.");

  return false; 

 }

 var product = frm.product.value; //sku or product id

 //var action = "01"; 		//frm.action.value;

 var vp = "";

 if (frm.vp_id)  vp = "&vp_id="+frm.vp_id.value;  // If it is a value pack, read vp id

/*** This is AJAX version of Add to Cart. 
      To use this, disable the traditional version below

 var url = "/cart_actions.asp?action=01&qty=" +qty+ "&product="+ product+ vp;
 var add = createRequest();
 add.open("GET",url,false);
 add.send(null);

 add = null;
 getGlobalCart();

**********************************************/

/****** This is traditional version of add to cart ******/
 var url = "http://www.testcountry.com/cart.html?action=01&qty=" +qty+ "&product="+ product+ vp;
 window.location = url;
/*************************************************/

}

/*
function updateGlobalCart()
{
//alert(request_global_cart.readyState);
	if (request_global_cart.readyState == 4)
	{
		//alert(request_global_cart.status);
		if (request_global_cart.status == 200)
		{
			document.getElementById('global_cart_content').innerHTML = request_global_cart.responseText;
			//alert(document.getElementById('global_cart_content').innerHTML);
			//alert(document.getElementById('global_cart'));
			Effect.toggle('global_cart','blind');
			document.getElementById('global_cart').style.zIndex = '99';
			//setTimeout('closeGlobalCart()',3000);
		}
	}
}
*/
function closeGlobalCart()
{
if (!document.getElementById('global_cart').style.display)
{
var close_cart = document.getElementById('close_cart');
close_cart.parentNode.removeChild(close_cart);

var checkout_header = document.createElement('img');
checkout_header.setAttribute('id','checkout_header');
checkout_header.style.cssText = "position: absolute; top: 144px; left: 50%; margin-left: 410px";
checkout_header.setAttribute('src','http://www.testcountry.com/images/checkout-button_white.gif');
document.body.appendChild(checkout_header);
}
else
{
var checkout_header = document.getElementById('checkout_header');
checkout_header.parentNode.removeChild(checkout_header);

var close_cart = document.createElement('img');
close_cart.setAttribute('id','close_cart');
close_cart.setAttribute('src','http://www.testcountry.com/images/x.gif');

close_cart.style.cssText = "position: absolute; top: 145px; left: 50%; margin-left: 460px; cursor: pointer; z-index: 99";
document.body.appendChild(close_cart);
document.getElementById('close_cart').onclick = function() {getGlobalCart();} ;
};

Effect.toggle('global_cart','blind');
}

function getResultFor(letter)
{
request_searchByLetter.open("GET","/get_search_results.asp?letter=" + letter, true);
request_searchByLetter.onreadystatechange = updateSearchResult;
request_searchByLetter.send(null);
}

function updateSearchResult()
{
if (request_searchByLetter.readyState == 4)
{
if (request_searchByLetter.status == 200)
{
document.getElementById('search_results').innerHTML = request_searchByLetter.responseText;
}
}
}

function getResultForDrug(drug)
{
request_searchByDrug.open("GET","/get_search_results_detail.asp?drug=" + drug, true);
request_searchByDrug.onreadystatechange = updateSearchResultDrug;
request_searchByDrug.send(null);
}

function updateSearchResultDrug()
{
if (request_searchByDrug.readyState == 4)
{
if (request_searchByDrug.status == 200)
{
document.getElementById('search_results').innerHTML = request_searchByDrug.responseText;
}
}
}

function getProductDescription(product)
{/*

*/}

function getProductInstructions(product)
{/*

*/
}

function getProductInformation(product)
{/*
*/
}

function updateProductDescription()
{/*
*/
}

function updateProductInstructions()
{/*
*/
}

function updateProductInformation()
{/*
*/
}

/*
function updateCartCount()
{
	//alert(request_cart_count.readyState);
	if (request_cart_count.readyState == 4 && request_global_cart.readyState == 4)
	{
		if (request_cart_count.status == 200)
		{
			document.getElementById('numOfItems').innerHTML = request_cart_count.responseText;
		}
	}
}
*/

function hoverinNav(id)
{
document.getElementById(id).style.backgroundColor = '#dfeffe';
}

function hoveroutNav(id)
{
document.getElementById(id).style.backgroundColor = '';
}

function showMenu(id,cat)
{
if (document.getElementById(id).style.display == "block")
{
document.getElementById(id).style.display = "none";
showCategory(cat);
}
else
{
document.getElementById(id).style.display = "block"
showCategory(cat);
}
}

function changeIcon(id)
{
var element = document.getElementById(id);

var fullpath = element.src;
var imagepath = fullpath.split("/");
var last = imagepath.length-1;
var image = imagepath[last];

switch (image)
{
case "arrow_1.gif":
element.src = "http://testcountry.com/buttons/arrow_1_down.gif";
break;
case "arrow_1_down.gif":
element.src = "http://testcountry.com/buttons/arrow_1.gif";
break;
case "arrow_2.gif":
element.src = "http://testcountry.com/buttons/arrow_2_down.gif";
break;
case "arrow_2_down.gif":
element.src = "http://testcountry.com/buttons/arrow_2.gif";
break;
default:
break;
}
}

function attention()
{
	posfooter();
}

function getThisCat(catid,p)
{
	request_catlistings.open("GET","/left_menu_displayer.asp?cat=" + catid + "&pid=" + p, true);
	request_catlistings.onreadystatechange = updateThisCat;
	request_catlistings.send(null);
}

function updateThisCat()
{
if (request_catlistings.readyState == 4)
{
if (request_catlistings.status == 200)
{
document.getElementById('catlistings').innerHTML = request_catlistings.responseText;
}
}
}

function showProducts(id)
{
	request_ProductDisplay.open("GET","/display_products.html?product=" + id, true);
	request_ProductDisplay.onreadystatechange = function() {updateProductDisplay(id)};
	request_ProductDisplay.send(null);
}

function updateProductDisplay(id)
{
if (request_ProductDisplay.readyState == 4)
{
if (request_ProductDisplay.status == 200)
{
document.getElementById('main_container').innerHTML = request_ProductDisplay.responseText;
getProductDescription(id);
}
}
}

function showCategory(catid, root, level)
{
if (!level || level == '1'){level = ""}
else
{level = "&level="+level};
request_CategoryDisplay.open("GET","/display_categories.html?cat="+catid+"&root="+root+level,true);
request_CategoryDisplay.onreadystatechange = function() {updateCategory(catid)};
request_CategoryDisplay.send(null);
}

function updateCategory(catid)
{
if (request_CategoryDisplay.readyState == 4)
{
if (request_CategoryDisplay.status == 200)
{
document.getElementById('main_container').innerHTML = request_CategoryDisplay.responseText;
getThisCat(catid,0);
}
}
}

function getStyle(oElm, strCssRule){
var strValue = "";
if(document.defaultView && document.defaultView.getComputedStyle){
strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
}
else if(oElm.currentStyle){
strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
return p1.toUpperCase();
});
strValue = oElm.currentStyle[strCssRule];
}
return strValue;
}

function highlight(nid)
{
/**/
}

function posfooter()
{
if (document.getElementById('footer'))
{
var footer = document.getElementById('footer')
var maxheight = 885
};


if (document.getElementById('footer2'))
{
var footer = document.getElementById('footer2')
var maxheight = 1185
};

var lemehe = parseInt(getStyle(document.getElementById('left_menu'), "height"));
var footo = lemehe + 175;

if (footo <= maxheight)
{footer.style.top = maxheight + "px"};
if (footo > maxheight)
{
newfooto = footo + 10;
footer.style.top = newfooto + "px";
}
}

function dostuff()
{

//document.getElementById('search_box').value = 'enter your search term';
document.getElementById('search_box').onmouseover = function(){document.getElementById('search_box').style.borderColor = '#3091f2'};
document.getElementById('search_box').onmouseout = function(){document.getElementById('search_box').style.borderColor = '#aaaaaa'};
//document.getElementById('search_box').onfocus = function(){if (document.getElementById('search_box').value == 'enter your search term'){document.getElementById('search_box').value = ''};};
document.getElementById('search_box').onblur = function(){if (document.getElementById('search_box').value == ''){document.getElementById('search_box').value = 'enter your search term'};}
//document.getElementById('search_button').onmouseover = function(){document.getElementById('search_button').src = 'http://www.testcountry.com/images/go-button_blue.gif'};  document.getElementById('search_button').onmouseout = function(){document.getElementById('search_button').src = 'http://www.testcountry.com/images/go-button.gif'};


if (document.getElementById('below_phone') && document.getElementById('SASSourceCodeHidden')) {
	document.getElementById('below_phone').innerHTML = document.getElementById('SASSourceCodeHidden').innerHTML;
}

if (document.getElementById('email_box')) {
	document.getElementById('email_box').value = 'enter your email';
	document.getElementById('email_box').onmouseover = function(){document.getElementById('email_box').style.borderColor = '#3091f2'};
	document.getElementById('email_box').onmouseout = function(){document.getElementById('email_box').style.borderColor = '#aaaaaa'};
	document.getElementById('email_box').onfocus = function(){if (document.getElementById('email_box').value == 'enter your email'){document.getElementById('email_box').value = ''};};
	document.getElementById('email_box').onblur = function(){if (document.getElementById('email_box').value == ''){document.getElementById('email_box').value = 'enter your email'};}
	document.getElementById('email_button').onmouseover = function(){document.getElementById('email_button').src = 'http://www.testcountry.com/images/go-button_blue.gif'};  document.getElementById('email_button').onmouseout = function(){document.getElementById('email_button').src = 'http://www.testcountry.com/images/go-button.gif'};
}

createAutoComplete();

if (document.getElementById('corporate_form_button'))
{
document.getElementById('corporate_form_button').onmouseover = function(){document.getElementById('corporate_form_button').src = 'http://www.testcountry.com/images/go-button_blue.gif'};  document.getElementById('corporate_form_button').onmouseout = function(){document.getElementById('corporate_form_button').src = 'http://www.testcountry.com/images/go-button.gif'};
}
}


function listHairFacilities(zip,third_party){

	var format = document.forms['facilityselectorform'].listing_format.value;

	document.getElementById('facility').innerHTML = listFacilities(zip,'h',format,third_party);


}

function listLegalHairFacilities(zip){

	var format = document.forms['facilityselectorform'].listing_format.value;

	document.getElementById('facility').innerHTML = listFacilities(zip,'l',format,'');

}


function listUrineFacilities(zip){

	var format = document.forms['facilityselectorform'].listing_format.value;

	document.getElementById('facility').innerHTML = listFacilities(zip,'u',format,'');


}


function listSameDayFacilities(zip){

	var format = document.forms['facilityselectorform'].listing_format.value;

	document.getElementById('facility').innerHTML = listFacilities(zip,'s',format,'');

}


function listHealthTestFacilities(zip){

	var format = document.forms['facilityselectorform'].listing_format.value;

	document.getElementById('facility').innerHTML = listFacilities(zip,'w',format,'');

}

function listFacilities(zip,t,format,tp)
{
	var xml = createRequest();
	xml.open("GET","/ajax_facilities.asp?z="+zip+"&t="+t+"&f="+format+"&tp="+tp, false);
	xml.send(null);
	return xml.responseText;
}




function facilitySelected(l){

	document.getElementById('lid').value = l;

}



function CheckZip(e, zip, skus)
{
	var keynum;
	var keychar;
	var numcheck;
	

	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	
	if (keynum != 8 && keynum != 46 && keynum !=18 && keynum != 17) { // if not backspace/delete/alt/CTRL

		if (zip.value.length == 4) {
			if (keynum >=96 && keynum <= 105) keynum = keynum - 48;
			if (keynum >=48 && keynum <=57) { // number
				keychar = String.fromCharCode(keynum);
				list_facilities(zip.value+keychar, skus);
			}
		}

		if (keynum == 13 || keynum == 9) { // Enter or Tab
			
	
			return CheckZip2(zip.value, skus, keynum);
			

		} else {

			if (keynum >=96 && keynum <= 105) 
				keynum = keynum - 48; // Numeric keypad


			keychar = String.fromCharCode(keynum);
			numcheck = /^\d+$/;

			return numcheck.test(keychar);

		}
	}
}

function CheckZip2(zip_code, skus, keynum){


	if (zip_code.length == 5) 
			
		list_facilities(zip_code, skus);

	else {
		if (keynum != 0) {

			alert("Please provide a 5-digit ZIP code.");

		}

		return false;
	}

}



function list_facilities(zip, skus){

	document.getElementById('facility').innerHTML = "SEARCHING FOR THE BEST MATCHES...";

	var sku = '';

	if (skus.type == 'hidden')
	{
		sku = skus.value;
	}

	if (skus.type == 'radio')
	{
		for (var i=0;i<skus.length;i++ )
		{
			if (skus[i].checked)
			{
				sku = skus[i].value;
			}
		}
	}

	if (sku.indexOf('-HAIR-') > 0) {

		if (sku.indexOf('-LABTEST10') > 0) 
		{ //10-panel hair
			listHairFacilities(zip,'1');
		}
		else //5-panel hair
		{
			listHairFacilities(zip,'0');
		}

	}

	else {  //Urine (same-day or not)

		if (sku.indexOf('-SAME-') > 0)

			listSameDayFacilities(zip);  //same-day

		else {
		
			if (sku.indexOf('HTCE-') == 0)
				listHealthTestFacilities(zip)
			else
				listUrineFacilities(zip); //urine regular
		}

	}

}


function pop(page,width,height,left_pos,top_pos) {
	var pw = window.open(page,'mini_tc','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',left='+left_pos+',top='+top_pos);
	pw.focus();
}

function updateBackBtn( cat ) {

  if ( document.getElementById('backbtn') ) {
	document.getElementById('backbtn').title = cat;
        document.getElementById('backbtn').style.visibility = 'visible';
  }

}

function gobackBtn ( btnobj ) {
   var cat = btnobj.title; //cat to go

   if (cat=='253') {//if back refers to the root, redirect to homepage
//      btnobj.style.visibility = 'hidden';
      window.location = 'http://www.testcountry.com/index.html';
      return true;
   }


   if (cat != '') {
     btnobj.title = parentCatOf( cat );

//     if (btnobj.title=='253') //if parent is root, hide the button
//        btnobj.style.visibility = 'hidden';

     showCategory ( cat, '', '1');
   }
}

function parentCatOf( cat ) {
 
 var bck = createRequest();
 bck.open("GET","get_parent_cat.asp?cat="+cat,false);
 bck.send(null);
 var rtn = bck.responseText;
 bck = null;
 return rtn;


}

function set_new_shipping_options(cid,country,sm)
{
  var bck = createRequest();
  bck.open("GET","ajax_shipping_options.asp?cid="+cid+"&sm="+sm+"&c="+country, false);
  bck.send(null);
  document.getElementById('shipping_options').innerHTML = bck.responseText;
  bck = null;
  return true;
}

function set_new_shipping_options2(cid,country,sm,zip)
{
  var bck = createRequest();
  bck.open("GET","ajax_shipping_options_zip.asp?cid="+cid+"&sm="+sm+"&c="+country+"&z="+zip, false);
  bck.send(null);
  document.getElementById('shipping_options').innerHTML = bck.responseText;
  bck = null;
  return true;
}


function same_as_billing()
{
	if (document.form2.m1) {
		var m1 = document.form2.m1.value
		var m2 = document.form2.m2.value
		var m3 = document.form2.m3.value
		var m4 = document.form2.m4.value
		var m5 = document.form2.m5.value
		var m6 = document.form2.m6.value
		var m7 = document.form2.m7.value
		var m8 = document.form2.m8.value
		var m9 = document.form2.m9.value
		set_combo(document.form2.s10,document.form2.m10.options.selectedIndex);
		var m11 = document.form2.m11.value
		var m12 = document.form2.m12.value
	} else 
	{
		var m1 = document.form2.b1.value
		var m2 = document.form2.b2.value
		var m3 = document.form2.b3.value
		var m4 = document.form2.b4.value
		var m5 = document.form2.b5.value
		var m6 = document.form2.b6.value
		var m7 = document.form2.b7.value
		var m8 = document.form2.b8.value
		var m9 = document.form2.b9.value
		set_combo(document.form2.s10,document.form2.b10.options.selectedIndex);
		var m11 = document.form2.b11.value
		var m12 = document.form2.b12.value

	}

	document.form2.s1.value = m1
	document.form2.s2.value = m2
	document.form2.s3.value = m3
	document.form2.s4.value = m4
	document.form2.s5.value = m5
	document.form2.s6.value = m6
	document.form2.s7.value = m7
	document.form2.s8.value = m8
	document.form2.s9.value = m9

	document.form2.s11.value = m11
	document.form2.s12.value = m12

	if (document.form2.s0)
	{
		if(document.form2.s0.options) 
		{
			document.form2.s0.options.selectedIndex = 0;
			document.form2.s0.disabled = true;
		}
	}


}