	var lots =0;
	var qty = 0;

function getProductList(mode , productid , subitem , filter)
{
	if (mode != "null") {
		type = "mode=" + mode + "&";
	} else {
		type = "";
	}

	var options={	method: 'get', 
					evalScripts: true
				};
	var url='/php/productlist/getPage.php?' + type + 'productid=' + productid + '&subitem=' + subitem + '&filter=' + filter;
   // window.location='http://dev.tph.co.nz/php/productlist/products_all.php?productid=' + productid + '&subitem=' + subitem + '&filter=' + filter +'&mode=' + mode;

	
//	window.dhtmlHistory.add(escape(url));

	if($('main'))
	{
		new Ajax.Updater('main',url,options);
		$('main').scrollTo();
	}
	
	getLefthandList(mode, productid, subitem, filter);
	
	$('main').scrollTo();
}

function getLefthandList(mode, productid, subitem, filter)
{
		
	if (mode == "null") 
	{
		if($('page_title'))
			$('page_title').innerHTML=unescape(subitem);
		var options={method: 'get'};
		var url='/php/productlist/getSubProducts.php?productid=' + productid + '&subitem=' + subitem + '&filter=' + filter;
		
		if($('list'))
		{
			new Ajax.Updater('list',url,options);
		}
	}
}

function alternate(id)
{
	
	if(document.getElementsByTagName)
	{  
		var table = $(id);  
		var rows = $$("#"+id+" tr");  
	var countedIndex=0;
		for(i = 0; i < rows.length-1; i++)
		{    
			if(rows[i].visible()==false)
				continue;
			rows[i].removeClassName('lightblue');
			rows[i].removeClassName('white');

			if(countedIndex % 2 == 0 )
			{
			
				rows[i].className = rows[i].className + " lightblue";
			} else {
				rows[i].className = rows[i].className + " white";
			}  

			countedIndex+=1;
		}
	}
}

function adjustPricing(lots,qty)
{
	
//	alert("adjusting");
	var form=$('order_form');
	var data=form.serialize();

	var options={onSuccess: adjustPrices, parameters: data};
	var url='/php/product_price.php?quantity='+qty+'&lots='+lots+'&reorder=0';
	new Ajax.Request(url,options);
	

}
function adjustPricingRetail(lots,qty)
{
	var form=$('order_form');
	var data=form.serialize();

	var options={onSuccess: adjustPrices, parameters: data};
	var url='/php/product_price_retail.php?quantity='+qty+'&lots='+lots+'&reorder=0';
	new Ajax.Request(url,options);
	

}
function adjustPricingReorder(lots,qty)
{
	
//	alert("adjusting");
	var form=$('order_form');
	var data=form.serialize();

	var options={onSuccess: adjustPrices, parameters: data};
	var url='/php/product_price.php?quantity='+qty+'&lots='+lots+'&reorder=1';
	new Ajax.Request(url,options);
	

}
function adjustPricingRetailReorder(lots,qty)
{
	var form=$('order_form');
	var data=form.serialize();

	var options={onSuccess: adjustPrices, parameters: data};
	var url='/php/product_price_retail.php?quantity='+qty+'&lots='+lots+'&reorder=1';
	new Ajax.Request(url,options);
	

}
var pricingOption = false;
function togPricing(val,val2){
	
	if($('quantity_entry')){
		qty = $('quantity_entry').value;
	}
	if($('lots_entry')){
		lots = $('lots_entry').value;
	}
	// val one is div id
	// val2 is for togel
	
	if(val2 == true){
		// don't change togel keep the pricing the same
		if(pricingOption == true){
			adjustPricingRetail(lots,qty);
			if(document.getElementById(val)){
				document.getElementById(val).innerHTML = "SUGGESTED RETAIL PRICES - Click to switch back to wholesale rates.";
			}
		}else{
			adjustPricing(lots,qty)
			if(document.getElementById(val)){
				document.getElementById(val).innerHTML = "WHOLESALE RATES displayed - Click here to view suggested retail.";
			}
		}
	}else{
		if(pricingOption == false){
			pricingOption = true;
			adjustPricingRetail(lots,qty);
			if(document.getElementById(val)){
				document.getElementById(val).innerHTML = "SUGGESTED RETAIL PRICES - Click to switch back to wholesale rates.";
			}
		}else{
			pricingOption = false;
			adjustPricing(lots,qty)
			if(document.getElementById(val)){
				document.getElementById(val).innerHTML = "WHOLESALE RATES displayed - Click here to view suggested retail.";
			}
		}
	}
}
function togPricingReorder(val,val2){
	
	if($('quantity_entry')){
		qty = $('quantity_entry').value;
	}
	if($('lots_entry')){
		lots = $('lots_entry').value;
	}
	// val one is div id
	// val2 is for togel
	
	if(val2 == true){
		// don't change togel keep the pricing the same
		if(pricingOption == true){
			adjustPricingRetailReorder(lots,qty);
			if(document.getElementById(val)){
				document.getElementById(val).innerHTML = "SUGGESTED RETAIL PRICES - Click to switch back to wholesale rates.";
			}
		}else{
			adjustPricingReorder(lots,qty)
			if(document.getElementById(val)){
				document.getElementById(val).innerHTML = "WHOLESALE RATES displayed - Click here to view suggested retail.";
			}
		}
	}else{
		if(pricingOption == false){
			pricingOption = true;
			adjustPricingRetailReorder(lots,qty);
			if(document.getElementById(val)){
				document.getElementById(val).innerHTML = "SUGGESTED RETAIL PRICES - Click to switch back to wholesale rates.";
			}
		}else{
			pricingOption = false;
			adjustPricingReorder(lots,qty)
			if(document.getElementById(val)){
				document.getElementById(val).innerHTML = "WHOLESALE RATES displayed - Click here to view suggested retail.";
			}
		}
	}
}

function adjustPrices(oReq, oJSN) {
	
    var data = oReq.responseText.evalJSON();

    $('console').innerHTML = '';
    //populate the list
   var realId = data['realid'];
    updateRealId(realId, false);
   
    var fullprice=data['fullprice'];
	updateOneSet(fullprice, true);

    var bestprice=data['bestprice'];
    updateOneSet(bestprice, false);
    
     var difference=data['difference'];
    updateOneSet(difference);
    
    var selectionPrice=data['selectionPrice'];
    var total=selectionPrice['price'];
    var element=$('prices_may_vary');
	if(element!=null){
    element.innerHTML="Click here for estimate";
}
    if(element!=null && total!=0){
    	element.innerHTML="Pricing Estimate: $"+total;
        element.style.display = 'block';
    }else{
		element.innerHTML="Click here for estimate";
		 element.style.display = 'block';
       // element.innerHTML="Error calculating price estimate";
        //element.style.display = 'none';
    }
    //alert(fullprice);
  


}


function toggle_pricingrows()
{
 var row_list=$$('tr.class_hidden');
 row_list.each(
 				function(row)
 				{
 					row.toggle();
 				}
 			);
 			
 	$('toggle_rows_href').toggle();
 	
 	alternate('priceTable');

 
}
function updateRealId(values, strikeThrough)
{

    var keyArray=Object.keys(values);
    keyArray.each(function(key) {
    							var value=values[key];
    							element=$('realid');
    							if(element)
    								{
    									var tempVal=value;
    									if(strikeThrough==true)
    										tempVal="<del>"+value+"</del>";
    								element.value=tempVal;
										
    								}
    							}
    			);
}
function updateOneSet(values, strikeThrough)
{

    var keyArray=Object.keys(values);
    keyArray.each(function(key) {
    							var value=values[key];
    							element=$(key);
    							if(element)
    								{
    									var tempVal=value;
    									if(strikeThrough==true)
    										tempVal="<del>"+value+"</del>";
    								element.innerHTML=tempVal;
										
    								}
    							}
    			);
}
//	var lots =0;
//	var qty = 0;
//	function getProductList(mode , productid , subitem , filter)
//{
//	if (mode != "null") {
//		type = "mode=" + mode + "&";
//	} else {
//		type = "";
//	}
//
//	var options={	method: 'get', 
//					evalScripts: true
//				};
//	var url='/php/productlist/getPage.php?' + type + 'productid=' + productid + '&subitem=' + subitem + '&filter=' + filter;
//   // window.location='http://dev.tph.co.nz/php/productlist/products_all.php?productid=' + productid + '&subitem=' + subitem + '&filter=' + filter +'&mode=' + mode;
//
//	
////	window.dhtmlHistory.add(escape(url));
//
//	if($('main'))
//	{
//		new Ajax.Updater('main',url,options);
//		$('main').scrollTo();
//	}
//	
//	getLefthandList(mode, productid, subitem, filter);
//	
//	$('main').scrollTo();
//}
//
//function getLefthandList(mode, productid, subitem, filter)
//{
//		
//	if (mode == "null") 
//	{
//		if($('page_title'))
//			$('page_title').innerHTML=unescape(subitem);
//		var options={method: 'get'};
//		var url='/php/productlist/getSubProducts.php?productid=' + productid + '&subitem=' + subitem + '&filter=' + filter;
//		
//		if($('list'))
//		{
//			new Ajax.Updater('list',url,options);
//		}
//	}
//}
//
//function alternate(id)
//{
//	if(document.getElementsByTagName)
//	{  
//		var table = $(id);  
//		var rows = $$("#"+id+" tr");  
//	var countedIndex=0;
//		for(i = 0; i < rows.length-1; i++)
//		{    
//			if(rows[i].visible()==false)
//				continue;
//			rows[i].removeClassName('lightblue');
//			rows[i].removeClassName('white');
//
//			if(countedIndex % 2 == 0 )
//			{
//			
//				rows[i].className = rows[i].className + " lightblue";
//			} else {
//				rows[i].className = rows[i].className + " white";
//			}  
//
//			countedIndex+=1;
//		}
//	}
//}
//
//function adjustPricing(qty,lots)
//{
//	
//	if($('quantity_entry')){
//		qty = $('quantity_entry').value;
//	}
//	if($('lots_entry')){
//		lots = $('lots_entry').value;
//	}
//	//alert(lots);
//	var form=$('order_form');
//	var data=form.serialize();
//
//	var options={onSuccess: adjustPrices, parameters: data};
//	var url='/php/product_price.php?quantity='+qty+'&lots='+lots+'';
//	new Ajax.Request(url,options);
//	
//
//}
//function adjustPricingRetail(qty,lots)
//{
//	if($('quantity_entry')){
//		qty = $('quantity_entry').value;
//	}
//	if($('lots_entry')){
//		lots = $('lots_entry').value;
//	}
////	alert("adjusting");
//	var form=$('order_form');
//	var data=form.serialize();
//
//	var options={onSuccess: adjustPrices, parameters: data};
//	var url='/php/product_price_retail.php?quantity='+qty+'&lots='+lots+'';
//	new Ajax.Request(url,options);
//	
//
//}
//var pricingOption = false;
//function togPricing(val,val2){
//
//	// val one is div id
//	// val2 is for togel
//	
//	//lots_entry //lots
//	//quantity_entry //quantity
//	if($('quantity_entry')){
//		qty = $('quantity_entry').value;
//	}
//	if($('lots_entry')){
//		lots = $('lots_entry').value;
//	}
//	
//	if(val2 == true){
//		// don't change togel keep the pricing the same
//		if(pricingOption == true){
//			adjustPricingRetail(qty,lots);
//			if(document.getElementById(val)){
//				document.getElementById(val).innerHTML = "SUGGESTED RETAIL PRICES - Click to switch back to wholesale rates.";
//			}
//		}else{
//			adjustPricing(qty,lots)
//			if(document.getElementById(val)){
//				document.getElementById(val).innerHTML = "WHOLESALE RATES displayed - Click here to view suggested retail.";
//			}
//		}
//	}else{
//		if(pricingOption == false){
//			pricingOption = true;
//			adjustPricingRetail(qty,lots);
//			if(document.getElementById(val)){
//				document.getElementById(val).innerHTML = "SUGGESTED RETAIL PRICES - Click to switch back to wholesale rates.";
//			}
//		}else{
//			pricingOption = false;
//			adjustPricing(qty,lots)
//			if(document.getElementById(val)){
//				document.getElementById(val).innerHTML = "WHOLESALE RATES displayed - Click here to view suggested retail.";
//			}
//		}
//	}
//}
//
//function adjustPrices(oReq, oJSN) {
//	
//    var data = oReq.responseText.evalJSON();
//
//    $('console').innerHTML = '';
//    //populate the list
//   
//    var fullprice=data['fullprice'];
//	
//	var tmpVal = updateOneSet(fullprice, true);
//	
//
//    var bestprice=data['bestprice'];
//    returnVal = updateOneSet(bestprice, false);
//    
//     var difference=data['difference'];
//    updateOneSet(difference);
//    
//    var selectionPrice=data['selectionPrice'];
//	
//    var total=selectionPrice['price'];//findBestBook(bestprice);
//	
//	
//    var element=$('prices_may_vary')
//	
//    
//    if(element!=null && total!=0){
//    	element.innerHTML="Pricing Estimate: $"+total;
//        element.style.display = 'block';
//    }else{
//        element.innerHTML="Error calculating price estimate";
//        element.style.display = 'none';
//    }
//    //alert(fullprice);
//  
//
//
//}
//
//
//function toggle_pricingrows()
//{
// var row_list=$$('tr.class_hidden');
// row_list.each(
// 				function(row)
// 				{
// 					row.toggle();
// 				}
// 			);
// 			
// 	$('toggle_rows_href').toggle();
// 	
// 	alternate('priceTable');
//
// 
//}
//function findBestBook(values){
//	var keyArray=Object.keys(values);
//    keyArray.each(function(key) {
//    							var value=values[key];
//    							element=$(key);
//    							if(element)
//    								{
//    									var tempVal=value;
//    									
//    								return tempVal;
//										
//    								}
//    							}
//    			);
//}
//
//function updateOneSet(values, strikeThrough)
//{
//	var retunVal = 0;
//    var keyArray=Object.keys(values);
//    keyArray.each(function(key) {
//    							var value=values[key];
//    							element=$(key);
//    							if(element)
//    								{
//    									var tempVal=value;
//    									if(strikeThrough==true){
//    										tempVal="<del>"+value+"</del>";
//											retunVal = value;
//    								element.innerHTML=tempVal;
//									
//										}
//										
//    								}
//    							}
//    			);
//				return retunVal;
//}
//
//

