var country = 25;
var pay = 0;



$(document).ready(function() {
PaymentOpts();

$('.objectsnum').change(function() {updaterows("objects", this.value);});
$('.Sortersnum').change(function() {updaterows("order", this.value);});
if ($(".sizes select").length > 0)
$(".sizes select").sSelect();
if ($(".page-object select").length > 0)
$(".page-object select").sSelect();

if ($(".art-qty select").length > 0) {
initCashier();
};



if ($('#advanced').length > 0)
$('#advanced').click(function(){
$('#Search4, #Search5').toggle();
return false;});




$('.buy form').submit(function() {if ($(this).find('select[name="ADDTOCART[Size]"]').val() != '-1') return true; else {alert(seltext);return false;}});
}); 

function initCashier() {
$(".art-qty select").change(function() {
$.post("/modules/shop/ajax/ajax.php", $("#summarybox form").serialize(), function(data) {
$("#fullsummary").html(data);
initCashier();
});
});
$(".art-rm a").click(function() {
$.get("/modules/shop/ajax/ajax.php"+this.rel+"&lang="+$("input[name=lang]").val(), function(data) {
if (data.length > 10) {
$("#fullsummary").html(data);
initCashier();
} else {
  location.reload(true);
}
});
return false;});
$(".art-qty select").sSelect({ddMaxHeight: '200px'});
}


function updaterows(t, v) {
if (v != "") {
$.get("/modules/shop/setrows.php?"+t+"="+v, function(data) {
  if (data == 'OK')
  location.reload(true);
});
}
return false;
}


var busybee = 0;

function flipimg() {
$('#frontdiv, #backdiv, .backimg, .front').toggle();
 
 
 
 var options =
            {

                zoomWidth: 288,
                zoomHeight: 330,
                position : 'right',
				xOffset: 22,
                title :false


            }
			if ($(".front").css('display') != 'none')
            $(".zoomable.front").jqzoom(options); else
			if ($(".backimg").css('display') != 'none')
            $(".zoomable.backimg").jqzoom(options);
			
return false;
}



function AFOrder(form)
 {
 if (busybee == 0) {
 busybee = 1;
  $('#processing').show();
  $('.verify').hide();

  $.post($(form).attr('action'), $(form).serialize(), function(data) {
  if (data.status == 'error') {
	  alert(data.content);
	  busybee = 0;
	  $('#processing').hide();
	  $('.verify').show();
  }
  else 
  if (data.status == 'OK')
  window.location = "/sv/skjortor/tack-af";
}, 'json');

  }
return false;

}


function ProcessOrder(form)
 {
 if (busybee == 0) {
 busybee = 1;
  $('#processing').show();
  $('#orderbtn').hide();

  $.post($(form).attr('action'), $(form).serialize(), function(data) {
  if (data.status == 'error') {
	  alert(data.content);
	  busybee = 0;
	  $('#processing').hide();
	  $('#orderbtn').show();
  }
  else 
  if (data.status == 'PAYER') {
  $('#payform').html(data.content);
  $('#makeorder').submit(); 
  }
  else
  if (data.status == 'REDIRECT')
  window.location = data.content;
	}, 'json');

  }
return false;

}



function PaymentOpts() {
if ($('#SW').length > 0) {
if (($('#INV:checked').length > 0 || $('#PART:checked').length > 0) && $('#coun').val() == 'Sweden')
$('#pno').show();
else
$('#pno').hide();

if (($('#INV:checked').length > 0 || $('#PART:checked').length > 0) && $('#coun').val() != 'Sweden') {
$('#CARD').attr('checked', true);
alert('Faktura eller delbetalning är endast möjligt inom Sverige.');
}

if ($('#coun').val() != 'Sweden')
$('#SW').hide();
else
$('#SW').show();
}

if ($('#CARD:checked').length == 0 && $('#BANK:checked').length == 0)
$('#ssl').hide();
else 
$('#ssl').show();
}


var keepAliveImage = null;

 function KeepAlive(){
     if(!keepAliveImage)
      {
          keepAliveImage = document.createElement("img");
          keepAliveImage.setAttribute("src", "/img/alive.gif");
          keepAliveImage.style.position = "absolute";
          keepAliveImage.style.height = "1px";
          keepAliveImage.style.width = "1px";
          $('body').append(keepAliveImage);
     }
     else
      {
         var d = new Date();
         var rand = d.getTime();
         keepAliveImage.src = "/img/alive.gif?d=" + rand;
     }
  }
  setInterval('KeepAlive();', '9000');

