﻿			
			
			//var CatalogName = '%CatalogName%'    Bu parametre scriptin eklendiği sayfadan geliyor. (Global tanımlanmış)
			function showdetailtable()
			{
				document.getElementById('detailtable').style.display='';
				document.getElementById('detailsLink').style.display='none';
			}
		
			function ProSelected(obj)
			{
				var catalogname = CatalogName;
				var dr = document.getElementById( obj );
				var sOption , sValue , sText, sType;
				sOption = dr.getAttribute( "attr" );
				sText = dr.getAttribute( "displayText" );
				sType = dr.getAttribute( "ProType" );
				if (sType == "0")
				{
					sValue = dr[dr.selectedIndex].value;
				}
				else
				{
					sValue = dr.getAttribute( "ProValue" );
				}
				
				var sourceControl = document.getElementById( "hdsearchPhrase" );
				if (sType =="0")
				{
					if ( sValue == 'Farketmez' )
						RemoveUserSelection( sourceControl , sOption , sValue , sText, sType);
					else
						AddorUpdateUserSelection( sourceControl , sOption , sValue , sText, sType );
				}
				else
				{
					AddorUpdateUserSelection( sourceControl , sOption , sValue , sText, sType );
				}
					
				RefreshScreen();
			}
			
		
			function RefreshScreen()
			{
				var sourceControl = document.getElementById( "hdsearchPhrase" );
				var destinationControl = document.getElementById( "divSelectedProperties" );
				UpdateScreenText( sourceControl , destinationControl );
				GetProductCount();
			}
			
			function AddorUpdateUserSelection( sourceControl , OptionName , OptionValue , OptionCaption, PropertyType )
			{
				if ( sourceControl.value.indexOf( OptionName ) > -1 )
				{
					UpdateSelection( sourceControl , OptionName , OptionValue , OptionCaption, PropertyType );
				}
				else
				{
					AddSelection( sourceControl , OptionName , OptionValue , OptionCaption, PropertyType );
				}
			}
			
			function AddSelection(sourceControl,OptionName,OptionValue,OptionCaption, PropertyType)
			{
				var totalStr = OptionName + '$$' + OptionValue + "$$" + OptionCaption +  "$$" + PropertyType + "##";
				sourceControl.value = ( sourceControl.value == null ? totalStr : sourceControl.value + totalStr )
			}
			
			function UpdateSelection( sourceControl , OptionName , OptionValue , OptionCaption, PropertyType )
			{
				var newValue = "";
				var falseUpdate = true;
				var Items = sourceControl.value.split( "##" )
				for( i = 0 ; i < Items.length ; i++ )
				{
					if ( Items[i] == null || Items[i] == '' )
						continue;
						
					var subItems = Items[i].split( "$$" );
				
					if ( subItems.length != 4)
						continue;
					
					if ( OptionName == subItems[0] )
					{
						newValue += OptionName + "$$" + OptionValue + "$$" + OptionCaption +  '$$' + PropertyType + "##"
						falseUpdate = false;
					}
					else
					{
						newValue += Items[i] + "##";
					}
				}
				
				if ( falseUpdate )
				{
					AddSelection( sourceControl , OptionName , OptionValue , OptionCaption, PropertyType )
				}
				
				sourceControl.value = newValue;
			}
			
			function RemoveUserSelection( sourceControl , OptionName , OptionValue , OptionCaption, PropertyType )
			{
				var newValue = "";
				var Items = sourceControl.value.split( "##" )
				for( i = 0 ; i < Items.length ; i++ )
				{
					if ( Items[i] == null || Items[i] == '' )
						continue;
						
					var subItems = Items[i].split( "$$" );
				
					if ( subItems.length != 4)
						continue;
					
					if ( OptionName != subItems[0] )
					{
						newValue += Items[i] + "##";
					}
				}
		
				sourceControl.value = newValue;
			}
			
			function UpdateScreenText( sourceControl , destinationControl )
			{
				var ctrlStock = document.getElementById( "drStock" );
				var ctrlBrand = document.getElementById( "drBrands" );
				var txtPriceFrom = document.getElementById( "txtPriceFrom" );
				var txtPriceTo = document.getElementById( "txtPriceTo" );
				
				var Stock = ( ctrlStock == null || ctrlStock[ctrlStock.selectedIndex].value == 0 ? -1 : ctrlStock[ctrlStock.selectedIndex].value);
				var Brand = ( ctrlBrand == null   || ctrlBrand[ctrlBrand.selectedIndex].value.indexOf( "Farketmez" ) > -1 ? "" : ctrlBrand[ctrlBrand.selectedIndex].value);
				var PriceFrom = ( !IsNumeric( txtPriceFrom.value.toString().replace(",",".") ) ? -1 : parseFloat( txtPriceFrom.value.toString().replace(",",".") ) );
				var PriceTo = ( !IsNumeric( txtPriceTo.value.toString().replace(",",".") ) ? -1 : parseFloat( txtPriceTo.value.toString().replace(",",".") ) );
				
				var content = "<table width='100%' align='left' height='140px'><tr><td></td><td></td><td><br><span class='SpanHeader'>&nbsp;&nbsp;&nbsp;&nbsp;Seçimleriniz</span><br></td></tr><tr><td width='40'>&nbsp;</td><td valign='center' width='120px' height='110px'><div id='dvPc' class='ProductCountSpanStyle'></td><td  class='SelectionSpanText' valign='top'><ul> "
				
				if ( Brand !=  "" )
				{
					content += " <li><span class='SpanPropertyCaption'>Markası :</span> <span class='SpanPropertyValue'>" + Brand  + "</span> </li> " ;
				}
				
				if ( Stock != -1 )
				{
					content += " <li><span class='SpanPropertyCaption'>Stok Durumu :</span> <span class='SpanPropertyValue'>" + ctrlStock[ctrlStock.selectedIndex].text  + "</span> </li> "; 
				}
					
				if ( PriceFrom > 0 && PriceTo > 0 )
				{
					content += " <li><span class='SpanPropertyCaption'>Fiyatı :</span> <span class='SpanPropertyValue'>" + PriceFrom + " ile " + PriceTo + " arası"  + "</span> </li> " ;
				}
				
				var initialText ;		
				initialText = content ;
				var Items = sourceControl.value.split( "##" );
				for( i = 0 ; i < Items.length ; i++ )
				{
					if (Items[i] == null || Items[i] == '')
						continue;
						
					var subItems = Items[i].split( "$$" );
				
					if ( subItems.length != 4 )
						continue;
						
					var displayText = " <li><span class='SpanPropertyCaption'> " + subItems[2] + " :</span> <span class='SpanPropertyValue'>" + subItems[1]  + "</span> </li> ";	
					content += displayText
				}
				if (content == initialText)
				{
					content = "";
					destinationControl.style.display = 'none';	
				}
				else
				{
					content = content + " </ul></td></tr><tr><td></td><td colspan='2'><img src='../images/urun_listele2.gif' style='cursor:pointer' onclick='GetProducts()'></td></tr></table></td></tr></table><br><br>";
					destinationControl.innerHTML = content;
					cb_GetProductCountLoading(  );
					destinationControl.style.display = 'block';	
				}
		
			}
			
			function GetProductCount()
			{	

				var catalogname = CatalogName;
				var sourceControl = document.getElementById( "hdsearchPhrase" );
				var txtPriceFrom = document.getElementById( "txtPriceFrom" );
				var txtPriceTo = document.getElementById( "txtPriceTo" );
				var ctrlStock = document.getElementById( "drStock" );
				var ctrlBrand = document.getElementById( "drBrands" );
				var definitionName = DefinitionName ;
				
				var Stock = ( ctrlStock == null || ctrlStock[ctrlStock.selectedIndex].value == 0 ? -1 : ctrlStock[ctrlStock.selectedIndex].value);
				var Brand = ( ctrlBrand == null   || ctrlBrand[ctrlBrand.selectedIndex].value.indexOf( "Farketmez" ) > -1 ? '' : ctrlBrand[ctrlBrand.selectedIndex].value);
				var PriceFrom = ( !IsNumeric( txtPriceFrom.value.toString().replace(",",".") ) ? -1 : parseFloat( txtPriceFrom.value.toString().replace(",",".") ) );
				var PriceTo = ( !IsNumeric( txtPriceTo.value.toString().replace(",",".") ) ? -1 : parseFloat( txtPriceTo.value.toString().replace(",",".") ) );
				
				Microsoft.CommerceServer.Site.Sihirbaz.GetProductCount( sourceControl.value , catalogname , Stock , Brand , PriceFrom , PriceTo, definitionName  , cb_GetProductCount);
			}
			
			function cb_GetProductCount( response )
			{
				var count = response.value;
				//var divCount = document.getElementById( "divProductCountProperties" );
				var divCount = document.getElementById( "dvPc" );
				var inhtml;
				if ( count != -1 )
				{
					inhtml = "<table align='center' height='100%' width='100%'><tr><td valign='middle' align='center'>"
					inhtml += "<b><span class='spnProductCount'>" + count.toString() + "</span></b><br><span class='spnProductCountText'> ürün bulundu.</span> <br>";
					divCount.innerHTML = inhtml;
					divCount.style.display = 'block';
				}
				//else
				//{
				//	divCount.style.display = 'none';
				//}
			}
			
			function cb_GetProductCountLoading(  )
			{
				//var divCount = document.getElementById( "divProductCountProperties" );
				var divCount = document.getElementById( "dvPc" );
				var inhtml;
				inhtml = "<table align='center' height='100%' width='100%'><tr><td valign='middle' align='center'><img src='images/tabs/spinner.gif'></td>"
				inhtml += "<td><span class='spnProductCountTextLoading'></span></td></tr></table>";
				divCount.innerHTML = inhtml;
				divCount.style.display = 'block';
			}
			
			function GetProducts()
			{
				var catalogname = CatalogName;
				var sourceControl = document.getElementById( "hdsearchPhrase" );
				var txtPriceFrom = document.getElementById( "txtPriceFrom" );
				var txtPriceTo = document.getElementById( "txtPriceTo" );
				var definitionName = DefinitionName ;
				
				var ctrlStock = document.getElementById( "drStock" );
				var ctrlBrand = document.getElementById( "drBrands" );
				var ctrlSort = document.getElementById( "drSorting" );
				
				var PriceFrom = ( !IsNumeric( txtPriceFrom.value.toString().replace(",",".") ) ? -1 : parseFloat( txtPriceFrom.value.toString().replace(",",".") ) );
				var PriceTo = ( !IsNumeric( txtPriceTo.value.toString().replace(",",".") ) ? -1 : parseFloat( txtPriceTo.value.toString().replace(",",".") ) );
				var Stock = ( ctrlStock == null || ctrlStock[ctrlStock.selectedIndex].value == 0 ? -1 : ctrlStock[ctrlStock.selectedIndex].value);
				var Brand = ( ctrlBrand == null   || ctrlBrand[ctrlBrand.selectedIndex].value.indexOf( "Farketmez" ) > -1 ? '' : ctrlBrand[ctrlBrand.selectedIndex].value);
				var Sort = ( ctrlSort == null ? -1 : ctrlSort[ctrlSort.selectedIndex].value ) ;
				
				Microsoft.CommerceServer.Site.Sihirbaz.GetProducts( sourceControl.value , catalogname , Stock , Brand , Sort , PriceFrom , PriceTo, definitionName  , cb_GetProducts);
				
				LoadSpinner("pnlWizardLinks") ;
				
			}
			
			function cb_GetProducts( response )
			{
				var sourceControl = document.getElementById( "pnlWizardLinks" );
				sourceControl.innerHTML = response.value;
			}
			
			function CheckPriceRange()
			{
				var txtPriceFrom = document.getElementById( "txtPriceFrom" );
				var txtPriceTo = document.getElementById( "txtPriceTo" );
				var PriceFrom = ( !IsNumeric( txtPriceFrom.value.toString().replace(",",".") ) ? -1 : parseFloat( txtPriceFrom.value.toString().replace(",",".") ) );
				var PriceTo = ( !IsNumeric( txtPriceTo.value.toString().replace(",",".") ) ? -1 : parseFloat( txtPriceTo.value.toString().replace(",",".") ) );
				
				if (PriceFrom == -1 || PriceTo == -1)
				{
					PriceFrom = -1;
					PriceTo = -1;
				}
				
				RefreshScreen();
			}
			
			function IsNumeric(sText)
			{
   				var ValidChars = "0123456789.,";
   				var IsNumber=true;
   				var Char;
   				if (sText == null || sText.length == 0)
   				{
   					return false;
   				}

   				for (i = 0; i < sText.length && IsNumber == true; i++) 
      			{ 
      				Char = sText.charAt(i); 
      				if (ValidChars.indexOf(Char) == -1) 
         			{
         				IsNumber = false;
         			}
      			}
   				return IsNumber;
   			}

			//Compare Kodu
			//********************************//
				var SubSeparator = "#" ; 
				var ItemSeparator = "$" ; 
				
				function CompareSelection( objID )
				{
					var CompareValueControl = document.getElementById( "hdCompareItems" );
					var ValueChangedControl = document.getElementById( objID );
					
					if (ValueChangedControl.checked)
					{
						AddToCompare( ValueChangedControl , CompareValueControl)
					}
					else
					{
						RemoveFromCompare( ValueChangedControl , CompareValueControl )
					}
				
				}
				
				function AddToCompare( ValueChangedControl , CompareValueControl )
				{
					var Pid = ValueChangedControl.getAttribute( "ProductId" );
					var TypeID = ValueChangedControl.getAttribute( "typeId" );
					var Catalog = ValueChangedControl.getAttribute( "catalogname" );
					var SKU = ValueChangedControl.getAttribute( "SKU" );
					
					if ( CompareValueControl.value ) 
					{
						if ( CompareValueControl.value.indexOf( Pid ) < 0 )
						{
							var Products = CompareValueControl.value.split( ItemSeparator );	
							for ( i = 0 ; i < Products.length ; i++  )
							{
								var Product = Products[i].split( SubSeparator ) ;
								
								if ( Product != null && Product.lenght == 4 && Product[1] != TypeID )
								{
									alert("İşaretlediğiniz Ürünlerin Tipleri farklı. İşaretlediğiniz Ürünlerden biri " +  Product[1] + " , Yeni Seçmeye çalıştığınız ürün tipi ise " +  TypeID + ".");
									return;
								}
									
							}
							CompareValueControl.value += Pid + SubSeparator + TypeID + SubSeparator + Catalog + SubSeparator + SKU + ItemSeparator ;
						}
						
					}
					else
					{
						CompareValueControl.value = Pid + SubSeparator + TypeID + SubSeparator + Catalog + SubSeparator + SKU + ItemSeparator ;
					}

				}
				
				function RemoveFromCompare( ValueChangedControl , CompareValueControl )
				{
					
					var Pid = ValueChangedControl.getAttribute( "ProductId" );
					var TypeID = ValueChangedControl.getAttribute( "typeId" );
					var Catalog = ValueChangedControl.getAttribute( "catalogname" );
					var SKU = ValueChangedControl.getAttribute( "SKU" );
					
					var Products = CompareValueControl.value.split( ItemSeparator );
					var NewValue = "";
					
					for ( i = 0 ; i < Products.length ; i++  )
					{
						var Product = Products[i].split( SubSeparator ) ;
						
						if ( Product.length != 4 || Product[0] == Pid )
						{
							continue;
						}
						
						NewValue = Products[i] + ItemSeparator ;
								
					}
					
					CompareValueControl.value = NewValue;
					
				}
				
				
				
				function CompareItems()
				{
					var CompareValueControl = document.getElementById( "hdCompareItems" );
					var TypeID = "";
					var CatalogName = "";
					var Pids = "";
					var qStr = "";
				
					if ( CompareValueControl == null || CompareValueControl.value == null || CompareValueControl.value.length < 1 )
					{
						alert( "Seçim Yapmadınız... Lütfen Kıyaslamak istediğiniz Ürünlerin yanındaki kutuyu işaretleyin..." );
						return;
					}
					
					var Products = CompareValueControl.value.split( ItemSeparator );
					var NewValue = "";
					
					for ( i = 0 ; i < Products.length ; i++  )
					{
						var Product = Products[i].split( SubSeparator ) ;
						
						if ( Product.length == 4 )
						{
							TypeID = Product[1];
							CatalogName = Product[2];
							Pids += Product[0] + ",";
						}

					}
					qStr = "pIds=" + escape(Pids) + "&type_id=" + escape(TypeID) + "&CatalogName=" + escape(CatalogName);
					document.location.href = "/product_compare.aspx?" + qStr;
				}
				
				function AddToCompareList()
				{
					var CompareValueControl = document.getElementById( "hdCompareItems" );
					var TypeID = "";
					var CatalogName = "";
					var Pids = "";
					var qStr = "";
				
					if ( CompareValueControl == null || CompareValueControl.value == null || CompareValueControl.value.length < 1 )
					{
						alert( "Seçim Yapmadınız... Lütfen Kıyaslamak istediğinizüÜrünlerin yanındaki kutuyu işaretleyin..." );
						return;
					}
					
					var Products = CompareValueControl.value.split( ItemSeparator );
					var NewValue = "";
					
					for ( i = 0 ; i < Products.length ; i++  )
					{
						var Product = Products[i].split( SubSeparator ) ;
						
						if ( Product.length == 4 )
						{
							TypeID = Product[1];
							CatalogName = Product[2];
							SKU = Product[3];
							var ProductSKUs = Product[0].split(",");
							for( y = 0 ; y < ProductSKUs.length ; y++)
							{
								if ( ProductSKUs[y] != null  && ProductSKUs[y] != "" )
								{
									if (Product[0].indexOf("@SKU") > -1)
										Pids += CatalogName + "@" + Product[0].replace("@SKU","@") + ",";
									else
										Pids += CatalogName + "@" + Product[0] + "@" + SKU + ",";
								}

							}
							
						}

					}
					qStr = "ProductID=" + escape(Pids) + "&bt=t&ty=0";
					document.location.href = "/kiyaslama_listem.aspx?" + qStr;
				}


			//********************************//


				function hideLayer()
				{
					var ly = document.getElementById("divQFHelp");
					ly.style.display='none' ;
				}
				
			
				function displayLayer(prop,x, obj)
				{
					var ly = document.getElementById("divQFHelp");
					ly.style.display='block' ;
					document.getElementById("divQFHelp").style.position="absolute" ;
					
					var a = getPosition(obj);
					
					document.getElementById("divQFHelp").style.left = a[0] + 25 ;
					document.getElementById("divQFHelp").style.top = a[1] - 10;
					
					/*
					document.getElementById("divQFHelp").style.left = document.getElementById(x).style.left
					document.getElementById("divQFHelp").style.top = document.getElementById(x).style.top ;
					*/
					document.getElementById("divQFHelp").innerHTML = "<table width='100%' cellspacing=2 cellpadding=2><tr valign=top><td align='right'><span style='cursor:pointer' onclick='hideLayer();'><img src='/images/wizard/kapat.gif'></span></td></tr><tr><td class=NText>" + prop + "<br><br></td></tr></table>" ;
					
					//document.getElementById("divQFHelp").innerText = prop ;

				}
				
				function getPosition(obj)
				{
					var curleft = curtop = 0;
					if (obj.offsetParent) {
						curleft = obj.offsetLeft
						curtop = obj.offsetTop
						while (obj = obj.offsetParent) {
								curleft += obj.offsetLeft
								curtop += obj.offsetTop
						}
					}
					return [curleft,curtop];

				
				}

				function LoadSpinner(DivId)
				{
					var a = document.getElementById(DivId) ;
					var loading = document.getElementById('divSpin') ;
					a.innerHTML = loading.innerHTML ;
				}
				