<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/


	
	$query = "select * from `".$Settings['DBPrefix']."ec-Settings`";
	$result = mysql_query($query) or die (mysql_error());
	while ($row = mysql_fetch_array($result)) {
		$ecSettings[$row['Name']] = $row['Value'];
	}
	
	
	$ImageExtension[1] = '.gif';
	$ImageExtension[2] = '.jpg';
	$ImageExtension[3] = '.png';
	
	$ThumbImageExtension[1] = '-thumb.gif';
	$ThumbImageExtension[2] = '-thumb.jpg';
	$ThumbImageExtension[3] = '-thumb.png';
	
	
	
	if ($ecSettings['ShippingAndHandling'] != 'n') {
		$SHTitle = $MsgText[9][187];
	}
	else {
		$SHTitle = $MsgText[9][186];
	}
	
	
	
	if ($ecSettings['OrdersEmail'] == '') {
		$ecSettings['OrdersEmail'] = $Settings['ContactEmail'];
	}
	

		
	function RandomCategoryImage($CatParent5) {
							
		Global $Settings, $ecSettings, $CategoryIDsArray, $ProductIDsWithImagesArray, $RandomImageProductIDsArray;

		$CategoryID = $CatParent5;
		
		for ($j = 0; $j < count($ProductIDsWithImagesArray[$CategoryID]); $j++) {
			$query = "select * from `".$Settings['DBPrefix']."ec-Items` where Product=".$ProductIDsWithImagesArray[$CategoryID][$j]." limit 1";
			$result = mysql_query($query) or die (mysql_error());
			if (mysql_num_rows($result) > 0 || $ecSettings['ShowNoPricing'] == 'y') {
				$RandomImageProductIDsArray[] = $ProductIDsWithImagesArray[$CategoryID][$j];
			}
		}
							
		for ($i = 0; $i < count($CategoryIDsArray[$CatParent5]); $i++) {
							
			$CategoryID = $CategoryIDsArray[$CatParent5][$i];
									
			for ($j = 0; $j < count($ProductIDsWithImagesArray[$CategoryID]); $j++) {
				$query = "select * from `".$Settings['DBPrefix']."ec-Items` where Product=".$ProductIDsWithImagesArray[$CategoryID][$j]." limit 1";
				$result = mysql_query($query) or die (mysql_error());
				if (mysql_num_rows($result) > 0) {
					$RandomImageProductIDsArray[] = $ProductIDsWithImagesArray[$CategoryID][$j];
				}
			}	
					
								
			if (count($CategoryIDsArray[$CategoryIDsArray[$CatParent5][$i]]) > 0) {
				RandomCategoryImage($CategoryIDsArray[$CatParent5][$i]);
			}
							
		}
							
		
	}
	
	
	function CategoryHasContents($CatParent5) {
							
		Global $CategoryIDsArray, $ProductIDsArray, $ReturnValue;

		if (count($ProductIDsArray[$CatParent5]) > 0) {
			$ReturnValue = 1;
		}
							
		for ($i = 0; $i < count($CategoryIDsArray[$CatParent5]); $i++) {
							
			$CategoryID = $CategoryIDsArray[$CatParent5][$i];
			
			if (count($ProductIDsArray[$CategoryID]) > 0) {
				$ReturnValue = 1;
			}
									
									
			if (count($CategoryIDsArray[$CategoryIDsArray[$CatParent5][$i]]) > 0) {
				CategoryHasContents($CategoryIDsArray[$CatParent5][$i]);
			}
							
		}
		
		return $ReturnValue;			
		
	}
	
	
	function BuildNavigationLinks($StartingCategory, $LinksType) {
	
		Global $MainURL, $Settings;
		
	
		$LoopCounter = 0;
		$StoreNavLinks = '';
		
		$CurrentCategoryID = $StartingCategory;
		
		
		while ($CurrentCategoryID != '0' && $LoopCounter < 10) {
			$LoopCounter++;
			
			if ($CurrentCategoryID != '') {
				$query100 = "select * from `".$Settings['DBPrefix']."ec-Categories` where RecordNumber='".$CurrentCategoryID."' limit 1";
				$result100 = mysql_query($query100) or die (mysql_error());
				$row100 = mysql_fetch_array($result100);
							
				if ($LinksType == 'category' && $CurrentCategoryID == $StartingCategory) {
					// don't add anything, we're on this category already
				}
				else {
					$StoreNavLinks = '<a href="'.$MainURL.'/store/browse/'.$row100['CategoryID'].'.html">'.$row100['Name'].'</a> > '.$StoreNavLinks;
				}
							
				$CurrentCategoryID = $row100['Parent'];
			}
			
		}
		
		return $StoreNavLinks;
	
	}
	
	
	
	
function CalculateShippingRate($ShippingID, $TotalWeight, $OrderTotal, $ItemsCount, $ZipPostalCode) {

	Global $Settings, $ecSettings;
	

	$query80 = "select * from `".$Settings['DBPrefix']."ec-Shipping` where RecordNumber=".$ShippingID." limit 1";
	$result80 = mysql_query($query80) or die (mysql_error());
	$row80 = mysql_fetch_array($result80);
	
	
	if ($row80['Calculations'] == 'w1') {
		
		if ($row80['Limit8'] > 0) {
			$MaxWeight = $row80['Limit8'];
		}
		else if ($row80['Limit7'] > 0) {
			$MaxWeight = $row80['Limit7'];
		}
		else if ($row80['Limit6'] > 0) {
			$MaxWeight = $row80['Limit6'];
		}
		else if ($row80['Limit5'] > 0) {
			$MaxWeight = $row80['Limit5'];
		}
		else if ($row80['Limit4'] > 0) {
			$MaxWeight = $row80['Limit4'];
		}
		else if ($row80['Limit3'] > 0) {
			$MaxWeight = $row80['Limit3'];
		}
		else if ($row80['Limit2'] > 0) {
			$MaxWeight = $row80['Limit2'];
		}
		else if ($row80['Limit1'] > 0) {
			$MaxWeight = $row80['Limit1'];
		}	
		else {
			$MaxWeight = $row80['BaseLimit'];
		}
		
		
		if ($TotalWeight <= $MaxWeight) {
			// fits in one package
			
			if ($TotalWeight <= $row80['BaseLimit']) {
				$TotalShipping += $row80['BasePrice'];
			}
			else if ($TotalWeight <= $row80['Limit1']) {
				$TotalShipping += $row80['BasePrice'];
				$TotalWeight -= $row80['BaseLimit'];
				while ($TotalWeight > 0) {
					$TotalShipping += $row80['Price1'];
					$TotalWeight -= $row80['Unit1'];
				}
			}
			else if ($TotalWeight <= $row80['Limit2']) {
				$TotalShipping += $row80['BasePrice'];
				$TotalWeight -= $row80['BaseLimit'];
				while ($TotalWeight > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$TotalWeight -= $row80['Unit2'];
				}
				while ($TotalWeight > 0) {
					$TotalShipping += $row80['Price1'];
					$TotalWeight -= $row80['Unit1'];
				}
			}
			else if ($TotalWeight <= $row80['Limit3']) {
				$TotalShipping += $row80['BasePrice'];
				$TotalWeight -= $row80['BaseLimit'];
				while ($TotalWeight > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$TotalWeight -= $row80['Unit3'];
				}	
				while ($TotalWeight > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$TotalWeight -= $row80['Unit2'];
				}
				while ($TotalWeight > 0) {
					$TotalShipping += $row80['Price1'];
					$TotalWeight -= $row80['Unit1'];
				}							
			}
			else if ($TotalWeight <= $row80['Limit4']) {
				$TotalShipping += $row80['BasePrice'];
				$TotalWeight -= $row80['BaseLimit'];
				while ($TotalWeight > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$TotalWeight -= $row80['Unit4'];
				}
				while ($TotalWeight > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$TotalWeight -= $row80['Unit3'];
				}	
				while ($TotalWeight > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$TotalWeight -= $row80['Unit2'];
				}
				while ($TotalWeight > 0) {
					$TotalShipping += $row80['Price1'];
					$TotalWeight -= $row80['Unit1'];
				}							
			}
			else if ($TotalWeight <= $row80['Limit5']) {
				$TotalShipping += $row80['BasePrice'];
				$TotalWeight -= $row80['BaseLimit'];
				while ($TotalWeight > $row80['Limit4']) {
					$TotalShipping += $row80['Price5'];
					$TotalWeight -= $row80['Unit5'];
				}
				while ($TotalWeight > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$TotalWeight -= $row80['Unit4'];
				}
				while ($TotalWeight > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$TotalWeight -= $row80['Unit3'];
				}	
				while ($TotalWeight > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$TotalWeight -= $row80['Unit2'];
				}
				while ($TotalWeight > 0) {
					$TotalShipping += $row80['Price1'];
					$TotalWeight -= $row80['Unit1'];
				}							
			}
			else if ($TotalWeight <= $row80['Limit6']) {
				$TotalShipping += $row80['BasePrice'];
				$TotalWeight -= $row80['BaseLimit'];
				while ($TotalWeight > $row80['Limit5']) {
					$TotalShipping += $row80['Price6'];
					$TotalWeight -= $row80['Unit6'];
				}
				while ($TotalWeight > $row80['Limit4']) {
					$TotalShipping += $row80['Price5'];
					$TotalWeight -= $row80['Unit5'];
				}
				while ($TotalWeight > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$TotalWeight -= $row80['Unit4'];
				}
				while ($TotalWeight > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$TotalWeight -= $row80['Unit3'];
				}	
				while ($TotalWeight > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$TotalWeight -= $row80['Unit2'];
				}
				while ($TotalWeight > 0) {
					$TotalShipping += $row80['Price1'];
					$TotalWeight -= $row80['Unit1'];
				}							
			}
			else if ($TotalWeight <= $row80['Limit7']) {
				$TotalShipping += $row80['BasePrice'];
				$TotalWeight -= $row80['BaseLimit'];
				while ($TotalWeight > $row80['Limit6']) {
					$TotalShipping += $row80['Price7'];
					$TotalWeight -= $row80['Unit7'];
				}
				while ($TotalWeight > $row80['Limit5']) {
					$TotalShipping += $row80['Price6'];
					$TotalWeight -= $row80['Unit6'];
				}
				while ($TotalWeight > $row80['Limit4']) {
					$TotalShipping += $row80['Price5'];
					$TotalWeight -= $row80['Unit5'];
				}
				while ($TotalWeight > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$TotalWeight -= $row80['Unit4'];
				}
				while ($TotalWeight > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$TotalWeight -= $row80['Unit3'];
				}	
				while ($TotalWeight > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$TotalWeight -= $row80['Unit2'];
				}
				while ($TotalWeight > 0) {
					$TotalShipping += $row80['Price1'];
					$TotalWeight -= $row80['Unit1'];
				}							
			}
			else {
				$TotalShipping += $row80['BasePrice'];
				$TotalWeight -= $row80['BaseLimit'];
				while ($TotalWeight > $row80['Limit7']) {
					$TotalShipping += $row80['Price8'];
					$TotalWeight -= $row80['Unit8'];
				}
				while ($TotalWeight > $row80['Limit6']) {
					$TotalShipping += $row80['Price7'];
					$TotalWeight -= $row80['Unit7'];
				}
				while ($TotalWeight > $row80['Limit5']) {
					$TotalShipping += $row80['Price6'];
					$TotalWeight -= $row80['Unit6'];
				}
				while ($TotalWeight > $row80['Limit4']) {
					$TotalShipping += $row80['Price5'];
					$TotalWeight -= $row80['Unit5'];
				}
				while ($TotalWeight > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$TotalWeight -= $row80['Unit4'];
				}
				while ($TotalWeight > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$TotalWeight -= $row80['Unit3'];
				}	
				while ($TotalWeight > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$TotalWeight -= $row80['Unit2'];
				}
				while ($TotalWeight > 0) {
					$TotalShipping += $row80['Price1'];
					$TotalWeight -= $row80['Unit1'];
				}							
			}
			
		}
		else {
			// needs several packages
			
			$WeightRemaining = $TotalWeight;
			
			while ($WeightRemaining > 0) {
			
				if ($WeightRemaining > $MaxWeight) {
					$TotalWeight = $MaxWeight;
					$WeightRemaining -= $MaxWeight;
				}
				else {
					$TotalWeight = $WeightRemaining;
					$WeightRemaining = 0;
				}
				
				
				if ($TotalWeight <= $row80['BaseLimit']) {
					$TotalShipping += $row80['BasePrice'];
				}
				else if ($TotalWeight <= $row80['Limit1']) {
					$TotalShipping += $row80['BasePrice'];
					$TotalWeight -= $row80['BaseLimit'];
					while ($TotalWeight > 0) {
						$TotalShipping += $row80['Price1'];
						$TotalWeight -= $row80['Unit1'];
					}
				}
				else if ($TotalWeight <= $row80['Limit2']) {
					$TotalShipping += $row80['BasePrice'];
					$TotalWeight -= $row80['BaseLimit'];
					while ($TotalWeight > $row80['Limit1']) {
						$TotalShipping += $row80['Price2'];
						$TotalWeight -= $row80['Unit2'];
					}
					while ($TotalWeight > 0) {
						$TotalShipping += $row80['Price1'];
						$TotalWeight -= $row80['Unit1'];
					}
				}
				else if ($TotalWeight <= $row80['Limit3']) {
					$TotalShipping += $row80['BasePrice'];
					$TotalWeight -= $row80['BaseLimit'];
					while ($TotalWeight > $row80['Limit2']) {
						$TotalShipping += $row80['Price3'];
						$TotalWeight -= $row80['Unit3'];
					}	
					while ($TotalWeight > $row80['Limit1']) {
						$TotalShipping += $row80['Price2'];
						$TotalWeight -= $row80['Unit2'];
					}
					while ($TotalWeight > 0) {
						$TotalShipping += $row80['Price1'];
						$TotalWeight -= $row80['Unit1'];
					}							
				}
				else if ($TotalWeight <= $row80['Limit4']) {
					$TotalShipping += $row80['BasePrice'];
					$TotalWeight -= $row80['BaseLimit'];
					while ($TotalWeight > $row80['Limit3']) {
						$TotalShipping += $row80['Price4'];
						$TotalWeight -= $row80['Unit4'];
					}
					while ($TotalWeight > $row80['Limit2']) {
						$TotalShipping += $row80['Price3'];
						$TotalWeight -= $row80['Unit3'];
					}	
					while ($TotalWeight > $row80['Limit1']) {
						$TotalShipping += $row80['Price2'];
						$TotalWeight -= $row80['Unit2'];
					}
					while ($TotalWeight > 0) {
						$TotalShipping += $row80['Price1'];
						$TotalWeight -= $row80['Unit1'];
					}							
				}
				else if ($TotalWeight <= $row80['Limit5']) {
					$TotalShipping += $row80['BasePrice'];
					$TotalWeight -= $row80['BaseLimit'];
					while ($TotalWeight > $row80['Limit4']) {
						$TotalShipping += $row80['Price5'];
						$TotalWeight -= $row80['Unit5'];
					}
					while ($TotalWeight > $row80['Limit3']) {
						$TotalShipping += $row80['Price4'];
						$TotalWeight -= $row80['Unit4'];
					}
					while ($TotalWeight > $row80['Limit2']) {
						$TotalShipping += $row80['Price3'];
						$TotalWeight -= $row80['Unit3'];
					}	
					while ($TotalWeight > $row80['Limit1']) {
						$TotalShipping += $row80['Price2'];
						$TotalWeight -= $row80['Unit2'];
					}
					while ($TotalWeight > 0) {
						$TotalShipping += $row80['Price1'];
						$TotalWeight -= $row80['Unit1'];
					}							
				}
				else if ($TotalWeight <= $row80['Limit6']) {
					$TotalShipping += $row80['BasePrice'];
					$TotalWeight -= $row80['BaseLimit'];
					while ($TotalWeight > $row80['Limit5']) {
						$TotalShipping += $row80['Price6'];
						$TotalWeight -= $row80['Unit6'];
					}
					while ($TotalWeight > $row80['Limit4']) {
						$TotalShipping += $row80['Price5'];
						$TotalWeight -= $row80['Unit5'];
					}
					while ($TotalWeight > $row80['Limit3']) {
						$TotalShipping += $row80['Price4'];
						$TotalWeight -= $row80['Unit4'];
					}
					while ($TotalWeight > $row80['Limit2']) {
						$TotalShipping += $row80['Price3'];
						$TotalWeight -= $row80['Unit3'];
					}	
					while ($TotalWeight > $row80['Limit1']) {
						$TotalShipping += $row80['Price2'];
						$TotalWeight -= $row80['Unit2'];
					}
					while ($TotalWeight > 0) {
						$TotalShipping += $row80['Price1'];
						$TotalWeight -= $row80['Unit1'];
					}							
				}
				else if ($TotalWeight <= $row80['Limit7']) {
					$TotalShipping += $row80['BasePrice'];
					$TotalWeight -= $row80['BaseLimit'];
					while ($TotalWeight > $row80['Limit6']) {
						$TotalShipping += $row80['Price7'];
						$TotalWeight -= $row80['Unit7'];
					}
					while ($TotalWeight > $row80['Limit5']) {
						$TotalShipping += $row80['Price6'];
						$TotalWeight -= $row80['Unit6'];
					}
					while ($TotalWeight > $row80['Limit4']) {
						$TotalShipping += $row80['Price5'];
						$TotalWeight -= $row80['Unit5'];
					}
					while ($TotalWeight > $row80['Limit3']) {
						$TotalShipping += $row80['Price4'];
						$TotalWeight -= $row80['Unit4'];
					}
					while ($TotalWeight > $row80['Limit2']) {
						$TotalShipping += $row80['Price3'];
						$TotalWeight -= $row80['Unit3'];
					}	
					while ($TotalWeight > $row80['Limit1']) {
						$TotalShipping += $row80['Price2'];
						$TotalWeight -= $row80['Unit2'];
					}
					while ($TotalWeight > 0) {
						$TotalShipping += $row80['Price1'];
						$TotalWeight -= $row80['Unit1'];
					}							
				}
				else {
					$TotalShipping += $row80['BasePrice'];
					$TotalWeight -= $row80['BaseLimit'];
					while ($TotalWeight > $row80['Limit7']) {
						$TotalShipping += $row80['Price8'];
						$TotalWeight -= $row80['Unit8'];
					}
					while ($TotalWeight > $row80['Limit6']) {
						$TotalShipping += $row80['Price7'];
						$TotalWeight -= $row80['Unit7'];
					}
					while ($TotalWeight > $row80['Limit5']) {
						$TotalShipping += $row80['Price6'];
						$TotalWeight -= $row80['Unit6'];
					}
					while ($TotalWeight > $row80['Limit4']) {
						$TotalShipping += $row80['Price5'];
						$TotalWeight -= $row80['Unit5'];
					}
					while ($TotalWeight > $row80['Limit3']) {
						$TotalShipping += $row80['Price4'];
						$TotalWeight -= $row80['Unit4'];
					}
					while ($TotalWeight > $row80['Limit2']) {
						$TotalShipping += $row80['Price3'];
						$TotalWeight -= $row80['Unit3'];
					}	
					while ($TotalWeight > $row80['Limit1']) {
						$TotalShipping += $row80['Price2'];
						$TotalWeight -= $row80['Unit2'];
					}
					while ($TotalWeight > 0) {
						$TotalShipping += $row80['Price1'];
						$TotalWeight -= $row80['Unit1'];
					}							
				}
				
			
			} // end while weight remaining
			
		} // end if multiple packages required
		
		
	} // end if type w1
	else if ($row80['Calculations'] == 'w2') {
		
		
		if ($row80['Limit8'] > 0) {
			$MaxWeight = $row80['Limit8'];
		}
		else if ($row80['Limit7'] > 0) {
			$MaxWeight = $row80['Limit7'];
		}
		else if ($row80['Limit6'] > 0) {
			$MaxWeight = $row80['Limit6'];
		}
		else if ($row80['Limit5'] > 0) {
			$MaxWeight = $row80['Limit5'];
		}
		else if ($row80['Limit4'] > 0) {
			$MaxWeight = $row80['Limit4'];
		}
		else if ($row80['Limit3'] > 0) {
			$MaxWeight = $row80['Limit3'];
		}
		else if ($row80['Limit2'] > 0) {
			$MaxWeight = $row80['Limit2'];
		}
		else if ($row80['Limit1'] > 0) {
			$MaxWeight = $row80['Limit1'];
		}	
		else {
			$MaxWeight = $row80['BaseLimit'];
		}
		
		
		if ($TotalWeight <= $MaxWeight) {
			// fits in one package
			
			$TotalShipping = $row80['BasePrice'];
		
			if ($row80['Limit1'] > 0 && $TotalWeight > $row80['BaseLimit']) {
				$TotalShipping = $row80['Price1'];
			}
			if ($row80['Limit2'] > 0 && $TotalWeight > $row80['Limit1']) {
				$TotalShipping = $row80['Price2'];
			}
			if ($row80['Limit3'] > 0 && $TotalWeight > $row80['Limit2']) {
				$TotalShipping = $row80['Price3'];
			}
			if ($row80['Limit4'] > 0 && $TotalWeight > $row80['Limit3']) {
				$TotalShipping = $row80['Price4'];
			}
			if ($row80['Limit5'] > 0 && $TotalWeight > $row80['Limit4']) {
				$TotalShipping = $row80['Price5'];
			}
			if ($row80['Limit6'] > 0 && $TotalWeight > $row80['Limit5']) {
				$TotalShipping = $row80['Price6'];
			}
			if ($row80['Limit7'] > 0 && $TotalWeight > $row80['Limit6']) {
				$TotalShipping = $row80['Price7'];
			}
			if ($row80['Limit8'] > 0 && $TotalWeight > $row80['Limit7']) {
				$TotalShipping = $row80['Price8'];
			}
			
		}
		else {
			// needs several packages
			
			$WeightRemaining = $TotalWeight;
			
			while ($WeightRemaining > 0) {
			
				if ($WeightRemaining > $MaxWeight) {
					$TotalWeight = $MaxWeight;
					$WeightRemaining -= $MaxWeight;
				}
				else {
					$TotalWeight = $WeightRemaining;
					$WeightRemaining = 0;
				}
				
				
				$TotalShippingToAdd = $row80['BasePrice'];
		
				if ($row80['Limit1'] > 0 && $TotalWeight > $row80['BaseLimit']) {
					$TotalShippingToAdd = $row80['Price1'];
				}
				if ($row80['Limit2'] > 0 && $TotalWeight > $row80['Limit1']) {
					$TotalShippingToAdd = $row80['Price2'];
				}
				if ($row80['Limit3'] > 0 && $TotalWeight > $row80['Limit2']) {
					$TotalShippingToAdd = $row80['Price3'];
				}
				if ($row80['Limit4'] > 0 && $TotalWeight > $row80['Limit3']) {
					$TotalShippingToAdd = $row80['Price4'];
				}
				if ($row80['Limit5'] > 0 && $TotalWeight > $row80['Limit4']) {
					$TotalShippingToAdd = $row80['Price5'];
				}
				if ($row80['Limit6'] > 0 && $TotalWeight > $row80['Limit5']) {
					$TotalShippingToAdd = $row80['Price6'];
				}
				if ($row80['Limit7'] > 0 && $TotalWeight > $row80['Limit6']) {
					$TotalShippingToAdd = $row80['Price7'];
				}
				if ($row80['Limit8'] > 0 && $TotalWeight > $row80['Limit7']) {
					$TotalShippingToAdd = $row80['Price8'];
				}
								
				$TotalShipping += $TotalShippingToAdd;
				
			
			} // end while weight remaining
			
		} // end if multiple packages required
		
		
	} // end if type w2
	else if ($row80['Calculations'] == 'v1') {
				
			if ($OrderTotal <= $row80['BaseLimit']) {
				$TotalShipping += $row80['BasePrice'];
			}
			else if ($OrderTotal <= $row80['Limit1']) {
				$TotalShipping += $row80['BasePrice'];
				$OrderTotal -= $row80['BaseLimit'];
				while ($OrderTotal > 0) {
					$TotalShipping += $row80['Price1'];
					$OrderTotal -= $row80['Unit1'];
				}
			}
			else if ($OrderTotal <= $row80['Limit2']) {
				$TotalShipping += $row80['BasePrice'];
				$OrderTotal -= $row80['BaseLimit'];
				while ($OrderTotal > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$OrderTotal -= $row80['Unit2'];
				}
				while ($OrderTotal > 0) {
					$TotalShipping += $row80['Price1'];
					$OrderTotal -= $row80['Unit1'];
				}
			}
			else if ($OrderTotal <= $row80['Limit3']) {
				$TotalShipping += $row80['BasePrice'];
				$OrderTotal -= $row80['BaseLimit'];
				while ($OrderTotal > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$OrderTotal -= $row80['Unit3'];
				}	
				while ($OrderTotal > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$OrderTotal -= $row80['Unit2'];
				}
				while ($OrderTotal > 0) {
					$TotalShipping += $row80['Price1'];
					$OrderTotal -= $row80['Unit1'];
				}							
			}
			else if ($OrderTotal <= $row80['Limit4']) {
				$TotalShipping += $row80['BasePrice'];
				$OrderTotal -= $row80['BaseLimit'];
				while ($OrderTotal > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$OrderTotal -= $row80['Unit4'];
				}
				while ($OrderTotal > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$OrderTotal -= $row80['Unit3'];
				}	
				while ($OrderTotal > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$OrderTotal -= $row80['Unit2'];
				}
				while ($OrderTotal > 0) {
					$TotalShipping += $row80['Price1'];
					$OrderTotal -= $row80['Unit1'];
				}							
			}
			else if ($OrderTotal <= $row80['Limit5']) {
				$TotalShipping += $row80['BasePrice'];
				$OrderTotal -= $row80['BaseLimit'];
				while ($OrderTotal > $row80['Limit4']) {
					$TotalShipping += $row80['Price5'];
					$OrderTotal -= $row80['Unit5'];
				}
				while ($OrderTotal > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$OrderTotal -= $row80['Unit4'];
				}
				while ($OrderTotal > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$OrderTotal -= $row80['Unit3'];
				}	
				while ($OrderTotal > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$OrderTotal -= $row80['Unit2'];
				}
				while ($OrderTotal > 0) {
					$TotalShipping += $row80['Price1'];
					$OrderTotal -= $row80['Unit1'];
				}							
			}
			else if ($OrderTotal <= $row80['Limit6']) {
				$TotalShipping += $row80['BasePrice'];
				$OrderTotal -= $row80['BaseLimit'];
				while ($OrderTotal > $row80['Limit5']) {
					$TotalShipping += $row80['Price6'];
					$OrderTotal -= $row80['Unit6'];
				}
				while ($OrderTotal > $row80['Limit4']) {
					$TotalShipping += $row80['Price5'];
					$OrderTotal -= $row80['Unit5'];
				}
				while ($OrderTotal > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$OrderTotal -= $row80['Unit4'];
				}
				while ($OrderTotal > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$OrderTotal -= $row80['Unit3'];
				}	
				while ($OrderTotal > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$OrderTotal -= $row80['Unit2'];
				}
				while ($OrderTotal > 0) {
					$TotalShipping += $row80['Price1'];
					$OrderTotal -= $row80['Unit1'];
				}							
			}
			else if ($OrderTotal <= $row80['Limit7']) {
				$TotalShipping += $row80['BasePrice'];
				$OrderTotal -= $row80['BaseLimit'];
				while ($OrderTotal > $row80['Limit6']) {
					$TotalShipping += $row80['Price7'];
					$OrderTotal -= $row80['Unit7'];
				}
				while ($OrderTotal > $row80['Limit5']) {
					$TotalShipping += $row80['Price6'];
					$OrderTotal -= $row80['Unit6'];
				}
				while ($OrderTotal > $row80['Limit4']) {
					$TotalShipping += $row80['Price5'];
					$OrderTotal -= $row80['Unit5'];
				}
				while ($OrderTotal > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$OrderTotal -= $row80['Unit4'];
				}
				while ($OrderTotal > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$OrderTotal -= $row80['Unit3'];
				}	
				while ($OrderTotal > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$OrderTotal -= $row80['Unit2'];
				}
				while ($OrderTotal > 0) {
					$TotalShipping += $row80['Price1'];
					$OrderTotal -= $row80['Unit1'];
				}							
			}
			else {
				$TotalShipping += $row80['BasePrice'];
				$OrderTotal -= $row80['BaseLimit'];
				while ($OrderTotal > $row80['Limit7']) {
					$TotalShipping += $row80['Price8'];
					$OrderTotal -= $row80['Unit8'];
				}
				while ($OrderTotal > $row80['Limit6']) {
					$TotalShipping += $row80['Price7'];
					$OrderTotal -= $row80['Unit7'];
				}
				while ($OrderTotal > $row80['Limit5']) {
					$TotalShipping += $row80['Price6'];
					$OrderTotal -= $row80['Unit6'];
				}
				while ($OrderTotal > $row80['Limit4']) {
					$TotalShipping += $row80['Price5'];
					$OrderTotal -= $row80['Unit5'];
				}
				while ($OrderTotal > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$OrderTotal -= $row80['Unit4'];
				}
				while ($OrderTotal > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$OrderTotal -= $row80['Unit3'];
				}	
				while ($OrderTotal > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$OrderTotal -= $row80['Unit2'];
				}
				while ($OrderTotal > 0) {
					$TotalShipping += $row80['Price1'];
					$OrderTotal -= $row80['Unit1'];
				}							
			}
		
	} // end if type v1
	else if ($row80['Calculations'] == 'v2') {
		
				
			$TotalShipping = $row80['BasePrice'];
		
			if ($row80['Limit1'] > 0 && $OrderTotal > $row80['BaseLimit']) {
				$TotalShipping = $row80['Price1'];
			}
			if ($row80['Limit2'] > 0 && $OrderTotal > $row80['Limit1']) {
				$TotalShipping = $row80['Price2'];
			}
			if ($row80['Limit3'] > 0 && $OrderTotal > $row80['Limit2']) {
				$TotalShipping = $row80['Price3'];
			}
			if ($row80['Limit4'] > 0 && $OrderTotal > $row80['Limit3']) {
				$TotalShipping = $row80['Price4'];
			}
			if ($row80['Limit5'] > 0 && $OrderTotal > $row80['Limit4']) {
				$TotalShipping = $row80['Price5'];
			}
			if ($row80['Limit6'] > 0 && $OrderTotal > $row80['Limit5']) {
				$TotalShipping = $row80['Price6'];
			}
			if ($row80['Limit7'] > 0 && $OrderTotal > $row80['Limit6']) {
				$TotalShipping = $row80['Price7'];
			}
			if ($row80['Limit8'] > 0 && $OrderTotal > $row80['Limit7']) {
				$TotalShipping = $row80['Price8'];
			}
			
		
	} // end if type v2
	else if ($row80['Calculations'] == 'i1') {
				
			if ($ItemsCount <= $row80['BaseLimit']) {
				$TotalShipping += $row80['BasePrice'];
			}
			else if ($ItemsCount <= $row80['Limit1']) {
				$TotalShipping += $row80['BasePrice'];
				$ItemsCount -= $row80['BaseLimit'];
				while ($ItemsCount > 0) {
					$TotalShipping += $row80['Price1'];
					$ItemsCount -= $row80['Unit1'];
				}
			}
			else if ($ItemsCount <= $row80['Limit2']) {
				$TotalShipping += $row80['BasePrice'];
				$ItemsCount -= $row80['BaseLimit'];
				while ($ItemsCount > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$ItemsCount -= $row80['Unit2'];
				}
				while ($ItemsCount > 0) {
					$TotalShipping += $row80['Price1'];
					$ItemsCount -= $row80['Unit1'];
				}
			}
			else if ($ItemsCount <= $row80['Limit3']) {
				$TotalShipping += $row80['BasePrice'];
				$ItemsCount -= $row80['BaseLimit'];
				while ($ItemsCount > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$ItemsCount -= $row80['Unit3'];
				}	
				while ($ItemsCount > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$ItemsCount -= $row80['Unit2'];
				}
				while ($ItemsCount > 0) {
					$TotalShipping += $row80['Price1'];
					$ItemsCount -= $row80['Unit1'];
				}							
			}
			else if ($ItemsCount <= $row80['Limit4']) {
				$TotalShipping += $row80['BasePrice'];
				$ItemsCount -= $row80['BaseLimit'];
				while ($ItemsCount > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$ItemsCount -= $row80['Unit4'];
				}
				while ($ItemsCount > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$ItemsCount -= $row80['Unit3'];
				}	
				while ($ItemsCount > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$ItemsCount -= $row80['Unit2'];
				}
				while ($ItemsCount > 0) {
					$TotalShipping += $row80['Price1'];
					$ItemsCount -= $row80['Unit1'];
				}							
			}
			else if ($ItemsCount <= $row80['Limit5']) {
				$TotalShipping += $row80['BasePrice'];
				$ItemsCount -= $row80['BaseLimit'];
				while ($ItemsCount > $row80['Limit4']) {
					$TotalShipping += $row80['Price5'];
					$ItemsCount -= $row80['Unit5'];
				}
				while ($ItemsCount > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$ItemsCount -= $row80['Unit4'];
				}
				while ($ItemsCount > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$ItemsCount -= $row80['Unit3'];
				}	
				while ($ItemsCount > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$ItemsCount -= $row80['Unit2'];
				}
				while ($ItemsCount > 0) {
					$TotalShipping += $row80['Price1'];
					$ItemsCount -= $row80['Unit1'];
				}							
			}
			else if ($ItemsCount <= $row80['Limit6']) {
				$TotalShipping += $row80['BasePrice'];
				$ItemsCount -= $row80['BaseLimit'];
				while ($ItemsCount > $row80['Limit5']) {
					$TotalShipping += $row80['Price6'];
					$ItemsCount -= $row80['Unit6'];
				}
				while ($ItemsCount > $row80['Limit4']) {
					$TotalShipping += $row80['Price5'];
					$ItemsCount -= $row80['Unit5'];
				}
				while ($ItemsCount > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$ItemsCount -= $row80['Unit4'];
				}
				while ($ItemsCount > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$ItemsCount -= $row80['Unit3'];
				}	
				while ($ItemsCount > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$ItemsCount -= $row80['Unit2'];
				}
				while ($ItemsCount > 0) {
					$TotalShipping += $row80['Price1'];
					$ItemsCount -= $row80['Unit1'];
				}							
			}
			else if ($ItemsCount <= $row80['Limit7']) {
				$TotalShipping += $row80['BasePrice'];
				$ItemsCount -= $row80['BaseLimit'];
				while ($ItemsCount > $row80['Limit6']) {
					$TotalShipping += $row80['Price7'];
					$ItemsCount -= $row80['Unit7'];
				}
				while ($ItemsCount > $row80['Limit5']) {
					$TotalShipping += $row80['Price6'];
					$ItemsCount -= $row80['Unit6'];
				}
				while ($ItemsCount > $row80['Limit4']) {
					$TotalShipping += $row80['Price5'];
					$ItemsCount -= $row80['Unit5'];
				}
				while ($ItemsCount > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$ItemsCount -= $row80['Unit4'];
				}
				while ($ItemsCount > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$ItemsCount -= $row80['Unit3'];
				}	
				while ($ItemsCount > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$ItemsCount -= $row80['Unit2'];
				}
				while ($ItemsCount > 0) {
					$TotalShipping += $row80['Price1'];
					$ItemsCount -= $row80['Unit1'];
				}							
			}
			else {
				$TotalShipping += $row80['BasePrice'];
				$ItemsCount -= $row80['BaseLimit'];
				while ($ItemsCount > $row80['Limit7']) {
					$TotalShipping += $row80['Price8'];
					$ItemsCount -= $row80['Unit8'];
				}
				while ($ItemsCount > $row80['Limit6']) {
					$TotalShipping += $row80['Price7'];
					$ItemsCount -= $row80['Unit7'];
				}
				while ($ItemsCount > $row80['Limit5']) {
					$TotalShipping += $row80['Price6'];
					$ItemsCount -= $row80['Unit6'];
				}
				while ($ItemsCount > $row80['Limit4']) {
					$TotalShipping += $row80['Price5'];
					$ItemsCount -= $row80['Unit5'];
				}
				while ($ItemsCount > $row80['Limit3']) {
					$TotalShipping += $row80['Price4'];
					$ItemsCount -= $row80['Unit4'];
				}
				while ($ItemsCount > $row80['Limit2']) {
					$TotalShipping += $row80['Price3'];
					$ItemsCount -= $row80['Unit3'];
				}	
				while ($ItemsCount > $row80['Limit1']) {
					$TotalShipping += $row80['Price2'];
					$ItemsCount -= $row80['Unit2'];
				}
				while ($ItemsCount > 0) {
					$TotalShipping += $row80['Price1'];
					$ItemsCount -= $row80['Unit1'];
				}							
			}
		
	} // end if type i1	
	else if ($row80['Calculations'] == 'i2') {
		
				
			$TotalShipping = $row80['BasePrice'];
		
			if ($row80['Limit1'] > 0 && $ItemsCount > $row80['BaseLimit']) {
				$TotalShipping = $row80['Price1'];
			}
			if ($row80['Limit2'] > 0 && $ItemsCount > $row80['Limit1']) {
				$TotalShipping = $row80['Price2'];
			}
			if ($row80['Limit3'] > 0 && $ItemsCount > $row80['Limit2']) {
				$TotalShipping = $row80['Price3'];
			}
			if ($row80['Limit4'] > 0 && $ItemsCount > $row80['Limit3']) {
				$TotalShipping = $row80['Price4'];
			}
			if ($row80['Limit5'] > 0 && $ItemsCount > $row80['Limit4']) {
				$TotalShipping = $row80['Price5'];
			}
			if ($row80['Limit6'] > 0 && $ItemsCount > $row80['Limit5']) {
				$TotalShipping = $row80['Price6'];
			}
			if ($row80['Limit7'] > 0 && $ItemsCount > $row80['Limit6']) {
				$TotalShipping = $row80['Price7'];
			}
			if ($row80['Limit8'] > 0 && $ItemsCount > $row80['Limit7']) {
				$TotalShipping = $row80['Price8'];
			}
			
		
	} // end if type i2
	else if ($row80['Calculations'] == 'usps_pm') {
						
		$OriginZip = $ecSettings['OriginZipCode'];
		$DestinationZip = $ZipPostalCode;
		
		
		if (number_format(substr($OriginZip,0,3),0) != number_format(substr($DestinationZip,0,3),0)) {
		
			$query = "select * from `".$Settings['DBPrefix']."ec-ZipCodes` where FirstThree=".number_format(substr($OriginZip,0,3),0)." limit 1";
			$result = mysql_query($query);
			$row = mysql_fetch_array($result);
	
			$Lat1 = $row['Latitude'];
			$Long1 = $row['Longitude'];
								
									
			$query = "select * from `".$Settings['DBPrefix']."ec-ZipCodes` where FirstThree=".number_format(substr($DestinationZip,0,3),0)." limit 1";
			$result = mysql_query($query);
			$row = mysql_fetch_array($result);
	
			$Lat2 = $row['Latitude'];
			$Long2 = $row['Longitude'];

										
			$MilesApart = ceil( acos( cos( deg2rad($Lat1) ) * cos( deg2rad($Long1) ) * cos( deg2rad($Lat2) ) * cos( deg2rad($Long2) ) + cos( deg2rad($Lat1) ) * sin( deg2rad($Long1) ) * cos( deg2rad($Lat2) ) * sin( deg2rad($Long2) ) + sin( deg2rad($Lat1) ) * sin( deg2rad($Lat2) ) ) * 3963.1 );
		}
		else {
			$MilesApart = 0;
		}

								
		
		if ($MilesApart <= 50) {
			$USPSZone = 1;
		}
		else if ($MilesApart <= 150) {
			$USPSZone = 2;
		}
		else if ($MilesApart <= 300) {
			$USPSZone = 3;
		}
		else if ($MilesApart <= 600) {
			$USPSZone = 4;
		}
		else if ($MilesApart <= 1000) {
			$USPSZone = 5;
		}
		else if ($MilesApart <= 1400) {
			$USPSZone = 6;
		}
		else if ($MilesApart <= 1800) {
			$USPSZone = 7;
		}
		else {
			$USPSZone = 8;
		}
								

		//if ($USPSZone <= 3) {
		//	$ZoneName = 'Zones123';
		//}
		//else {
			$ZoneName = 'Zone'.$USPSZone;
		//}

		
		$MaxWeight = 70;
		$WeightRemaining = $TotalWeight;
			
		while ($WeightRemaining > 0) {
			
			if ($WeightRemaining > $MaxWeight) {
				$TotalWeight = $MaxWeight;
				$WeightRemaining -= $MaxWeight;
			}
			else {
				$TotalWeight = $WeightRemaining;
				$WeightRemaining = 0;
			}
				
			
			$query20 = "select * from `".$Settings['DBPrefix']."ec-USPSPriorityMailRates` where Weight>=".$TotalWeight." order by Weight asc limit 1";
			$result20 = mysql_query($query20);
			$row20 = mysql_fetch_array($result20);

			$TotalShipping += $row20[$ZoneName];
				
			
		} // end while weight remaining
		
	
	} // end if type usps_pm
	else if ($row80['Calculations'] == 'fp') {
		
		$TotalShipping = $row80['BasePrice'];
			
	} // end if type usps_pm
	
	
	//print $ShippingID.', '.$TotalWeight.', '.$OrderTotal.', '.$ItemsCount.', '.$ZipPostalCode.'<br><br>';
	
	//print $row80['Calculations'].' -- total: $'.$TotalShipping.'<br><br>';
	
	//print 'miles apart: '.$MilesApart.'<br>zone: '.$USPSZone.'<br><br>';
	
	
	$TotalShipping += $row80['Handling'];
	
	
	return $TotalShipping;


}
	
	
	
	
	if ($ecSettings['HighlightColor'] != '') {
		$HighlightColor = $ecSettings['HighlightColor'];
	}
	else {
		$HighlightColor = '#ff0000';
	}
	
	
	$InStock = '';
	if ($ecSettings['ShowInStock'] != 'n') {
		if ($ecSettings['ShowInStockOther'] != '') {
			$InStock = $ecSettings['ShowInStockOther'];
		}
		else {
			$InStock = $MsgText[9][158];
		}
	}
		
	$SoldOut = '';
	if ($ecSettings['ShowSoldOut'] != 'n') {
		if ($ecSettings['ShowSoldOutOther'] != '') {
			$SoldOut = $ecSettings['ShowSoldOutOther'];
		}
		else {
			$SoldOut = $MsgText[9][162];
		}
	}
	
	
	
	if ($ecSettings['CurrencyLocation'] == '' || $ecSettings['CurrencyLocation'] == 'b') {
		if ($ecSettings['Currency'] == '') {
			$CurrencyBefore = '$';
		}
		else {
			$CurrencyBefore = $ecSettings['Currency'];
		}
	}
	else {
		if ($ecSettings['Currency'] == '') {
			$CurrencyAfter = '$';
		}
		else {
			$CurrencyAfter = $ecSettings['Currency'];
		}
	}
	
	
	
	if ($ecSettings['PriceDecimals'] == '') {
		$ecSettings['PriceDecimals'] = 2;
	}
	
	
	if ($ecSettings['DecimalSymbol'] == '') {
		$ecSettings['DecimalSymbol'] = '.';
	}
	
	
	if ($ecSettings['ThousandsSep'] == '') {
		$ecSettings['ThousandsSep'] = ',';
	}
	
	
	
	if ($ecSettings['WeightUnits'] == '' || $ecSettings['WeightUnits'] == 'lbs') {
		$WeightUnits = 'Lbs.';
	}
	else {
		$WeightUnits = 'Kg';
	}
	
	
	if ($ecSettings['CurrencyCode'] != '') {
		$CurrencyCode = $ecSettings['CurrencyCode'];
	}
	else {
		$CurrencyCode = 'USD';
	}
	
	
	
	
	if ($Arguments2 == 'browse' || $Arguments2 == '') {
	
		$Category = $Arguments3;
	
		if ($Category == '') {
			$Category = '0';
		}
		
		
		$query = "select * from `".$Settings['DBPrefix']."ec-Categories` where CategoryID='".$Category."' limit 1";
		$result = mysql_query($query) or die (mysql_error());
		$row = mysql_fetch_array($result);
		
		
		if ($ecSettings['PageTitle'] == '') {
			$ecSettings['PageTitle'] = $MsgText[9][271];
		}
		
		
		if ($Category == '0') {
		
			if ($ecSettings['TitleImage'] != '') {
				$PageTitle = '<div align="'.$AlignmentCodes[$ecSettings['TitleAlignment']].'"><img src="'.$BaseURL.$ecSettings['TitleImage'].'" alt="'.$ecSettings['PageTitle'].'" border="0"></div>';	
			}
			else {
				$PageTitle = '<div align="'.$AlignmentCodes[$ecSettings['TitleAlignment']].'">'.$ecSettings['PageTitle'].'</div>';
			}
									
			
			$BrowserTitle = $ecSettings['PageTitle'];
			$LocationBar = '<a href="'.$MainURL.'">'.$MsgText[0][1].'</a> > '.$ecSettings['PageTitle'];
			
			if ($ecSettings['TopText'] != '') {
				$TopText = str_replace("\n",'<br>',$ecSettings['TopText']).'<br><br>';			
			}
			if ($ecSettings['BottomText'] != '') {
				$BottomText = '<br><br>'.str_replace("\n",'<br>',$ecSettings['BottomText']);			
			}
			
		}
		else {
			$PageTitle = $row['Name'];
			$BrowserTitle = $ecSettings['PageTitle'].' - '.$row['Name'];
			$LocationBar = '<a href="'.$MainURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/store.html">'.$ecSettings['PageTitle'].'</a> > '.BuildNavigationLinks($row['RecordNumber'],'category').$row['Name'];
			
			if ($row['Description'] != '') {
				$TopText = $row['Description'] . '<br><br>';
			}
		}
		
		
		
		$query0 = "select RecordNumber, Parent from `".$Settings['DBPrefix']."ec-Categories`";
		$result0 = mysql_query($query0) or die (mysql_error());
		while ($row0 = mysql_fetch_array($result0)) {
			$CategoryIDsArray[$row0['Parent']][] = $row0['RecordNumber'];
		}
				
		$query0 = "select RecordNumber, Category, Category2, Category3, Category4, Category5, ImageType from `".$Settings['DBPrefix']."ec-Products` where Active=1";
		$result0 = mysql_query($query0) or die (mysql_error());
		while ($row0 = mysql_fetch_array($result0)) {
						
			$ProductIDsArray[$row0['Category']][] = $row0['RecordNumber'];
			if ($row0['Category2'] > 0) {
				$ProductIDsArray[$row0['Category2']][] = $row0['RecordNumber'];
			}
			if ($row0['Category3'] > 0) {
				$ProductIDsArray[$row0['Category3']][] = $row0['RecordNumber'];
			}
			if ($row0['Category4'] > 0) {
				$ProductIDsArray[$row0['Category4']][] = $row0['RecordNumber'];
			}
			if ($row0['Category5'] > 0) {
				$ProductIDsArray[$row0['Category5']][] = $row0['RecordNumber'];
			}
			
			if ($row0['ImageType'] > 0) {
				$ProductIDsWithImagesArray[$row0['Category']][] = $row0['RecordNumber'];
				
				if ($row0['Category2'] > 0) {
					$ProductIDsWithImagesArray[$row0['Category2']][] = $row0['RecordNumber'];
				}
				if ($row0['Category3'] > 0) {
					$ProductIDsWithImagesArray[$row0['Category3']][] = $row0['RecordNumber'];
				}
				if ($row0['Category4'] > 0) {
					$ProductIDsWithImagesArray[$row0['Category4']][] = $row0['RecordNumber'];
				}
				if ($row0['Category5'] > 0) {
					$ProductIDsWithImagesArray[$row0['Category5']][] = $row0['RecordNumber'];
				}
			}
			
		}
		
		
		
		$query3 = "select * from `".$Settings['DBPrefix']."ec-Categories` where Parent='".$row['RecordNumber']."' order by Name asc";
		$result3 = mysql_query($query3) or die (mysql_error());
		$SubCatsCount = mysql_num_rows($result3);
		if ($SubCatsCount > 0) {
		
			// sub categories found
			while ($row3 = mysql_fetch_array($result3)) {
				
				if ($row3['Description'] != '') {
					$row3['Description'] = '<br><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="5" alt="" border="0"><br>'.$row3['Description'];
				}
				
				$ImageTag = '';
				
				if ($row3['CategoryImage'] != '') {
				
					if (substr($row3['CategoryImage'],0,4) != 'http') {
						$row3['CategoryImage'] = $ImagesURL.'/store/'.$row3['CategoryImage'];
					}
				
					$ImageTag = '<a href="'.$MainURL.'/store/browse/'.$row3['CategoryID'].'.html"><img src="'.$row3['CategoryImage'].'" alt="" border="0"></a>';
				
				}
				else {
					$RandomImageProductIDsArray = '';
								
					RandomCategoryImage($row3['RecordNumber']);
				
					$RandomProductImage = $RandomImageProductIDsArray[rand(0,(count($RandomImageProductIDsArray)-1))];
				
					if ($RandomProductImage != '') {
				
						$query7 = "select * from `".$Settings['DBPrefix']."ec-Products` where RecordNumber=".$RandomProductImage." limit 1";
						$result7 = mysql_query($query7) or die (mysql_error());
						if (mysql_num_rows($result7) > 0) {
					
							$row7 = mysql_fetch_array($result7);
						
							$ImageWidth = $row7['ImageWidth'];
							$ImageHeight = $row7['ImageHeight'];
							
							$NewWidth = $ecSettings['ThumbMaxWidth'];
							$NewHeight = $ecSettings['ThumbMaxHeight'];
						
							$WidthRatio = $ImageWidth / $NewWidth;
							$HeightRatio = $ImageHeight / $NewHeight;
							
							if ($WidthRatio >= $HeightRatio) {
								$NewWidthCalc = number_format($ImageWidth / $WidthRatio, 0);
								$NewHeightCalc = number_format($ImageHeight / $WidthRatio, 0);
							}
							else {
								$NewWidthCalc = number_format($ImageWidth / $HeightRatio, 0);
								$NewHeightCalc = number_format($ImageHeight / $HeightRatio, 0);
							}
					
							$ImageTag = '<a href="'.$MainURL.'/store/browse/'.$row3['CategoryID'].'.html"><img src="'.$ImagesURL.'/store/store_'.$row7['RecordNumber'].$ThumbImageExtension[$row7['ImageType']].'" width="'.$NewWidthCalc.'" height="'.$NewHeightCalc.'" alt="" border="0"></a>';
													
						}
					}
				
				}
				
				$ReturnValue = 0;
				
				if (CategoryHasContents($row3['RecordNumber']) == 1) {
					if ($ecSettings['CategoryPictureLocation'] == 'R') {
						$PageContents .= '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="10" alt="" border="0"><br><div align="center"><table width="80%" border="0" cellpadding="0" cellspacing="0"><tr><td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/store/browse/'.$row3['CategoryID'].'.html">'.$row3['Name'].'</a></b>'.$row3['Description'].'<br><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="12" alt="" border="0"><br><a href="'.$MainURL.'/store/browse/'.$row3['CategoryID'].'.html">'.$MsgText[9][272].' '.$row3['Name'].'</a></td><td width="10"><img src="'.$ImagesURL.'/admin/spacer.gif" width="10" height="1" alt="" border="0"></td><td width="'.$ecSettings['ThumbMaxWidth'].'" align="center" valign="top"><img src="'.$ImagesURL.'/admin/spacer.gif" width="'.$ecSettings['ThumbMaxWidth'].'" height="1" alt="" border="0"><br>'.$ImageTag.'</td></tr></table></div><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="15" alt="" border="0"><br>';
					}
					else {
						$PageContents .= '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="10" alt="" border="0"><br><div align="center"><table width="80%" border="0" cellpadding="0" cellspacing="0"><tr><td width="'.$ecSettings['ThumbMaxWidth'].'" align="center" valign="top"><img src="'.$ImagesURL.'/admin/spacer.gif" width="'.$ecSettings['ThumbMaxWidth'].'" height="1" alt="" border="0"><br>'.$ImageTag.'</td><td width="10"><img src="'.$ImagesURL.'/admin/spacer.gif" width="10" height="1" alt="" border="0"></td><td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/store/browse/'.$row3['CategoryID'].'.html">'.$row3['Name'].'</a></b>'.$row3['Description'].'<br><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="12" alt="" border="0"><br><a href="'.$MainURL.'/store/browse/'.$row3['CategoryID'].'.html">'.$MsgText[9][272].' '.$row3['Name'].'</a></td></tr></table></div><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="15" alt="" border="0"><br>';
					}
				}

			}
		
		}
		
	
		$CategoryNum = intval($row['RecordNumber']);
		
		if ($row['RecordNumber'] > 0) {
			$query = "select * from `".$Settings['DBPrefix']."ec-Products` where (Category='".$row['RecordNumber']."' or Category2='".$row['RecordNumber']."' or Category3='".$row['RecordNumber']."' or Category4='".$row['RecordNumber']."' or Category5='".$row['RecordNumber']."') and Active=1 order by Name asc";
		}
		else {
			$query = "select * from `".$Settings['DBPrefix']."ec-Products` where Category='".$row['RecordNumber']."' and Active=1 order by Name asc";
		}
		$result = mysql_query($query) or die (mysql_error());
		if (mysql_num_rows($result) > 0) {
		
			if ($SubCatsCount > 0) {
				$PageContents .= '<br><br>';
			}
		
		
			while ($row = mysql_fetch_array($result)) {	
							
				$MinPrice = 10000000000;
				$MaxPrice = 0;
				
				$MinComparePrice = 10000000000;
				$MaxComparePrice = 0;
				
				$StockFound = false;
				$PricesFound = false;
				
				$query2 = "select * from `".$Settings['DBPrefix']."ec-Items` where Product='".$row['RecordNumber']."' order by Price1 asc";
				$result2 = mysql_query($query2) or die (mysql_error());
				while ($row2 = mysql_fetch_array($result2)) {
					
					if ($row2['Price1'] < $MinPrice) {
						$MinPrice = $row2['Price1'];
					}
					if ($row2['Price1'] > $MaxPrice) {
						$MaxPrice = $row2['Price1'];
					}
					
					if ($row2['ComparePrice'] < $MinComparePrice) {
						$MinComparePrice = $row2['ComparePrice'];
					}
					if ($row2['ComparePrice'] > $MaxComparePrice) {
						$MaxComparePrice = $row2['ComparePrice'];
					}
					
					$PricesFound = true;
					
					if ($row2['Stock'] != 0) {
						$StockFound = true;
					}
					
				
				}
				
				if ($MaxPrice > 0 || $ecSettings['ShowNoPricing'] == 'y') {
					// if item details were found 
					
					if ($row['ProductID'] == '') {
						$row['ProductID'] = $row['RecordNumber'];
					}
					
					$ProductsFound++;
					
					$ImageTag = '';
					if ($row['ImageType'] > 0) {
					
						$ImageWidth = $row['ImageWidth'];
						$ImageHeight = $row['ImageHeight'];
						
						$NewWidth = $ecSettings['ThumbMaxWidth'];
						$NewHeight = $ecSettings['ThumbMaxHeight'];
					
						$WidthRatio = $ImageWidth / $NewWidth;
						$HeightRatio = $ImageHeight / $NewHeight;
				
						if ($WidthRatio >= $HeightRatio) {
							$NewWidthCalc = number_format($ImageWidth / $WidthRatio, 0);
							$NewHeightCalc = number_format($ImageHeight / $WidthRatio, 0);
						}
						else {
							$NewWidthCalc = number_format($ImageWidth / $HeightRatio, 0);
							$NewHeightCalc = number_format($ImageHeight / $HeightRatio, 0);
						}
					
						$ImageTag = '<a href="'.$MainURL.'/store/details/'.$row['ProductID'].'/'.$CategoryNum.'.html"><img src="'.$ImagesURL.'/store/store_'.$row['RecordNumber'].$ThumbImageExtension[$row['ImageType']].'" width="'.$NewWidthCalc.'" height="'.$NewHeightCalc.'" alt="" border="0"></a>';
					}
					
										
					
					// check to see if there are any active sales to apply to this item
					
					$Sale = false;
					
					$CurrentTime = GetTimestamp();
					
					$SalesList = '';
					$SalesDetails = '';
					
					$WorkingCategoryNum = $CategoryNum;
					while ($WorkingCategoryNum >= 0) {
						$query24 = "select * from `".$Settings['DBPrefix']."ec-Sales` where StartDate<='".$CurrentTime."' and EndDate>='".$CurrentTime."' and (Categories LIKE '%,".$WorkingCategoryNum.",%' or Products LIKE '%,".$row['RecordNumber'].",%') limit 1";
						$result24 = mysql_query($query24) or die (mysql_error());
						if (mysql_num_rows($result24) > 0) {
							$row24 = mysql_fetch_array($result24);
						
							if ($SalesDetails[$row24['RecordNumber']] == '') {
								$SalesDetails[$row24['RecordNumber']] = $row24;
								$SalesList[] = $row24['RecordNumber'];
							}
						}
						
						if ($WorkingCategoryNum > 0) {
							$query25 = "select * from `".$Settings['DBPrefix']."ec-Categories` where RecordNumber='".$WorkingCategoryNum."' limit 1";
							$result25 = mysql_query($query25) or die (mysql_error());
							$row25 = mysql_fetch_array($result25);
							
							$WorkingCategoryNum = $row25['Parent'];
						}
						else {
							$WorkingCategoryNum = -1;
						}
						
					}
						
					//for ($SalesCount = 0; $SalesCount < count($SalesList); $SalesCount++) {
						$row24 = $SalesDetails[$SalesList[0]];
					//}	
						
					
					if ($row24['DiscountAmount'] > 0 || $row24['DiscountPercent'] > 0) {
					
						if ($row24['DiscountAmount'] > 0) {
							$SaleMinPrice = ($MinPrice - $row24['DiscountAmount']);
							$SaleMaxPrice = ($MaxPrice - $row24['DiscountAmount']);
						}
						if ($row24['DiscountPercent'] > 0) {
							$SaleMinPrice = ($MinPrice - ($MinPrice * ($row24['DiscountPercent']/100)));
							$SaleMaxPrice = ($MaxPrice - ($MaxPrice * ($row24['DiscountPercent']/100)));
						}
												
						$Sale = true;
						$SaleName = $row24['Name'];
						
					}	
					
					
					// end sales portion
					
								
					if ($MinPrice == $MaxPrice) {
						// just one price
						
						if ($Sale == true) {
							if ($MinComparePrice > 0 && $MinComparePrice > $MinPrice) {
								$PriceSection = '<b>SALE! '.$CurrencyBefore.number_format($SaleMinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>, Regular <b>'.$CurrencyBefore.number_format($MinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b> &nbsp;<strike><font color="'.$HighlightColor.'"><b>'.$CurrencyBefore.number_format($MinComparePrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></strike><br><font size="1">'.$SaleName.'</font>';
							}
							else {
								$PriceSection = '<b>SALE! '.$CurrencyBefore.number_format($SaleMinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>, Regular <b>'.$CurrencyBefore.number_format($MinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b><br><font size="1">'.$SaleName.'</font>';
							}
						}
						else {
							if ($MinComparePrice > 0 && $MinComparePrice > $MinPrice) {
								$PriceSection = '<b>'.$CurrencyBefore.number_format($MinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b> &nbsp;<strike><font color="'.$HighlightColor.'"><b>'.$CurrencyBefore.number_format($MinComparePrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></strike>';
							}
							else {
								$PriceSection = '<b>'.$CurrencyBefore.number_format($MinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>';
							}
						}
						
					}
					else {
						// range of prices
						
						if ($Sale == true) {
							if ($MinComparePrice > 0 && $MinComparePrice > $MinPrice) {
								if ($MaxComparePrice > $MinComparePrice) {
									$PriceSection = '<b>SALE! '.$CurrencyBefore.number_format($SaleMinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.' - '.$CurrencyBefore.number_format($SaleMaxPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>, Regular <b>'.$CurrencyBefore.number_format($MinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.' - '.$CurrencyBefore.number_format($MaxPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b> &nbsp;<strike><font color="'.$HighlightColor.'"><b>'.$CurrencyBefore.number_format($MinComparePrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.' - '.$CurrencyBefore.number_format($MaxComparePrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></strike><br><font size="1">'.$SaleName.'</font>';
								}
								else {
									$PriceSection = '<b>SALE! '.$CurrencyBefore.number_format($SaleMinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.' - '.$CurrencyBefore.number_format($SaleMaxPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>, Regular <b>'.$CurrencyBefore.number_format($MinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.' - '.$CurrencyBefore.number_format($MaxPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b> &nbsp;<strike><font color="'.$HighlightColor.'"><b>'.$CurrencyBefore.number_format($MinComparePrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></strike><br><font size="1">'.$SaleName.'</font>';
								}
							}
							else {
								$PriceSection = '<b>SALE! '.$CurrencyBefore.number_format($SaleMinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.' - '.$CurrencyBefore.number_format($SaleMaxPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>, Regular <b>'.$CurrencyBefore.number_format($MinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.' - '.$CurrencyBefore.number_format($MaxPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b><br><font size="1">'.$SaleName.'</font>';
							}
						}
						else {
							if ($MinComparePrice > 0 && $MinComparePrice > $MinPrice) {
								if ($MaxComparePrice > $MinComparePrice) {
									$PriceSection = '<b>'.$CurrencyBefore.number_format($MinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.' - '.$CurrencyBefore.number_format($MaxPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b> &nbsp;<strike><font color="'.$HighlightColor.'"><b>'.$CurrencyBefore.number_format($MinComparePrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.' - '.$CurrencyBefore.number_format($MaxComparePrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></strike>';
								}
								else {
									$PriceSection = '<b>'.$CurrencyBefore.number_format($MinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.' - '.$CurrencyBefore.number_format($MaxPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b> &nbsp;<strike><font color="'.$HighlightColor.'"><b>'.$CurrencyBefore.number_format($MinComparePrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></strike>';
								}
							}
							else {
								$PriceSection = '<b>'.$CurrencyBefore.number_format($MinPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.' - '.$CurrencyBefore.number_format($MaxPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>';
							}
						}
					
					}
					
					
					if ($StockFound == false && $PricesFound == true) {
						$PriceSection = '<font color="'.$HighlightColor.'"><b>'.$SoldOut.'</b></font>';
					}
					
					
					if ($MaxPrice <= 0) {
						$PriceSection = '';
					}
					
					
					if ($ecSettings['CategoryPictureLocation'] == 'R') {
						$PageContents .= '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="10" alt="" border="0"><br><div align="center"><table width="80%" border="0" cellpadding="0" cellspacing="0"><tr><td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/store/details/'.$row['ProductID'].'/'.$CategoryNum.'.html">'.$row['Name'].'</a></b><br>'.$row['ShortDescription'].'<br><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="8" alt="" border="0"><br>'.$PriceSection.'<br><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="8" alt="" border="0"><br><a href="'.$MainURL.'/store/details/'.$row['ProductID'].'/'.$CategoryNum.'.html"><b>'.$MsgText[9][273].'</b></a></td><td width="10"><img src="'.$ImagesURL.'/admin/spacer.gif" width="10" height="1" alt="" border="0"></td><td width="'.$ecSettings['ThumbMaxWidth'].'" align="center" valign="top"><img src="'.$ImagesURL.'/admin/spacer.gif" width="'.$ecSettings['ThumbMaxWidth'].'" height="1" alt="" border="0"><br>'.$ImageTag.'</td></tr></table></div><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="15" alt="" border="0"><br>';
					}
					else {
						$PageContents .= '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="10" alt="" border="0"><br><div align="center"><table width="80%" border="0" cellpadding="0" cellspacing="0"><tr><td width="'.$ecSettings['ThumbMaxWidth'].'" align="center" valign="top"><img src="'.$ImagesURL.'/admin/spacer.gif" width="'.$ecSettings['ThumbMaxWidth'].'" height="1" alt="" border="0"><br>'.$ImageTag.'</td><td width="10"><img src="'.$ImagesURL.'/admin/spacer.gif" width="10" height="1" alt="" border="0"></td><td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/store/details/'.$row['ProductID'].'/'.$CategoryNum.'.html">'.$row['Name'].'</a></b><br>'.$row['ShortDescription'].'<br><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="8" alt="" border="0"><br>'.$PriceSection.'<br><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="8" alt="" border="0"><br><a href="'.$MainURL.'/store/details/'.$row['ProductID'].'/'.$CategoryNum.'.html"><b>'.$MsgText[9][273].'</b></a></td></tr></table></div><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="15" alt="" border="0"><br>';
					}

					
				}
				
			}
	
		}
		
		
		if ($ProductsFound < 1 && $SubCatsCount < 1) {
		
			$PageContents = '['.$MsgText[9][274].']'; 	
		
		}
		else {
		
			$PageContents = $TopText . $PageContents . $BottomText;
		
		}
		
		
	} // end if $Arguments2 == 'browse'
	else if ($Arguments2 == 'details') {
	
		$Product = $Arguments3;
		
	
		$query = "select * from `".$Settings['DBPrefix']."ec-Products` where ProductID='".$Product."' and Active=1 limit 1";
		$result = mysql_query($query) or die (mysql_error());
		$row = mysql_fetch_array($result);
		
		$ThisProductRecordNumber = $row['RecordNumber'];
		
		
		$query8 = "select * from `".$Settings['DBPrefix']."ec-Stats` where ProductID='".$row['RecordNumber']."' and Year='".date('Y',GetTimestamp())."' and Month='".date('n',GetTimestamp())."' and Day='".date('j',GetTimestamp())."' limit 1";
		$result8 = mysql_query($query8) or die (mysql_error());
		if (mysql_num_rows($result8) > 0) {
		// day exists, just increment the number
		
			$query9 = "update `".$Settings['DBPrefix']."ec-Stats` set Count=Count+1 where ProductID='".$row['RecordNumber']."' and Year='".date('Y',GetTimestamp())."' and Month='".date('n',GetTimestamp())."' and Day='".date('j',GetTimestamp())."' limit 1";
			$result9 = mysql_query($query9) or die (mysql_error());
	
		}
		else {
		// day doesn't exist, so add it
		
			$query9 = "insert into `".$Settings['DBPrefix']."ec-Stats` (ProductID,Year,Month,Day,Count) values ('".$row['RecordNumber']."','".date('Y',GetTimestamp())."','".date('n',GetTimestamp())."','".date('j',GetTimestamp())."','1')";
			$result9 = mysql_query($query9) or die (mysql_error());
	
		}
		
		
		$Arguments4 = intval($Arguments4);
		if ($Arguments4 == 0) {
			$Arguments4 = $row['Category'];
		}
		
		
		
		$PageTitle = $row['Name'];
		//$BrowserTitle = $MsgText[9][271].' - '.$row['Name'].' '.$MsgText[9][275];
		$BrowserTitle = $MsgText[9][271].' - '.$row['Name'];
		$LocationBar = '<a href="'.$MainURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/store.html">'.$MsgText[9][271].'</a> > '.BuildNavigationLinks($Arguments4,'product').$MsgText[9][276];
		
		
			
		
		$MinPrice = 10000000000;
		$MaxPrice = 0;
		
		$MinComparePrice = 10000000000;
		$MaxComparePrice = 0;
		
		
		$query2 = "select * from `".$Settings['DBPrefix']."ec-Items` where Product='".$row['RecordNumber']."' order by Option1 asc, Option2 asc, Option3 asc, Price1 asc";
		$result2 = mysql_query($query2) or die (mysql_error());
		if (mysql_num_rows($result2) == 1) {
			// only one item/option
			
			
			if ($Arguments6 != '') {
				$ProductReturn = $Arguments2 .'/'. $Arguments3 .'/'. $Arguments4 .'/'. $Arguments5 .'/'. $Arguments6;
			}
			else if ($Arguments5 != '') {
				$ProductReturn = $Arguments2 .'/'. $Arguments3 .'/'. $Arguments4 .'/'. $Arguments5;
			}
			else if ($Arguments4 != '') {
				$ProductReturn = $Arguments2 .'/'. $Arguments3 .'/'. $Arguments4;
			}
			else {
				$ProductReturn = $Arguments2 .'/'. $Arguments3;
			}
			
		
			$row2 = mysql_fetch_array($result2);
			
			
			$CompareSection = '';
			if ($row2['ComparePrice'] > 0) {
				$CompareSection = '<strike><font color="'.$HighlightColor.'"><b>'.$CurrencyBefore.number_format($row2['ComparePrice'],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></strike><br><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="6" alt="" border="0"><br>';
			}
			
			
			
					// check to see if there are any active sales to apply to this item
					
					$Sale = false;
					
					$CurrentTime = GetTimestamp();
					
					$SalesList = '';
					$SalesDetails = '';
					
					for ($CategoriesCount = 1; $CategoriesCount <= 5; $CategoriesCount++) {
					
						if ($CategoriesCount > 1) {
							$WorkingCategoryNum = $row['Category'.$CategoriesCount];
						}
						else {
							$WorkingCategoryNum = $row['Category'];
						}
							
						while ($WorkingCategoryNum >= 0) {
							$query24 = "select * from `".$Settings['DBPrefix']."ec-Sales` where StartDate<='".$CurrentTime."' and EndDate>='".$CurrentTime."' and (Categories LIKE '%,".$WorkingCategoryNum.",%' or Products LIKE '%,".$row['RecordNumber'].",%') limit 1";
							$result24 = mysql_query($query24) or die (mysql_error());
							if (mysql_num_rows($result24) > 0) {
								$row24 = mysql_fetch_array($result24);
							
								if ($SalesDetails[$row24['RecordNumber']] == '') {
									$SalesDetails[$row24['RecordNumber']] = $row24;
									$SalesList[] = $row24['RecordNumber'];
								}
							}
						
							if ($WorkingCategoryNum > 0) {
								$query25 = "select * from `".$Settings['DBPrefix']."ec-Categories` where RecordNumber='".$WorkingCategoryNum."' limit 1";
								$result25 = mysql_query($query25) or die (mysql_error());
								$row25 = mysql_fetch_array($result25);
								
								$WorkingCategoryNum = $row25['Parent'];
							}
							else {
								$WorkingCategoryNum = -1;
							}
						
						}
						
					} // end loop categories 1-5
						
					//for ($SalesCount = 0; $SalesCount < count($SalesList); $SalesCount++) {
						$row24 = $SalesDetails[$SalesList[0]];
					//}	
						
										
					// end sales portion
			
						
			if ($row2['PriceQty2'] == 0) {
			
			
				if ($row24['DiscountAmount'] > 0 || $row24['DiscountPercent'] > 0) {
					
					if ($row24['DiscountAmount'] > 0) {
						$SaleMinPrice = ($MinPrice - $row24['DiscountAmount']);
						$SaleMaxPrice = ($MaxPrice - $row24['DiscountAmount']);
						$row2['SalePrice1'] = ($row2['Price1'] - $row24['DiscountAmount']);
					}
					if ($row24['DiscountPercent'] > 0) {
						$SaleMinPrice = ($MinPrice - ($MinPrice * ($row24['DiscountPercent']/100)));
						$SaleMaxPrice = ($MaxPrice - ($MaxPrice * ($row24['DiscountPercent']/100)));
						$row2['SalePrice1'] = ($row2['Price1'] - ($row2['Price1'] * ($row24['DiscountPercent']/100)));
					}
											
					$Sale = true;
					$SaleName = $row24['Name'];
						
				}	
			

				if ($Sale == true) {
					$PricePrint = '<b>SALE! '.$CurrencyBefore.number_format($row2['SalePrice1'],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>, Regular <b>'.$CurrencyBefore.number_format($row2['Price1'],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b><br><font size="1">'.$SaleName.'</font>';
				}
				else {
					$PricePrint = '<b>'.$CurrencyBefore.number_format($row2['Price1'],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>';
				}

			}
			else {
				
				for ($i = 1; $i <= 10; $i++) {
					if ($row2['Price'.$i] > 0) {
						
						if ($row2['Price'.$i] < $MinPrice) {
							$MinPrice = $row2['Price'.$i];
						}
						if ($row2['Price'.$i] > $MaxPrice) {
							$MaxPrice = $row2['Price'.$i];
						}
						
						$PricesList[] = $row2['Price'.$i];
						$PriceQuantitiesList[] = $row2['PriceQty'.$i];
						
						
						if ($row24['DiscountAmount'] > 0 || $row24['DiscountPercent'] > 0) {
					
							if ($row24['DiscountAmount'] > 0) {
								$SalePricesList[] = ($row2['Price'.$i] - $row24['DiscountAmount']);
							}
							if ($row24['DiscountPercent'] > 0) {
								$SalePricesList[] = ($row2['Price'.$i] - ($row2['Price'.$i] * ($row24['DiscountPercent']/100)));
							}
															
							$Sale = true;
							$SaleName = $row24['Name'];
							
						}
						
						
					}
				}
				
				$PriceQuantitiesList[0] = 1;
				for ($i = 0; $i < count($PricesList); $i++) {
				
				
					$SaleCol = '';
					if ($Sale == true) {
						$SaleCol = '<td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>'.$CurrencyBefore.number_format($SalePricesList[$i],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>&nbsp;&nbsp;</font></td>';
					}
				
					
					if ($i == 0) {
						if ($PriceQuantitiesList[$i] < ($PriceQuantitiesList[$i+1]-1)) {
							$PricingChart .= '<tr><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;1-'.number_format(($PriceQuantitiesList[$i+1]-1),0).'&nbsp;&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>'.$CurrencyBefore.number_format($PricesList[$i],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>&nbsp;&nbsp;</font></td>'.$SaleCol.'</tr>';
						}
						else {
							$PricingChart .= '<tr><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;1&nbsp;&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>'.$CurrencyBefore.number_format($PricesList[$i],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>&nbsp;&nbsp;</font></td>'.$SaleCol.'</tr>';
						}
					}
					else if ($i < (count($PricesList)-1)) {
						if ($PriceQuantitiesList[$i] < ($PriceQuantitiesList[$i+1]-1)) {
							$PricingChart .= '<tr><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;'.number_format($PriceQuantitiesList[$i],0).'-'.number_format(($PriceQuantitiesList[$i+1]-1),0).'&nbsp;&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>'.$CurrencyBefore.number_format($PricesList[$i],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>&nbsp;&nbsp;</font></td>'.$SaleCol.'</tr>';
						}
						else {
							$PricingChart .= '<tr><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;'.number_format(($PriceQuantitiesList[$i+1]-1),0).'&nbsp;&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>'.$CurrencyBefore.number_format($PricesList[$i],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>&nbsp;&nbsp;</font></td>'.$SaleCol.'</tr>';
						}
					}
					else {
						$PricingChart .= '<tr><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;'.number_format($PriceQuantitiesList[$i],0).'+&nbsp;&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>'.$CurrencyBefore.number_format($PricesList[$i],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>&nbsp;&nbsp;</font></td>'.$SaleCol.'</tr>';
					}
									
				}
				
				
				$SaleRow = '';
				$SaleNameBelow = '';
				if ($Sale == true) {
					$SaleRow = '<tr><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;Regular&nbsp;&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>SALE!</b>&nbsp;&nbsp;</font></td></tr>';
					$SaleNameBelow = '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="3" alt="" border="0"><br><font size="1">'.$SaleName.'</font>';
				}
												
				$PricePrint = '<table cellpadding="3" cellspacing="0" border="0">'.$SaleRow.$PricingChart.'</table>'.$SaleNameBelow;
				
				
			}
			
			
			if ($PricePrint != '') {
			
				if ($row2['Stock'] != 0) {
					if ($row2['Stock'] > 0) {
						if ($ecSettings['DisplayActualStock'] == 'y') {
							if ($row2['Stock'] <= $ecSettings['DisplayActualStockMax']) {
								$StockPrint = '<br><br><b><font color="'.$HighlightColor.'">'.$MsgText[9][279].' '.number_format($row2['Stock'],0).' '.$MsgText[9][280].'</font></b>';
							}
							else {
								$StockPrint = '<br><br><b>'.$InStock.'</b>';
								}				
						}
						else {
							$StockPrint = '<br><br><b>'.$InStock.'</b>';
						}
					}
					else {
						$StockPrint = '<br><br><b>'.$InStock.'</b>';
					}
					
					$AddToCart = '<form name="AddToCart" action="'.$MainURL.'/store/addtocart.html" method="post"><input type="hidden" name="ProductID" value="'.$row['ProductID'].'"><input type="hidden" name="ItemID" value="'.$row2['ItemID'].'"><input type="hidden" name="ProductReturn" value="'.$ProductReturn.'"><input type="text" name="Quantity" value="1" size="2" maxlength="8" style="text-align:center; '.$FormStyle.'">&nbsp;&nbsp;<input type="submit" value="'.$MsgText[9][281].'" style="'.$FormStyle.'"></form>';

				}
				else {
					$AddToCart = '<br><br><font color="'.$HighlightColor.'"><b>'.$SoldOut.'</b></font>';
				}
			
			
				$BottomSection = $CompareSection . $PricePrint . $StockPrint.'<br>'.$AddToCart;
			
			}
		
		}
		else if (mysql_num_rows($result2) > 1) {
			// multiple options
			
			if ($Arguments6 != '') {
				$ItemID = $Arguments6;
				$Option1Selected[$Arguments5] = ' selected';
				$Option2Selected[$Arguments6] = ' selected';
				
				$ProductReturn = $Arguments2 .'/'. $Arguments3 .'/'. $Arguments4 .'/'. $Arguments5 .'/'. $Arguments6;
			}
			else if ($Arguments5 != '') {
				$ItemID = $Arguments5;
				$Option1Selected[$Arguments5] = ' selected';
				
				$ProductReturn = $Arguments2 .'/'. $Arguments3 .'/'. $Arguments4 .'/'. $Arguments5;
			}
			else {
				$ItemID = '';
				
				$ProductReturn = $Arguments2 .'/'. $Arguments3 .'/'. $Arguments4;
			}
			
						
			while ($row2 = mysql_fetch_array($result2)) {
			
				if ($Arguments5 == '') {
					$Arguments5 = $row2['ItemID'];
					$ItemID = $Arguments5;
				}
					
				if ($Option1Printed[$row2['Option1']] != 'y') {
					$Dropdown1 .= '<option value="'.$row2['ItemID'].'"'.$Option1Selected[$row2['ItemID']].'> '.$row2['Option1'].'</option>';
					$Option1Printed[$row2['Option1']] = 'y';
					
					if ($row2['ItemID'] == $Arguments5) {
						$Option1Saved = $row2['Option1'];
					}
				}
				
				//if ($row2['Option2'] != '' && $row2['Option1'] == $Option1Saved) {
				if ($row2['Option1'] == $Option1Saved) {
					if ($row2['Option2'] != '') {
						$Dropdown2Count++;
					}
					
					$Dropdown2 .= '<option value="'.$row2['ItemID'].'"'.$Option2Selected[$row2['ItemID']].'> '.$row2['Option2'].'</option>';
				}
				
				if ($row2['ItemID'] == $ItemID) {
				
					$CompareSection = '';
					if ($row2['ComparePrice'] > 0) {
						$CompareSection = '<strike><font color="'.$HighlightColor.'"><b>'.$CurrencyBefore.number_format($row2['ComparePrice'],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></strike><br><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="6" alt="" border="0"><br>';
					}
					
					$ThisStock = $row2['Stock'];
				
				
					
					// check to see if there are any active sales to apply to this item
					
					$Sale = false;
					
					$CurrentTime = GetTimestamp();
					
					$SalesList = '';
					$SalesDetails = '';
					
					for ($CategoriesCount = 1; $CategoriesCount <= 5; $CategoriesCount++) {
					
						if ($CategoriesCount > 1) {
							$WorkingCategoryNum = $row['Category'.$CategoriesCount];
						}
						else {
							$WorkingCategoryNum = $row['Category'];
						}
							
						while ($WorkingCategoryNum >= 0) {
							$query24 = "select * from `".$Settings['DBPrefix']."ec-Sales` where StartDate<='".$CurrentTime."' and EndDate>='".$CurrentTime."' and (Categories LIKE '%,".$WorkingCategoryNum.",%' or Products LIKE '%,".$row['RecordNumber'].",%') limit 1";
							$result24 = mysql_query($query24) or die (mysql_error());
							if (mysql_num_rows($result24) > 0) {
								$row24 = mysql_fetch_array($result24);
							
								if ($SalesDetails[$row24['RecordNumber']] == '') {
									$SalesDetails[$row24['RecordNumber']] = $row24;
									$SalesList[] = $row24['RecordNumber'];
								}
							}
						
							if ($WorkingCategoryNum > 0) {
								$query25 = "select * from `".$Settings['DBPrefix']."ec-Categories` where RecordNumber='".$WorkingCategoryNum."' limit 1";
								$result25 = mysql_query($query25) or die (mysql_error());
								$row25 = mysql_fetch_array($result25);
								
								$WorkingCategoryNum = $row25['Parent'];
							}
							else {
								$WorkingCategoryNum = -1;
							}
						
						}
						
					} // end loop categories 1-5
						
					//for ($SalesCount = 0; $SalesCount < count($SalesList); $SalesCount++) {
						$row24 = $SalesDetails[$SalesList[0]];
					//}	
														
					
					// end sales portion
					
				
		
					if ($row2['PriceQty2'] == 0) {
					
						
						if ($row24['DiscountAmount'] > 0 || $row24['DiscountPercent'] > 0) {
					
							if ($row24['DiscountAmount'] > 0) {
								$SaleMinPrice = ($MinPrice - $row24['DiscountAmount']);
								$SaleMaxPrice = ($MaxPrice - $row24['DiscountAmount']);
								$row2['SalePrice1'] = ($row2['Price1'] - $row24['DiscountAmount']);
							}
							if ($row24['DiscountPercent'] > 0) {
								$SaleMinPrice = ($MinPrice - ($MinPrice * ($row24['DiscountPercent']/100)));
								$SaleMaxPrice = ($MaxPrice - ($MaxPrice * ($row24['DiscountPercent']/100)));
								$row2['SalePrice1'] = ($row2['Price1'] - ($row2['Price1'] * ($row24['DiscountPercent']/100)));
							}
													
							$Sale = true;
							$SaleName = $row24['Name'];
							
						}
									
						
						if ($Sale == true) {
							$PricePrint = '<b>SALE! '.$CurrencyBefore.number_format($row2['SalePrice1'],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>, Regular <b>'.$CurrencyBefore.number_format($row2['Price1'],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b><br><font size="1">'.$SaleName.'</font>';
						}
						else {
							$PricePrint = '<b>'.$CurrencyBefore.number_format($row2['Price1'],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>';
						}
	
					}
					else {
						
						for ($i = 1; $i <= 10; $i++) {
							if ($row2['Price'.$i] > 0) {
								
								if ($row2['Price'.$i] < $MinPrice) {
									$MinPrice = $row2['Price'.$i];
								}
								if ($row2['Price'.$i] > $MaxPrice) {
									$MaxPrice = $row2['Price'.$i];
								}
								
								$PricesList[] = $row2['Price'.$i];
								$PriceQuantitiesList[] = $row2['PriceQty'.$i];
								
								
								if ($row24['DiscountAmount'] > 0 || $row24['DiscountPercent'] > 0) {
					
									if ($row24['DiscountAmount'] > 0) {
										$SalePricesList[] = ($row2['Price'.$i] - $row24['DiscountAmount']);
									}
									if ($row24['DiscountPercent'] > 0) {
										$SalePricesList[] = ($row2['Price'.$i] - ($row2['Price'.$i] * ($row24['DiscountPercent']/100)));
									}
															
									$Sale = true;
									$SaleName = $row24['Name'];
									
								}
								
								
							}
						}
						
						$PriceQuantitiesList[0] = 1;
						for ($i = 0; $i < count($PricesList); $i++) {
							
							$SaleCol = '';
							if ($Sale == true) {
								$SaleCol = '<td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>'.$CurrencyBefore.number_format($SalePricesList[$i],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>&nbsp;&nbsp;</font></td>';
							}
							
							
							if ($i == 0) {
								if ($PriceQuantitiesList[$i] < ($PriceQuantitiesList[$i+1]-1)) {
									$PricingChart .= '<tr><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;1-'.number_format(($PriceQuantitiesList[$i+1]-1),0).'&nbsp;&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>'.$CurrencyBefore.number_format($PricesList[$i],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>&nbsp;&nbsp;</font></td>'.$SaleCol.'</tr>';
								}
								else {
									$PricingChart .= '<tr><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;1&nbsp;&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>'.$CurrencyBefore.number_format($PricesList[$i],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>&nbsp;&nbsp;</font></td>'.$SaleCol.'</tr>';
								}
							}
							else if ($i < (count($PricesList)-1)) {
								if ($PriceQuantitiesList[$i] < ($PriceQuantitiesList[$i+1]-1)) {
									$PricingChart .= '<tr><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;'.number_format($PriceQuantitiesList[$i],0).'-'.number_format(($PriceQuantitiesList[$i+1]-1),0).'&nbsp;&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>'.$CurrencyBefore.number_format($PricesList[$i],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>&nbsp;&nbsp;</font></td>'.$SaleCol.'</tr>';
								}
								else {
									$PricingChart .= '<tr><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;'.number_format(($PriceQuantitiesList[$i+1]-1),0).'&nbsp;&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>'.$CurrencyBefore.number_format($PricesList[$i],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>&nbsp;&nbsp;</font></td>'.$SaleCol.'</tr>';
								}
							}
							else {
								$PricingChart .= '<tr><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;'.number_format($PriceQuantitiesList[$i],0).'+&nbsp;&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>'.$CurrencyBefore.number_format($PricesList[$i],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b>&nbsp;&nbsp;</font></td>'.$SaleCol.'</tr>';
							}
									
						}
						
						
						$SaleRow = '';
						$SaleNameBelow = '';
						if ($Sale == true) {
							$SaleRow = '<tr><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;Regular&nbsp;&nbsp;</font></td><td align="center"><font face=".$FontFace." size="'.$FontSize.'">&nbsp;&nbsp;<b>SALE!</b>&nbsp;&nbsp;</font></td></tr>';
							$SaleNameBelow = '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="3" alt="" border="0"><br><font size="1">'.$SaleName.'</font>';
						}
												
						$PricePrint = '<table cellpadding="3" cellspacing="0" border="0">'.$SaleRow.$PricingChart.'</table>'.$SaleNameBelow;
						
					}
				
					
				}
			
			}
			
			
			$BottomSection = '<br><a name="options"></a>';
				
			if ($Dropdown1 != '') {
				$BottomSection .= '<form name="ProductOptions"><br><b>'.$MsgText[9][282].':</b><br><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="8" alt="" border="0"><br>';
				
				if ($row['Option1Title'] != '') {
					$BottomSection .= '<br><b>'.$row['Option1Title'].'</b>:<br>';
				}
				$BottomSection .= '<select name="ItemOption1" style="'.$FormStyle.'" onchange="window.location=\''.$MainURL.'/store/'.$Arguments2.'/'.$Arguments3.'/'.$Arguments4.'/\'+document.forms[\'ProductOptions\'].elements[\'ItemOption1\'].value+\'#options\';">'.$Dropdown1.'</select>';

				if ($Dropdown2 != '' && $Dropdown2Count > 0) {
				
					if ($row['Option2Title'] != '') {
						$BottomSection .= '<br><br><b>'.$row['Option2Title'].'</b>:<br>';
					}
				
					$BottomSection .= '<select name="ItemOption2" style="'.$FormStyle.'" onchange="window.location=\''.$MainURL.'/store/'.$Arguments2.'/'.$Arguments3.'/'.$Arguments4.'/'.$Arguments5.'/\'+document.forms[\'ProductOptions\'].elements[\'ItemOption2\'].value+\'#options\';">'.$Dropdown2.'</select><br><br>';
				}
				
				$BottomSection .= '</form>';
			}
			
			$BottomSection .= $CompareSection . $PricePrint;
			
			
			if ($ThisStock != 0) {
				if ($ThisStock > 0) {
					if ($ecSettings['DisplayActualStock'] == 'y') {
						if ($ThisStock <= $ecSettings['DisplayActualStockMax']) {
							$StockPrint = '<br><br><b><font color="'.$HighlightColor.'">'.$MsgText[9][279].' '.number_format($ThisStock,0).' '.$MsgText[9][280].'</font></b>';
						}
						else {
							$StockPrint = '<br><br><b>'.$InStock.'</b>';
						}				
					}
					else {
						$StockPrint = '<br><br><b>'.$InStock.'</b>';
					}
				}
				else {
					$StockPrint = '<br><br><b>'.$InStock.'</b>';
				}
					
				$AddToCart = '<form name="AddToCart" action="'.$MainURL.'/store/addtocart.html" method="post"><input type="hidden" name="ProductID" value="'.$row['ProductID'].'"><input type="hidden" name="ItemID" value="'.$ItemID.'"><input type="hidden" name="ProductReturn" value="'.$ProductReturn.'"><input type="text" name="Quantity" value="1" size="2" maxlength="8" style="text-align:center; '.$FormStyle.'">&nbsp;&nbsp;<input type="submit" value="'.$MsgText[9][281].'" style="'.$FormStyle.'"></form>';

			}
			else {
				$AddToCart = '<br><br><font color="'.$HighlightColor.'"><b>'.$SoldOut.'</b></font>';
			}
				
			$BottomSection .= $StockPrint.'<br>'.$AddToCart.'</font><br>';
					
		}
		else {
			// no pricing information located
			
			$BottomSection = '<br><br>'.$MsgText[9][283];
			
		}
		
		
		
		
		if ($row['ImageType'] > 0) {
		
			if ($row['ImageType2'] > 0 || $row['ImageType3'] > 0 || $row['ImageType4'] > 0 || $row['ImageType5'] > 0) {
			
				$MaxWidth = max($row['ImageWidth'], $row['ImageWidth2'], $row['ImageWidth3'], $row['ImageWidth4'], $row['ImageWidth5']);
				$MaxHeight = max($row['ImageHeight'], $row['ImageHeight2'], $row['ImageHeight3'], $row['ImageHeight4'], $row['ImageHeight5']);
				
				
				$ScriptSection = '<script>
					var CurrentPic = 1;
				
					var ImageURLs = new Array("", "'.$ImagesURL.'/store/store_'.$row['RecordNumber'].$ImageExtension[$row['ImageType']].'", "'.$ImagesURL.'/store/store_'.$row['RecordNumber'].'_2'.$ImageExtension[$row['ImageType2']].'", "'.$ImagesURL.'/store/store_'.$row['RecordNumber'].'_3'.$ImageExtension[$row['ImageType3']].'", "'.$ImagesURL.'/store/store_'.$row['RecordNumber'].'_4'.$ImageExtension[$row['ImageType4']].'", "'.$ImagesURL.'/store/store_'.$row['RecordNumber'].'_5'.$ImageExtension[$row['ImageType5']].'");
				
					var ImageWidths = new Array(1, '.number_format($row['ImageWidth'],0,'','').', '.number_format($row['ImageWidth2'],0,'','').', '.number_format($row['ImageWidth3'],0,'','').', '.number_format($row['ImageWidth4'],0,'','').', '.number_format($row['ImageWidth5'],0,'','').');

					var ImageHeights = new Array(1, '.number_format($row['ImageHeight'],0,'','').', '.number_format($row['ImageHeight2'],0,'','').', '.number_format($row['ImageHeight3'],0,'','').', '.number_format($row['ImageHeight4'],0,'','').', '.number_format($row['ImageHeight5'],0,'','').');


					var LargeImageURLs = new Array("", "'.$ImagesURL.'/store/store_'.$row['RecordNumber'].'-large'.$ImageExtension[$row['ImageType']].'", "'.$ImagesURL.'/store/store_'.$row['RecordNumber'].'_2-large'.$ImageExtension[$row['ImageType2']].'", "'.$ImagesURL.'/store/store_'.$row['RecordNumber'].'_3-large'.$ImageExtension[$row['ImageType3']].'", "'.$ImagesURL.'/store/store_'.$row['RecordNumber'].'_4-large'.$ImageExtension[$row['ImageType4']].'", "'.$ImagesURL.'/store/store_'.$row['RecordNumber'].'_5-large'.$ImageExtension[$row['ImageType5']].'");

					var LargeImageWidths = new Array(1, '.number_format($row['LargeImageWidth'],0,'','').', '.number_format($row['LargeImageWidth2'],0,'','').', '.number_format($row['LargeImageWidth3'],0,'','').', '.number_format($row['LargeImageWidth4'],0,'','').', '.number_format($row['LargeImageWidth5'],0,'','').');

					var LargeImageHeights = new Array(1, '.number_format($row['LargeImageHeight'],0,'','').', '.number_format($row['LargeImageHeight2'],0,'','').', '.number_format($row['LargeImageHeight3'],0,'','').', '.number_format($row['LargeImageHeight4'],0,'','').', '.number_format($row['LargeImageHeight5'],0,'','').');
					
					
					function ViewLargeImage() {
		
						var Width = "'.($ecSettings['LargeImageMaxWidth']+100).'";
						var Height = "'.($ecSettings['LargeImageMaxHeight']+110).'";
			
						var Left = "150";
						var Top = "50";
			
						if (screen.width > 0) {
							Left = ((screen.width-Width)/2);
						}
						if (screen.height > 0) {
							Top = ((screen.height-Height)/2);
						}
		
						var WindowID = window.open("'.$MainURL.'/store/image/'.$row['RecordNumber'].'/"+CurrentPic,"ViewLargeImage","width="+Width+",height="+Height+",top="+Top+",left="+Left+",toolbars=no,scrollbars=no");
			
						//WindowID.document.write(\'<html><head></head><body bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000" alink="#000000" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" rightmargin="0" style="margin:0"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><a href="javascript:window.close();"><img id="MainImage" src="\'+LargeImageURLs[CurrentPic]+\'" width="\'+LargeImageWidths[CurrentPic]+\'" height="\'+LargeImageHeights[CurrentPic]+\'" alt="" border="0"></a></td></tr></table></body></html>\');
					}
					
					
					function SwapThumb(NewPicID) {
						var PictureHandle = document.getElementById("MainImage");
						PictureHandle.src = ImageURLs[NewPicID];
						PictureHandle.width = ImageWidths[NewPicID];
						PictureHandle.height = ImageHeights[NewPicID];
						
						CurrentPic = NewPicID;
					}
				</script>';
				
				
				$ThumbsSection = '<br><br><table width="100%" cellpadding="3" cellspacing="0" border="0"><tr>';				
			
				$RowCount++;
				
				$ThumbsSection .= '<td align="center"><a href="javascript:SwapThumb(1);"><img src="'.$ImagesURL.'/store/store_'.$row['RecordNumber'].$ThumbImageExtension[$row['ImageType']].'" alt="" border="0"></a></td>';


				for ($ThumbCounter = 2; $ThumbCounter <= 5; $ThumbCounter++) {
				
					if ($row['ImageType'.$ThumbCounter] > 0) {
					
						$RowCount++;
				
						$ThumbsSection .= '<td align="center"><a href="javascript:SwapThumb('.$ThumbCounter.');"><img src="'.$ImagesURL.'/store/store_'.$row['RecordNumber'].'_'.$ThumbCounter.$ThumbImageExtension[$row['ImageType'.$ThumbCounter]].'" alt="" border="0"></a></td>';
					
						if ($RowCount == 2) {
							$ThumbsSection .= '</tr><tr>';
							$RowCount = 0;
						}
						
					}
					
				}
				
				
				$ThumbsSection .= '</tr></table>';
			}
			else {
			
				
				$ScriptSection = '<script>
									
					function ViewLargeImage() {
		
						var Width = "'.($ecSettings['LargeImageMaxWidth']+100).'";
						var Height = "'.($ecSettings['LargeImageMaxHeight']+110).'";
			
						var Left = "150";
						var Top = "50";
			
						if (screen.width > 0) {
							Left = ((screen.width-Width)/2);
						}
						if (screen.height > 0) {
							Top = ((screen.height-Height)/2);
						}
		
						//var WindowID = window.open("","ViewLargeImage","width="+Width+",height="+Height+",top="+Top+",left="+Left+",toolbars=no,scrollbars=no");
						var WindowID = window.open("'.$MainURL.'/store/image/'.$row['RecordNumber'].'/1","ViewLargeImage","width="+Width+",height="+Height+",top="+Top+",left="+Left+",toolbars=no,scrollbars=no");
			
						//WindowID.document.write(\'<html><head></head><body bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000" alink="#000000" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" rightmargin="0" style="margin:0"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><a href="javascript:window.close();"><img id="MainImage" src="'.$ImagesURL.'/store/store_'.$row['RecordNumber'].'-large'.$ImageExtension[$row['LargeImageType']].'" width="'.$row['LargeImageWidth'].'" height="'.$row['LargeImageHeight'].'" alt="" border="0"></a></td></tr></table></body></html>\');
					}
					
				</script>';
			
			
			}
				 
		
		}
		
		
		
		
		if ($row['LargeImageType'] > 0 || $row['LargeImageType2'] > 0 || $row['LargeImageType3'] > 0 || $row['LargeImageType4'] > 0 || $row['LargeImageType5'] > 0) {
			
			if ($ecSettings['DetailsPictureLocation'] == 'R') {
				$PageContents .= '<div align="center"><table width="90%" border="0" cellpadding="0" cellspacing="0"><tr><td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'">'.str_replace("\n",'<br>',$row['Description']).'<br><br><br><br>'.$BottomSection.'</td><td><img src="'.$ImagesURL.'/admin/spacer.gif" width="15" height="15" alt="" border="0"></td><td valign="top" align="center"><table width="'.$MaxWidth.'" height="'.$MaxHeight.'" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><a href="javascript:ViewLargeImage();"><img id="MainImage" src="'.$ImagesURL.'/store/store_'.$row['RecordNumber'].$ImageExtension[$row['ImageType']].'" width="'.$row['ImageWidth'].'" height="'.$row['ImageHeight'].'" alt="'.$MsgText[9][277].'" border="0"></a></td></tr></table><a href="javascript:ViewLargeImage();"><font size="1">'.$MsgText[9][278].'</font></a>'.$ThumbsSection.'</td></tr></table></div>';
			}
			else {
				$PageContents .= '<div align="center"><table width="90%" border="0" cellpadding="0" cellspacing="0"><tr><td valign="top" align="center"><table width="'.$MaxWidth.'" height="'.$MaxHeight.'" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><a href="javascript:ViewLargeImage();"><img id="MainImage" src="'.$ImagesURL.'/store/store_'.$row['RecordNumber'].$ImageExtension[$row['ImageType']].'" width="'.$row['ImageWidth'].'" height="'.$row['ImageHeight'].'" alt="'.$MsgText[9][277].'" border="0"></a></td></tr></table><a href="javascript:ViewLargeImage();"><font size="1">'.$MsgText[9][278].'</font></a>'.$ThumbsSection.'</td><td><img src="'.$ImagesURL.'/admin/spacer.gif" width="15" height="15" alt="" border="0"></td><td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'">'.str_replace("\n",'<br>',$row['Description']).'<br><br><br><br>'.$BottomSection.'</td></tr></table></div>';
			}		
		}
		else if ($row['ImageType'] > 0) {
			if ($ecSettings['DetailsPictureLocation'] == 'R') {
				$PageContents .= '<div align="center"><table width="90%" border="0" cellpadding="0" cellspacing="0"><tr><td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'">'.str_replace("\n",'<br>',$row['Description']).'<br><br><br><br>'.$BottomSection.'</td><td><img src="'.$ImagesURL.'/admin/spacer.gif" width="15" height="15" alt="" border="0"></td><td valign="top" align="center"><table width="'.$MaxWidth.'" height="'.$MaxHeight.'" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><img id="MainImage" src="'.$ImagesURL.'/store/store_'.$row['RecordNumber'].$ImageExtension[$row['ImageType']].'" width="'.$row['ImageWidth'].'" height="'.$row['ImageHeight'].'" alt="'.$MsgText[9][277].'" border="0"></td></tr></table>'.$ThumbsSection.'</td></tr></table></div>';
			}
			else {
				$PageContents .= '<div align="center"><table width="90%" border="0" cellpadding="0" cellspacing="0"><tr><td valign="top" align="center"><table width="'.$MaxWidth.'" height="'.$MaxHeight.'" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><img id="MainImage" src="'.$ImagesURL.'/store/store_'.$row['RecordNumber'].$ImageExtension[$row['ImageType']].'" width="'.$row['ImageWidth'].'" height="'.$row['ImageHeight'].'" alt="'.$MsgText[9][277].'" border="0"></td></tr></table>'.$ThumbsSection.'</td><td><img src="'.$ImagesURL.'/admin/spacer.gif" width="15" height="15" alt="" border="0"></td><td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'">'.str_replace("\n",'<br>',$row['Description']).'<br><br><br><br>'.$BottomSection.'</td></tr></table></div>';
			}			
		}
		else {
		
			$PageContents .= '<div align="center"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'">'.str_replace("\n",'<br>',$row['Description']).'<br><br>'.$BottomSection.'</font></td></tr></table></div>';
		
		}
		
		
				
		$query69 = "select * from `".$Settings['DBPrefix']."ec-Products` where (Category='".intval($Arguments4)."' or Category2='".intval($Arguments4)."' or Category3='".intval($Arguments4)."' or Category4='".intval($Arguments4)."' or Category5='".intval($Arguments4)."') and Active=1 order by Name asc";
		$result69 = mysql_query($query69) or die (mysql_error());
		if (mysql_num_rows($result69) > 1) {
			while ($row69 = mysql_fetch_array($result69)) {
			
				$query691 = "select * from `".$Settings['DBPrefix']."ec-Items` where Product='".$row69['RecordNumber']."' and Price1>0 limit 1";
				$result691 = mysql_query($query691) or die (mysql_error());
				if (mysql_num_rows($result691) > 0) {
			
					$ProdIDsCounter++;
					$ProdIDsArray[] = $row69['ProductID'];
					$ProdNamesArray[] = $row69['Name'];
				
					if ($row69['RecordNumber'] == $ThisProductRecordNumber) {
						$ThisProductPosition = $ProdIDsCounter;
					}
					
				}
						
			}
			
			
			$PrevProdID = ($ThisProductPosition-1);
			$NextProdID = ($ThisProductPosition+1);
			
			if ($PrevProdID < 1) {
				if ($ProdIDsCounter >= 3) {
					$PrevProdID = $ProdIDsCounter;
				}
			}
			if ($NextProdID > $ProdIDsCounter) {
				if ($ProdIDsCounter >= 3) {
					$NextProdID = 1;
				}
			}
			
			
			if ($PrevProdID > 0) {
				$PrevProdLink = '<a href="'.$MainURL.'/store/details/'.$ProdIDsArray[($PrevProdID-1)].'/'.$Arguments4.'.html">'.$ProdNamesArray[($PrevProdID-1)].'</a>';
			}
			if ($NextProdID <= $ProdIDsCounter) {
				$NextProdLink = '<a href="'.$MainURL.'/store/details/'.$ProdIDsArray[($NextProdID-1)].'/'.$Arguments4.'.html">'.$ProdNamesArray[($NextProdID-1)].'</a>';
			}
			
			
			//$PageContents .= '<br><br><div align="center"><table width="95%" border="0" cellpadding="0" cellspacing="0"><tr><td width="5%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&lt;</font></td><td width="42%" align="left"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$PrevProdLink.'&nbsp;</font></td><td width="6%"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></td><td width="42%" align="right"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;'.$NextProdLink.'</font></td><td width="5%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&gt;</font></td></tr></table></div>';
			$PageContents = '<div align="center"><table width="95%" border="0" cellpadding="0" cellspacing="0"><tr><td width="5%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&lt;</font></td><td width="42%" align="left"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$PrevProdLink.'&nbsp;</font></td><td width="6%"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></td><td width="42%" align="right"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;'.$NextProdLink.'</font></td><td width="5%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&gt;</font></td></tr></table></div><br><br>'
 . $PageContents .
'<br><br><div align="center"><table width="95%" border="0" cellpadding="0" cellspacing="0"><tr><td width="5%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&lt;</font></td><td width="42%" align="left"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$PrevProdLink.'&nbsp;</font></td><td width="6%"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></td><td width="42%" align="right"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;'.$NextProdLink.'</font></td><td width="5%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&gt;</font></td></tr></table></div>';
			
		}
		
			
		
		$PageContents .= $ScriptSection;
		
		
	} // end if $Arguments2 == 'details'
	else if ($Arguments2 == 'image') {
	
		
		$Arguments3 = intval($Arguments3);
		$Arguments4 = intval($Arguments4);
		$Arguments5 = intval($Arguments5);
		
					
			
			$SlideshowRunning = "false";
			if ($Arguments5 == 1) {
				$SlideshowRunning = "true";
			}
			
			
			$query5 = "select * from `".$Settings['DBPrefix']."ec-Products` where RecordNumber=".$Arguments3." limit 1";
			$result5 = mysql_query($query5) or die (mysql_error());
			$row5 = mysql_fetch_array($result5);
			
			
			if ($row5['Name'] != '') {
				$BrowserTitle = $row5['Name'];
			}
						
			
			if ($row5['LargeImageType'] > 0) {
				$ImageIDs[] = 1;
			}
			if ($row5['LargeImageType2'] > 0) {
				$ImageIDs[] = 2;
			}
			if ($row5['LargeImageType3'] > 0) {
				$ImageIDs[] = 3;
			}
			if ($row5['LargeImageType4'] > 0) {
				$ImageIDs[] = 4;
			}
			if ($row5['LargeImageType5'] > 0) {
				$ImageIDs[] = 5;
			}
			
			$ArrayLength = count($ImageIDs);
			
			if ($ArrayLength > 1) {
			
				for ($x = 0; $x < $ArrayLength; $x++) {
				
					if ($ImageIDs[$x] == $Arguments4) {
					
						$CurrentImagePosition = $x;
					
						if ($x == 0) {
							$PreviousImageID = $ImageIDs[$ArrayLength-1];
							$NextImageID = $ImageIDs[$x+1];
						}
						else if ($x == $ArrayLength-1) {
							$PreviousImageID = $ImageIDs[$x-1];
							$NextImageID = $ImageIDs[0];
						}
						else {
							$PreviousImageID = $ImageIDs[$x-1];
							$NextImageID = $ImageIDs[$x+1];
						}
					
					}
				
				}
			
				// pick a random id for the next one if 'random' is clicked,
				// making sure it isn't the same one they're viewing now
				$ImageIDs[$CurrentImagePosition] = $ImageIDs[$ArrayLength-1];
		
				$RandomNumber = rand(0,$ArrayLength-2);
				$RandomImageID = $ImageIDs[$RandomNumber];
				
				
				$NavigationButtons = '<table width="80%" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="20%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/store/image/'.$Arguments3.'/'.$PreviousImageID.'.html">'.$MsgText[3][70].'</a></font></td>
      <td width="20%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/store/image/'.$Arguments3.'/'.$NextImageID.'.html">'.$MsgText[3][71].'</a></font></td>
      <td width="10%">&nbsp;</td>
      <td width="20%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/store/image/'.$Arguments3.'/'.$RandomImageID.'.html">'.$MsgText[3][72].'</a></font></td>
      <td width="10%">&nbsp;</td>
      <td width="20%" align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:StartStopSlideshow();">'.$MsgText[3][73].'</a></font></td>
    </tr>
</table>';
				
			}
			else {
		
				$NavigationButtons = '<a href="javascript:window.close();">'.$MsgText[3][8].'</a>';	
			
			}
			
			
			if ($Arguments4 > 1) {
				$ImageNumberPart = '_'.$Arguments4;
				$ImageNumberPart2 = $Arguments4;
			}
			
			$Extensions[1] = '.gif';
			$Extensions[2] = '.jpg';
			$Extensions[3] = '.png';
			
			$PageContents = '<div align="center"><table width="100%" height="'.($ecSettings['LargeImageMaxHeight']+2).'" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><table border="0" cellpadding="1" cellspacing="0"><tr><td bgcolor="'.$Colors['Text'].'"><table border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="'.$Colors['BG'].'"><img src="'.$ImagesURL.'/store/store_'.$Arguments3.$ImageNumberPart.'-large'.$Extensions[$row5['LargeImageType'.$ImageNumberPart2]].'" width="'.$row5['LargeImageWidth'.$ImageNumberPart2].'" height="'.$row5['LargeImageHeight'.$ImageNumberPart2].'" border="0"></td></tr></table></td></tr></table></td></tr></table><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""><br><table width="100%" height="80" border="0" cellpadding="0" cellspacing="0"><tr><td height="40" align="center" valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$row5['Name'].'</b></font></td></tr><tr><td align="center" valign="middle" height="40"><script>
				
					var SlideshowRunning = '.$SlideshowRunning.';
					var TimerCode = "";
					
					function PageLoaded() {
						if (SlideshowRunning == true) {
							TimerCode = window.setInterval(AdvanceSlideshow,5000);
						}
					}
					
					function StartStopSlideshow() {
					
						if (SlideshowRunning == false) {
							SlideshowRunning = true;
							TimerCode = window.setInterval(AdvanceSlideshow,5000);
						}
						else {
							SlideshowRunning = false;
							window.clearInterval(TimerCode);
						}
					
					}
					
					function AdvanceSlideshow() {
						window.location = "'.$MainURL.'/store/image/'.$Arguments3.'/'.$NextImageID.'/1.html";
					}
				
				</script>'.$NavigationButtons.'</td></tr></table></div>';
		
				
		
	
		
		print '<html><head>
<title>'.$BrowserTitle.'</title>
<meta name="Description" content="">
<meta name="Keywords" content="">
<meta name="Author" content="">
<meta name="Generator" content="">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
</head>
<body bgcolor="'.$Colors['BG'].'" text="'.$Colors['Text'].'" link="'.$Colors['Link'].'" vlink="'.$Colors['VLink'].'" alink="'.$Colors['ALink'].'" leftmargin="5" marginwidth="5" topmargin="5" marginheight="5" rightmargin="5" style="margin:5" onLoad="PageLoaded();">
'.$PageContents.'
</body>
</html>';

		exit();
		
		

	} // end if $Arguments2 == 'image'
	else if ($Arguments2 == 'addtocart') {
	
		ReadFormArguments();
		Global $FormArguments;
		
		$FormArguments['Quantity'] = intval($FormArguments['Quantity']);
		
		
		$query = "select * from `".$Settings['DBPrefix']."ec-Products` where ProductID='".$FormArguments['ProductID']."' and Active=1 limit 1";
		$result = mysql_query($query) or die (mysql_error());
		$row = mysql_fetch_array($result);
		
		$ProductNumber = $row['RecordNumber'];
	
		$query2 = "select * from `".$Settings['DBPrefix']."ec-Items` where Product='".$row['RecordNumber']."' and ItemID='".$FormArguments['ItemID']."' limit 1";
		$result2 = mysql_query($query2) or die (mysql_error());
		$row2 = mysql_fetch_array($result2);
		
		$ItemNumber = $row2['RecordNumber'];
		
			
		if ($row2['Option2'] != '') {
			$row['Name'] .= ' ('.$row2['Option1'].', '.$row2['Option2'].')';
		}
		else if ($row2['Option1'] != '') {
			$row['Name'] .= ' ('.$row2['Option1'].')';
		}
		
		
		$PricingLevel = 1;
		for ($i = 1; $i <= 10; $i++) {
			if ($row2['PriceQty'.$i] > 0 && $FormArguments['Quantity'] >= $row2['PriceQty'.$i]) {
				$PricingLevel = $i;
			}
		}
		
		
		if ($LoggedIn == 'y') {
			$query3 = "select ShoppingCartContents from `".$Settings['DBPrefix']."core-Users` where Username='".$CookieUsername."' limit 1";
			$result3 = mysql_query($query3) or die (mysql_error());
			$row3 = mysql_fetch_array($result3);
			$ShoppingCartContents = $row3['ShoppingCartContents'];
		}
		else {
			if ($HTTP_COOKIE_VARS[$CookieName.'Cart'] != 'empty') {
				$ShoppingCartContents = $HTTP_COOKIE_VARS[$CookieName.'Cart'];
			}
		}
			
		
		if ($ShoppingCartContents != '') {
			$ItemsList = explode(',',$ShoppingCartContents);
			$ItemFound = false;
				
			for ($i = 0; $i < (count($ItemsList)-1); $i++) {
				list ($ItemNum, $Qty) = explode('x',$ItemsList[$i]);
				
				if ($ItemNum == $ItemNumber) {
					$Qty += $FormArguments['Quantity'];
					$ItemsList[$i] = $ItemNum.'x'.$Qty;
					$ItemFound = true;
				}
			}
				
			if ($ItemFound == true) {
				$NewCartContents = implode(',',$ItemsList);				
			}
			else {
				$NewCartContents = $ShoppingCartContents . $ItemNumber.'x'.$FormArguments['Quantity'].',';
			}							
		}
		else {
			$NewCartContents = $ItemNumber.'x'.$FormArguments['Quantity'].',';
		}
		
		
		if ($LoggedIn == 'y') {
			$query3 = "update `".$Settings['DBPrefix']."core-Users` set ShoppingCartContents='".$NewCartContents."' where Username='".$CookieUsername."' limit 1";
			$result3 = mysql_query($query3) or die (mysql_error());
		}
		else {
			setcookie ($CookieName.'Cart', $NewCartContents, 0, '/');
		}
		
		
		
		
					// check to see if there are any active sales to apply to this item
					
					$Sale = false;
					
					$CurrentTime = GetTimestamp();
					
					$SalesList = '';
					$SalesDetails = '';
					
					for ($CategoriesCount = 1; $CategoriesCount <= 5; $CategoriesCount++) {
					
						if ($CategoriesCount > 1) {
							$WorkingCategoryNum = $row['Category'.$CategoriesCount];
						}
						else {
							$WorkingCategoryNum = $row['Category'];
						}
							
						while ($WorkingCategoryNum >= 0) {
							$query24 = "select * from `".$Settings['DBPrefix']."ec-Sales` where StartDate<='".$CurrentTime."' and EndDate>='".$CurrentTime."' and (Categories LIKE '%,".$WorkingCategoryNum.",%' or Products LIKE '%,".$row['RecordNumber'].",%') limit 1";
							$result24 = mysql_query($query24) or die (mysql_error());
							if (mysql_num_rows($result24) > 0) {
								$row24 = mysql_fetch_array($result24);
							
								if ($SalesDetails[$row24['RecordNumber']] == '') {
									$SalesDetails[$row24['RecordNumber']] = $row24;
									$SalesList[] = $row24['RecordNumber'];
								}
							}
						
							if ($WorkingCategoryNum > 0) {
								$query25 = "select * from `".$Settings['DBPrefix']."ec-Categories` where RecordNumber='".$WorkingCategoryNum."' limit 1";
								$result25 = mysql_query($query25) or die (mysql_error());
								$row25 = mysql_fetch_array($result25);
								
								$WorkingCategoryNum = $row25['Parent'];
							}
							else {
								$WorkingCategoryNum = -1;
							}
						
						}
						
					} // end loop categories 1-5
					
						
					//for ($SalesCount = 0; $SalesCount < count($SalesList); $SalesCount++) {
						$row24 = $SalesDetails[$SalesList[0]];
					//}	
						
					
					if ($row24['DiscountAmount'] > 0 || $row24['DiscountPercent'] > 0) {
					
						if ($row24['DiscountAmount'] > 0) {
							$row2['Price'.$PricingLevel] = ($row2['Price'.$PricingLevel] - $row24['DiscountAmount']);
						}
						if ($row24['DiscountPercent'] > 0) {
							$row2['Price'.$PricingLevel] = ($row2['Price'.$PricingLevel] - ($row2['Price'.$PricingLevel] * ($row24['DiscountPercent']/100)));
						}
												
						$Sale = true;
						$SaleName = $row24['Name'];
						
					}	
					
					
					// end sales portion
		
						
		
		$ItemPrice = $CurrencyBefore.number_format($row2['Price'.$PricingLevel],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter;
		
		$Subtotal = $CurrencyBefore.number_format(($row2['Price'.$PricingLevel]*$FormArguments['Quantity']),$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter;
		
		if ($FormArguments['Quantity'] == 1) {
			$Message = $MsgText[9][284];
		}
		else {
			$Message = $MsgText[9][285];
		}
			
		$PageContents = $Message.':<br><br><br><b>'.$row['Name'].'<br><br>'.$MsgText[9][286].': '.$FormArguments['Quantity'].'<br><br>'.$MsgText[9][250].': '.$ItemPrice.'<br><br>'.$MsgText[9][252].': '.$Subtotal.'</b><br><br><br><br><b><a href="'.$MainURL.'/store/'.$FormArguments['ProductReturn'].'.html">'.$MsgText[9][287].'</a><br><br><a href="'.$MainURL.'/store.html">'.$MsgText[9][288].'</a><br><br><a href="'.$MainURL.'/store/viewcart.html">'.$MsgText[9][289].'</a><br><br><a href="'.$MainURL.'/store/viewcart.html">'.$MsgText[9][290].'</a></b><br><br><br><br><div align="center"><font size="'.($FontSize-1).'">'.$MsgText[9][291].'</font></div>';
	
	
	} // end if $Arguments2 == 'addtocart'
	else if ($Arguments2 == 'viewcart') {
	
		$PageTitle = $MsgText[9][271].' - '.$MsgText[9][289];
		$BrowserTitle = $MsgText[9][271].' - '.$MsgText[9][289];
		$LocationBar = '<a href="'.$MainURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/store.html">'.$MsgText[9][271].'</a> > '.$MsgText[9][289];
		
		
		if ($LoggedIn == 'y') {
			$query3 = "select ShoppingCartContents from `".$Settings['DBPrefix']."core-Users` where Username='".$CookieUsername."' limit 1";
			$result3 = mysql_query($query3) or die (mysql_error());
			$row3 = mysql_fetch_array($result3);
			$ShoppingCartContents = $row3['ShoppingCartContents'];
		}
		else {
			if ($HTTP_COOKIE_VARS[$CookieName.'Cart'] != 'empty') {
				$ShoppingCartContents = $HTTP_COOKIE_VARS[$CookieName.'Cart'];
			}
		}
		
		if ($ShoppingCartContents != '') {
			$ItemsList = explode(',',$ShoppingCartContents);
			$ItemFound = false;
				
			for ($i = 0; $i < (count($ItemsList)-1); $i++) {
				list ($ItemNumA, $Qty) = explode('x',$ItemsList[$i]);
				
				list ($ItemNum, $Incentive) = explode('-', $ItemNumA);
				
				
				$query3 = "select * from `".$Settings['DBPrefix']."ec-Items` where RecordNumber='".$ItemNum."' limit 1";
				$result3 = mysql_query($query3) or die (mysql_error());
				$row3 = mysql_fetch_array($result3);
						
				$query4 = "select * from `".$Settings['DBPrefix']."ec-Products` where RecordNumber='".$row3['Product']."' limit 1";
				$result4 = mysql_query($query4) or die (mysql_error());
				$row4 = mysql_fetch_array($result4);
				
						
				if ($row3['Option2'] != '') {
					$row4['Name'] .= ' ('.$row3['Option1'].', '.$row3['Option2'].')';
				}
				else if ($row3['Option1'] != '') {
					$row4['Name'] .= ' ('.$row3['Option1'].')';
				}
				
				
				if ($Incentive == '') {
					
									
					$PricingLevel = 1;
					for ($k = 1; $k <= 10; $k++) {
						if ($row3['PriceQty'.$k] > 0 && $Qty >= $row3['PriceQty'.$k]) {
							$PricingLevel = $k;
						}
					}
					
					
					
					// check to see if there are any active sales to apply to this item
					
					$Sale = false;
					
					$CurrentTime = GetTimestamp();
					
					$SalesList = '';
					$SalesDetails = '';
					
					for ($CategoriesCount = 1; $CategoriesCount <= 5; $CategoriesCount++) {
					
						if ($CategoriesCount > 1) {
							$WorkingCategoryNum = $row4['Category'.$CategoriesCount];
						}
						else {
							$WorkingCategoryNum = $row4['Category'];
						}
							
						while ($WorkingCategoryNum >= 0) {
							$query24 = "select * from `".$Settings['DBPrefix']."ec-Sales` where StartDate<='".$CurrentTime."' and EndDate>='".$CurrentTime."' and (Categories LIKE '%,".$WorkingCategoryNum.",%' or Products LIKE '%,".$row4['RecordNumber'].",%') limit 1";
							$result24 = mysql_query($query24) or die (mysql_error());
							if (mysql_num_rows($result24) > 0) {
								$row24 = mysql_fetch_array($result24);
							
								if ($SalesDetails[$row24['RecordNumber']] == '') {
									$SalesDetails[$row24['RecordNumber']] = $row24;
									$SalesList[] = $row24['RecordNumber'];
								}
							}
						
							if ($WorkingCategoryNum > 0) {
								$query25 = "select * from `".$Settings['DBPrefix']."ec-Categories` where RecordNumber='".$WorkingCategoryNum."' limit 1";
								$result25 = mysql_query($query25) or die (mysql_error());
								$row25 = mysql_fetch_array($result25);
								
								$WorkingCategoryNum = $row25['Parent'];
							}
							else {
								$WorkingCategoryNum = -1;
							}
						
						}
						
					} // end loop categories 1-5
					
						
					//for ($SalesCount = 0; $SalesCount < count($SalesList); $SalesCount++) {
						$row24 = $SalesDetails[$SalesList[0]];
					//}	
						
					
					if ($row24['DiscountAmount'] > 0 || $row24['DiscountPercent'] > 0) {
					
						if ($row24['DiscountAmount'] > 0) {
							$row3['Price'.$PricingLevel] = ($row3['Price'.$PricingLevel] - $row24['DiscountAmount']);
						}
						if ($row24['DiscountPercent'] > 0) {
							$row3['Price'.$PricingLevel] = ($row3['Price'.$PricingLevel] - ($row3['Price'.$PricingLevel] * ($row24['DiscountPercent']/100)));
						}
												
						$Sale = true;
						$SaleName = $row24['Name'];
						
					}	
					
					
					// end sales portion
					
						
					$ItemPrice = $row3['Price'.$PricingLevel];
			
					$Subtotal = ($row3['Price'.$PricingLevel]*$Qty);
						
					$ItemsTotal += $Subtotal;
					
					
				} // end if not incentive
				else {
					// incentive item
					
					$query7 = "select * from `".$Settings['DBPrefix']."ec-Incentives` where RecordNumber='".$Incentive."' and Active=1 limit 1";
					$result7 = mysql_query($query7) or die (mysql_error());
					if (mysql_num_rows($result7) != 0) {
						$row7 = mysql_fetch_array($result7);
						
						if ($Qty > $row7['Arguments3']) {
							$Qty = $row7['Arguments3'];
						}
						
						
						$ItemPrice = $row7['Arguments5'];
			
						$Subtotal = ($row7['Arguments5']*$Qty);
						
						$ItemsTotal += $Subtotal;
						
																		
					}
				
				}
				
			} // end loop
				
								
			// check for new incentives that haven't been applied yet
			$query7 = "select * from `".$Settings['DBPrefix']."ec-Incentives` where Active=1";
			$result7 = mysql_query($query7) or die (mysql_error());
			$IncentivesCount = mysql_num_rows($result7);
			
			for ($IncentivesCounter = 0; $IncentivesCounter < $IncentivesCount; $IncentivesCounter++) {
				$query7 = "select * from `".$Settings['DBPrefix']."ec-Incentives` where Active=1";
				$result7 = mysql_query($query7) or die (mysql_error());
				while ($row7 = mysql_fetch_array($result7)) {
			
					$IncentiveItemQty = 0;
					
					if ($row7['IncentiveType'] == 'MinCartValue' && $ItemsTotal >= $row7['Arguments1']) {
					
						for ($i = 0; $i < (count($ItemsList)-1); $i++) {
							list ($ItemNumA, $Qty) = explode('x',$ItemsList[$i]);
					
							list ($ItemNum, $Incentive) = explode('-', $ItemNumA);
							
							if ($Incentive != '' && $ItemNum == $row7['Arguments4']) {
								
								$IncentiveItemQty = $Qty;
								
							}
						}
					
						
						if ($IncentiveItemQty == 0) {
						
							$ShoppingCartContents .= $row7['Arguments4'] . '-' . $row7['RecordNumber'] . 'x' . $row7['Arguments2'] . ',';
							
						
							if ($LoggedIn == 'y') {
								$query33 = "update `".$Settings['DBPrefix']."core-Users` set ShoppingCartContents='".$ShoppingCartContents."' where Username='".$CookieUsername."' limit 1";
								$result33 = mysql_query($query33) or die (mysql_error());
							}
							else {
								setcookie ($CookieName.'Cart', $ShoppingCartContents, 0, '/');
							}
													

							$ItemsList = explode(',',$ShoppingCartContents);
							
							$StillQualifiesForIncentive[$row7['RecordNumber']] = true;
					
						} // if incentive qty = 0
						else {
							$StillQualifiesForIncentive[$row7['RecordNumber']] = true;
						}
						
					} // if this cart qualifies for the incentive
					else {
						$StillQualifiesForIncentive[$row7['RecordNumber']] = false;
					}
								
				
				} // mysql loop
				
			} // incentives count loop
			
			
			
			// check to make sure there aren't any incentives present that they no longer qualify for
			$query7 = "select * from `".$Settings['DBPrefix']."ec-Incentives` where Active=1";
			$result7 = mysql_query($query7) or die (mysql_error());
			while ($row7 = mysql_fetch_array($result7)) {
			
				if ($row7['IncentiveType'] == 'MinCartValue' && $ItemsTotal >= $row7['Arguments1']) {
				// if this cart qualifies for the incentive
					$StillQualifiesForIncentive[$row7['RecordNumber']] = true;
				} 
				else {
					$StillQualifiesForIncentive[$row7['RecordNumber']] = false;
				}
					
			} // mysql loop
				
					
			
			
			for ($i = 0; $i < (count($ItemsList)-1); $i++) {
				list ($ItemNumA, $Qty) = explode('x',$ItemsList[$i]);
				
				list ($ItemNum, $Incentive) = explode('-', $ItemNumA);
				
				if ($Incentive != '' && $StillQualifiesForIncentive[$Incentive] != true) {
				
					$ItemsList[$i] = '';
					
					$ItemRemoved = true;
					
					$query7 = "select * from `".$Settings['DBPrefix']."ec-Incentives` where RecordNumber='".$Incentive."' limit 1";
					$result7 = mysql_query($query7) or die (mysql_error());
					$row7 = mysql_fetch_array($result7);
					
					
					$AmountRemoved += $Qty * $row7['Arguments5'];
				
				}
			}
				
			
			if ($ItemRemoved == true) {
			
				$ItemsTotal -= $AmountRemoved;
			
				$NewCartContents = '';
			
				for ($i = 0; $i < (count($ItemsList)-1); $i++) {
					if ($ItemsList[$i] != '') {
						$NewCartContents .= $ItemsList[$i].',';
					}
				}
				
				$ItemsList = explode(',',$NewCartContents);
				
				
				if ($LoggedIn == 'y') {
					$query3 = "update `".$Settings['DBPrefix']."core-Users` set ShoppingCartContents='".$NewCartContents."' where Username='".$CookieUsername."' limit 1";
					$result3 = mysql_query($query3) or die (mysql_error());
				}
				else {
					setcookie ($CookieName.'Cart', $NewCartContents, 0, '/');
				}
			
			}
			
			
			
			$ItemsTotal = 0;
			
			
			for ($i = 0; $i < (count($ItemsList)-1); $i++) {
				list ($ItemNumA, $Qty) = explode('x',$ItemsList[$i]);
				
				list ($ItemNum, $Incentive) = explode('-', $ItemNumA);
				
				
				if ($ItemNum != '') {
				
									
					$query3 = "select * from `".$Settings['DBPrefix']."ec-Items` where RecordNumber='".$ItemNum."' limit 1";
					$result3 = mysql_query($query3) or die (mysql_error());
					$row3 = mysql_fetch_array($result3);
							
					$query4 = "select * from `".$Settings['DBPrefix']."ec-Products` where RecordNumber='".$row3['Product']."' limit 1";
					$result4 = mysql_query($query4) or die (mysql_error());
					$row4 = mysql_fetch_array($result4);
					
						
					if ($row3['Option2'] != '') {
						$row4['Name'] .= ' ('.$row3['Option1'].', '.$row3['Option2'].')';
					}
					else if ($row3['Option1'] != '') {
						$row4['Name'] .= ' ('.$row3['Option1'].')';
					}
					
					
					if ($Incentive == '') {
						
										
						$PricingLevel = 1;
						for ($k = 1; $k <= 10; $k++) {
							if ($row3['PriceQty'.$k] > 0 && $Qty >= $row3['PriceQty'.$k]) {
								$PricingLevel = $k;
							}
						}
						
						
						
					// check to see if there are any active sales to apply to this item
					
					$Sale = false;
					
					$CurrentTime = GetTimestamp();
					
					$SalesList = '';
					$SalesDetails = '';
					
					for ($CategoriesCount = 1; $CategoriesCount <= 5; $CategoriesCount++) {
					
						if ($CategoriesCount > 1) {
							$WorkingCategoryNum = $row4['Category'.$CategoriesCount];
						}
						else {
							$WorkingCategoryNum = $row4['Category'];
						}
							
						while ($WorkingCategoryNum >= 0) {
							$query24 = "select * from `".$Settings['DBPrefix']."ec-Sales` where StartDate<='".$CurrentTime."' and EndDate>='".$CurrentTime."' and (Categories LIKE '%,".$WorkingCategoryNum.",%' or Products LIKE '%,".$row4['RecordNumber'].",%') limit 1";
							$result24 = mysql_query($query24) or die (mysql_error());
							if (mysql_num_rows($result24) > 0) {
								$row24 = mysql_fetch_array($result24);
							
								if ($SalesDetails[$row24['RecordNumber']] == '') {
									$SalesDetails[$row24['RecordNumber']] = $row24;
									$SalesList[] = $row24['RecordNumber'];
								}
							}
						
							if ($WorkingCategoryNum > 0) {
								$query25 = "select * from `".$Settings['DBPrefix']."ec-Categories` where RecordNumber='".$WorkingCategoryNum."' limit 1";
								$result25 = mysql_query($query25) or die (mysql_error());
								$row25 = mysql_fetch_array($result25);
								
								$WorkingCategoryNum = $row25['Parent'];
							}
							else {
								$WorkingCategoryNum = -1;
							}
						
						}
						
					} // end loop categories 1-5
					
						
					//for ($SalesCount = 0; $SalesCount < count($SalesList); $SalesCount++) {
						$row24 = $SalesDetails[$SalesList[0]];
					//}	
						
					
					if ($row24['DiscountAmount'] > 0 || $row24['DiscountPercent'] > 0) {
					
						if ($row24['DiscountAmount'] > 0) {
							$row3['Price'.$PricingLevel] = ($row3['Price'.$PricingLevel] - $row24['DiscountAmount']);
						}
						if ($row24['DiscountPercent'] > 0) {
							$row3['Price'.$PricingLevel] = ($row3['Price'.$PricingLevel] - ($row3['Price'.$PricingLevel] * ($row24['DiscountPercent']/100)));
						}
												
						$Sale = true;
						$SaleName = $row24['Name'];
						
					}	
					
					
					// end sales portion
						
						
						
							
						$ItemPrice = $row3['Price'.$PricingLevel];
				
						$Subtotal = ($row3['Price'.$PricingLevel]*$Qty);
							
						$ItemsTotal += $Subtotal;
						
						
						$ContentsPrint .= '<tr><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><input type="text" name="Item'.($i+1).'Quantity" value="'.$Qty.'" size="2" maxlength="8" style="text-align:center; '.$FormStyle.'"></font></td><td><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/store/details/'.$row4['ProductID'].'.html">'.$row4['Name'].'</a></font></td><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$CurrencyBefore.number_format($ItemPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</font></td><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$CurrencyBefore.number_format($Subtotal,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</font></td></tr>';
					
					
					} // end if not incentive
					else {
						// incentive item
						
						$query7 = "select * from `".$Settings['DBPrefix']."ec-Incentives` where RecordNumber='".$Incentive."' and Active=1 limit 1";
						$result7 = mysql_query($query7) or die (mysql_error());
						if (mysql_num_rows($result7) != 0) {
							$row7 = mysql_fetch_array($result7);
							
							if ($Qty > $row7['Arguments3']) {
								$Qty = $row7['Arguments3'];
							}
							
							
							$ItemPrice = $row7['Arguments5'];
			
							$Subtotal = ($row7['Arguments5']*$Qty);
							
							$ItemsTotal += $Subtotal;
							
							
							if ($row7['Arguments6'] != '') {
								$row7['Arguments6'] = '<br><b>'.$row7['Arguments6'].'</b>';						
							}
							
							
							$ContentsPrint .= '<tr><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><input type="text" name="Item'.($i+1).'Quantity" value="'.$Qty.'" size="2" maxlength="8" style="text-align:center; '.$FormStyle.'"></font></td><td><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/store/details/'.$row4['ProductID'].'.html">'.$row4['Name'].'</a>'.$row7['Arguments6'].'</font></td><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$CurrencyBefore.number_format($ItemPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</font></td><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$CurrencyBefore.number_format($Subtotal,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</font></td></tr>';
						
																		
						}
						
					} // end if item num != ''
				
				}
				
			
			
			
			}
			
			
			
			$Total = ($ItemsTotal + $TotalTaxes);
			
		}
		
		
		
		if ($ContentsPrint != '') {
			$ContentsPrint = '<form action="'.$MainURL.'/store/updatecart" method="post"><input type="hidden" name="Random" value="'.rand(0,100000).'"><div align="center"><font size="'.($FontSize-1).'">'.$MsgText[9][292].'<br></font><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="8" alt="" border="0"><br><table width="98%" cellpadding="4" cellspacing="0" border="0"><tr><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[9][248].'</b></font></td><td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[9][249].'</b></font></td><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[9][250].'</b></font></td><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[9][251].'</b></font></td></tr>'.$ContentsPrint.'<tr><td colspan="4"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="5" alt="" border="0"></td></tr><tr><td colspan="2"><font face="'.$FontFace.'" size="'.$FontSize.'"><input type="submit" value="'.$MsgText[9][293].'" style="'.$FormStyle.'"></font></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[9][252].':</b></font></td><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$CurrencyBefore.number_format($ItemsTotal,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></td></tr>'.$TaxesSection.'<tr><td colspan="3" align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$SHTitle.':</b><br>'.$MsgText[9][294].'</font></td><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>?</b></font></td></tr><tr><td colspan="3" align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[9][253].':</b></font></td><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$CurrencyBefore.number_format($Total,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></td></tr></table><br></div></form>';

			$CheckoutLink = '<a href="'.$MainURL.'/store/checkout.html">'.$MsgText[9][295].'</a>';			
		}
		else {
			$ContentsPrint = '<br><div align="center">['.$MsgText[9][296].']</div><br>';
		}
					
		
		
		
		$PageContents = $ContentsPrint.'<br><div align="center"><table width="98%" border="0" cellpadding="0" cellspacing="0"><tr>
	      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/store.html">'.$MsgText[9][288].'</a></b></font></td>
    	  <td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;<b>'.$CheckoutLink.'</b></font></td>
	    </tr></table></div>';
		
	
	} // end if $Arguments2 == 'viewcart'
	else if ($Arguments2 == 'updatecart') {
	
		ReadFormArguments();
		Global $FormArguments;
		
		if (count($FormArguments) > 0) {
		
			if ($LoggedIn == 'y') {
				$query3 = "select ShoppingCartContents from `".$Settings['DBPrefix']."core-Users` where Username='".$CookieUsername."' limit 1";
				$result3 = mysql_query($query3) or die (mysql_error());
				$row3 = mysql_fetch_array($result3);
				$ShoppingCartContents = $row3['ShoppingCartContents'];
			}
			else {
				if ($HTTP_COOKIE_VARS[$CookieName.'Cart'] != 'empty') {
					$ShoppingCartContents = $HTTP_COOKIE_VARS[$CookieName.'Cart'];
				}
			}
				
				
			$ItemsList = explode(',',$ShoppingCartContents);
			$ItemFound = false;
					
			for ($i = 0; $i < (count($ItemsList)-1); $i++) {
				list ($ItemNum, $Qty) = explode('x',$ItemsList[$i]);
				
				if ($FormArguments['Item'.($i+1).'Quantity'] > 0) {
					$ItemsList[$i] = $ItemNum.'x'.number_format($FormArguments['Item'.($i+1).'Quantity'],0,'.','');
				}
				else {
					$ItemsList[$i] = '';
				}		
			}
					
				
			for ($i = 0; $i < (count($ItemsList)-1); $i++) {
				if ($ItemsList[$i] != '') {
					$NewCartContents .= $ItemsList[$i].',';
				}
			}
				
			
			if ($LoggedIn == 'y') {
				$query3 = "update `".$Settings['DBPrefix']."core-Users` set ShoppingCartContents='".$NewCartContents."' where Username='".$CookieUsername."' limit 1";
				$result3 = mysql_query($query3) or die (mysql_error());
			}
			else {
				setcookie ($CookieName.'Cart', $NewCartContents, 0, '/');
			}
					
			
			//header('Location: '.$MainURL.'/store/viewcart/'.rand(0,1000).'.html');
			header('Location: '.$MainURL.'/store/viewcart.html');
		
		}
		
	
	} // end if $Arguments2 == 'updatecart'
	else if ($Arguments2 == 'checkout') {
	
		$PageTitle = $MsgText[9][271].' - '.$MsgText[9][295];
		$BrowserTitle = $MsgText[9][271].' - '.$MsgText[9][295];
		$LocationBar = '<a href="'.$MainURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/store.html">'.$MsgText[9][271].'</a> > '.$MsgText[9][271].' - '.$MsgText[9][295];
		
		$Arguments3 = intval($Arguments3);
		
		
		if ($LoggedIn == 'y') {
			$query3 = "select ShoppingCartContents from `".$Settings['DBPrefix']."core-Users` where Username='".$CookieUsername."' limit 1";
			$result3 = mysql_query($query3) or die (mysql_error());
			$row3 = mysql_fetch_array($result3);
			$ShoppingCartContents = $row3['ShoppingCartContents'];

						
			if ($Arguments3 < 2) {
				$Arguments3 = 2;
			}
		}
		else {
			if ($HTTP_COOKIE_VARS[$CookieName.'Cart'] != 'empty') {
				$ShoppingCartContents = $HTTP_COOKIE_VARS[$CookieName.'Cart'];
			}
		}
		
		
		if ($ShoppingCartContents != '') {
		
		if ($Arguments3 <= 1 || $LoggedIn != 'y') {
			
			$PageContents = '<b>'.$MsgText[9][297].'</b><br><br><b>'.$MsgText[9][298].'</b><br><br><b>'.$MsgText[9][299].':</b><br><form action="'.$MainURL.'/login-submit" method="post">'.$MsgText[0][99].':<br><input type="hidden" name="ReturnTo" value="store+++checkout+++2"><input type="text" name="Username" size="20" maxlength="40" style="'.$FormStyle.'"><br><br>'.$MsgText[0][131].':<br><input type="password" name="Password" size="20" maxlength="40" style="'.$FormStyle.'"><br><br><input type="submit" value="&nbsp;'.$MsgText[0][146].'&nbsp;" style="'.$FormStyle.'"></form><a href="'.$MainURL.'/lost_password.html">'.$MsgText[0][500].'</a><br><br><table width="90%" border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="'.$Colors['Text'].'"><img src="'.$MainURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0"></td></tr></table><br><b>'.$MsgText[9][300].':</b><br><br><b><a href="'.$MainURL.'/register/store+++checkout+++2">'.$MsgText[9][301].'</a></b>';
			
		} // end if $Arguments3 == 1
		else if ($Arguments3 == 2 && $Arguments4 == '') {
		
			$PageContents = '<b>'.$MsgText[9][302].'</b><br><br><b>'.$MsgText[9][303].'</b>';
			
		
					
			$query3 = "select * from `".$Settings['DBPrefix']."ec-Addresses` where Account='".$UserNumber."' and Active=1";
			$result3 = mysql_query($query3) or die (mysql_error());
			while ($row3 = mysql_fetch_array($result3)) {
				if ($row3['Type'] == 0 || $row3['Type'] == 1) {
					$BillingAddresses[] = $row3['RecordNumber'];
				}
				if ($row3['Type'] == 0 || $row3['Type'] == 2) {
					$ShippingAddresses[] = $row3['RecordNumber'];
				}
				
				$AddressData[$row3['RecordNumber']] = $row3;
			}
			
			
			$query3 = "select * from `".$Settings['DBPrefix']."ec-Orders` where Account='".$UserNumber."' order by DateCode desc limit 1";
			$result3 = mysql_query($query3) or die (mysql_error());
			$row3 = mysql_fetch_array($result3);
			
			if ($row3['BillingAddress'] > 0) {
				$BillingSelected[$row3['BillingAddress']] = ' checked';
			}
			else {
				$BillingSelected[$BillingAddresses[count($BillingAddresses)-1]] = ' checked';
			}
			
			if ($row3['ShippingAddress'] > 0) {
				$ShippingSelected[$row3['ShippingAddress']] = ' checked';
			}
			else {
				$ShippingSelected[$ShippingAddresses[count($ShippingAddresses)-1]] = ' checked';
			}
			
			
			$AddressesSection .= '<b>'.$MsgText[9][245].':</b>';
			
			if (count($BillingAddresses) > 0) {
								
				for ($x = 0; $x < count($BillingAddresses); $x++) {
				
					$ThisAddressData = $AddressData[$BillingAddresses[$x]];
					
					if ($ThisAddressData['OrganizationCompany'] != '') {
						$ThisAddressData['OrganizationCompany'] = '<br>'.$ThisAddressData['OrganizationCompany'];
					}
					
					if ($ThisAddressData['Address2'] != '') {
						$ThisAddressData['Address1'] .= '<br>'.$ThisAddressData['Address2'];
					}
					if ($ThisAddressData['Address3'] != '') {
						$ThisAddressData['Address1'] .= '<br>'.$ThisAddressData['Address3'];
					}
					if ($ThisAddressData['Address4'] != '') {
						$ThisAddressData['Address1'] .= '<br>'.$ThisAddressData['Address4'];
					}
					
				
					$AddressesSection .= '<table width="100%" border="0" cellpadding="4" cellspacing="0">
    <tr>
      <td width="30" align="center"><img src="'.$ImagesURL.'/admin/spacer.gif" width="30" height="1" alt="" border="0"><br><input type="radio" name="BillingAddress" value="'.$BillingAddresses[$x].'"'.$BillingSelected[$BillingAddresses[$x]].'></td>
      <td width="50%"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$ThisAddressData['FirstName'].' '.$ThisAddressData['LastName'].$ThisAddressData['OrganizationCompany'].'<br>'.$ThisAddressData['Address1'].'<br>'.$ThisAddressData['City'].', '.$ThisAddressData['StateProvince'].'<br>'.$ThisAddressData['ZipPostal'].'<br>'.$ThisAddressData['Country'].'<br>'.$MsgText[9][242].': '.$ThisAddressData['Phone'].'</font></td>
	  <td width="50%"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/store/checkout/2/remove/'.$ThisAddressData['RecordNumber'].'.html">'.$MsgText[9][304].'</a></font></td>
    </tr>
</table>';
				}
				
			}
			else {
				$AddressesSection .= '<br>';
			}
			
			$AddressesSection .= '<br><b><a href="'.$MainURL.'/store/checkout/2/new.html">'.$MsgText[9][305].'</a></b><br>';
			
			
			if ($ecSettings['RequireShipToBilling'] != 'y') {
			
				$AddressesSection .= '<br><br><b>'.$MsgText[9][246].':</b>';
			
				if (count($ShippingAddresses) > 0) {
									
					for ($x = 0; $x < count($ShippingAddresses); $x++) {
					
						$ThisAddressData = $AddressData[$ShippingAddresses[$x]];
						
						if ($ThisAddressData['OrganizationCompany'] != '') {
							$ThisAddressData['OrganizationCompany'] = '<br>'.$ThisAddressData['OrganizationCompany'];
						}
					
						if ($ThisAddressData['Address2'] != '') {
							$ThisAddressData['Address1'] .= '<br>'.$ThisAddressData['Address2'];
						}
						if ($ThisAddressData['Address3'] != '') {
							$ThisAddressData['Address1'] .= '<br>'.$ThisAddressData['Address3'];
						}
						if ($ThisAddressData['Address4'] != '') {
							$ThisAddressData['Address1'] .= '<br>'.$ThisAddressData['Address4'];
						}
						
					
						$AddressesSection .= '<table width="100%" border="0" cellpadding="4" cellspacing="0">
    <tr>
      <td width="30" align="center"><img src="'.$ImagesURL.'/admin/spacer.gif" width="30" height="1" alt="" border="0"><br><input type="radio" name="ShippingAddress" value="'.$ShippingAddresses[$x].'"'.$ShippingSelected[$ShippingAddresses[$x]].'></td>
      <td width="50%"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$ThisAddressData['FirstName'].' '.$ThisAddressData['LastName'].$ThisAddressData['OrganizationCompany'].'<br>'.$ThisAddressData['Address1'].'<br>'.$ThisAddressData['City'].', '.$ThisAddressData['StateProvince'].'<br>'.$ThisAddressData['ZipPostal'].'<br>'.$ThisAddressData['Country'].'<br>'.$MsgText[9][242].': '.$ThisAddressData['Phone'].'</font></td>
	  <td width="50%"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/store/checkout/2/remove/'.$ThisAddressData['RecordNumber'].'.html">'.$MsgText[9][304].'</a></font></td>
    </tr>
</table>';
					}
					
				}
				else {
					$AddressesSection .= '<br>';
				}
				
				$AddressesSection .= '<br><b><a href="'.$MainURL.'/store/checkout/2/new.html">'.$MsgText[9][305].'</a></b><br>';
				
			}
			else {
				$AddressesSection .= '<br><br><b>'.$MsgText[9][246].':</b><br>['.$MsgText[9][306].']';
			}
			
			
			if (count($BillingAddresses) > 0 && (count($ShippingAddresses) > 0 || $ecSettings['RequireShipToBilling'] == 'y')) {
				
				$PageContents .= '<form action="'.$MainURL.'/store/checkout/3.html" method="post"><br>'.$AddressesSection.'<br><br><br><div align="center"><input type="submit" value="'.$MsgText[0][564].'" style="'.$FormStyle.'"></div></form>';

			}
			else {
			
				header('Location: '.$MainURL.'/store/checkout/2/new.html');
			
			}
			
		} // end if $Arguments3 == 2 && $Arguments4 == ''
		else if ($Arguments3 == 2 && $Arguments4 == 'new') {
		
			ReadFormArguments();
			Global $FormArguments;
				
						
			if ($FormArguments['StateProv'] != '' && $FormArguments['Country'] != '' && $FormArguments['FirstName'] != '' && $FormArguments['LastName'] != '' && $FormArguments['City'] != '' && $FormArguments['ZipPostal'] != '' && $FormArguments['Address1'] != '' && $FormArguments['Phone'] != '') {


				$query3 = "select * from `".$Settings['DBPrefix']."ec-Taxes` where Type='L' and Arguments1='".$FormArguments['Country']."' and Arguments2='".$FormArguments['StateProv']."' and Rate>0 and Active=1 order by Title";
				$result3 = mysql_query($query3) or die (mysql_error());
				while ($row3 = mysql_fetch_array($result3)) {
					if ($FormArguments['LocalTax'.$row3['RecordNumber']] == 'y') {
						$TaxesString .= $row3['RecordNumber'].',';
					}
				}

			
				$query3 = "insert into `".$Settings['DBPrefix']."ec-Addresses` (Account, FirstName, LastName, OrganizationCompany, Address1, Address2, Address3, Address4, City, StateProvince, ZipPostal, Country, Phone, Type, Taxes, Active) values ('".$UserNumber."','".$FormArguments['FirstName']."','".$FormArguments['LastName']."','".$FormArguments['OrganizationCompany']."','".$FormArguments['Address1']."','".$FormArguments['Address2']."','".$FormArguments['Address3']."','".$FormArguments['Address4']."','".$FormArguments['City']."','".$FormArguments['StateProv']."','".$FormArguments['ZipPostal']."','".$FormArguments['Country']."','".$FormArguments['Phone']."','".$FormArguments['Type']."','".$TaxesString."',1)";
				$result3 = mysql_query($query3) or die (mysql_error());
				
				header('Location: '.$MainURL.'/store/checkout/2.html');
			
			}
			else if ($FormArguments['StateProv'] != '' && $FormArguments['Country'] != '') {
			
			
				if ($FormArguments['Resubmit'] == 1) {
					$AddressesSection .= '<b>'.$MsgText[9][307].'</b><br><br><br>';
				}
				
				$AddressesSection .= '<input type="hidden" name="Resubmit" value="1">';
			
			
				$Country = $FormArguments['Country'];
				
				$AddressesSection .= '<input type="hidden" name="Country" value="'.$FormArguments['Country'].'">';
				
				
				$query77 = "select * from `".$Settings['DBPrefix']."core-Countries` where Code='".$FormArguments['Country']."' limit 1";
				$result77 = mysql_query($query77) or die (mysql_error());
				$row77 = mysql_fetch_array($result77);
				
				$CountryNames[$FormArguments['Country']] = $row77['Name'];
				$StateProvTitle[$FormArguments['Country']] = $row77['StateProvTitle'];
				
				if ($StateProvTitle[$FormArguments['Country']] == '') {
					$StateProvTitle[$FormArguments['Country']] = 'State/Province';
				}
				
				
							
				$StateProv = $FormArguments['StateProv'];
				
				$query77 = "select * from `".$Settings['DBPrefix']."core-StatesProvinces` where Country='".$FormArguments['Country']."' and Code='".$FormArguments['StateProv']."' limit 1";
				$result77 = mysql_query($query77) or die (mysql_error());
				if (mysql_num_rows($result77) > 0) {
					$row77 = mysql_fetch_array($result77);
					
					$StateProvinceNames[$FormArguments['Country']][$FormArguments['StateProv']] = $row77['Name'];
					
					$StateProvSection = $StateProvinceNames[$Country][$StateProv];
					
				}
				else {
				
					$StateProvSection = $FormArguments['StateProv'];
				
				}
					
				
								
				
				$AddressesSection .= '<input type="hidden" name="StateProv" value="'.$FormArguments['StateProv'].'">';
				
				
				if ($ecSettings['RequireShipToBilling'] != 'y') {
				
					$AddressTypeSelected[$FormArguments['Type']] = ' selected';
				
					$AddressesSection .= $MsgText[9][308].'<br><br><b>'.$MsgText[9][309].':</b><br><select name="Type" style="'.$FormStyle.'">
	<option value="0"'.$AddressTypeSelected[0].'> '.$MsgText[9][310].'</option>
	<option value="1"'.$AddressTypeSelected[1].'> '.$MsgText[9][311].'</option>
	<option value="2"'.$AddressTypeSelected[2].'> '.$MsgText[9][312].'</option>
</select><br><br><br>';
				
				}
				else {
				
					$AddressesSection .= $MsgText[9][313].'<br><br><br>';
				
				}
				
				$AddressesSection .= '<b>'.$MsgText[0][100].':</b><br><input type="text" name="FirstName" size="20" maxlength="40" style="'.$FormStyle.'" value="'.stripslashes(str_replace('"','&#'.'34;',$FormArguments['FirstName'])).'"><br><b>'.$MsgText[0][101].':</b><br><input type="text" name="LastName" size="20" maxlength="40" style="'.$FormStyle.'" value="'.stripslashes(str_replace('"','&#'.'34;',$FormArguments['LastName'])).'"><br><br><b>'.$MsgText[0][102].':</b> ('.$MsgText[0][418].')<br><input type="text" name="OrganizationCompany" size="35" maxlength="50" style="'.$FormStyle.'" value="'.stripslashes(str_replace('"','&#'.'34;',$FormArguments['OrganizationCompany'])).'"><br><br><b>'.$MsgText[0][103].':</b><br><input type="text" name="Address1" size="30" maxlength="40" style="'.$FormStyle.'" value="'.stripslashes(str_replace('"','&#'.'34;',$FormArguments['Address1'])).'"><br><input type="text" name="Address2" size="30" maxlength="40" style="'.$FormStyle.'" value="'.str_replace('"','&#'.'34;',$FormArguments['Address2']).'"> ('.$MsgText[0][418].')<br><input type="text" name="Address3" size="30" maxlength="40" style="'.$FormStyle.'" value="'.stripslashes(str_replace('"','&#'.'34;',$FormArguments['Address3'])).'"> ('.$MsgText[0][418].')<br><input type="text" name="Address4" size="30" maxlength="40" style="'.$FormStyle.'" value="'.stripslashes(str_replace('"','&#'.'34;',$FormArguments['Address4'])).'"> ('.$MsgText[0][418].')<br><br><b>'.$MsgText[0][104].':</b><br><input type="text" name="City" size="20" maxlength="40" style="'.$FormStyle.'" value="'.stripslashes(str_replace('"','&#'.'34;',$FormArguments['City'])).'"><br><br><b>'.$StateProvTitle[$Country].':</b><br>'.$StateProvSection.'<br><br><b>'.$MsgText[0][106].':</b><br><input type="text" name="ZipPostal" size="10" maxlength="15" style="'.$FormStyle.'" value="'.stripslashes(str_replace('"','&#'.'34;',$FormArguments['ZipPostal'])).'"><br><br><b>'.$MsgText[0][107].':</b><br>'.$CountryNames[$Country].'<br><br><b>'.$MsgText[9][314].':</b><br><input type="text" name="Phone" size="15" maxlength="30" style="'.$FormStyle.'" value="'.stripslashes(str_replace('"','&#'.'34;',$FormArguments['Phone'])).'">';

			


				$query3 = "select * from `".$Settings['DBPrefix']."ec-Taxes` where Type='L' and Arguments1='".$Country."' and Arguments2='".$StateProv."' and Rate>0 and Active=1 order by Title";
				$result3 = mysql_query($query3) or die (mysql_error());
				if (mysql_num_rows($result3) > 0) {
					$AddressesSection .= '<br><br><br><b>'.$MsgText[9][315].':</b><br>('.$MsgText[9][316].')';
				
					while ($row3 = mysql_fetch_array($result3)) {
						
						while (substr($row3['Rate'],strlen($row3['Rate'])-1,1) == '0' || substr($row3['Rate'],strlen($row3['Rate'])-1,1) == '.') {
							$row3['Rate'] = substr($row3['Rate'],0,strlen($row3['Rate'])-1);
						}
					
					
						$AddressesSection .= '<br>	<input type="checkbox" name="LocalTax'.$row3['RecordNumber'].'" value="y"> <b>'.$row3['Title'].'</b> '.$row3['Description'].' ('.$row3['Rate'].'%)';
					}
				}
				
							
			
			}
			else if ($FormArguments['Country'] != '') {
			
				$Country = $FormArguments['Country'];
				
				$query77 = "select * from `".$Settings['DBPrefix']."core-Countries` where Code='".$FormArguments['Country']."' limit 1";
				$result77 = mysql_query($query77) or die (mysql_error());
				$row77 = mysql_fetch_array($result77);
				
				$CountryNames[$FormArguments['Country']] = $row77['Name'];
				$StateProvTitle[$FormArguments['Country']] = $row77['StateProvTitle'];
				
				if ($StateProvTitle[$FormArguments['Country']] == '') {
					$StateProvTitle[$FormArguments['Country']] = 'State/Province';
				}
				
				$AddressesSection .= '<input type="hidden" name="Country" value="'.$FormArguments['Country'].'">';
																
				$query77 = "select * from `".$Settings['DBPrefix']."core-StatesProvinces` where Country='".$FormArguments['Country']."' order by Name asc";
				$result77 = mysql_query($query77) or die (mysql_error());
				if (mysql_num_rows($result77) > 0) {
				
					$AddressesSection .= $MsgText[9][317].' '.$StateProvTitle[$Country].' '.$MsgText[9][318].'  '.$MsgText[9][319].'<br><br><b>'.$MsgText[0][107].':</b><br>'.$CountryNames[$Country].'<br><br><b>'.$StateProvTitle[$Country].':</b><br><select name="StateProv" style="'.$FormStyle.'">';
					
					while ($row77 = mysql_fetch_array($result77)) {
						$AddressesSection .= '<option value="'.$row77['Code'].'"> '.$row77['Name'].'</option>';
					}
						
					$AddressesSection .= '</select>';
					
				}
				else {
				
					$AddressesSection .= $MsgText[9][320].' '.$StateProvTitle[$Country].' '.$MsgText[9][321].'<br><br><b>'.$MsgText[0][107].':</b><br>'.$CountryNames[$Country].'<br><br><b>'.$StateProvTitle[$Country].':</b><br><input type="text" name="StateProv" size="20" maxlength="40" style="'.$FormStyle.'" value="'.stripslashes(str_replace('"','&#'.'34;',$FormArguments['StateProv'])).'">';
				
				}
					
			
			}
			else {
				
				$AddressesSection = $MsgText[9][322].'<br><br><b>'.$MsgText[0][107].':</b><br><select name="Country" style="'.$FormStyle.'">';

				
				$query77 = "select * from `".$Settings['DBPrefix']."core-Countries` where AllowSales=1 order by Name asc";
				$result77 = mysql_query($query77) or die (mysql_error());
				while ($row77 = mysql_fetch_array($result77)) {
					if ($Settings['SiteCountry'] == $row77['Code']) {
						$Selected = ' selected';
					}
					else {
						$Selected = '';
					}
					
					$AddressesSection .= '<option value="'.$row77['Code'].'"'.$Selected.'> '.$row77['Name'].'</option>';
					
				}


				$AddressesSection .= '</select>';
							
			}
			
			
			$PageContents .= '<form action="'.$MainURL.'/store/checkout/2/new.html" method="post">'.$AddressesSection.'<br><br><br><br><div align="center"><input type="submit" value="'.$MsgText[0][564].'" style="'.$FormStyle.'"></div></form>';
			
			
		} // end if $Arguments3 == 2 && $Arguments4 == 'new'
		else if ($Arguments3 == 2 && $Arguments4 == 'remove' && intval($Arguments5) > 0) {
		
			$PageContents .= '<form action="'.$MainURL.'/store/checkout/2/remove_confirm.html" method="post"><input type="hidden" name="RecordNumberToEdit" value="'.$Arguments5.'"><b>'.$MsgText[9][323].'</b><br><br><br><div align="center"><input type="submit" value="'.$MsgText[9][324].'" style="'.$FormStyle.'"></div></form>';
		
		}
		else if ($Arguments3 == 2 && $Arguments4 == 'remove_confirm') {
		
			ReadFormArguments();
			Global $FormArguments;
			
			$query3 = "update `".$Settings['DBPrefix']."ec-Addresses` set Active=0 where Account='".$UserNumber."' and RecordNumber='".$FormArguments['RecordNumberToEdit']."' limit 1";
			$result3 = mysql_query($query3) or die (mysql_error());
			
			header('Location: '.$MainURL.'/store/checkout/2.html');
		
		}
		else if ($Arguments3 == 3) {
		
			ReadFormArguments();
			Global $FormArguments;
			
			if ($FormArguments['ShippingAddress'] == '') {
				$FormArguments['ShippingAddress'] = $FormArguments['BillingAddress'];
			}
			
						
			$query103 = "select * from `".$Settings['DBPrefix']."ec-Addresses` where RecordNumber=".intval($FormArguments['ShippingAddress'])." and Account=".$UserNumber." and Active=1 limit 1";
			$result103 = mysql_query($query103) or die (mysql_error());
			if (mysql_num_rows($result3) > 0) {
			
			$row103 = mysql_fetch_array($result103);
			
								
			$PageContents = '<b>'.$MsgText[9][325].'</b><br><br>';
			
			//$query77 = "select * from `".$Settings['DBPrefix']."core-Users` where RecordNumber=".$UserNumber." limit 1";
			//$result77 = mysql_query($query77) or die (mysql_error());
			//$row77 = mysql_fetch_array($result77);
			
			//$ShoppingCartContents = $row77['ShoppingCartContents'];
							
			$ItemsList = explode(',',$ShoppingCartContents);
							
			$ItemsCount = (count($ItemsList)-1);
			
			if ($ItemsCount > 1) {
				// multiple items
				
				for ($i = 0; $i < $ItemsCount; $i++) {
					list ($ItemNumA, $Qty) = explode('x',$ItemsList[$i]);
					$ItemsQty += $Qty;
				
					list ($ItemNum, $Incentive) = explode('-', $ItemNumA);
					
					
					if ($ItemNum != '') {
													
						$query3 = "select * from `".$Settings['DBPrefix']."ec-Items` where RecordNumber='".$ItemNum."' limit 1";
						$result3 = mysql_query($query3) or die (mysql_error());
						$row3 = mysql_fetch_array($result3);
								
						$query4 = "select * from `".$Settings['DBPrefix']."ec-Products` where RecordNumber='".$row3['Product']."' limit 1";
						$result4 = mysql_query($query4) or die (mysql_error());
						$row4 = mysql_fetch_array($result4);
						
							
						if ($row3['Option2'] != '') {
							$row4['Name'] .= ' ('.$row3['Option1'].', '.$row3['Option2'].')';
						}
						else if ($row3['Option1'] != '') {
							$row4['Name'] .= ' ('.$row3['Option1'].')';
						}
						
						
						if ($Incentive == '') {
							
											
							$PricingLevel = 1;
							for ($k = 1; $k <= 10; $k++) {
								if ($row3['PriceQty'.$k] > 0 && $Qty >= $row3['PriceQty'.$k]) {
									$PricingLevel = $k;
								}
							}
							
							
							
					// check to see if there are any active sales to apply to this item
					
					$Sale = false;
					
					$CurrentTime = GetTimestamp();
					
					$SalesList = '';
					$SalesDetails = '';
					
					for ($CategoriesCount = 1; $CategoriesCount <= 5; $CategoriesCount++) {
					
						if ($CategoriesCount > 1) {
							$WorkingCategoryNum = $row4['Category'.$CategoriesCount];
						}
						else {
							$WorkingCategoryNum = $row4['Category'];
						}
							
						while ($WorkingCategoryNum >= 0) {
							$query24 = "select * from `".$Settings['DBPrefix']."ec-Sales` where StartDate<='".$CurrentTime."' and EndDate>='".$CurrentTime."' and (Categories LIKE '%,".$WorkingCategoryNum.",%' or Products LIKE '%,".$row4['RecordNumber'].",%') limit 1";
							$result24 = mysql_query($query24) or die (mysql_error());
							if (mysql_num_rows($result24) > 0) {
								$row24 = mysql_fetch_array($result24);
							
								if ($SalesDetails[$row24['RecordNumber']] == '') {
									$SalesDetails[$row24['RecordNumber']] = $row24;
									$SalesList[] = $row24['RecordNumber'];
								}
							}
						
							if ($WorkingCategoryNum > 0) {
								$query25 = "select * from `".$Settings['DBPrefix']."ec-Categories` where RecordNumber='".$WorkingCategoryNum."' limit 1";
								$result25 = mysql_query($query25) or die (mysql_error());
								$row25 = mysql_fetch_array($result25);
								
								$WorkingCategoryNum = $row25['Parent'];
							}
							else {
								$WorkingCategoryNum = -1;
							}
						
						}
						
					} // end loop categories 1-5
					
						
					//for ($SalesCount = 0; $SalesCount < count($SalesList); $SalesCount++) {
						$row24 = $SalesDetails[$SalesList[0]];
					//}	
						
					
					if ($row24['DiscountAmount'] > 0 || $row24['DiscountPercent'] > 0) {
					
						if ($row24['DiscountAmount'] > 0) {
							$row3['Price'.$PricingLevel] = ($row3['Price'.$PricingLevel] - $row24['DiscountAmount']);
						}
						if ($row24['DiscountPercent'] > 0) {
							$row3['Price'.$PricingLevel] = ($row3['Price'.$PricingLevel] - ($row3['Price'.$PricingLevel] * ($row24['DiscountPercent']/100)));
						}
												
						$Sale = true;
						$SaleName = $row24['Name'];
						
					}	
					
					
					// end sales portion
							
							
						
							$AdditionalShipping += 	($row3['AdditionalShipping']*$Qty);
							$OrderTotal += ($row3['Price'.$PricingLevel]*$Qty);
								
						
						} // end if not incentive
						else {
							// incentive item
							
							$query7 = "select * from `".$Settings['DBPrefix']."ec-Incentives` where RecordNumber='".$Incentive."' and Active=1 limit 1";
							$result7 = mysql_query($query7) or die (mysql_error());
							if (mysql_num_rows($result7) != 0) {
								$row7 = mysql_fetch_array($result7);
								
								if ($Qty > $row7['Arguments3']) {
									$Qty = $row7['Arguments3'];
								}
								
								$OrderTotal += ($row7['Arguments5']*$Qty);
														
																			
							}
						}
						
										
				
						$query2 = "select Product,ShippingWeight from `".$Settings['DBPrefix']."ec-Items` where RecordNumber='".$ItemNum."' limit 1";
						$result2 = mysql_query($query2) or die (mysql_error());
						$row2 = mysql_fetch_array($result2);
						
						$ShippingWeight += ($row2['ShippingWeight']*$Qty);
															
						if ($Categories[$row2['Product']] != '') {
							$ThisCategory = $Categories[$row2['Product']];
						}
						else {
							$query5 = "select Category from `".$Settings['DBPrefix']."ec-Products` where RecordNumber='".$row2['Product']."' limit 1";
							$result5 = mysql_query($query5) or die (mysql_error());
							$row5 = mysql_fetch_array($result5);
							
							$Categories[$row2['Product']] = $row5['Category'];
							$ThisCategory = $row5['Category'];
						}
						
						if ($ShippingOptions[$ThisCategory] != '') {
							$ThisShippingList = $ShippingOptions[$ThisCategory];
						}
						else {
							if ($ecSettings['ShippingOptions'] != '') {
								$row5['ShippingOptions'] = $ecSettings['ShippingOptions'];
							}
							else {
								$query5 = "select ShippingOptions from `".$Settings['DBPrefix']."ec-Categories` where RecordNumber='".$ThisCategory."' limit 1";
								$result5 = mysql_query($query5) or die (mysql_error());
								$row5 = mysql_fetch_array($result5);
							}
							
							$ShippingOptions[$ThisCategory] = $row5['ShippingOptions'];
							$ThisShippingList = $row5['ShippingOptions'];
						}					
						
						
						$ShippingOptionsArray = explode(',',$ThisShippingList);
					
						for ($j = 0; $j < (count($ShippingOptionsArray)-1); $j++) {
							$ShippingItemsCount[$ShippingOptionsArray[$j]]++;
							
							if ($ShippingOptionsArray[$j] > $HighestOptionFound) {
								$HighestOptionFound = $ShippingOptionsArray[$j];
							}
						
						}
						
					} // end if item num != ''
					
				} // end items loop
				
				for ($j = 1; $j <= $HighestOptionFound; $j++) {
				
					if ($ShippingItemsCount[$j] == $ItemsCount) {
						// this shipping option can be used for all products found in list
						$ShippingOptionAvailable[$j] = true;
					}
								
				}
					
				
				
			}
			else {
				// just one item
				
				list ($ItemNumA, $Qty) = explode('x',$ItemsList[0]);
				$ItemsQty += $Qty;
				
				list ($ItemNum, $Incentive) = explode('-', $ItemNumA);
				
				
				if ($ItemNum != '') {
				
									
					$query3 = "select * from `".$Settings['DBPrefix']."ec-Items` where RecordNumber='".$ItemNum."' limit 1";
					$result3 = mysql_query($query3) or die (mysql_error());
					$row3 = mysql_fetch_array($result3);
							
					$query4 = "select * from `".$Settings['DBPrefix']."ec-Products` where RecordNumber='".$row3['Product']."' limit 1";
					$result4 = mysql_query($query4) or die (mysql_error());
					$row4 = mysql_fetch_array($result4);
					
						
					if ($row3['Option2'] != '') {
						$row4['Name'] .= ' ('.$row3['Option1'].', '.$row3['Option2'].')';
					}
					else if ($row3['Option1'] != '') {
						$row4['Name'] .= ' ('.$row3['Option1'].')';
					}
					
					
					if ($Incentive == '') {
						
										
						$PricingLevel = 1;
						for ($k = 1; $k <= 10; $k++) {
							if ($row3['PriceQty'.$k] > 0 && $Qty >= $row3['PriceQty'.$k]) {
								$PricingLevel = $k;
							}
						}
						
						
						
					// check to see if there are any active sales to apply to this item
					
					$Sale = false;
					
					$CurrentTime = GetTimestamp();
					
					$SalesList = '';
					$SalesDetails = '';
					
					for ($CategoriesCount = 1; $CategoriesCount <= 5; $CategoriesCount++) {
					
						if ($CategoriesCount > 1) {
							$WorkingCategoryNum = $row4['Category'.$CategoriesCount];
						}
						else {
							$WorkingCategoryNum = $row4['Category'];
						}
							
						while ($WorkingCategoryNum >= 0) {
							$query24 = "select * from `".$Settings['DBPrefix']."ec-Sales` where StartDate<='".$CurrentTime."' and EndDate>='".$CurrentTime."' and (Categories LIKE '%,".$WorkingCategoryNum.",%' or Products LIKE '%,".$row4['RecordNumber'].",%') limit 1";
							$result24 = mysql_query($query24) or die (mysql_error());
							if (mysql_num_rows($result24) > 0) {
								$row24 = mysql_fetch_array($result24);
							
								if ($SalesDetails[$row24['RecordNumber']] == '') {
									$SalesDetails[$row24['RecordNumber']] = $row24;
									$SalesList[] = $row24['RecordNumber'];
								}
							}
						
							if ($WorkingCategoryNum > 0) {
								$query25 = "select * from `".$Settings['DBPrefix']."ec-Categories` where RecordNumber='".$WorkingCategoryNum."' limit 1";
								$result25 = mysql_query($query25) or die (mysql_error());
								$row25 = mysql_fetch_array($result25);
								
								$WorkingCategoryNum = $row25['Parent'];
							}
							else {
								$WorkingCategoryNum = -1;
							}
						
						}
						
					} // end loop categories 1-5
					
						
					//for ($SalesCount = 0; $SalesCount < count($SalesList); $SalesCount++) {
						$row24 = $SalesDetails[$SalesList[0]];
					//}	
						
					
					if ($row24['DiscountAmount'] > 0 || $row24['DiscountPercent'] > 0) {
					
						if ($row24['DiscountAmount'] > 0) {
							$row3['Price'.$PricingLevel] = ($row3['Price'.$PricingLevel] - $row24['DiscountAmount']);
						}
						if ($row24['DiscountPercent'] > 0) {
							$row3['Price'.$PricingLevel] = ($row3['Price'.$PricingLevel] - ($row3['Price'.$PricingLevel] * ($row24['DiscountPercent']/100)));
						}
												
						$Sale = true;
						$SaleName = $row24['Name'];
						
					}	
					
					
					// end sales portion
						
						
						$AdditionalShipping += 	($row3['AdditionalShipping']*$Qty);
						$OrderTotal += ($row3['Price'.$PricingLevel]*$Qty);
							
					
					} // end if not incentive
					else {
						// incentive item
						
						$query7 = "select * from `".$Settings['DBPrefix']."ec-Incentives` where RecordNumber='".$Incentive."' and Active=1 limit 1";
						$result7 = mysql_query($query7) or die (mysql_error());
						if (mysql_num_rows($result7) != 0) {
							$row7 = mysql_fetch_array($result7);
							
							if ($Qty > $row7['Arguments3']) {
								$Qty = $row7['Arguments3'];
							}
							
							$OrderTotal += ($row7['Arguments5']*$Qty);
													
																		
						}
					}
						
				} // end if item num != ''
				
				
				$query2 = "select Product,ShippingWeight from `".$Settings['DBPrefix']."ec-Items` where RecordNumber='".$ItemNum."' limit 1";
				$result2 = mysql_query($query2) or die (mysql_error());
				$row2 = mysql_fetch_array($result2);
				
				$ShippingWeight = ($row2['ShippingWeight']*$Qty);
															
				
				$query5 = "select Category,ShippingOptions from `".$Settings['DBPrefix']."ec-Products` where RecordNumber='".$row2['Product']."' limit 1";
				$result5 = mysql_query($query5) or die (mysql_error());
				$row5 = mysql_fetch_array($result5);
				
				$ThisShippingList = $row5['ShippingOptions'];
				
				
				$query5 = "select ShippingOptions from `".$Settings['DBPrefix']."ec-Categories` where RecordNumber='".$row5['Category']."' limit 1";
				$result5 = mysql_query($query5) or die (mysql_error());
				$row5 = mysql_fetch_array($result5);
				
				$ThisShippingList .= ','.$row5['ShippingOptions'];
								
									
				//print '<br><br>==='.$ThisShippingList.'===<br><br>';
				
				$ShippingOptionsArray = explode(',',$ThisShippingList);
				
				for ($j = 0; $j < (count($ShippingOptionsArray)-1); $j++) {
					if ($ShippingOptionsArray[$j] != '') {
						$ShippingOptionAvailable[$ShippingOptionsArray[$j]] = true;
					}
				}
										
			}
			
			
			if (count($ShippingOptionAvailable) < 1) {
				 $UseAllActiveShipping = true;
			}
			
											
			$query6 = "select * from `".$Settings['DBPrefix']."ec-Shipping` where (Countries LIKE '%".$row103['Country'].",%' or Countries='') and Active=1 order by Priority asc, BasePrice asc";
			$result6 = mysql_query($query6) or die (mysql_error());
			while ($row6 = mysql_fetch_array($result6)) {
															
				if ($ShippingOptionAvailable[$row6['RecordNumber']] == true || $UseAllActiveShipping == true) {
					if ($row6['Countries'] != '') {
						$CountryOptionsFound++;
					}
				
					if ($row6['Countries'] != '' || ($row6['Countries'] == '' && $CountryOptionsFound < 1)) {
											
						// CalculateShippingRate(ShippingID, ShippingWeight, OrderTotal, ItemsCount, DestinationZip) <<Returns Shipping Price>>
						$ShippingPrice = CalculateShippingRate($row6['RecordNumber'], $ShippingWeight, $OrderTotal, $ItemsQty, $row103['ZipPostal']);
						
						//print '<br>CalculateShippingRate('.$row6['RecordNumber'].', '.$ShippingWeight.', '.$OrderTotal.', '.$ItemsQty.', '.$row103['ZipPostal'].')<br>';
						
						//if ($ShippingPrice != '') {
							$ShippingAvailableID[] = $row6['RecordNumber'];
							$ShippingAvailableName[] = $row6['Description'];
							$ShippingAvailablePrice[] = ($ShippingPrice+$AdditionalShipping);
						//}
						
			
					} // end if available for person
			
				} // end if available for products
			
			} // end loop
			
							
			
			if (count($ShippingAvailableID) > 0) {
			
				$PageContents .= '<b>'.$MsgText[9][326].'</b><br>'.$MsgText[9][327].'<form action="'.$MainURL.'/store/checkout/4.html" method="post">';
			
				$ShippingChecked[0] = ' checked';
											
				for ($x = 0; $x < count($ShippingAvailableID); $x++) {
					$PageContents .= '<input type="radio" name="ShippingType" value="'.$ShippingAvailableID[$x].'"'.$ShippingChecked[$x].'> 
<b>'.$ShippingAvailableName[$x].'</b> ('.$CurrencyBefore.number_format($ShippingAvailablePrice[$x],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.')<br><br>';
				}
			
				$PageContents .= '<br><div align="center"><input type="hidden" name="BillingAddress" value="'.$FormArguments['BillingAddress'].'"><input type="hidden" name="ShippingAddress" value="'.$FormArguments['ShippingAddress'].'"><input type="submit" value="'.$MsgText[0][564].'" style="'.$FormStyle.'"></div></form>';
			
			}
			else {
				
				$PageContents = '<br><b>'.$MsgText[9][328].'</b>';
							
			} 
			
			}
			else {
				$PageContents = '<br><b>'.$MsgText[9][329].': <b><a href="'.$MainURL.'/store/checkout.html">'.$MsgText[9][303].'</a></b></b>';
			}
			
			
		} // end if $Arguments3 == '3'
		
		else if ($Arguments3 == '4') {
		
			ReadFormArguments();
			Global $FormArguments;
		
			if (count($FormArguments) > 0) {
			
				if ($ShoppingCartContents != '') {
				
					$query37 = "select * from `".$Settings['DBPrefix']."ec-Addresses` where RecordNumber=".intval($FormArguments['ShippingAddress'])." and Account=".$UserNumber." and Active=1 limit 1";
					$result37 = mysql_query($query37) or die (mysql_error());
					$row37 = mysql_fetch_array($result37);
					
					
					if ($FormArguments['ShippingAddress'] != $FormArguments['BillingAddress']) {
						$query39 = "select * from `".$Settings['DBPrefix']."ec-Addresses` where RecordNumber=".intval($FormArguments['BillingAddress'])." and Account=".$UserNumber." and Active=1 limit 1";
						$result39 = mysql_query($query39) or die (mysql_error());
						$row39 = mysql_fetch_array($result39);
					}
					else {
						$row39 = $row37;
					}
					
					
				
					$ItemsList = explode(',',$ShoppingCartContents);
					$ItemFound = false;
				
					for ($i = 0; $i < (count($ItemsList)-1); $i++) {
						list ($ItemNumA, $Qty) = explode('x',$ItemsList[$i]);
						$ItemsQty += $Qty;
						
						list ($ItemNum, $Incentive) = explode('-', $ItemNumA);
						
						
						$query3 = "select * from `".$Settings['DBPrefix']."ec-Items` where RecordNumber='".$ItemNum."' limit 1";
						$result3 = mysql_query($query3) or die (mysql_error());
						$row3 = mysql_fetch_array($result3);
						
						$ShippingWeight += ($row3['ShippingWeight']*$Qty);
						
						$query4 = "select * from `".$Settings['DBPrefix']."ec-Products` where RecordNumber='".$row3['Product']."' limit 1";
						$result4 = mysql_query($query4) or die (mysql_error());
						$row4 = mysql_fetch_array($result4);
						
						
						if ($row3['Option2'] != '') {
							$row4['Name'] .= ' ('.$row3['Option1'].', '.$row3['Option2'].')';
							}
						else if ($row3['Option1'] != '') {
							$row4['Name'] .= ' ('.$row3['Option1'].')';
						}
						
						
						if ($Incentive == '') {
						
													
							$PricingLevel = 1;
							for ($k = 1; $k <= 10; $k++) {
								if ($row3['PriceQty'.$k] > 0 && $Qty >= $row3['PriceQty'.$k]) {
									$PricingLevel = $k;
								}
							}
							
							
							
					// check to see if there are any active sales to apply to this item
					
					$Sale = false;
					
					$CurrentTime = GetTimestamp();
					
					$SalesList = '';
					$SalesDetails = '';
					
					for ($CategoriesCount = 1; $CategoriesCount <= 5; $CategoriesCount++) {
					
						if ($CategoriesCount > 1) {
							$WorkingCategoryNum = $row4['Category'.$CategoriesCount];
						}
						else {
							$WorkingCategoryNum = $row4['Category'];
						}
							
						while ($WorkingCategoryNum >= 0) {
							$query24 = "select * from `".$Settings['DBPrefix']."ec-Sales` where StartDate<='".$CurrentTime."' and EndDate>='".$CurrentTime."' and (Categories LIKE '%,".$WorkingCategoryNum.",%' or Products LIKE '%,".$row4['RecordNumber'].",%') limit 1";
							$result24 = mysql_query($query24) or die (mysql_error());
							if (mysql_num_rows($result24) > 0) {
								$row24 = mysql_fetch_array($result24);
							
								if ($SalesDetails[$row24['RecordNumber']] == '') {
									$SalesDetails[$row24['RecordNumber']] = $row24;
									$SalesList[] = $row24['RecordNumber'];
								}
							}
						
							if ($WorkingCategoryNum > 0) {
								$query25 = "select * from `".$Settings['DBPrefix']."ec-Categories` where RecordNumber='".$WorkingCategoryNum."' limit 1";
								$result25 = mysql_query($query25) or die (mysql_error());
								$row25 = mysql_fetch_array($result25);
								
								$WorkingCategoryNum = $row25['Parent'];
							}
							else {
								$WorkingCategoryNum = -1;
							}
						
						}
						
					} // end loop categories 1-5
					
						
					//for ($SalesCount = 0; $SalesCount < count($SalesList); $SalesCount++) {
						$row24 = $SalesDetails[$SalesList[0]];
					//}	
						
					
					if ($row24['DiscountAmount'] > 0 || $row24['DiscountPercent'] > 0) {
					
						if ($row24['DiscountAmount'] > 0) {
							$row3['Price'.$PricingLevel] = ($row3['Price'.$PricingLevel] - $row24['DiscountAmount']);
						}
						if ($row24['DiscountPercent'] > 0) {
							$row3['Price'.$PricingLevel] = ($row3['Price'.$PricingLevel] - ($row3['Price'.$PricingLevel] * ($row24['DiscountPercent']/100)));
						}
												
						$Sale = true;
						$SaleName = $row24['Name'];
						
					}	
					
					
					// end sales portion
							
							
							
							$ItemPrice = $row3['Price'.$PricingLevel];
				
							$Subtotal = ($row3['Price'.$PricingLevel]*$Qty);
							$AdditionalShipping += 	($row3['AdditionalShipping']*$Qty);
							
							$ItemsTotal += $Subtotal;
							
						
							$ContentsPrint .= '<tr><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$Qty.'</b></font></td><td><font face="'.$FontFace.'" size="'.$FontSize.'">'.$row4['Name'].'</font></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$CurrencyBefore.number_format($ItemPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</font></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$CurrencyBefore.number_format($Subtotal,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</font></td></tr>';

						
						} // end if not incentive
						else {
					
							$query7 = "select * from `".$Settings['DBPrefix']."ec-Incentives` where RecordNumber='".$Incentive."' and Active=1 limit 1";
							$result7 = mysql_query($query7) or die (mysql_error());
							if (mysql_num_rows($result7) != 0) {
								$row7 = mysql_fetch_array($result7);
								
								if ($Qty > $row7['Arguments3']) {
									$Qty = $row7['Arguments3'];
								}
							
	
								if ($row7['Arguments6'] != '') {
									$row7['Arguments6'] = '<br><b>'.$row7['Arguments6'].'</b>';						
								}
							
						
								$ItemPrice = $row7['Arguments5'];
			
								$Subtotal = ($row7['Arguments5']*$Qty);
							
								$ItemsTotal += $Subtotal;
								
							
								$ContentsPrint .= '<tr><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$Qty.'</b></font></td><td><font face="'.$FontFace.'" size="'.$FontSize.'">'.$row4['Name'].$row7['Arguments6'].'</font></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$CurrencyBefore.number_format($ItemPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</font></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$CurrencyBefore.number_format($Subtotal,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</font></td></tr>';
						
																		
							}
							
						} // end if incentive
					
					}
				
								
					$Total = ($ItemsTotal + $TotalTaxes);
													
				
				}
							
						
						
				
				
				
				$query6 = "select * from `".$Settings['DBPrefix']."ec-Shipping` where RecordNumber='".$FormArguments['ShippingType']."' limit 1";
				$result6 = mysql_query($query6) or die (mysql_error());
				$row6 = mysql_fetch_array($result6);
							
				$ShippingName = $row6['Description'];
				
				// CalculateShippingRate(ShippingID, ShippingWeight, OrderTotal, ItemsCount, DestinationZip) <<Returns Shipping Price>>
				$ShippingPrice = (CalculateShippingRate($FormArguments['ShippingType'], $ShippingWeight, $ItemsTotal, $ItemsQty, $row37['ZipPostal'])+$AdditionalShipping);
						
				//print '<br>CalculateShippingRate('.$FormArguments['ShippingType'].', '.$ShippingWeight.', '.$ItemsTotal.', '.$ItemsQty.', '.$row37['ZipPostal'].')<br>';
				
				
				
				$query69 = "select * from `".$Settings['DBPrefix']."ec-Taxes` where ((Type='N' and Arguments1='".$row39['Country']."') or (Type='S' and Arguments1='".$row39['Country']."' and Arguments2='".$row39['StateProvince']."')) and Active=1 order by Type asc";
				$result69 = mysql_query($query69);
				while ($row69 = mysql_fetch_array($result69)) {
					if ($row69['Number'] != '') {
						$row69['Number'] = ' ('.$row69['Number'].')';
					}
					
					if ($row69['TaxShipping'] == 1) {
						$TaxAmount = number_format((($Total+$ShippingPrice)*($row69['Rate']/100)),$ecSettings['PriceDecimals'],'.','');
					}
					else {
						$TaxAmount = number_format(($Total*($row69['Rate']/100)),$ecSettings['PriceDecimals'],'.','');
					}
				
					$TaxesSection .= '<tr><td colspan="3" align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$row69['Title'].$row69['Number'].' '.$row69['Description'].' ('.(($row69['Rate']+1)-1).'%)</b></font></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$CurrencyBefore.number_format($TaxAmount,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></td></tr>';
					$TaxesTotal += $TaxAmount;
				}
				
				
				$LocalTaxesList = explode(',',$row39['Taxes']);
				
				for ($z = 0; $z < (count($LocalTaxesList)-1); $z++) {
				
					$query69 = "select * from `".$Settings['DBPrefix']."ec-Taxes` where Type='L' and Arguments1='".$row39['Country']."' and Arguments2='".$row39['StateProvince']."' and Active=1 and RecordNumber=".$LocalTaxesList[$z]." limit 1";
					$result69 = mysql_query($query69);
					if (mysql_num_rows($result69) > 0) {
						$row69 = mysql_fetch_array($result69);
					
						if ($row69['Number'] != '') {
							$row69['Number'] = ' ('.$row69['Number'].')';
						}
					
						if ($row69['TaxShipping'] == 1) {
							$TaxAmount = number_format((($Total+$ShippingPrice)*($row69['Rate']/100)),$ecSettings['PriceDecimals'],'.','');
						}
						else {
							$TaxAmount = number_format(($Total*($row69['Rate']/100)),$ecSettings['PriceDecimals'],'.','');
						}
				
						$TaxesSection .= '<tr><td colspan="3" align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$row69['Title'].$row69['Number'].' '.$row69['Description'].' ('.(($row69['Rate']+1)-1).'%)</b></font></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$CurrencyBefore.number_format($TaxAmount,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></td></tr>';
						$TaxesTotal += $TaxAmount;
					}
					
				}
				
				
				$PaymentOptions = 0;
				
				if ($ecSettings['PaypalEmail'] != '') {
					$PaypalOption = '<br><br>
<input type="radio" name="PaymentMethod" value="1"> '.$MsgText[9][330].'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="'.$ImagesURL.'/admin/creditcards.gif" alt="" border="0">';
					$PaymentOptions++;
				}
				
				if ($ecSettings['GoogleCheckoutMerchantID'] != '') {
					$GoogleCheckoutOption = '<br><br>
<input type="radio" name="PaymentMethod" value="4"> '.$MsgText[9][363].'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="'.$ImagesURL.'/admin/creditcards_googlecheckout.gif" alt="" border="0">';
					$PaymentOptions++;
				}
				
				if ($ecSettings['OfflinePayableTo'] != '') {
					$OfflineOption = '<br><br>
<input type="radio" name="PaymentMethod" value="2"> '.$MsgText[9][177].'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="'.$ImagesURL.'/admin/cheque.gif" alt="" border="0">';
					$PaymentOptions++;
				}
				
					
								
					
				
				$PageContents = '<br><b>'.$MsgText[9][331].'</b><br><br><b>'.$MsgText[9][332].'</b><br><br><br><div align="center"><table width="90%" cellpadding="4" cellspacing="0" border="0"><tr><td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[9][248].'</b></font></td><td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[9][249].'</b></font></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[9][250].'</b></font></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[9][251].'</b></font></td></tr>'.$ContentsPrint.'<tr><td colspan="4"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="5" alt="" border="0"></td></tr><tr><td colspan="2"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/store/viewcart.html"><b>'.$MsgText[9][333].'</b></a></font></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[9][252].'</b></font></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$CurrencyBefore.number_format($ItemsTotal,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></td></tr>'.$TaxesSection.'<tr><td colspan="3" align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$SHTitle.'</b> - '.$ShippingName.'<br><b><a href="'.$MainURL.'/store/checkout/2.html">'.$MsgText[9][334].'</a></b></font></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$CurrencyBefore.number_format($ShippingPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></td></tr><tr><td colspan="3" align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[9][253].'</b></font></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$CurrencyBefore.number_format(($Total+$ShippingPrice+$TaxesTotal),$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b></font></td></tr></table><br></div><br><div align="center"><form name="SubmitForm" action="'.$MainURL.'/store/completeorder.html" method="post"><input type="hidden" name="ShippingType" value="'.$FormArguments['ShippingType'].'"><input type="hidden" name="BillingAddress" value="'.$FormArguments['BillingAddress'].'"><input type="hidden" name="ShippingAddress" value="'.$FormArguments['ShippingAddress'].'"><br><b>'.$MsgText[9][335].' ('.$MsgText[0][418].'):</b><br><textarea name="NotesComments" cols="40" rows="3" style="'.$FormStyle.'"></textarea>';
				
				
				if ($PaymentOptions > 0) {
				
					$PageContents .= '<br><br><br><table border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[9][211].':</b>'.$PaypalOption.$GoogleCheckoutOption.$OfflineOption.'</td>
    </tr>
</table>

<script>
function CheckPayment() {

	var PaymentSelected = false;
	if (document.forms["SubmitForm"].elements["PaymentMethod"].length) {
		for (x=0; x < document.forms["SubmitForm"].elements["PaymentMethod"].length; x++) {
		
			if (document.forms["SubmitForm"].elements["PaymentMethod"][x].checked == true) {
				PaymentSelected = true;
			}
		}
	}
	else {
		if (document.forms["SubmitForm"].elements["PaymentMethod"].checked == true) {
			PaymentSelected = true;
		}
	}

	if (PaymentSelected == false) {
		alert("'.$MsgText[9][336].'");
	}
	else {
		document.forms["SubmitForm"].submit();
	}
	
}
</script>
<br><br><br><input type="button" value="'.$MsgText[9][332].'" onClick="CheckPayment();" style="'.$FormStyle.'"></form>';

				}
				else {
				
					$PageContents .= '<br><br><br><b>'.$MsgText[9][367].'</b>';
				
				}
				
				
				$PageContents .= '</div>';
				
			
			}
			else {
			
				$PageContents = $MsgText[9][337];
			
			}
		
		} // end if $Arguments3 == '4'
		
		} // end if cart not empty
		else {
		
			$PageContents = '<br><div align="center">['.$MsgText[9][296].']</div><br><br><a href="'.$MainURL.'/store.html"><b>'.$MsgText[9][288].'</b></a>';
		
		}
					
	} // end if $Arguments2 == 'checkout'
	else if ($Arguments2 == 'completeorder') {
	
		ReadFormArguments();
		Global $FormArguments;
		
		if (count($FormArguments) > 0) {
	
			$query3 = "select Email,ShoppingCartContents from `".$Settings['DBPrefix']."core-Users` where Username='".$CookieUsername."' limit 1";
			$result3 = mysql_query($query3) or die (mysql_error());
			$row3 = mysql_fetch_array($result3);
			$ShoppingCartContents = $row3['ShoppingCartContents'];
			$UserEmail = $row3['Email'];
			
			
			if ($ShoppingCartContents != '') {
			
			
					$query37 = "select * from `".$Settings['DBPrefix']."ec-Addresses` where RecordNumber=".intval($FormArguments['ShippingAddress'])." and Account=".$UserNumber." and Active=1 limit 1";
					$result37 = mysql_query($query37) or die (mysql_error());
					$row37 = mysql_fetch_array($result37);
					
					if ($row37['OrganizationCompany'] != '') {
						$row37['OrganizationCompany'] .= "\n";
					}
					
					if ($row37['Address2'] != '') {
						$row37['Address1'] .= "\n".$row37['Address2'];
					}
					if ($row37['Address3'] != '') {
						$row37['Address1'] .= "\n".$row37['Address3'];
					}
					if ($row37['Address4'] != '') {
						$row37['Address1'] .= "\n".$row37['Address4'];
					}
					
					$ShippingAddressPrint = $row37['FirstName'].' '.$row37['LastName']."\n".$row37['OrganizationCompany'].$row37['Address1']."\n" . $row37['City'].', '.$row37['StateProvince']."\n".$row37['ZipPostal']."\n\n".$MsgText[0][108].": ".$row37['Phone'];
					
					
					if ($FormArguments['ShippingAddress'] != $FormArguments['BillingAddress']) {
						$query39 = "select * from `".$Settings['DBPrefix']."ec-Addresses` where RecordNumber=".intval($FormArguments['BillingAddress'])." and Account=".$UserNumber." and Active=1 limit 1";
						$result39 = mysql_query($query39) or die (mysql_error());
						$row39 = mysql_fetch_array($result39);
					}
					else {
						$row39 = $row37;
					}
			
			
			
					$ItemsList = explode(',',$ShoppingCartContents);
					$ItemFound = false;
				
					for ($i = 0; $i < (count($ItemsList)-1); $i++) {
						list ($ItemNumA, $Qty) = explode('x',$ItemsList[$i]);
						$ItemsQty += $Qty;
						
						list ($ItemNum, $Incentive) = explode('-', $ItemNumA);
						
						
						$query3 = "select * from `".$Settings['DBPrefix']."ec-Items` where RecordNumber='".$ItemNum."' limit 1";
						$result3 = mysql_query($query3) or die (mysql_error());
						$row3 = mysql_fetch_array($result3);
						
					
						// if stock is being tracked (-1 if it's not)
						if ($row3['Stock'] >= 0) {
							$row3['Stock'] = ($row3['Stock']-$Qty);
							
							if ($row3['Stock'] < 0) {
								$row3['Stock'] = 0;
							}
							
							$query123 = "update `".$Settings['DBPrefix']."ec-Items` set Stock='".$row3['Stock']."' where RecordNumber='".$ItemNum."' limit 1";
							$result123 = mysql_query($query123) or die (mysql_error());
						}
					
						
						
						$ShippingWeight += ($row3['ShippingWeight']*$Qty);
						
						$query4 = "select * from `".$Settings['DBPrefix']."ec-Products` where RecordNumber='".$row3['Product']."' limit 1";
						$result4 = mysql_query($query4) or die (mysql_error());
						$row4 = mysql_fetch_array($result4);
						
						
						if ($row3['Option2'] != '') {
							$row4['Name'] .= ' ('.$row3['Option1'].', '.$row3['Option2'].')';
						}
						else if ($row3['Option1'] != '') {
							$row4['Name'] .= ' ('.$row3['Option1'].')';
						}
						
						
						if ($Incentive == '') {
						
							
							$PricingLevel = 1;
							for ($k = 1; $k <= 10; $k++) {
								if ($row3['PriceQty'.$k] > 0 && $Qty >= $row3['PriceQty'.$k]) {
									$PricingLevel = $k;
								}
							}
						
						
					// check to see if there are any active sales to apply to this item
					
					$Sale = false;
					
					$CurrentTime = GetTimestamp();
					
					$SalesList = '';
					$SalesDetails = '';
					
					for ($CategoriesCount = 1; $CategoriesCount <= 5; $CategoriesCount++) {
					
						if ($CategoriesCount > 1) {
							$WorkingCategoryNum = $row4['Category'.$CategoriesCount];
						}
						else {
							$WorkingCategoryNum = $row4['Category'];
						}
							
						while ($WorkingCategoryNum >= 0) {
							$query24 = "select * from `".$Settings['DBPrefix']."ec-Sales` where StartDate<='".$CurrentTime."' and EndDate>='".$CurrentTime."' and (Categories LIKE '%,".$WorkingCategoryNum.",%' or Products LIKE '%,".$row4['RecordNumber'].",%') limit 1";
							$result24 = mysql_query($query24) or die (mysql_error());
							if (mysql_num_rows($result24) > 0) {
								$row24 = mysql_fetch_array($result24);
							
								if ($SalesDetails[$row24['RecordNumber']] == '') {
									$SalesDetails[$row24['RecordNumber']] = $row24;
									$SalesList[] = $row24['RecordNumber'];
								}
							}
						
							if ($WorkingCategoryNum > 0) {
								$query25 = "select * from `".$Settings['DBPrefix']."ec-Categories` where RecordNumber='".$WorkingCategoryNum."' limit 1";
								$result25 = mysql_query($query25) or die (mysql_error());
								$row25 = mysql_fetch_array($result25);
								
								$WorkingCategoryNum = $row25['Parent'];
							}
							else {
								$WorkingCategoryNum = -1;
							}
						
						}
						
					} // end loop categories 1-5
					
						
					//for ($SalesCount = 0; $SalesCount < count($SalesList); $SalesCount++) {
						$row24 = $SalesDetails[$SalesList[0]];
					//}	
						
					
					if ($row24['DiscountAmount'] > 0 || $row24['DiscountPercent'] > 0) {
					
						if ($row24['DiscountAmount'] > 0) {
							$row3['Price'.$PricingLevel] = ($row3['Price'.$PricingLevel] - $row24['DiscountAmount']);
						}
						if ($row24['DiscountPercent'] > 0) {
							$row3['Price'.$PricingLevel] = ($row3['Price'.$PricingLevel] - ($row3['Price'.$PricingLevel] * ($row24['DiscountPercent']/100)));
						}
												
						$Sale = true;
						$SaleName = $row24['Name'];
						
					}	
					
					
					// end sales portion
						
						
						
						
							$ItemPrice = $row3['Price'.$PricingLevel];
				
							$Subtotal = ($row3['Price'.$PricingLevel]*$Qty);
							$AdditionalShipping = ($row3['AdditionalShipping']*$Qty);
							
							$ItemsTotal += $Subtotal;
							
					
							$ContentsPrint .= $Qty.'- '.$row4['Name'].' ('.$CurrencyBefore.number_format($ItemPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.')'."\n";


							$OrderString .= $ItemNum.'x'.$Qty.'@'.$ItemPrice.',';
							
							
						}
						else {
						
							$query7 = "select * from `".$Settings['DBPrefix']."ec-Incentives` where RecordNumber='".$Incentive."' and Active=1 limit 1";
							$result7 = mysql_query($query7) or die (mysql_error());
							if (mysql_num_rows($result7) != 0) {
								$row7 = mysql_fetch_array($result7);
								
								if ($Qty > $row7['Arguments3']) {
									$Qty = $row7['Arguments3'];
								}
							
	
								if ($row7['Arguments6'] != '') {
									$row7['Arguments6'] = ' - '.$row7['Arguments6'];						
								}
							
						
								$ItemPrice = $row7['Arguments5'];
			
								$Subtotal = ($row7['Arguments5']*$Qty);
							
								$ItemsTotal += $Subtotal;
								
							
								$ContentsPrint .= $Qty.'- '.$row4['Name'].$row7['Arguments6'].' ('.$CurrencyBefore.number_format($ItemPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.')'."\n";

								$OrderString .= $ItemNum.'x'.$Qty.'@'.$ItemPrice.',';
													
																		
							}
							
						} // end if incentive						
						
											
							
					}
				
								
					
					
				$query6 = "select * from `".$Settings['DBPrefix']."ec-Shipping` where RecordNumber='".$FormArguments['ShippingType']."' limit 1";
				$result6 = mysql_query($query6) or die (mysql_error());
				$row6 = mysql_fetch_array($result6);
							
				// CalculateShippingRate(ShippingID, ShippingWeight, OrderTotal, ItemsCount, DestinationZip) <<Returns Shipping Price>>
				$ShippingPrice = (CalculateShippingRate($FormArguments['ShippingType'], $ShippingWeight, $ItemsTotal, $ItemsQty, $row37['ZipPostal'])+$AdditionalShipping);
				$TotalShipping = $ShippingPrice;
						
				//print '<br>CalculateShippingRate('.$FormArguments['ShippingType'].', '.$ShippingWeight.', '.$ItemsTotal.', '.$ItemsQty.', '.$row37['ZipPostal'].')<br>';
			
			
			
				$query69 = "select * from `".$Settings['DBPrefix']."ec-Taxes` where ((Type='N' and Arguments1='".$row39['Country']."') or (Type='S' and Arguments1='".$row39['Country']."' and Arguments2='".$row39['StateProvince']."')) and Active=1 order by Type asc";
				$result69 = mysql_query($query69);
				while ($row69 = mysql_fetch_array($result69)) {
					if ($row69['Number'] != '') {
						$row69['Number'] = ' ('.$row69['Number'].')';
					}
					
					if ($row69['TaxShipping'] == 1) {
						$TaxAmount = number_format((($ItemsTotal+$TotalShipping)*($row69['Rate']/100)),$ecSettings['PriceDecimals'],'.','');
					}
					else {
						$TaxAmount = number_format(($ItemsTotal*($row69['Rate']/100)),$ecSettings['PriceDecimals'],'.','');
					}
				
					$TaxesSection .= "\n".$row69['Title'].$row69['Number'].' '.$row69['Description'].' ('.(($row69['Rate']+1)-1).'%): '.$CurrencyBefore.number_format($TaxAmount,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter;
					$TaxesTotal += $TaxAmount;
					$TaxesString .= $row69['RecordNumber'].'-'.$row69['Rate'].'-'.$TaxAmount.',';
				}
				
				
				$LocalTaxesList = explode(',',$row39['Taxes']);
				
				for ($z = 0; $z < (count($LocalTaxesList)-1); $z++) {
				
					$query69 = "select * from `".$Settings['DBPrefix']."ec-Taxes` where Type='L' and Arguments1='".$row39['Country']."' and Arguments2='".$row39['StateProvince']."' and Active=1 and RecordNumber=".$LocalTaxesList[$z]." limit 1";
					$result69 = mysql_query($query69);
					if (mysql_num_rows($result69) > 0) {
						$row69 = mysql_fetch_array($result69);
					
						if ($row69['Number'] != '') {
							$row69['Number'] = ' ('.$row69['Number'].')';
						}
						
						if ($row69['TaxShipping'] == 1) {
							$TaxAmount = number_format((($ItemsTotal+$TotalShipping)*($row69['Rate']/100)),$ecSettings['PriceDecimals']);
						}
						else {
							$TaxAmount = number_format(($ItemsTotal*($row69['Rate']/100)),$ecSettings['PriceDecimals']);
						}
				
						$TaxesSection .= "\n".$row69['Title'].$row69['Number'].' '.$row69['Description'].' ('.(($row69['Rate']+1)-1).'%): '.$CurrencyBefore.number_format($TaxAmount,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter;
						$TaxesTotal += $TaxAmount;
						$TaxesString .= $row69['RecordNumber'].'-'.$row69['Rate'].'-'.$TaxAmount.',';
					}
					
				}
				
				if ($TaxesSection != '') {
					$TaxesSection = $TaxesSection."\n\n";
				}
			
			
						
			
			$OrderTotal = ($ItemsTotal + $TaxesTotal + $TotalShipping);
			$PayPalItemsTotal = ($ItemsTotal + $TaxesTotal);
		
		
			//$OrderID = $UserNumber.'-'.date('Ymd',GetTimestamp()).'-'.rand(100,5000);
			$OrderID = $UserNumber.'-'.date('Ymd',GetTimestamp());
		
			$query8 = "insert into `".$Settings['DBPrefix']."ec-Orders` (Account, OrderID, DateCode, Items, ItemsTotal, ShippingAmount, ShippingType, BillingAddress, ShippingAddress, Taxes, NotesComments, PaymentMethod, OrderStatus) values ('".$UserNumber."', '".$OrderID."', '".GetTimestamp()."', '".$OrderString."', '".$ItemsTotal."', '".$TotalShipping."', '".$FormArguments['ShippingType']."', '".$FormArguments['BillingAddress']."', '".$FormArguments['ShippingAddress']."', '".$TaxesString."', '".$FormArguments['NotesComments']."', '".$FormArguments['PaymentMethod']."', 'a')";
			$result8 = mysql_query($query8) or die (mysql_error());
			$RecordNumberCreated = mysql_insert_id();
			
			$OrderID = $RecordNumberCreated.'-'.$OrderID;
			
			
			
			// send emails
			$Message = $MsgText[9][338]."\n\n\n".$ContentsPrint."\n".$TaxesSection."\n".$SHTitle.': '.$CurrencyBefore.number_format($TotalShipping,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.' ('.$row6['Description'].")\n\n".$MsgText[9][253].': '.$CurrencyBefore.number_format($OrderTotal,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter."\n\n\n".$MsgText[9][246].':'."\n".$ShippingAddressPrint."\n\n\n".$FormArguments['NotesComments']."\n\n\n\n".$MsgText[0][142].','."\n".$Settings['SiteName']."\n".$IndexURL;
			mail($UserEmail, $MsgText[9][339].' '.$OrderID, $Message, 'From: "'.$Settings['SiteName'].'" <'.$ecSettings['OrdersEmail'].'>','-f'.$ecSettings['OrdersEmail']);

			$Message = $MsgText[9][340]."\n\n\n".$ContentsPrint."\n".$TaxesSection."\n".$SHTitle.': '.$CurrencyBefore.number_format($TotalShipping,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.' ('.$row6['Description'].")\n\n".$MsgText[9][253].': '.$CurrencyBefore.number_format($OrderTotal,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter."\n\n\n".$MsgText[9][246].':'."\n".$ShippingAddressPrint."\n\n\n".$FormArguments['NotesComments']."\n\n------------------------------\n\n".$MsgText[9][341];
			mail($ecSettings['OrdersEmail'], $MsgText[9][339].' '.$OrderID, $Message, 'From: "'.$Settings['SiteName'].'" <'.$ecSettings['OrdersEmail'].'>','-f'.$ecSettings['OrdersEmail']);
			
			
			// clear cart
			$query3 = "update `".$Settings['DBPrefix']."core-Users` set ShoppingCartContents='' where Username='".$CookieUsername."' limit 1";
			$result3 = mysql_query($query3) or die (mysql_error());
			
			setcookie ($CookieName.'Cart', false, 0, '/');
			
			
			$PageTitle = $MsgText[9][271].' - '.$MsgText[9][342];
			$BrowserTitle = $MsgText[9][271].' - '.$MsgText[9][342];
			
			
			if ($FormArguments['PaymentMethod'] == 1) {
									
				$PageContents = '<br>'.$MsgText[9][343].'<div align="center"><form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="'.$ecSettings['PaypalEmail'].'">
<input type="hidden" name="item_name" value="'.$Settings['SiteName'].' '.$MsgText[9][339].' '.$OrderID.'">
<input type="hidden" name="currency_code" value="'.$CurrencyCode.'">
<input type="hidden" name="amount" value="'.number_format($OrderTotal,$ecSettings['PriceDecimals'],'.','').'">
<input type="hidden" name="return" value="'.$MainURL.'/store/pages-thankyou.html/#">
<input type="hidden" name="cancel_return" value="'.$MainURL.'/store/pages-cancel.html/#">
<div align="center"><br><input type="submit" value="'.$MsgText[9][344].'" style="'.$FormStyle.' width:300px;"></div>
</form></div><br>';
			
			}
			else if ($FormArguments['PaymentMethod'] == 2) {
			
				$PageContents = $MsgText[9][345].'<script>
function OfflineForm(OrderNum) {
var WindowCode = window.open(\''.$MainURL.'/store/offlineorder/\'+OrderNum+\'.html\',\'offlineorder\');
window.location = \''.$MainURL.'/store/pages-thankyou.html\';
}</script><div align="center"><form><input type="button" value="'.$MsgText[9][346].'" style="'.$FormStyle.' width:300px;" onclick="OfflineForm(\''.$OrderID.'\');"></form></div>
<br>';

			}
			
			// Payment Method #3 is Cash/In Person
			
			else if ($FormArguments['PaymentMethod'] == 4) {
									
				$PageContents = '<br>'.$MsgText[9][362].'<div align="center"><form method="POST" action="https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/'.$ecSettings['GoogleCheckoutMerchantID'].'" accept-charset="utf-8">
<input type="hidden" name="item_name_1" value="'.$Settings['SiteName'].' '.$MsgText[9][339].' '.$OrderID.'"/>
<input type="hidden" name="item_description_1" value=""/>
<input type="hidden" name="item_quantity_1" value="1"/>
<input type="hidden" name="item_price_1" value="'.number_format($OrderTotal,$ecSettings['PriceDecimals'],'.','').'"/>
<input type="hidden" name="item_currency_1" value="'.$CurrencyCode.'"/>
<input type="hidden" name="_charset_" value="utf-8"/>
<input type="image" name="Google Checkout" alt="Complete Payment with Google Checkout"
src="http://checkout.google.com/buttons/checkout.gif?merchant_id='.$ecSettings['GoogleCheckoutMerchantID'].'&w=180&h=46&style=white&variant=text&loc=en_US"
height="46" width="180"/>
</form>
</div><br>';
			
			}
			
			$PageContents .= '<br><br>'.$MsgText[9][347];

			} // if cart not empty
			else {
			
				$PageTitle = $MsgText[9][271].' - '.$MsgText[9][342];
				$BrowserTitle = $MsgText[9][271].' - '.$MsgText[9][342];
			
				$PageContents = '<br><div align="center">['.$MsgText[9][348].']<br><br>'.$MsgText[9][349].'</div>';
			
			}		
	
		}
	
	} // end if $Arguments2 == 'completeorder'
	else if ($Arguments2 == 'offlineorder') {
	
		$OrderPieces = explode('-',$Arguments3);
		
		$OrderID = $OrderPieces[0].'-'.$OrderPieces[1].'-'.$OrderPieces[2];
		
		$DBOrderID = $OrderPieces[1].'-'.$OrderPieces[2];
		$DBRecordNumber = $OrderPieces[0];
		
			
		$query = "select * from `".$Settings['DBPrefix']."ec-Orders` where RecordNumber='".$DBRecordNumber."' and OrderID='".$DBOrderID."' limit 1";
		$result = mysql_query($query) or die (mysql_error());
		$row = mysql_fetch_array($result);
		if ($row['Account'] == $UserNumber && $OrderPieces[1] == $UserNumber) {
		
				
					$query37 = "select * from `".$Settings['DBPrefix']."ec-Addresses` where RecordNumber=".intval($row['ShippingAddress'])." and Account=".$UserNumber." limit 1";
					$result37 = mysql_query($query37) or die (mysql_error());
					$row37 = mysql_fetch_array($result37);
					
					if ($row37['OrganizationCompany'] != '') {
						$row37['OrganizationCompany'] .= "<br>";
					}
					
					if ($row37['Address2'] != '') {
						$row37['Address1'] .= "<br>".$row37['Address2'];
					}
					if ($row37['Address3'] != '') {
						$row37['Address1'] .= "<br>".$row37['Address3'];
					}
					if ($row37['Address4'] != '') {
						$row37['Address1'] .= "<br>".$row37['Address4'];
					}
					
					$ShippingAddressPrint = $row37['FirstName'].' '.$row37['LastName']."<br>".$row37['OrganizationCompany'].$row37['Address1']."<br>" . $row37['City'].', '.$row37['StateProvince']."<br>".$row37['ZipPostal'];
		
		
				$query23 = "select * from `".$Settings['DBPrefix']."ec-Shipping` where RecordNumber='".$row['ShippingType']."' limit 1";
				$result23 = mysql_query($query23) or die (mysql_error());
				$row23 = mysql_fetch_array($result23);
				
		
				$ShoppingCartContents = $row['Items'];
		
				if ($ShoppingCartContents != '') {
			
					$ItemsList = explode(',',$ShoppingCartContents);
					$ItemFound = false;
				
					for ($i = 0; $i < (count($ItemsList)-1); $i++) {
						list ($ItemNum, $Qty) = explode('x',$ItemsList[$i]);
						list ($Qty, $ItemPrice) = explode('@',$Qty);
												
						$ItemsQty += $Qty;
												
						
						$query3 = "select * from `".$Settings['DBPrefix']."ec-Items` where RecordNumber='".$ItemNum."' limit 1";
						$result3 = mysql_query($query3) or die (mysql_error());
						$row3 = mysql_fetch_array($result3);
						
						$ShippingWeight += ($row3['ShippingWeight']*$Qty);
						
						$query4 = "select * from `".$Settings['DBPrefix']."ec-Products` where RecordNumber='".$row3['Product']."' limit 1";
						$result4 = mysql_query($query4) or die (mysql_error());
						$row4 = mysql_fetch_array($result4);
						
						
						if ($row3['Option2'] != '') {
							$row4['Name'] .= ' ('.$row3['Option1'].', '.$row3['Option2'].')';
						}
						else if ($row3['Option1'] != '') {
							$row4['Name'] .= ' ('.$row3['Option1'].')';
						}
						
						
						
						

						$Subtotal = ($ItemPrice*$Qty);
						
						$ItemsTotal += $Subtotal;
								
							
						$ContentsPrint .= $Qty.'- '.$row4['Name'].$row7['Arguments6'].' ('.$CurrencyBefore.number_format($ItemPrice,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.')<br>';
													
																		
						
							
						
					}
					
				}
				
												
				$TaxesList = explode(',',$row['Taxes']);
				
				for ($z = 0; $z < (count($TaxesList)-1); $z++) {
				
					list ($TaxID, $TaxRate, $AmountCharged) = explode('-',$TaxesList[$z]);
				
					$query69 = "select * from `".$Settings['DBPrefix']."ec-Taxes` where RecordNumber=".$TaxID." limit 1";
					$result69 = mysql_query($query69);
					if (mysql_num_rows($result69) > 0) {
						$row69 = mysql_fetch_array($result69);
					
						if ($row69['Number'] != '') {
							$row69['Number'] = ' ('.$row69['Number'].')';
						}
														
						$TaxesSection .= "<br>".$row69['Title'].$row69['Number'].' '.$row69['Description'].' ('.(($TaxRate+1)-1).'%): '.$CurrencyBefore.number_format($AmountCharged,$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter;
						$TaxesTotal += $AmountCharged;
					}
					
				}
				
				if ($TaxesSection != '') {
					$TaxesSection = $TaxesSection."<br><br>";
				}
		
		
			print '<div align="center"><font size="4"><b>'.$MsgText[9][350].'</b></font><br><br>'.$MsgText[9][351].': '.date('F j, Y',GetTimestamp()).'<br><br>'.$MsgText[9][196].': '.$Arguments3.'<br><br><b>'.$MsgText[9][246].':</b><br><table border="0">
    <tr>
      <td>'.$ShippingAddressPrint.'</td>
    </tr>
</table><br><b>'.$MsgText[9][247].':</b><br><table border="0">
    <tr>
      <td>'.$ContentsPrint.'</td>
    </tr>
</table><br>'.$TaxesSection.$SHTitle.' ('.$row23['Description'].'): '.$CurrencyBefore.number_format($row['ShippingAmount'],$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'<br><br><b>'.$MsgText[9][352].': '.$CurrencyBefore.number_format(($row['ItemsTotal']+$TaxesTotal+$row['ShippingAmount']),$ecSettings['PriceDecimals'], $ecSettings['DecimalSymbol'], $ecSettings['ThousandsSep']).$CurrencyAfter.'</b><br><br><br><b>'.$MsgText[9][353].'</b><br><br><br><table border="0">
    <tr>
      <td>'.str_replace("\n",'<br>',$ecSettings['OfflinePaymentDetails']).'</td>
    </tr>
</table><br><b>'.$MsgText[9][354].' "'.$ecSettings['OfflinePayableTo'].'"</b><br><br><br>'.$MsgText[9][347].'</div>';

			exit();
		
		}
		else {
			$PageContents = $MsgText[9][355];
		}
	
	} // end if $Arguments2 == 'offlineorder'
	else if ($Arguments2 == 'pages-thankyou') {
	
		$PageTitle = $MsgText[9][271].' - '.$MsgText[9][357];
		$BrowserTitle = $MsgText[9][271].' - '.$MsgText[9][357];
		$LocationBar = '<a href="'.$MainURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/store.html">'.$MsgText[9][271].'</a> > '.$MsgText[9][357];
		
		$PageContents = $MsgText[9][356];
	
	} // end if $Arguments2 == 'pages-thankyou'
	else if ($Arguments2 == 'pages-cancel') {
	
		$PageTitle = $MsgText[9][271].' - '.$MsgText[9][358];
		$BrowserTitle = $MsgText[9][271].' - '.$MsgText[9][358];
		$LocationBar = '<a href="'.$MainURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/store.html">'.$MsgText[9][271].'</a> > '.$MsgText[9][358];
		
		$PageContents = $MsgText[9][359];
	
	} // end if $Arguments2 == 'pages-cancel'
		
	
	// ========================================================================================


	$PageTitle = '<div align="'.$AlignmentCodes[$ecSettings['TitleAlignment']].'">'.$PageTitle.'</div>';
	


?>
