function readKeyCode(e) {
			var evtobj=window.event? window.event : e;			
			var code = (evtobj.charCode ? evtobj.charCode : evtobj.keyCode);			
			if((code>=48) && (code<=58))return true;
			else return false;
		} 
		
// ----------------- currency values ----------------
/*			
var EUR_values={"10":'10,00',"25":'25,00',"50":'50,00',"100":'100,00',"150":'150,00'}; //base pricing array.				
var WMZ_values={"10":'11,20', "25":'28,50', "50":'56,00',"100":'112,00', "150":'168,00'	};			
var WMU_values={"10":'112,00', "25":'285,00', "50":'560,00', "100":'1120,00', "150":'1680,00'};
var LVL_values={"10":'7,00', "25":'17,7', "50":'35,00', "100":'70,00', "150":'105,00'};
*/
var EUR_values={"10":'10,00',"25":'25,00',"50":'50,00',"100":'100,00',"150":'150,00'};
var RUB_values={"10":'415,00',"25":'1037,50',"50":'2075,00',"100":'4150,00',"150":'6225,00'};
var LVL_values={"10":'7,00',"25":'17,50',"50":'35,00',"100":'70,00',"150":'105,00'};
var URH_values={"10":'112,00',"25":'280,00',"50":'560,00',"100":'1120,00',"150":'1680,00'};
var WMZ_values={"10":'17,00',"25":'42,50',"50":'85,00',"100":'170,00',"150":'255,00'};
var UAH_values={"10":'110,00',"25":'275,00',"50":'550,00',"100":'1100,00',"150":'1650,00'};
var WME_values={"10":'12,00',"25":'30,00',"50":'60,00',"100":'120,00',"150":'180,00'};
var WMU_values={"10":'130,00',"25":'325,00',"50":'650,00',"100":'1300,00',"150":'1950,00'};
var WMR_values={"10":'532,80',"25":'1332,00',"50":'2664,00',"100":'5328,00',"150":'7992,00'};
var LV1_values={"10":'7,00',"25":'17,50',"50":'35,00',"100":'70,00',"150":'105,00'}; 

function setValuesTopupS(cur){
	var currencySelect=document.getElementById('topupCurrencySelectS');				
	var valuesSelect=document.getElementById('TopupCurencySelectS');	
	var currentValue=valuesSelect.selectedIndex; //storring current value		
	
	var values = new Array();
	
	for (i=0; i<valuesSelect.options.length; i++){
		values[i]=valuesSelect.options[i].value;		
	}

	valuesSelect.options.length=0;	
	
	//bonus hack
	var psystem = document.getElementById('topupPaymentSystsmsS').value;
	
	var i=0;
	for (var val in EUR_values){		
		if (cur=="EUR"){
				// reset topup values
			valuesSelect.options[valuesSelect.options.length]=new Option(EUR_values[val],values[i]);
		} else if (cur=="WMZ"){
			valuesSelect.options[valuesSelect.options.length]=new Option(WMZ_values[val],values[i]);
		} else if (cur=="WMU"){
			valuesSelect.options[valuesSelect.options.length]=new Option(WMU_values[val],values[i]);
		} else if (cur=="LVL"){
			valuesSelect.options[valuesSelect.options.length]=new Option(LVL_values[val],values[i]);
		} else if (cur=="LV1"){
			valuesSelect.options[valuesSelect.options.length]=new Option(LV1_values[val],values[i]);
		}
/*		if ((psystem=='visa') || (psystem=='hansa') || (psystem=='els')){
			if (val>=50){
				valuesSelect.options[valuesSelect.options.length-1].style.color='#ff0000';
			}
		}*/
		i++;
	}
	
	valuesSelect.selectedIndex=currentValue; //reselecting stored value
	
	for (i=0;i<currencySelect.options.length;i++){ //select propriate value from the currencies selector
		if (currencySelect.options[i].value==cur){
			currencySelect.selectedIndex=i;
			break;
		}
	}	
}

function checkTopupSum(){
		var s = document.getElementById('TopupCurencySelectS').options[document.getElementById('TopupCurencySelectS').selectedIndex].value;
		var psystem = document.getElementById('topupPaymentSystsmsS').value;
	/*	if ((psystem=='visa') || (psystem=='hansa') || (psystem=='els')){			
			 if (s=='5'){
					$('#tarif_info6').hide();
					$('#tarif_info7').hide();
					$('#tarif_info5').show();
			 } else if(s=='6'){
					$('#tarif_info6').show();
					$('#tarif_info7').hide();
					$('#tarif_info5').hide();
			 } else if(s=='7'){
					$('#tarif_info6').hide();
					$('#tarif_info7').show();
					$('#tarif_info5').hide();
			} else {
					$('#tarif_info6').hide();
					$('#tarif_info7').hide();
					$('#tarif_info5').hide();
			}
		} else {			
			$('#tarif_info6').hide();
			$('#tarif_info7').hide();
			$('#tarif_info5').hide();		
		} */
	}

function switchPaymentsystemsTopupS(obj){ // attached to topup payment systems changes
	var currencySelect=document.getElementById('topupCurrencySelectS');	
	
	if (obj.options[obj.selectedIndex].value=='webmoney'){ //webmoney payment system is chosen		
		setValuesTopupS('WMZ');		
	} else if(obj.options[obj.selectedIndex].value=='visa') { //firstdata payment system is chosen. fistdata supports LVL and EUR currencies				
		if ((currencySelect.options[currencySelect.selectedIndex].value!="EUR")&&(currencySelect.options[currencySelect.selectedIndex].value!="LVL")){			
			setValuesTopupS('EUR');			
		} 						
	} else if(obj.options[obj.selectedIndex].value=='els'){ //e-LS payment system is chosen. e-LS supports LVL and EUR currencies
		if (currencySelect.options[currencySelect.selectedIndex].value!="EUR"){	
			setValuesTopupS('EUR');
		}
	} else if(obj.options[obj.selectedIndex].value=='amex'){ //e-LS payment system is chosen. e-LS supports LVL and EUR currencies
		if (currencySelect.options[currencySelect.selectedIndex].value!="LVL"){	
			setValuesTopupS('LVL');
		}
	} else if(obj.options[obj.selectedIndex].value=='hansa'){ //e-LS payment system is chosen. e-LS supports LVL and EUR currencies
		if ((currencySelect.options[currencySelect.selectedIndex].value!="EUR")&&(currencySelect.options[currencySelect.selectedIndex].value!="LVL")){	
			setValuesTopupS('LVL');
		}
	} else if(obj.options[obj.selectedIndex].value=='wmnotes'){ //e-LS payment system is chosen. e-LS supports LVL and EUR currencies
		if (currencySelect.options[currencySelect.selectedIndex].value!="LV1"){	
			setValuesTopupS('LV1');
		}
	}	
	checkTopupSum();
}

function switchCurencyTopupS(obj){ // attached to topup currency changes.		
	var cur = obj.options[obj.selectedIndex].value;	
	paymentS=document.getElementById('topupPaymentSystsmsS');
	if (cur=="WMZ"){
		for (i=0; i<paymentS.options.length;i++){
			if 	(paymentS.options[i].value=="webmoney"){
				paymentS.selectedIndex=i;
				break;
			}
		}	
	} else if (cur=="WMU"){
		for (i=0; i<paymentS.options.length;i++){
			if 	(paymentS.options[i].value=="webmoney"){
				paymentS.selectedIndex=i;
				break;
			}
		}		
	} else if (cur=="LVL"){		
		for (i=0; i<paymentS.options.length;i++){
			if 	(paymentS.options[i].value=="visa"){
				paymentS.selectedIndex=i;
				break;
			}
		}	
	} else if (cur=="EUR"){
		for (i=0; i<paymentS.options.length;i++){
			if 	(paymentS.options[i].value=="visa"){
				paymentS.selectedIndex=i;
				break;
			}
		}	
	} else if (cur=="LV1"){
		for (i=0; i<paymentS.options.length;i++){
			if 	(paymentS.options[i].value=="wmnotes"){
				paymentS.selectedIndex=i;
				break;
			}
		}	
	}
	setValuesTopupS(cur);
	checkTopupSum();
}
			
// -------------------------------			
	
function additem(id){								
	$.post('/getdata2.php', {'action': 'itemtoCart', 'itemid': id}, function (data){
		//if (data!="false"){
		//	alert(data);
			//alert(id);
			updateCart();
		//}
	});
}

function truncitem(id){						
	//alert(id);
	$.post('/getdata2.php', {'action': 'itemfromCart', 'itemid': id}, function (data){
		updateCart();
	});
}

function deleteItemFromCart(id){
	$.post('/getdata2.php', {'action': 'deleteItemFromCart', 'itemid': id}, function (data){
		if (data=="OK"){
			updateCart();
			return true;
		}
	});
}

function buyitem(id){
	var count = document.getElementById('item_'+id+'_count').value;	
	count = parseInt(count);
	if ((!isNaN(count))&&(count>0)){		
		$.post('/getdata2.php', {'action': 'buyItem', 'itemid': id, 'itemcount': count}, function(data){
			if (data=="OK"){			
				document.getElementById('shopmessage').innerHTML="tovar dobavlen v karzinu";					
				updateCart();
			}																						  
		});		
	} else {
		document.getElementById('shopmessage').innerHTML="nekorrektnoje zna4enije koli4estva";					
	}
	document.getElementById('item_'+id+'_count').value='0';
}

function updateCart(){
	$.post('/getdata2.php', {'action': 'cartTotal'}, function (data){		
	 //   if (typeof(document.getElementById('cartBalance')!='undefined')){	    
	//	alert(data);
		if ((data!='false')&&(data!=0)){

			$("#cartdiv").css('display', 'block');
			getBorders();//dlje tavo chtobi borderi negljucheli HACK by Arnej :((
		 	document.getElementById('cartBalance').innerHTML=formatmoney(data);
		} else {
			$("#cartdiv").css('display', 'none');
			getBorders();//dlje tavo chtobi borderi negljucheli HACK by Arnej :((
		}
//			$('#cartBalance').innerHTML=data;
	  //  }
	});
}

function emptyCart(){
	$.post('/getdata2.php', {'action': 'emptyCart'}, function (data){
		if (data!='false'){
			updateCart();
		}
	});
}

function getBorders(){
	$('.lb').height(($('#ctn').height()));
	
   $('.rb').height(($('#ctn').height()));
}
$(document).ready(function() {
$(document).pngFix();
//	showDate()1; //engage girls change by time
	
  
	$('.cont-error').fadeIn(2000);	

	var size = screen.width;
	
	if(size == 1024){
		$('.sf-menu li').attr('style', 'margin-left:15px');
		$('#menubox .center').width(480);
		$('#topWrap').width(992);
		$('#pageWrap').width(992);
		$('#container').width(980);
		$('#rightContent').attr('style','margin-left:5px; width:180px;');
		$('#leftContent').attr('style','width:200px; margin-right:10px;');
		$('#leftContent .box').width(200);
		$('#centerContent').width(530);
		$('#centerContentTpl2').width(700);
		$('#wheretobuy').width(530);
		$('#wheretobuy .right').css('margin-left', '69px');
		$('#last2').css('display', 'none');
		$('#last').css('display', 'none');
		$('.logform').attr('style', 'width:84px');
		$('#leftContent .selbox').width(180);
		$('.box-bottom').width(220);
		$('.box-bottom1').width(200);
		$('#hack').attr('style', 'float:right; margin-right:0px;  width:90px; text-align:right');
		$('.box-txt').width(100);
		$('#container .bottom').attr('style', 'padding-left:0');
		$('.logform1').width(30);
		$('.logform2').width(137);
		$('.selbox1').width(40);
		$('.bottom-navi-a').width(965);
		$('.bottom-navi-b').width(965);
		$('.where-to-buy').width(550);
		$('#wtb .selbox').width(135);
		$('p#cross-links').attr('style', 'margin-left:20px');	
		$('#top .logo').attr('style', 'margin-left:20px;');
		$('#top .menu').attr('style', 'margin-left:10px;');
                $('.c1').attr('style', 'margin-left:10px; margin-top:10px; width:80px; margin-right:15px');
                $('.c2').attr('style', 'margin-top:10px; width:80px; margin-right:15px');
                $('.c3').attr('style', 'margin-top:10px; width:80px; margin-right:15px');
	}

	jQuery('ul.sf-menu').superfish();	//menu

	jQuery("div#slider1").codaSlider(); //middle part ith news and stuff
	
	updateCart();
	
	
});






