$(document).ready(function() {						   
    $('.voucher h2 a').click(function() {
		var linkas = $(this).attr('href').split("/");
		if (linkas[2] != 'voucher')
			return true;
		var id =  "v-" + linkas[3];
		if ($("#"+id).length == 0)
			return true;
		var $sp = $("#"+id)[0].nextSibling.nextSibling;
		if ($sp.nodeName != 'SPAN')
			return true;
		var kodas = $sp.innerHTML;
		return revealme(id, kodas);
  	});	
    $('a[id|="v"]').click(function() {
		var id = $(this).attr('id');
		var $sp = $(this)[0].nextSibling.nextSibling;
		if ($sp.nodeName != 'SPAN')
			return true;
		var kodas = $sp.innerHTML;
		return revealme(id, kodas);
  	});		 
	$('.butonas span').each(function(index) {
    	$(this).css('visibility', 'hidden');
	});
});

function newme(id){
	if (id.indexOf("-") != -1)
	{id = id.substring(1);}
	id = id.substring(1);
	 var mywindow = window.open("http://www.vouchercodes.eu/out/voucher/" + id +
								"/", '_blank','toolbar=1,location=1,directories=1,scrollbars=1,resizable=1,status=1,menubar=1');
	 if (mywindow != null)
	 {
		mywindow.blur();
		return false;
	 }
	 return true;
}

function revealme(id, kodas){
	var b = newme(id);
	naujas = '<div class="voucheropen"><span>Voucher Code: '+kodas+
			 '</span>Shop\'s website has been opened in a new window for you. <br />Voucher code is: '+kodas+'</div>';		
	var polas = '<div id="poll' + id + '" class="poll">Did you get a discount? Yes:<input type="radio" name="vote" value="0" onclick="getVote(this.value)" />   No:<input type="radio" name="vote" value="1" onclick="getVote(this.value)" /></div>';	
	var naujas = $(naujas + polas).hide();
	var tevas = $("#"+id)[0].parentNode;
	$(tevas).replaceWith(naujas);
	naujas.show("normal");
	pollid ="poll" + id;
    return b;
}

