var RootPath=document.location.protocol+'//'+document.location.host+'/';
var ImagePath=RootPath+'UrunFiles/';//yalnıca urun resimleri için
var FlushSet=new Array;
var FlushSide=new Array();
function all_ch(frm,el1,tf)//formdaki check boxlari isaretleme
{
	eleman=document.forms[frm].elements[el1];
	elemansay=eleman.length;
	if(elemansay!=undefined)
	{
		for(i=0;i<elemansay;i++)
			eleman[i].checked=tf;
	}
	else
	{
		eleman.checked=tf;
	}
	return;
}

function nitelikShow(object)
{
	ht=object.getElementsByTagName('DIV')[0];
	ha=object.getElementsByTagName('A')[0];
	ht.onmouseout		= function(){ ht.style.display='none';ha.className=''; };
	ht.onmouseover		= function(){ ht.style.display='block';ha.className='c'; };
	object.onmouseout	= function(){ ht.style.display='none';ha.className=''; };
	ht.style.display='block';
	ha.className='c';
}
/*smoothScroll*/
function smoothScroll(hash)
{
	$target=$('[name='+hash+']');
	if ($target.length)
	{
		var targetOffset = hash=="top"?0:$target.offset().top;
		$('html,body').animate({"scrollTop":targetOffset});
	}
}
/*end smoothScroll*/
var inputValue={
	clear:function(ob,s){if(ob.value==s) ob.value='';},
	back:function(ob,s){if(ob.value=='') ob.value=s;}
}

/*hareketli banner*/
var sliderClass = 
{
	curDist:[],curPanel:[],curDirec:[],
	change:function(direction,thisId)//direction true = right, false = left
	{
		if(!$('#'+thisId).length || $('#'+thisId).data("currentlyMoving") == true) return;
		$('#'+thisId).data("currentlyMoving",true);
		var $panels=$('#'+thisId+' ul').children();
		var totalPanels=$panels.size();
		var next=direction?this.curPanel[thisId]+1:this.curPanel[thisId]-1;
		var leftValue=$('#'+thisId+' ul').css("margin-left");
		var parseLeft=parseInt(leftValue);
		if(!direction && parseLeft>=0)//sondan alip basa ekliyoruz
		{
			leftValue=parseLeft-this.curDist[thisId];
			$('#'+thisId+' ul li').first().before("<li>"+$panels[totalPanels-1].innerHTML+"</li>");
			$('#'+thisId+' ul').css("margin-left",leftValue);
			$panels[0].parentNode.removeChild($panels[totalPanels-1]);
			next++;
		}
		else if(direction && next>totalPanels)//bastan alip sona ekliyoruz
		{
			leftValue=parseLeft+this.curDist[thisId];
			$('#'+thisId+' ul li').last().after("<li>"+$panels[0].innerHTML+"</li>");
			$('#'+thisId+' ul').css("margin-left",leftValue);
			$panels[0].parentNode.removeChild($panels[0]);
			next--;
		}
		var movement=direction?parseFloat(leftValue,10)-this.curDist[thisId]:parseFloat(leftValue,10)+this.curDist[thisId];
		$('#'+thisId+' ul').stop().animate({"margin-left":movement},function(){$('#'+thisId).data("currentlyMoving",false);});
		this.curPanel[thisId]=next;
	},	
	sliderFunc:function(thisId,movingDistance,curPanel,oto)
	{
		if(!$('#'+thisId).length){return false;}
		this.curPanel[thisId]=(curPanel)?curPanel:3;
		this.curDist[thisId]=(movingDistance)?movingDistance:190;		
		$('#'+thisId).data("currentlyMoving",false);
		$('#'+thisId+' #right').click(function(){sliderClass.curDirec[thisId]=true;sliderClass.change(true,thisId);}).mouseover(function(){this.className='hover'}).mouseout(function(){this.className=''});
		$('#'+thisId+' #left').click(function(){sliderClass.curDirec[thisId]=false;sliderClass.change(false,thisId);}).mouseover(function(){this.className='hover'}).mouseout(function(){this.className=''});
		if(oto)
		{
			setTimeout("sliderClass.sliderOto('"+thisId+"')",2000);
		}
	},
	sliderOto:function(thisId)
	{
		sliderClass.change(this.curDirec[thisId],thisId);
		setTimeout("sliderClass.sliderOto('"+thisId+"')",3000);
	}
};
/*end slideshow*/
var inputValue={
	clear:function(ob,s){if(ob.value==s) ob.value='';},
	back:function(ob,s){if(ob.value=='') ob.value=s;}
}

var lightBox={	
	open:function()
	{
		$(".ie select").css({display:"none"});
		$("#fullBgOpacity").css({height:$(document).height()+"px",display:"block"});
		$("#fullBgMessage").css({left:($("html").scrollLeft()+($(window).width()/2)-93)+"px",display:"block"});		
	},
	close:function()
	{
		$("#fullBgMessage").css({display:"none"});
		$("#fullBgOpacity").css({display:"none"});
		$(".ie select").css({display:""});
	}	
}

/*sepete atma ile ilgili*/
var lastAreaMenu=1;
function AreaMenu(area)
{
	document.getElementById('brkAreaT'+lastAreaMenu).className='';
	document.getElementById('brkAreaC'+lastAreaMenu).className='passive';
	document.getElementById('brkAreaT'+area).className=document.getElementById('brkAreaC'+area).className='active';
	lastAreaMenu=area;
}

function ChangPrAdet(is)
{
	var q=parseInt(document.SPF.adet.value);
	q=(is)?q+1:q-1;
	if(q<1 || q>100)
	{
		alert('1-100 arasında alabilirsiniz!');
		return false;
	}
	document.SPF.adet.value=q;
}


function changedSelectBox(id,PI)//secim kutusu degisimi
{
	lightBox.open();
	vid=document.forms['SPF'].elements['att['+id+']'].value;
	url=RootPath+'Urun/UrunSecenekleriSelectChanged.php?PI='+PI+'&sid='+id+'&vid='+vid;
	for(k=0;k<SpfSelects.length;k++)
	{
		url+='&val['+SpfSelects[k]+']='+document.forms['SPF'].elements['att['+SpfSelects[k]+']'].value;
	}
	ifrm.window.location.href=url;
}

function changedCheckBox(ob)
{
	if(ob.type!="checkbox" || ob.name=="")
		return;
	var e=ob.form.elements;
	for(var i=0;i<e.length;i++)
	{
		if(e[i].type!="checkbox" || e[i].name!=ob.name || e[i]==ob)
			continue;
		e[i].checked=false;
	}
}

function CheckBasket()
{
	if(typeof SpfSelects!="undefined")
	{
		for(var i=0;i<SpfSelects.length;i++)
		{
			var SpfSelect=document.forms['SPF'].elements['att['+SpfSelects[i]+']'];
			if(SpfSelect.value=='')
			{
				alert('Lütfen '+SpfSelect[0].innerHTML);
				SpfSelect.focus();
				return false;
			}
		}
	}
	if(typeof SpfTexts!="undefined")
	{
		for(var i=0;i<SpfTexts.length;i++)
		{
			var SpfText=document.forms['SPF'].elements['aty['+SpfTexts[i]+']'];
			if(SpfText.value=='' && SpfText.disabled!=true)
			{
				alert('Lütfen "'+SpfText.getAttribute("label")+'" giriniz.');
				SpfText.focus();
				return false;
			}
		}
	}
	lightBox.open();
	return true;
}
/*end sepete atma*/
/*tooltip*/
var ToolTips={
	overrides:['title','width','height','content'],
	title:'',	
	width:250,
	height:150,
	screenSizes:function()
	{
		var w,h;
		if(document.documentElement && document.documentElement.clientWidth)
		{
			w=document.documentElement.clientWidth;
			h=document.documentElement.clientHeight;
		}
		else if(document.body && document.body.clientWidth)
		{
			w=document.body.clientWidth;
			h=document.body.clientHeight;
		}
		else if(window.innerWidth)
		{
			w=window.innerWidth;
			h=window.innerHeight;
		}
		return [w,h];
	},
	scroolXY:function()
	{
		var scrOfX=scrOfY=0;
		if(typeof(window.pageYOffset)=='number')//Netscape compliant
		{
			scrOfY=window.pageYOffset;
			scrOfX=window.pageXOffset;
		}
		else if(document.body && (document.body.scrollLeft || document.body.scrollTop))//DOM compliant
		{
			scrOfY=document.body.scrollTop;
			scrOfX=document.body.scrollLeft;
		}
		else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))//IE6 standards compliant mode
		{
			scrOfY=document.documentElement.scrollTop;
			scrOfX=document.documentElement.scrollLeft;
		}
		return [scrOfX,scrOfY];
	},
	calcXY:function(ob,dv)
	{
		var scrool=this.scroolXY();//
		var dest=ss.getDestinationXY(ob);
		var cw=document.body.clientWidth;
		var ch=document.body.clientHeight;
		var dw=dv.clientWidth;
		var dh=dv.clientHeight;
		var nh=dest[1]-scrool[1]-dh;
		var nw=dest[0]+dw;
		var nt=(nh<0)?dest[1]+5:dest[1]-dh-10;
		var nl=(nw<cw)?dest[0]:cw-dw;
		return [nl,nt];
	},
	show : function (ob,params)
	{
		var a=ob.getElementsByTagName("div");
		for (var i=0;i<a.length;i++)
		{
			if(a[i].id=="brkTip")
			{
				a[i].style.display="block";
				var coorDinat=this.calcXY(ob,a[i]);
				a[i].style.top=coorDinat[1]+"px";
				a[i].style.left=coorDinat[0]+"px";
				return;
			}
		}
		for(var i=0;i<this.overrides.length;i++)
		{
			var name = this.overrides[i];
			this[name] = (params && typeof params[name] != 'undefined' )?params[name] : this[name];
		}
		titleH=(this.title=="")?"":"<div class=brkTipT>"+this.title+"</div>";		
		var dv=document.createElement('div');		
		dv.id="brkTip";		
		dv.style.width=this.width+"px";
		dv.innerHTML=titleH+"<div class=brkTipC>"+this.content+"</div>";
		ob.appendChild(dv);
		var coorDinat=this.calcXY(ob,dv);
		dv.style.top=coorDinat[1]+"px";
		dv.style.left=coorDinat[0]+"px";
	},
	hide : function (ob){
		a=ob.getElementsByTagName("div");
		for(var i=0;i<a.length;i++)
		{
			if(a[i].id=="brkTip")
			{
				a[i].style.display="none";
				return;
			}
		}
	}
}
/*end tooltip*/


function CharLimit(ob,limit)
{
	sid=ob.getAttribute('sid');
	if(ob.value.length>limit)
		ob.value=ob.value.substring(0,limit);
	document.getElementById(sid).innerHTML=limit-ob.value.length;
}

var cookieProgress={
	read:function(name)
	{
		var c=document.cookie;
		if (c.indexOf(name)==-1) 
			return '';
		pos1=c.indexOf("=", c.indexOf(name))+1;
		pos2=c.indexOf(";",pos1);
		if(pos2==-1)
			pos2=c.length;
		return c.substring(pos1,pos2);
	},
	write:function(name,value,day)
	{
		if(day==null || day=='')	day=30;
		var d=new Date();
		d.setTime(d.getTime()+(day*24*60*60*1000));
		var expires="; expires="+d.toGMTString();
		document.cookie =name+"="+value+expires+"; path=/; domain=.hediyefabrikasi.com";
	},
	regexp:function(s)
	{
		s=s.replace(/ç/g,'&ccedil;');
		s=s.replace(/Ç/g,'&Ccedil;');
		s=s.replace(/ğ/g,'&#287;');
		s=s.replace(/Ğ/g,'&#286;');
		s=s.replace(/ı/g,'&#305;');
		s=s.replace(/İ/g,'&#304;');
		s=s.replace(/ö/g,'&ouml;');
		s=s.replace(/Ö/g,'&Ouml;');
		s=s.replace(/ş/g,'&#351;');
		s=s.replace(/Ş/g,'&#350;');
		s=s.replace(/ü/g,'&uuml;');
		s=s.replace(/Ü/g,'&Uuml;');
		s=s.replace(/;/g,'##');
		return s;
	}
}
var ClientTripProduct=
{	
	add:function(PI,CI,st,urunadi,image)
	{
		var OldData=cookieProgress.read('tripProducts').split('@@');
		var NewData=PI+'~'+CI+'~'+st+'~'+cookieProgress.regexp(urunadi)+'~'+image+'@@';
		for(var i=0;i<(OldData.length-1);i++)
		{
			if(i>5)		break;
			var ExpData=OldData[i].split('~');
			if(ExpData[0]==PI)	continue;
			NewData+=OldData[i]+'@@';			
		}
		cookieProgress.write('tripProducts',NewData,30);
	},
	write:function()
	{
		var eleman=document.getElementById('tripsProducts');
		if(!eleman)	return;
		var Data=cookieProgress.read('tripProducts').split('@@');
		var DataCount=Data.length-1;
		if(DataCount<1)	return;
		var output='<div id="sidebar2" style="position:relative;margin-top:-6px "><div id="sidebar2ContentT"><div id="sidebar2Content"><b>Son gezdiklerin</b>';
		for(i=0;i<DataCount;i++)
		{
			ExpData=Data[i].split('~');
			output+='<div class=line></div><a href="'+RootPath+'hediye+sitesi/hediyeler/?PI='+ExpData[0]+'&CI='+ExpData[1]+'&st='+ExpData[2]+'" title="'+ExpData[3].replace(/##/g,';')+'">';
			output+='<img src="'+ImagePath+'U500/'+ExpData[4]+'" />'+ExpData[3].replace(/##/g,';');
			output+='</a>';
		}
		output+='</div></div></div>';
		eleman.innerHTML+=output;
	}
}

var nmRegions=new Array('Ülke','Şehir','İlçe','Semt');
function jsRegion(obj)
{
	lightBox.open();
	ifrm.window.location.href=RootPath+'Scripts/region.php?is=2&r='+obj.value+'&e='+obj.id.replace('region','');	
}
$(function(){
	$("ul.tabs").tabs("div.tabs > div");
	$(".brkTip[title]").tooltip();
	$('a[href*=#]').click(function(){		
		if (location.pathname.replace(/^\//,'')==this.pathname.replace(/^\//,'') && location.hostname == this.hostname)
		{
			smoothScroll(this.hash.slice(1));
			return false;
		}
	});
});
