var categoryURL=[["1939", "Sapphire-Rings/1939"],["1928", "Sapphire-Pendants/1928"],["1940", "Sapphire-Earrings/1940"],["1929", "Ruby-Rings/1929"],["1938", "Ruby-Pendants/1938"],["1937", "Ruby-Earrings/1937"],["1944", "Emerald-Rings/1944"],["1930", "Emerald-Pendants/1930"],["1943", "Emerald-Earrings/1943"],["1941", "Tanzanite-Rings/1941"],["1927", "Tanzanite-Pendants/1927"],["1942", "Tanzanite-Earrings/1942"],["1946", "Aquamarine-Rings/1946"],["1945", "Aquamarine-Pendants/1945"],["1931", "Aquamarine-Earrings/1931"],["1957", "Emerald-Engagement-Rings/1957"],["1958", "Ruby-Engagement-Rings/1958"],["1945", "Aquamarine-Pendants/1945"],["1781", "Gemstone-Engagement-Rings/1781"]];
var categoryArray=[["1", "Rings"],["2", "Engagement Rings"],["3", "Pendants"],["4", "Earrings"],["5", "Bracelets"],["6", "Stud Earrings"],["7", "Solitaire Pendant"],["8", "Loose Stones"]];
var productArray=[["8", [["10001","Sapphire"],["10002","Ruby"],["10003","Emerald"],["10004","Tanzanite"],["10005","Aquamarine"],["10006","Citrine"]]],["1", [["1939","Sapphire"],["1929","Ruby"],["1944","Emerald"],["1941","Tanzanite"],["1946","Aquamarine"],["1845","Diamond"]]],["3", [["1928","Sapphire"],["1938","Ruby"],["1930","Emerald"],["1927","Tanzanite"],["1945","Aquamarine"],["1738","Diamond"],["1879","Journey"]]],["7", [["1737","Diamond"]]],["6", [["1728","Diamond"]]],["5", [["1881","Charm"],["1752","Diamond"]]],["4", [["1940","Sapphire"],["1937","Ruby"],["1943","Emerald"],["1942","Tanzanite"],["1931","Aquamarine"],["1729","Diamond"],["1880","Journey"]]],["2", [["1850","Sapphire"],["1958","Ruby"],["1957","Emerald"],["1839","Tanzanite"],["1860","Diamond"],["1723","Bands for Her"],["1724","Bands for Him"]]]];
var productToCategoryArray=[["Charm", [["5","Bracelets"]]],["Diamond", [["1","Rings"],["2","Engagement Rings"],["3","Pendants"],["4","Earrings"],["5","Bracelets"]]],["Aquamarine", [["1","Rings"],["3","Pendants"],["4","Earrings"]]],["Emerald", [["1","Rings"],["2","Engagement Rings"],["3","Pendants"],["4","Earrings"]]],["Journey", [["3","Pendants"],["4","Earrings"]]],["Ruby", [["1","Rings"],["2","Engagement Rings"],["3","Pendants"],["4","Earrings"]]],["Sapphire", [["1","Rings"],["2","Engagement Rings"],["3","Pendants"],["4","Earrings"]]], ["Tanzanite", [["1","Rings"],["2","Engagement Rings"],["3","Pendants"],["4","Earrings"]]],["Bends for Him", [["2","Engagement Rings"]]],["Bands for Her", [["2","Engagement Rings"]]],["Studs", [["4","Earrings"]]],["Solitare", [["3","Pendants"]]],];
var priceArray= [["10006", [["/Loose-Gemstone/Citrine/0","Price Range"],["/search-gemstone.do?method=stoneCatalog&sq=st-ci*price-price1&selPage=1&sort_order=asc","$1-$50"],["/search-gemstone.do?method=stoneCatalog&sq=st-ci*price-price2&selPage=1&sort_order=asc","Over $50"]]],["10005", [["/Loose-Gemstone/Aquamarine/0","Price Range"],["/search-gemstone.do?method=stoneCatalog&sq=st-aq*price-price2&selPage=1&sort_order=asc","$51-$200"],["/search-gemstone.do?method=stoneCatalog&sq=st-aq*price-price3&selPage=1&sort_order=asc","Over $200"]]],["10004", [["/Loose-Gemstone/Tanzanite/0","Price Range"],["/search-gemstone.do?method=stoneCatalog&sq=st-ta*price-price2&selPage=1&sort_order=asc","$51-$200"],["/search-gemstone.do?method=stoneCatalog&sq=st-ta*price-price3&selPage=1&sort_order=asc","$201-$500"],["/search-gemstone.do?method=stoneCatalog&sq=st-ta*price-price4&selPage=1&sort_order=asc","$501 $2000"],["/search-gemstone.do?method=stoneCatalog&sq=st-ta*price-price5&selPage=1&sort_order=asc","Over $2000"]]],["10003", [["/Loose-Gemstone/Emerald/0","Price Range"],["/search-gemstone.do?method=stoneCatalog&sq=st-em*price-price2&selPage=1&sort_order=asc","$51-$200"],["/search-gemstone.do?method=stoneCatalog&sq=st-em*price-price3&selPage=1&sort_order=asc","$201-$500"],["/search-gemstone.do?method=stoneCatalog&sq=st-em*price-price4&selPage=1&sort_order=asc","Over $2000"]]],["10002", [["/Loose-Gemstone/Ruby/0","Price Range"],["/search-gemstone.do?method=stoneCatalog&sq=st-ru*price-price2&selPage=1&sort_order=asc","$51-$200"],["/search-gemstone.do?method=stoneCatalog&sq=st-ru*price-price3&selPage=1&sort_order=asc","$201-$500"],["/search-gemstone.do?method=stoneCatalog&sq=st-ru*price-price4&selPage=1&sort_order=asc","$501 $2000"],["/search-gemstone.do?method=stoneCatalog&sq=st-ru*price-price5&selPage=1&sort_order=asc","Over $2000"]]],["10001", [["/Loose-Gemstone/Sapphire/0","Price Range"],["/search-gemstone.do?method=stoneCatalog&sq=st-sa*price-price2&selPage=1&sort_order=asc","$51-$200"],["/search-gemstone.do?method=stoneCatalog&sq=st-sa*price-price3&selPage=1&sort_order=asc","$201-$500"],["/search-gemstone.do?method=stoneCatalog&sq=st-sa*price-price4&selPage=1&sort_order=asc","$501 $2000"],["/search-gemstone.do?method=stoneCatalog&sq=st-sa*price-price5&selPage=1&sort_order=asc","Over $2000"]]],["1881", [["1-infty","Price Range"],["1-200","$1-$200"],["201-500","$201-$500"],["501-infty","Over $500"]]],["1752", [["1-infty","Price Range"],["1-1500","$1-$1500"],["1501-infty","Over $1500"]]],["1931", [["1-infty","Price Range"],["1-500","$1-$500"],["501-600","$501-$600"],["601-infty","Over $600"]]],["1729", [["1-infty","Price Range"],["1-500","$1-$500"],["501-1000","$501-$1000"],["1001-infty","Over $1000"]]],["1943", [["1-infty","Price Range"],["1-500","$1-$500"],["501-infty","Over 500"]]],["1880", [["1-infty","Price Range"],["1-500","$1-$500"],["501-infty","Over $500"]]],["1937", [["1-infty","Price Range"],["1-500","$1-$500"],["501-infty","Over $500"]]],["1940", [["1-infty","Price Range"],["1-500","$1-$500"],["501-1000","$501-$1000"],["1001-infty","Over $1000"]]],["1942", [["1-infty","Price Range"],["1-500","$1-$500"],["501-800","$501-$800"],["801-infty","Over $800"]]],["1860", [["1-infty","Price Range"],["1-1000","$1-$1000"],["1001-2000","$1001-$2000"],["2001-4000","$2001-$4000"],["4001-infty","Over $4000"]]],["1957", [["1-infty","Price Range"],["1-500","$1-$500"],["501-1000","$501-$1000"],["1001-2000","$1001-$2000"],["2001-infty","Over $2000"]]],["1958", [["1-infty","Price Range"],["1-500","$1-$500"],["501-1000","$501-$1000"],["1001-2000","$1001-$2000"],["2001-infty","Over $2000"]]],["1850", [["1-infty","Price Range"],["1-1000","$1-$1000"],["1001-1500","$1001-$1500"],["1501-infty","Over $1500"]]],["1839", [["1-infty","Price Range"],["1-500","$1-$500"],["501-800","$501-$800"],["801-infty","Over $800"]]],["1723", [["1-infty","Price Range"],["1-250","$1-$250"],["251-500","$251-$500"],["501-infty","Over $500"]]],["1724", [["1-infty","Price Range"],["1-300","$1-$300"],["301-infty","Over $300"]]],["1945", [["1-infty","Price Range"],["1-200","$1-$200"],["201-300","$201-$300"],["301-450","$301-$450"],["451-infty","Over $450"]]],["1738", [["1-infty","Price Range"],["1-500","$1-$500"],["501-1000","$501-$1000"],["1001-infty","Over $1000"]]],["1930", [["1-infty","Price Range"],["1-500","$1-$500"],["501-1000","$501-$1000"],["1001-infty","Over $1000"]]],["1879", [["1-infty","Price Range"],["1-500","$1-$500"],["501-700","$501-$700"],["701-infty","Over $700"]]],	["1938", [["1-infty","Price Range"],["1-500","$1-$500"],["501-800","$501-$800"],["801-infty","Over $800"]]],["1928", [["1-infty","Price Range"],["1-500","$1-$500"],["501-1000","$501-$1000"],["1001-infty","Over $1000"]]],	["1927", [["1-infty","Price Range"],["1-350","$1-$350"],["351-600","$351-$600"],["601-infty","Over $600"]]],["1946", [["1-infty","Price Range"],["1-500","$1-$500"],["501-800","$501-$800"],["801-1000","$801-$1000"],["1001-infty","Over $1000"]]],["1845", [["1-infty","Price Range"],["1-1000","$1-$1000"],["1001-infty","Over $1000"]]],["1944", [["1-infty","Price Range"],["1-500","$1-$500"],["501-1000","$501-$1000"],["1001-2000","$1001-$2000"],["2001-infty","Over $2000"]]],["1929", [["1-infty","Price Range"],["1-500","$1-$500"],["501-1000","$501-$1000"],["1001-1300","$1001-$1300"],["1301-2000","$1301-$2000"],["2001-infty","Over $2000"]]],["1939", [["1-infty","Price Range"],["1-500","$1-$500"],["501-800","$501-$800"],["801-1200","$801-$1200"],["1201-1500","$1201-$1500"],["1501-3000","$1501-$3000"],["3001-infty","Over $3000"]]],["1737", [["1-infty","Price Range"]]],["1728", [["1-infty","Price Range"]]],["1941", [["1-infty","Price Range"],["1-500","$1-$500"],["501-800","$501-$800"],["801-1000","$801-$1000"],["1001-2000","$1001-$2000"],["2001-infty","Over $2000"]]]];

function getProductByCategory(){
 	            	var category=document.getElementById("category")[document.getElementById("category").selectedIndex].value;
				var textValure=document.getElementById('productString').value
				var select_list_field1 = document.getElementById('category');
				var select_list_selected_index1 = select_list_field1.selectedIndex;
				var text1 = select_list_field1.options[select_list_selected_index1].text;
				document.getElementById('categoryString').value=text1;
				var cID=document.getElementById("cID");
 				 if(cID.length>0)
 				   {
 				   for(var index=cID.length;index>=0;index--)
 				      cID.remove(index);
 				   }
				var cIDs=document.getElementById("cID");
 				for(var start_index=0;start_index < productArray.length;start_index++)
				{
					var subProductArray=productArray[start_index];
					if(category==subProductArray[0]){
						var subProductArray=productArray[start_index];
						var subsubArray=subProductArray[1];
						for(var start_index1=0;start_index1 < subsubArray.length;start_index1++)
						{
							
							  var option=document.createElement("option");
							  option.value=subsubArray[start_index1][0];
							  option.text=subsubArray[start_index1][1];
							  if(textValure==subsubArray[start_index1][1])
							  		option.selected=true;
							  cIDs.options.add(option);
						}
					}
				}
				var select_list_field = document.getElementById('cID');
				var select_list_selected_index = select_list_field.selectedIndex;
				var text = select_list_field.options[select_list_selected_index].text;
				document.getElementById('productString').value=text;
				getPriceRangeByCategory();
				getFinalUrl();
}

function getPriceRangeByCategory(){
 	            var cID=document.getElementById("cID")[document.getElementById("cID").selectedIndex].value;
				var priceRangeId=document.getElementById("priceRangeId");
 				 if(priceRangeId.length>0)
 				   {
 				   for(var index=priceRangeId.length;index>=0;index--)
 				      priceRangeId.remove(index);
 				   }
				var priceRangeIds=document.getElementById("priceRangeId");
 				for(var start_index=0;start_index < priceArray.length;start_index++)
				{
					var subPriceArray=priceArray[start_index];
					if(cID==subPriceArray[0]){
						var subPriceArray=priceArray[start_index];
						var subsubPriceArray=subPriceArray[1];
						for(var start_index1=0;start_index1 < subsubPriceArray.length;start_index1++)
						{
							  var option=document.createElement("option");
							  option.value=subsubPriceArray[start_index1][0];
							  option.text=subsubPriceArray[start_index1][1];
							  priceRangeIds.options.add(option);
						}
					}
				}
				
				var select_list_field = document.getElementById('cID');
				var select_list_selected_index = select_list_field.selectedIndex;
				var text = select_list_field.options[select_list_selected_index].text;
				document.getElementById('productString').value=text;
				var categorynext=document.getElementById("category")
				var categoryString=document.getElementById('categoryString').value
				if(text!="Diamond" && text!="Charm"){
					if(categorynext.length>0)
					{
					   for(var index=categorynext.length;index>=0;index--)
						  categorynext.remove(index);
					}
					for(var start_index=0;start_index < categoryArray.length;start_index++)
					{
							   if(categoryArray[start_index][1]!="Bracelets"){
								  var option=document.createElement("option");
								  option.value=categoryArray[start_index][0];
								  option.text=categoryArray[start_index][1];
								  if(categoryString==categoryArray[start_index][1]){
										option.selected=true;
								  }
								  categorynext.options.add(option);
							   }
					}
				}
				else{
						if(categorynext.length>0)
						{
						   for(var index=categorynext.length;index>=0;index--)
							  categorynext.remove(index);
						}
						
						for(var start_index=0;start_index < categoryArray.length;start_index++)
						{
									  var option=document.createElement("option");
									  option.value=categoryArray[start_index][0];
									  option.text=categoryArray[start_index][1];
									  if(categoryString==categoryArray[start_index][1]){
											option.selected=true;
									  }
									  categorynext.options.add(option);
						}
				}
				/**var categorynext=document.getElementById("category");
 				 if(categorynext.length>0)
 				   {
 				   for(var index=categorynext.length;index>=0;index--)
 				      categorynext.remove(index);
 				   }
				var categoryString=document.getElementById('categoryString').value
 				for(var start_index=0;start_index < productToCategoryArray.length;start_index++)
				{
					var subProductToCategoryArray=productToCategoryArray[start_index];
					
					if(text==subProductToCategoryArray[0]){
						var subProductToCategoryArray=productToCategoryArray[start_index];
						var subsubProductToCategoryArray=subProductToCategoryArray[1];
						for(var start_index1=0;start_index1 < subsubProductToCategoryArray.length;start_index1++)
						{
							  var option=document.createElement("option");
							  option.value=subsubProductToCategoryArray[start_index1][0];
							  option.text=subsubProductToCategoryArray[start_index1][1];
							  if(categoryString==subsubProductToCategoryArray[start_index1][1]){
							  		option.selected=true;
							  }
							  categorynext.options.add(option);
						}
						

					}
				}**/
				getFinalUrl();
 }

 function getFinalUrl(){
 				var select_list_field = document.getElementById('category');
				var select_list_selected_index = select_list_field.selectedIndex;
				var text = select_list_field.options[select_list_selected_index].text;
				document.getElementById('categoryString').value=text;
				
				var select_list_field1 = document.getElementById('cID');
				var select_list_selected_index1 = select_list_field1.selectedIndex;
				var text1 = select_list_field1.options[select_list_selected_index1].text;
				document.getElementById('productString').value=text1;
 }

 function validateProduct(){
	var category=document.getElementById("category")[document.getElementById("category").selectedIndex].value;
	var cID=document.getElementById("cID")[document.getElementById("cID").selectedIndex].value;
	var flag=0;
 	for(var start_index=0;start_index < productArray.length;start_index++)
	{
					var subProductArray=productArray[start_index];
					if(category==subProductArray[0]){
						var subProductArray=productArray[start_index];
						var subsubArray=subProductArray[1];
						for(var start_index1=0;start_index1 < subsubArray.length;start_index1++)
						{
							if(cID==subsubArray[start_index1][0]){
							  	flag=1;
							}
						}
					}
	}
	if(flag==0){
		alert("Sorry we don't have this combination please try again...!");
		return 0;
	}
	flag=0;
	var priceRange=document.getElementById("priceRangeId")[document.getElementById("priceRangeId").selectedIndex].value;
	var cID=document.getElementById("cID")[document.getElementById("cID").selectedIndex].value;
	for(var start_index=0;start_index < priceArray.length;start_index++)
	{
					var subPriceArray=priceArray[start_index];
					if(cID==subPriceArray[0]){
						var subPriceArray=priceArray[start_index];
						var subsubPriceArray=subPriceArray[1];
						for(var start_index1=0;start_index1 < subsubPriceArray.length;start_index1++)
						{
							if(priceRange==subsubPriceArray[start_index1][0]){
								 flag=1;
							}
						}
					}
	}
	if(flag==0){
		alert("Sorry we don't have this combination please try again...!");
		return 0;
	}
	return 1;	
 }

function go()
{
	var flag=validateProduct();
	if(flag=1){
		if(document.getElementById("category")[document.getElementById("category").selectedIndex].value==8){
			document.getElementById("searchByproduct").action=document.getElementById("priceRangeId")[document.getElementById("priceRangeId").selectedIndex].value;
			document.getElementById("searchByproduct").submit();

		}
		else{
			var priceRange=document.getElementById("priceRangeId")[document.getElementById("priceRangeId").selectedIndex].value;
			var category=document.getElementById("category")[document.getElementById("category").selectedIndex].value;
			var cID=document.getElementById("cID")[document.getElementById("cID").selectedIndex].value;
 			var url="/shop.do?cID="+cID+"&priceRangeId="+priceRange;
			if(cID==1688)
				url="/engagement-rings/1688/1/BEST/"+priceRange;
			else if(cID==1845)
				url="/Diamond-Rings/1845/1/BEST/"+priceRange;
			else if(cID==1729)
				url="/Diamond-Earrings/1729/1/BEST/"+priceRange;
			else if(cID==1738)
				url="/Diamond-Pendants/1738/1/BEST/"+priceRange;
				
			else if(cID==1737)
				url="/Solitaire-Diamond-Pendants/1737/1/BEST/"+priceRange;
			else if(cID==1728)
				url="/Diamond-Stud-Earrings/1728/1/BEST/"+priceRange;
			else if(cID==1752)
				url="/Diamond-Bracelets/1752/1/BEST/"+priceRange;
			else if(cID==1881)
				url="/Charm-Bracelets/1881/1/BEST/"+priceRange;
			else if(cID==1879)
				url="/Journey-Nacklace-Pendants/1879/1/BEST/"+priceRange;
			else if(cID==1880)
				url="/Journey-Earrings/1880/1/BEST/"+priceRange;
				
			else if(cID==1850)
				url="/Sapphire-Engagement-Rings/1850/1/BEST/"+priceRange;
			else if(cID==1958)
				url="/Ruby-Engagement-Rings/1958/1/BEST/"+priceRange;
			else if(cID==1957)
				url="/Emerald-Engagement-Rings/1957/1/BEST/"+priceRange;
				
			else if(cID==1839)
				url="/Tanzanite-Engagement-Rings/1839/1/BEST/"+priceRange;
			else if(cID==1860)
				url="/Diamond-Engagement-Rings/1860/1/BEST/"+priceRange;
			else if(cID==1723)
				url="/Wedding-Bands-For-Her/1723/1/BEST/"+priceRange;
			else if(cID==1724)
				url="/Wedding-Bands-For-Him/1724/1/BEST/"+priceRange;
			else		
				var url="/shop.do?cID="+cID+"&priceRangeId="+priceRange;
			
 			for(var start_index=0;start_index < categoryURL.length;start_index++)
			{	
				//alert(cID+"="+categoryURL[start_index][0]);
				if(cID==categoryURL[start_index][0]){
						//alert("inside");
						url="/"+categoryURL[start_index][1]+"/1/BEST/"+priceRange;
				}
						
			}
		
			document.getElementById("searchByproduct").action=url;
			document.getElementById("searchByproduct").submit();
			}
		}

}