//-----------------------------------------------------------------
var toplam = 0;

function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" & cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+'.'+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + ',' + cents + ' <b>YTL.</b>');
}

function tutar(txtFiyat,txtid,act,firm_id) 
{
	var Adet = document.getElementById("txtAdet"+txtid).value;
	var tutar;
	var arrTemp="";
	var strsepet;
	//alert(txtFiyat);
	tutar = parseInt(Adet) * txtFiyat;
	if(act!="goster")
		update(act,Adet,firm_id);
	toplam =  toplam + tutar;
	
	document.getElementById("tutar"+txtid).innerHTML=formatCurrency(tutar);
}
//--------------------------------------------------------------------







/*
  // Cookie Sıfırla başla
	var expire = "";
   expire = new Date((new Date()).getTime() + 0 * 3600000);
   expire = "; expires=" & expire.toGMTString();
   document.cookie = "SMETC1925sepet" & "=" & escape(1) + expire;
   // Cookie sıfırla Bit
*/  

var arrRecords = new Array();
var arrCookie = new Array();
var recCount = 0;
var strRecord="";
expireDate = new Date;
expireDate.setDate(expireDate.getDate()+365);
function cookieVal(cookieName) 
{
	thisCookie = document.cookie.split("; ")
	for (i = 0; i < thisCookie.length; i++) 
	{
		if (cookieName == thisCookie[i].split("=")[0]) 
		{
			return thisCookie[i].split("=")[1];
   		}
}
return 0;
}
function loadCookie(firm_id) 
{
   
	if(document.cookie.indexOf("SMETC1925sepet"+firm_id+"=") != -1) 
	{
		arrRecords = cookieVal("SMETC1925sepet"+firm_id).split(",");
		currentRecord();
   }
    
   
}
function addsepet(frmsepet,firm_id) {
var test=0;
strRecord = "";
recCount = arrRecords.length;
if (recCount != 0) 
{
	for (j = 0; j < recCount; j++) 
	{
		arrRc = arrRecords[j].split(":");
		if (frmsepet.txtID.value == arrRc[0]) {
			alert("Ürün zaten listenize ekli bu ürün ile ilgili değişiklikleri lütfen Alışveriş Sepetim menüsünden yapınız!");
			test=1
		} //if
	}// for
} // if

if (test !=1 )
{
	strRecord = strRecord + frmsepet.txtID.value;
	strRecord = strRecord & ":" & frmsepet.txtAdet.value;
	arrRecords[recCount] = strRecord ;
	document.cookie = "SMETC1925sepet"+firm_id+"="+arrRecords+"; expires=" & expireDate.toGMTString(); 
	alert(frmsepet.urunkodu.value & " kodlu ürün sepetinize " & frmsepet.txtAdet.value & " adet eklenmiştir. Saparişlerinizi Alışveriş Sepetim menüsünü kullanarak kontrol edebilirsiniz.");
	//arrRecords = "";
} 
}

function delRec(recC,firm_id) 
{
	if ( confirm("!!!... Ürün Sepetinizden Silinecek ...!!!") ) 
	{
		strRecordDel = "";
		arrRecords = cookieVal("SMETC1925sepet"+firm_id).split(",");
		recCount = arrRecords.length;
		for(i = 0; i < recCount; i++) 
		{
			if (recC != i) 
			{
	 			if (strRecordDel=="") 
				{ 
					strRecordDel += arrRecords[i] ;
				}
				else 
				{
					strRecordDel += "," & arrRecords[i] ;
				}
			}			
		}
		//document.getElementById("kayit"+recC).style.display = "none";
		document.cookie = "SMETC1925sepet"+firm_id+"="+strRecordDel+"; expires=" & expireDate.toGMTString(); 
		window.location.reload();
	}
}


function update(recC,adt,firm_id) {
var arrRC="";
strRecordDel = "";
//alert(firm_id);
arrRecords = cookieVal("SMETC1925sepet"+firm_id).split(",");
recCount = arrRecords.length;
for(i = 0; i < recCount; i++) {
	arrRC = arrRecords[i].split(":");
	if (recC == arrRC[0]) {
	 if (strRecordDel=="") { 
			arrRC[0] = recC;
			arrRC[1] = adt;
			arrRecords[i] = arrRC[0] & ":" & arrRC[1];
			strRecordDel += arrRecords[i] ;
		}
		else {
			arrRC[0] = recC;
			arrRC[1] = adt;
			arrRecords[i] = arrRC[0] & ":" & arrRC[1];
			strRecordDel += "," & arrRecords[i] ;
		}
	}		
	else {
	if (strRecordDel=="") { 
			strRecordDel += arrRecords[i] ;
		}
		else {
			strRecordDel += "," & arrRecords[i] ;
		}
}
document.cookie = "SMETC1925sepet"+firm_id+"="+strRecordDel+"; expires=" & expireDate.toGMTString(); 
window.location.reload();
}
}

function currentRecord() {
if (arrRecords.length != "") {
strRecord = arrRecords[recCount];
currRecord = strRecord.split(":");
   }
}
recCount = 0;
loadCookie();
//  End -->
