function AnimateCode(id){
      $("#cartItem_"+id+" .currency").animate({"opacity": 0}, 1000, "linear", function(){
      		$("#cartItem_"+id+" .currency").text('Ls 0.00');
      		$("#cartItem_"+id+" .currency").css({ color: "red"});
      		$("#cartItem_"+id+" .currency").animate({"opacity": 1}, 1000 );
      });
    //$("#cartItem_"+id+" .currency span").slideDown();
}

function ContionueWithoutAllSong(){
	$("#redeamCode p.msg").hide();
	var  inputValue = $("#redeamCode :text").val();
	GetSponsorData(inputValue);
	GetNewTotal(inputValue);
	$(".redeamCodeInput").hide();
	$(".redeamCodeButton").hide();
	$(".codeData").text(inputValue);
	$(".codeData").show();
}
function AddSongToCart(songID){
	var data = jQuery.ajax({type: "POST",async: false,url: "/CodeCheker.php?addSongToCart",data: "songID="+songID }).responseText;
	var DataType = data.split('|');
	if(DataType[0] =='put'){
		$("#cart-content tbody").append(DataType[1]);
		if(DataType[2] > 0){
			$("#cartItem_"+DataType[2]).slideDown('slow');
			var  inputValue = $("#redeamCode :text").val();	
			GetNewTotal(inputValue);
		}
	}
	readeamCode();
}
function GetNewTotal(inputValue){
	var data = jQuery.ajax({type: "POST",async: false,url: "/CodeCheker.php?total",data: "code="+inputValue }).responseText;
	var DataType = data.split('|');
	$("#total_cost").animate({"opacity": 0}, 1000, "linear", function(){
      		$("#total_cost").text(DataType[0]);
      		$("#total_cost").animate({"opacity": 1}, 1000 );
    });
    $("#total_pvn").animate({"opacity": 0}, 1000, "linear", function(){
      		$("#total_pvn").text(DataType[1]);
      		$("#total_pvn").animate({"opacity": 1}, 1000 );
    });
    
    
    if(DataType[0] == '0.00'){
    	$("#payment_method").remove();
    	$("#paymentMethodTittle").remove();
    	$("#paymentContionue").toggle();
    	$("#paymentContionue").append('<input type="hidden" name="payment_type" value="999" id="payment_method_free" />');
    	$("#paymentOrder").toggle(); 
    	var data ='<input type="hidden" value="1" id="payedBYSponsor" name="payedBYSponsor" />';
    	$("#interactive").append(data); 
    	   	
	} else {
	$("#paymentContionue").append('<input type="hidden" name="cart_checkout" value="1" />');
	}
}
function GetSponsorData(code){
		var data = jQuery.ajax({type: "POST",async: false,url: "/CodeCheker.php?sponsor",data: "code="+code }).responseText;
		data = data.split('|');
		if(data[0] == 'flash'){
			var out ='<div id="artist-short"></div><script type="text/javascript">';
			out +='var so = new SWFObject(\'/images/mediaplayer.swf\',\'artist-short-1\',\'366\',\'366\',\'8\',\'0x000000\');';
			out +='so.addParam(\'allowfullscreen\',\'false\');';
			out +='so.addParam(\'allowscriptaccess\',\'false\');';
			out +='so.addVariable(\'file\',\''+data[1]+'\');';
			out +='so.addVariable(\'width\',\'366\');';
			out +='so.addVariable(\'height\',\'366\');';
			out +='so.addVariable(\'displayheight\',\'366\');';
			out +='so.addVariable(\'shownavigation\',\'false\');';
			out +='so.addVariable(\'frontcolor\',\'0xffffff\');';
			out +='so.addVariable(\'backcolor\',\'0x000000\');';
			out +='so.addVariable(\'lightcolor\',\'0xcccccc\');';
			out +='so.addVariable(\'repeat\',\'false\');';
			out +='so.addVariable(\'shuffle\',\'false\');';
			out +='so.addVariable(\'autostart\',\'true\');';
			out +='so.addVariable(\'enablejs\',\'true\');';
			out +='so.addVariable(\'clickTAG\',\'\');';
			out +='so.write(\'artist-short\');';
			out +='</script>';
		} else {
			var out ='<img src="'+data[1]+'" alt="sponsor Image" />';
		}
		//
		//alert(out);
		$("#interactive").append(out);
//		alert(data[2]);
		$("#interactive").append(data[2]);
}
function readeamCode(){
	
	$("#redeamCode p.msg").hide();
	var  inputValue = $("#redeamCode :text").val();
	if(inputValue.length > 0){
		var data = jQuery.ajax({type: "POST",async: false,url: "/CodeCheker.php",data: "code="+inputValue }).responseText;
		data = data.split('|');
		
		if(data[0] == 'pause'){
			counter = data.length;
			counter = counter-1;
			for(i=1; i<counter; i++){
				AnimateCode(data[i]);
			}
			//alert(data[counter]);
			$("#redeamCode p.msg").html(data[counter]);
			$("#redeamCode p.msg").show();
			
		} else if(data[0] == 'err'){
			$("#redeamCode p.msg").html(data[1]);
			$("#redeamCode p.msg").show();
		} else{
			counter = data.length;
			for(i=1; i<counter; i++){
				AnimateCode(data[i]);
			}
			GetSponsorData(inputValue);
			GetNewTotal(inputValue);
			$(".redeamCodeInput").hide();
			$(".redeamCodeButton").hide();
			$(".codeData").text(inputValue);
			$(".codeData").show();
		}
		
	} else {
		$("#redeamCode p.msg").show();
	}
}
function SwichSearchTabs(type,el){
	$("ul.ShopGerneTabs li").removeClass('selected');
	$(el).addClass('selected');
	$("#searchType").val(type);
	document.location.href='?searchType='+type;
}

function SwichFirstpageTabs(type,el){
	$(".GerneTabs li").removeClass('selected');
	$(el).addClass('selected');
	$("#media-short div").hide();
	$("#tab"+type).show();
	//console.info(type);
	$("#firstPagePupupOpener").attr("onClick","openMediaPlayer('"+(type > 0 ? "shlager" : "")+"');");
}


function openGallery(gal_id, img_id){
	window.open('/gallery.php?gal_id='+gal_id+'&img_id='+img_id,'gallery','width=1000,height=700,top=40,left=40,status=0,resizable=0');
	return false;
}

function openImgPopUp(imgUrl, imgName){
	MyWindow = window.open(imgUrl,"Picture","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,width=400,height=400");
	MyWindow.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
	MyWindow.document.write('<html>');
	MyWindow.document.write('<head>');
	MyWindow.document.write('	<script type="text/javascript">');
	MyWindow.document.write('		function resizePopUp() {');
	MyWindow.document.write('			iWidth = document.documentElement.clientWidth;');
	MyWindow.document.write('			iHeight = window.innerHeight;');
	MyWindow.document.write('			if(iHeight == undefined) { iHeight = document.documentElement.clientHeight; }');
	MyWindow.document.write('			iWidth = document.images[0].width - iWidth;');
	MyWindow.document.write('			iHeight = document.images[0].height - iHeight;');
	MyWindow.document.write('			window.resizeBy(iWidth, iHeight);');
	MyWindow.document.write('		};');
	MyWindow.document.write('	</script>');
	MyWindow.document.write('	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
	MyWindow.document.write('	<title>'+imgName+'</title>');
	MyWindow.document.write('</head>');
	MyWindow.document.write('<body style="margin:0; padding:0;" onLoad="resizePopUp();">');
	MyWindow.document.write('	<img src="'+imgUrl+'" alt="'+imgName+'" />');
	MyWindow.document.write('</body>');
	MyWindow.document.write('</html>');
	MyWindow.document.close();
	return(false);
}

function openMediaPlayer(parameters){
	window.open('/popup_player.php?'+parameters, 'MediaPlayer', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=340,height=636');
}

function openSMS_buy(track_id){
	window.open('/sms_buy.php?track_id='+track_id, 'SMS', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=460,height=240');
}

/*****************************
** Skripti priekš CD/MP3 veikala mp3 atskaņotāja *** BEGIN ***
******************************/
// some variables to save
var playerCurrentPosition;
var playerCurrentVolume;
var playerCurrentItem;

// these functions are caught by the JavascriptView object of the player.
function sendEvent(typ,prm) {
	thisMovie("album_media_player").sendEvent(typ,prm);
};
function getUpdate(typ,pr1,pr2,pid) {
	if(typ == "time") {
		playerCurrentPosition = pr1;
	}
	else if(typ == "volume") {
		playerCurrentVolume = pr1;
	}
	else if(typ == 'item') {
		playerCurrentItem = pr1;
	}
	else if(typ == 'state'){
		var oPlTable = document.getElementById('playlist_table');
		var oTr = oPlTable.getElementsByTagName('tr');
		for(var i=0; i < oTr.length; i++){
			if(oTr[i].nodeType == 1){
				oTr[i].className = '';
			}
		}
		if(pr1 == 2){
			document.getElementById('playlist_item_'+playerCurrentItem).className = 'active';
		}
	}
};

// These functions are caught by the feeder object of the player.
function loadFile(obj) { thisMovie("album_media_player").loadFile(obj); };
function addItem(obj,idx) { thisMovie("album_media_player").addItem(obj,idx); }
function removeItem(idx) { thisMovie("album_media_player").removeItem(idx); }
// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
    if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};
/*****************************
** Skripti priekš CD/MP3 veikala mp3 atskaņotāja *** END ***
******************************/


function cart_recount(entry_id){
	var oHref = document.getElementById('cart_count_button_'+entry_id);
	oHref.setAttribute('href', 'cart.php?cart_change='+entry_id+'&count='+document.getElementById('cart_count_'+entry_id).value);
}

function validate_cart_form(){
	if($("#getSingleSponsor").val() > 0){
		return true;
	}else if($("#payedBYSponsor").val() == 1){
		return true;
	} else {
		var oP = document.getElementById('payment_method');
		var oInput = document.getElementsByTagName('input');
		for(var i=0; i < oInput.length; i++){
			if(oInput[i].checked == true){
				return true;
			}
		}
		alert('Norādi maksāšanas metodi');
		return false;
	}
}




