window.addEvent("domready",
function() {
								page.runStartup();
									
});

//isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
var page={
items:[],
tips:null,
runStartup:function(){
	this.setTips();
	this.setMenuOpenClose();
	for(i=0;i< this.items.length;i++)
		if ( typeof(this.items[i]=='function') )
			this.items[i]();
			
},

add:function(obj){
	this.items.push(  function() { eval(obj) } );
},

addF:function(obj){
	this.items.push(  obj );
},
setTips:function() {

	$$(".question").addEvents({
		mouseover:function(){
			var ann=this.get("alt");
			if (ann!=null) tooltip.show(ann);
			ann=null;
		},
		mouseout:function(){

			var ann=this.get("alt");
			if (ann!=null) tooltip.hide();
			ann=null;
			
		}
	});

},
removeGrupSelectorCookies:function(){
	return;
			Cookie.dispose("postFormCopyName");
			Cookie.dispose("postFormCopy");
},
fillMarka:function(markaobjstr,altgrupobjstr,markaSelectedKod,altgrupSelectedKod){
	//$("mainform").set("action","urunler.asp");
	
	var elm=$(markaobjstr);
	smarkalar.each(function(item, index){
 		elm.options[elm.options.length] = new Option( item[1],item[0])
			if(markaSelectedKod!=null )
				if ( item[0]==markaSelectedKod)
					elm.options[elm.options.length-1].selected=true;
	});
	
	if(elm.id.substr(0,2)!='aa')
	elm.addEvent("change",function(){ 
								   
			page.removeGrupSelectorCookies();
								   
								   $("key").set("value","");
								   $("altgruplar").selectedIndex=0;
								   $("mainform").submit(); });
	
	elm=$(altgrupobjstr);
	saltgruplar.each(function(item, index){
 		elm.options[elm.options.length] = new Option( item[2],item[0])
			if(altgrupSelectedKod!=null )
				if ( item[0]==altgrupSelectedKod)
					elm.options[elm.options.length-1].selected=true;
					
	});
	
	if(elm.id.substr(0,2)!='aa')
	elm.addEvent("change",function(){ 
								  page.removeGrupSelectorCookies();
								  
								   $("key").set("value","");
								   $("markalar").selectedIndex=0;
								   $("mainform").submit();
								   
								   });
	if ($("ssend")!=null)
	$("ssend").addEvent("click",function(){ 
								   
									page.removeGrupSelectorCookies();
								   
								   $("altgruplar").selectedIndex=0;
								   $("markalar").selectedIndex=0;
								   $("mainform").submit();
								   
								   });
	
},
setStates:function (item,konum,day) {
	Cookie.write(item+"",konum,{ duration:(day!=null)?day:1 } );
},
fillAnaGruplar:function (anagrupobjstr) {
	var elm=$(anagrupobjstr);
	sanagruplar.each(function(item, index){
 		elm.options[elm.options.length] = new Option( item[1],item[0] )
	});
	
},


getStates:function (item) {
	
	if ( Cookie.read (item+"")!=null ) 
		return 	Cookie.read (item+"");
	else
		return null;
},
hideOdemeBilgilendirme:function(){
	$("odemeBilgilendirme").set("style","display:none");
},

swapMenu:function(){
	
	
	var elm=$("menuImg");
	var opened=false;
	var stateStr="rightMenu";
	
	if (elm.get("src").indexOf('close.png')>=0){
		opened=true;
	}
	if (opened) {
		
		this.setStates(stateStr,1,2);
	} else {
		Cookie.dispose(stateStr); 
		
	}

	document.location.href=document.location;

},

menuSelectAnaGrup:function(itm){
	if ($(itm)!=null) {
		$(itm).set("styles",{ "display":"block" } );
		$(itm).getPrevious().setStyle("background-image","url(/images/urunHeaderBaslik.gif)");
	}
},
menuSelectAltGrup:function(itm){
	
	if ($("n"+itm)!=null) {
		$("n"+itm).addClass("select")
	}
},
setRightMenuEvents:function(){

	$("right").getElements("a.an").addEvents({ "click":function(el){
																
																	if( this.getNext().getStyle("display")!="none" ) { 
																		this.getNext().setStyle("display","none");
																		this.setStyle("background-image","url(/images/nb.jpg)");
																	}
																	else {
																		this.getNext().setStyle("display","block");
																		this.setStyle("background-image","url(/images/urunHeaderBaslik.gif)");
																	}
																return false;		
																} });	
},






/* sepetim.asp için */
setAktifSepetEvents:function(){
	
	$$("div.sepetAktifSepetler","div.sepetAktifSepetlerLng").each(function(item){
				item.getChildren()[0].addEvent("click",function(){
											location.href='/sepetim.asp?aktifsepetid='+this.get("as");
										}
		
				);
				
				item.getChildren()[2].addEvent("click",function(){
											var elm=this;
											
											if (elm.getParent().getChildren()[1].hasClass('kirmizi'))
												elm.getParent().setStyle("opacity","0.5");
											new Request({method:"post",url:"/sepetim.asp",onSuccess:function(responseText, responseXML){  
  														
														
															(function(){ 
																	  elm.getParent().dispose();
																	  
																		
																			if ( elm.getParent().getChildren()[1].hasClass('kirmizi') ){
																				  page.sepetIcerikHtmliniSil();
																				var sonSptler=$$("div.sepetAktifSepetler");
																				if(sonSptler.length>0)
																				sonSptler[sonSptler.length-1].getChildren()[0].click();
																				sonSptler=null;
																		
																				 
																			}
																	  
																	  } ).delay(800);
														 }.bind(elm) }).send("action=delete&kompleSil=1&itemId="+this.get("as"));
										}
		
				);
				
				item.getChildren()[3].addEvent("click",function(){
										
							window.location.href="/sepetim.asp?action=kopyala&id="+this.get("as");			
							
															}
		
				);
				
				
				
			
	});
		
	$$("img.sepetItem").each(function(item){
									  
							item.addEvent("click",function(){
								this.getParent().getParent().setStyle("opacity","0.5");							
								var elm=this;
								new Request({method:"post",url:"/sepetim.asp",onSuccess:function(responseText, responseXML){  
													
													
													
													var obj=null;
													page.sepetToplamFiyatlariYenile( eval( "("+responseText +")") );
													
														(function(){ 
																  elm.getParent().getParent().dispose();
																  			if ($$("img.sepetItem").length==0){
																				page.sepetIcerikHtmliniSil();	
																			}
																  } ).delay(800);
														
													 }.bind(elm) }).send("action=delete&kompleSil=0&itemId="+this.getParent().getParent().get("itemId"));

										   }
									  );
							});
		
	
	
	
	$$("div.kampis").each(function(item){
									  
							item.addEvent("click",function(){
							var elm=this;
							elm.getParent().setStyle("opacity","0.5");		
							
								new Request({method:"post",url:"/sepetim.asp",onSuccess:function(responseText, responseXML){  
										
										
										
										var tmp=eval( "("+responseText +")");
										page.sepetToplamFiyatlariYenile( tmp );
										(function(){ 
												elm.getParent().setStyle("opacity","1");
												
													if (tmp.satir.gosterim){
															
														elm.getPrevious().getChildren()[0].getChildren()[1].set("html",tmp.satir.sk.fiyati);
														elm.getPrevious().getChildren()[0].getChildren()[2].set("html",tmp.satir.sk.doviz);
														elm.getPrevious().getChildren()[1].getChildren()[1].set("html",tmp.satir.kendi.fiyati);
														elm.getPrevious().getChildren()[1].getChildren()[2].set("html",tmp.satir.kendi.doviz);
												
													} else {
												
														elm.getPrevious().getChildren()[0].getChildren()[1].set("html",tmp.satir.sk.fiyati);
														elm.getPrevious().getChildren()[0].getChildren()[2].set("html",tmp.satir.sk.doviz);
													
													}
											tmp=null;			

										} ).delay(800);
										
										
										
										}.bind(elm) }).send("action=edit&itemId="+ this.getParent().get("itemId") +"&adet="+this.getPrevious().getPrevious().getFirst().get("value").toInt());
												
										}
								);
					});					

},
yuzdeKarOraniDegisimi:function(){

														   
							var elm=$("karorani");
								new Request({method:"post",url:"/sepetim.asp",onSuccess:function(responseText, responseXML){  
										elm.setStyle("background-color","ff0000");
										var tmp=eval( "("+responseText +")");
										page.sepetToplamFiyatlariYenile( tmp );
										(function(){ 
												elm.setStyle("background-color","fff");
											tmp=null;			

										} ).delay(800);
										
										
										
										}.bind(elm) }).send("action=yuzdeli&yuzde="+ $("karorani").get("value"));
												
										




},
yeniSepet:function(){
new Request({ url:"/sepetim.asp",method:"post",onSuccess:function(text,xml){ alert(text); } } ).send("action=yenisepet");	
},

sepetToplamFiyatlariYenile:function(yenidegerler){
$("kkUS").set("html",yenidegerler.kkUS);
$("kkTL").set("html",yenidegerler.kkTL);
$("tUS").set("html",yenidegerler.tUS);
$("tTL").set("html",yenidegerler.tTL);
$("tkUS").set("html",yenidegerler.tkUS);
$("tkTL").set("html",yenidegerler.tkTL);
$("gtUS").set("html",yenidegerler.gtUS);
$("gtTL").set("html",yenidegerler.gtTL);

														 
													  		
													 
													  		


														 
													  		

yenidegerler=null;
},

sepetIcerikHtmliniSil:function(){
		var yenidegerler={kkUS:"0 TL",kkTL:"0 TL",tUS:"0 US",tTL:"0 TL",tkUS:"0 US",tkTL:"0 TL",gtUS:"0 US",gtTL:"0 TL",satir:{ gosterim:false,sk:{fiyati:0,doviz:'US'},kendi:{fiyati:0,doviz:'TL'} } };
		

		$$("div.uconti").each(function(item){ item.dispose(); });	
		
		$("kkUS").set("html",yenidegerler.kkUS);
		$("kkTL").set("html",yenidegerler.kkTL);
		$("tUS").set("html",yenidegerler.tUS);
		$("tTL").set("html",yenidegerler.tTL);
		$("tkUS").set("html",yenidegerler.tkUS);
		$("tkTL").set("html",yenidegerler.tkTL);
		$("gtUS").set("html",yenidegerler.gtUS);
		$("gtTL").set("html",yenidegerler.gtTL);
		
		if ( $("sepetItemleriBaslangici")!=null )
		$("sepetItemleriBaslangici").set("html",'<div style="display:block;padding:10px 10px; height:10px; color:#fc0000" class="sagalt solust">Sepetinizde ürün bulunmamaktadir.</div>');
},

setSepetClickEvent:function() {
	
$$('div.addSepet').addEvents({
	
	'click': function(){
		var adet=this.getParent().getPrevious().getFirst().get("value").toInt();
		
		new Request({ url:"/sepetim.asp",method:"post",onSuccess:function(responseText,responseXml){
																		 
																			this.addClass("addSepetdolu");
																		 ( function() { 
																					this.removeClass("addSepetdolu");
																					}.bind(this) ).delay(3000);
																		  
																		  }.bind(this)   }).send("action=ekle&sto_kod="+this.getParent().getParent().get("skod").replace(/\ /i,'+') +"&adet="+adet);
		
	},
	"mouseover":function(){
			this.addClass("addSepet_");			 
						 }
	,					 
	"mouseout":function(){
			this.removeClass("addSepet_");			 
						 }

								});


},
checkLiveStok:function(){
	$("stkImg").set("opacity",.5)
	new Request({ url:"/sepetim.asp",method:"post",onSuccess:function(text,xml){
																				//$("aciklama").set("value",text);
																				eval(text);
																				
																				if (sonuc>0) {
																				for(i=0;i<urunler.length;i++) {
																					var elm=$("u"+urunler[i][0]);
																					elm.set("class",urunler[i][1]);
																					}
																				(function(){ $("stkImg").set("opacity",1)} ).delay(700);	
																				} else {
																					alert("Sipariş verme yetkiniz bulunmadığı için stok kontrolünü yapamıyoruz.")	
																				}
																							} }).send("checkStok=true");
},



sepetAdiGuncelle:function(itemId,yazi) {
	
								new Request({method:"post",url:"/sepetim.asp",onSuccess:function(text,xml){
																							
																							if (text=="OK"){
																								$("s"+itemId).set("opacity",.5);
																								(function(){ $("s"+itemId).set("opacity",1)} ).delay(700)			
																							}	
																							
																							
																								 
																								} }).send(  "action=sepetAdiGuncelle&id="+itemId+"&yazi="+yazi.replace(/[\ ]/g,"+") );
											

}, // /sepetAdiGuncelle 


robotSepeteEkle:function(adet) {
var yazi=robot.getSelectedProductsAndTotal();
if (yazi!=null && ( adet>0 && adet<20 )  ) {
new Request({method:"post",url:"/sepetim.asp",onSuccess:function(text,xml){

	if(text=='OK'){
		
		var karorani=$("karorani").get("value").toInt();
		
		if ( confirm("Ürünler Sepetinize Eklendi.\nYeni bir sayfada sepetinizi açmak istermisiniz ?"))
			window.open("/sepetim.asp","hmd");
	}
	
} }).send(  "action=robottanEkle&uruns="+yazi+"&adet=" + adet);

} // /(yazi!=null)

} // /robotSepeteEkle
										
										
																								 
/* sepetim.asp için */

,
setMenuOpenClose:function(){
	if ($("menuImg")!=null)
		$("menuImg").addEvent("click",function(){ page.swapMenu(); });
},
karsilastirmayaGit:function(){
	var olabilir=0;
	$$("input[name=urun]").each(function(item){
										 	if (item.checked)
												olabilir++;	
										 });
	if (olabilir==2) {
	$("formKarsilastirma").set("action","/karsilastir.asp");
	$("formKarsilastirma").submit();
	}
	else {
		alert("Karşılaştırma için en fazla 2 ürün seçmelisiniz!..");	
	}
}

,openPopup:function(url,w,h,name){
	
var settings='height='+ h + ',width=' + w + ',top=' + (screen.width-w)/2 + ',left=' + (screen.height-h)/2+ ',scrollbars=yes,toolbar=yes,resizable=yes';
return window.open(url,name,settings)

}


};


























var tooltip=function(){
	var id = 'tt';
	var top = -20;
	var left = 20;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){

			if (v==null) return;
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=100)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
				t.style.zIndex = "10000";
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();











Number.implement({
	numberFormat : function(decimals, dec_point, thousands_sep) {
		decimals = Math.abs(decimals) + 1 ? decimals : 2;
		dec_point = dec_point || '.';
		thousands_sep = thousands_sep || ',';
	
		var matches = /(-)?(\d+)(\.\d+)?/.exec((isNaN(this) ? 0 : this) + '');
		var remainder = matches[2].length > 3 ? matches[2].length % 3 : 0;
		return (matches[1] ? matches[1] : '') + (remainder ? matches[2].substr(0, remainder) + thousands_sep : '') + matches[2].substr(remainder).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep) + 
				(decimals ? dec_point + (+matches[3] || 0).toFixed(decimals).substr(2) : '');
	}


});



var imgPreLoad={
n:0,
imgs:null,
imgsT:[],
interval:null,
len:0,
changeProductsImg:function(){
	if(this.imgs==null) {
		this.imgs=$$("img[h^=/i]")
			//if (this.imgs.length<20)
			//	this.n=-1;
		
		//$each(this.imgs,function(el){
		//								this.imgsT[this.imgsT.push( new Image() )-1].src=el.getAttribute("h");
		//						},this);

		this.len=this.imgs.length

		this.interval=this.changeImg.periodical(400,this);		
	}
},
changeImg:function(){
	var s=0;
	for (s=0;s<30;s++) {
		if (this.len==this.n) { 
				$clear(this.interval);
				this.imgs=null;
				this.imgsT=null;
				return;
			}
		if (s<30 && this.len>this.n ) {
			//this.imgs[this.n].src=this.imgsT[this.n].src;
			this.imgs[this.n].src=this.imgs[this.n].getAttribute("h");
			this.n++;
		}
		
	}
	
	

}


};



var SplashScreen = new Class({
  Implements: Options,
  options: {
    'delay':5000 ,
    'showOnce':true
  },
  initialize: function(element, options){
    this.setOptions(options);
    this.splash=document.id(element);
    if(this.options.showOnce){
      // check cookie to see if splash has been shown in this session
      var splashCookie = Cookie.read('showSplashCookie') || 'yes';
      if(splashCookie=='yes'){
        this.showSplash();
        Cookie.write('showSplashCookie', 'no',{ duration:1 });
      }
    }else{
      this.showSplash();
    }
  },
  showSplash:function(){
    this.splash.setStyles({
      'height':window.getScrollHeight(),
      'display':'block',
      'opacity':'1'
    });
    // iframe for ie6 <Bah! Humbug!>
    if(Browser.Engine.trident4){
      var iframe2 = new Element('iframe',{
        styles:{'position':'absolute','width':'120%','height':'120%','top':'-10%','left':'-10%'},
	height:'100%',
	width:'100%',
        frameborder:0
      }).setOpacity(0).inject(this.splash,'top');
    }
    this.closeSplash.delay(this.options.delay, this);
  },
  closeSplash: function(){
    this.splash.fade('out');
  }
});




