//İ

var _l_sayfa=false;
var _s_sayfa=false;

function _(sId){return document.getElementById(sId);}

Array.prototype.sum || (Array.prototype.sum = function(iterator){
   var result = 0;
   this.each(function(value, index) {
      value = (iterator || Prototype.K)(value, index);
      try { result += parseInt(value || 0); } catch(e){}
   });
   return result;	
});

function showHide(el,show,dispStyle)
{
	if (!dispStyle) dispStyle = 'block';
	var _e = _(el);
	if (show)
		_e.style.display=dispStyle;
	else
		_e.style.display='none';
}
function togggle(el)
{
	var _e = document.getElementById(el);
	if(_e.style.display=='' || _e.style.display=='none')
		_e.style.display='block';
	else
		_e.style.display='none';
}
function showImg(path, title, winName)
{
	window.open('showImg.htm?i='+encodeURI(path)+'&amp;title='+encodeURI(title),winName,'toolbar=no,status=yes,location=no,menubar=no,width=200,height=100,left=150,top=50');
}

// ---------------------------------------------------

function fReq(virgullu)
{
	var names = virgullu.split(",");
	var elArr;
	var el;
	for (i=0;i<names.length;i++)
	{
		elArr = document.getElementsByName(names[i]);
		el = elArr[0];
		var ck=true;
		if (el.type=='radio')
		{
			ck = false;
			for (j=0;j<elArr.length;j++)
				if (elArr[j].checked) ck = true;
		}
		if (el.value=='' || !ck)
		{
			alert(FREQ1+el.title+FREQ2);
			el.focus();
			return false;
		}
	}
	return true;
}

// ---------------------------------------------------

Event.observe(window, 'load', function(){
	Event.observe(window,'resize',function(){
		_('qm0').style.display='none';
		_('qm0').style.display='block';
	});

	$$('.mo').each(function(s) {
		Event.observe(s,'mouseover',function(){
			s.removeClassName('normal');
			s.addClassName('over');
		});
		Event.observe(s,'mouseout',function(){
			s.removeClassName('over');
			s.addClassName('normal');
		});
	});
});

// ---------------------------------------------------

function createCookie(name,value,days) {
	if (days && days>0) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = encodeURIComponent(name)+"="+encodeURIComponent(value)+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = encodeURIComponent(name) + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return decodeURIComponent(c.substring(nameEQ.length,c.length));
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// -----------------------------------------------------------------------------

function _spt(iUid,adet)
{
	cpl_s.add(iUid,adet);
	if (_s_sayfa)
		location.href=location.href;
	else
	{
		sptUpdAndEfect();
	}
}
function sptUpdAndEfect()
{
	var top = cpl_s.qtys.sum();
	if (top<1)
	{
		$('spt_ust').hide();
		if ($('l_emp_c'))
		{
			$('sip_dis').hide();
			$('l_emp_c').show();
		}
	}
	else
	{
		$('spt_ust').show();
		$('spt_adet').update(top);
		new Effect.Parallel(
			[
				new Effect.Pulsate('spt_ust', { sync: true, pulses: 2, duration: 0.8 }), 
				new Effect.Highlight('spt_ust', { sync: true, startcolor: '#ffccaa', endcolor: '#fffffff' })
			],
			{ duration: 0.8 }
		);
	}
}
function _updSpt(iUid,adet)
{
	cpl_s.upd(iUid,adet);
	sptUpdAndEfect();
	//location.href=location.href;
}
function _delSpt(iUid, sUad)
{
	if ( confirm(sUad+'\n\n'+L_R_U_SURE_RMV) )
	{
		cpl_s.del(iUid);
		$('sip_'+iUid).remove();
		sptUpdAndEfect();
		//location.href=location.href;
	}
}
function _clrSpt()
{
	if ( confirm(L_R_U_SURE_RMV_ALL))
	{
		cpl_s.clr();
		sptUpdAndEfect();
		//location.href=location.href;
	}
}

function lstYukle()
{
	var top = cpl_s.qtys.sum();
	if (top>0)
		$('spt_adet').update(top);
}


// Cookie based Product List - Çerezde Saklanan Adetli Ürün Listesi Tipi © Halil Özgür
// Prototype 1.6 kullanır.
// _sepet ve_liste çerezlerinin formatı: 12,42,11,...,3-1,12,5,...1 (id'ler-adetler)

var cpl = Class.create({
	initialize: function(sCkn, iExpDays) {
		this.sCkn = sCkn;
		this.iExpDays = iExpDays;
		this.ids = Array();
		this.qtys = Array();
		var s = readCookie(sCkn);
		if (s)
		{
			var arr =  s.split('-');
			if (arr.length===2)
			{
				this.ids = arr[0].split(',');
				this.qtys = arr[1].split(',');
			}
		}
	},
	
	findPos: function(iId)  {
		var sid = iId.toString();
		var pos = this.ids.indexOf(sid);
		return pos;
	},
	
	add: function(iId, iQty) {
		var pos = this.findPos(iId);
		var iQty = parseInt(iQty);
		if (pos!==-1)
		{
			this.qtys[pos] = parseInt(this.qtys[pos]) + iQty;
		}
		else
		{
			this.ids.push(iId.toString());
			this.qtys.push(iQty);
		}
		this.updCookie();
	},
	
	del: function(iId) {
		var pos = this.findPos(iId);
		if (pos!==-1)
		{
			this.ids[pos] = null;
			this.qtys[pos] = null;
			this.ids = this.ids.compact();
			this.qtys = this.qtys.compact();
			this.updCookie();
		}
	},
	
	clr: function() {
		this.ids = Array();
		this.qtys = Array();
		this.updCookie();
	},
	
	upd: function(iId, iQty) {
		var pos = this.findPos(iId);
		var iQty = parseInt(iQty);
		if (pos!==-1)
		{
			this.qtys[pos] = iQty;
			this.updCookie();
		}
	},
	
	updCookie: function() {
		var s = '';
		if (this.ids.length>0)
			createCookie(this.sCkn, this.ids.join(',') + '-' + this.qtys.join(','), this.iExpDays);
		else
			eraseCookie(this.sCkn);
	},
	
	liYap: function() {
		var s='';
		var sa='';
		var lim = this.ids.length;
		if (lim>3)
		{
			lim=3;
			sa = '<li>&hellip;</li>';
		}
		for (var i=0;i<lim;i++)
		{
			s += '<li><a href="?act=prodDet&amp;id='+this.ids[i]+'">'+this.qtys[i]+' &times; '+parseInt(this.ids[i])+'</a></li>';
		}
		return s+sa;
	}
	
});

var cpl_s = new cpl('_sepet', _SEdays);

