function ajaxLightboxAdd(lang, sid, pnr, remove) {
	$('lb_'+sid+'_'+pnr).innerHTML = '<a href="/' + lang + '/lightbox/' + sid + '/' + pnr + '/d" onclick="javascript:ajaxLightboxDel(\'' + lang + '\',\''+ sid + '\',\'' + pnr + '\','+remove+');return false;"><img src="/_layout/images/icons/sm_lightb_pas.gif" width="20" height="20" align="absmiddle" /> Remove from Lightbox</a>';

	new Ajax.Request('/' + lang + '/lightbox/'+sid+'/'+pnr+'/a', { 
		method: 'get', 
		parameters: { ajax: 1 }, 
		onSuccess: function(transport) { updateLightboxTotals(transport.responseText); }
	}); 
}

function ajaxLightboxDel(lang, sid, pnr, remove) 
{
	new Ajax.Request('/' + lang + '/lightbox/'+sid+'/'+pnr+'/d', { 
		method: 'get', 
		parameters: { ajax: 1 }, 
		onSuccess: function(transport) { updateLightboxTotals(transport.responseText); }
	}); 

	if (remove)
	{
		$('pic_'+sid+'_'+pnr).remove();
		if ($('lightbox').innerHTML == "")
			$('lightbox').innerHTML = "<p>There are currently no pictures in your lightbox</p>";
	}
	else
		$('lb_'+sid+'_'+pnr).innerHTML = '<a href="/' + lang + '/lightbox/' + sid + '/' + pnr + '/a" onclick="javascript:ajaxLightboxAdd(\'' + lang + '\',\''+ sid + '\',\'' + pnr + '\','+remove+');return false;"><img src="/_layout/images/icons/sm_lightb_act.gif" width="20" height="20" align="absmiddle" /> Add to Lightbox</a>';
}

function updateLightboxTotals(text)
{
	$('lb').innerHTML = text;
}


function ajaxCartAdd(lang, sid, pnr, remove) {
	$('sc_'+sid+'_'+pnr).innerHTML = '<a href="/' + lang + '/cart/' + sid + '/' + pnr + '/d" onclick="javascript:ajaxCartDel(\'' + lang + '\',\''+ sid + '\',\'' + pnr + '\','+remove+');return false;"><img src="/_layout/images/icons/sm_cart_pas.gif" width="20" height="20" align="absmiddle" /> Remove from Cart</a>';

	new Ajax.Request('/' + lang + '/cart/'+sid+'/'+pnr+'/a', { 
		method: 'get', 
		parameters: { ajax: 1 }, 
		onSuccess: function(transport) { updateCartTotals(transport.responseText); }
	}); 
}

function ajaxCartDel(lang, sid, pnr, remove) 
{
	if (remove)
	{
		$('pic_'+sid+'_'+pnr).remove();
		count = parseInt($('ca_count').value) - 1;
		$('ca_count').value = count;
		
		if (count < 1)
			$('cart').innerHTML = "<p>There are currently no pictures in your cart</p>";
		else
			ajaxCartCheck();
	}
	else
		$('sc_'+sid+'_'+pnr).innerHTML = '<a href="/' + lang + '/cart/' + sid + '/' + pnr + '/a" onclick="javascript:ajaxCartAdd(\'' + lang + '\',\''+ sid + '\',\'' + pnr + '\','+remove+');return false;"><img src="/_layout/images/icons/sm_cart_act.gif" width="20" height="20" align="absmiddle" /> Add to Cart</a>';

	new Ajax.Request('/' + lang + '/cart/'+sid+'/'+pnr+'/d', { 
		method: 'get', 
		parameters: { ajax: 1 }, 
		onSuccess: function(transport) { updateCartTotals(transport.responseText); }
	}); 
}

function ajaxCartUpd(lang, count) 
{
	var type = $('form_cart').getInputs('radio', 'ca_type_'+count).find(function(r){return r.checked}).value;
	var usage = $('ca_usage_'+count).value;
	var id = $('ca_id_'+count).value;

	new Ajax.Request('/' + lang + '/cart/' + id + '/u', {
		method: 'post',
		parameters: { "ajax": 1, "type": type, "usage": usage },
		onSuccess: function(transport) {
			var json = transport.responseText.evalJSON();
			$('ca_price_'+count).innerHTML = json.item_price;
			ajaxCartCheck();
		}
	});
}

function ajaxCartCheck()
{
	var count = parseInt($('ca_maxcount').value);
	var fail = false;

	for(var i=1; i <= count; i++ )
	{
		
		if ($('ca_usage_'+i) && $('ca_usage_'+i).value == "")
		{
			fail = true;
			break;
		}
	}
	
	toggleCart(fail, false);
	
	return (fail == false);
}

function toggleCart(off, button)
{
	if (off)
	{	
		$('cart_fail').show();
		if (button)
			$('cart_submit').disable();
	}
	else
	{
		$('cart_fail').hide();
		if (button)
			$('cart_submit').enable();
	}
	
}
var cartUsageValue = "";

function cartUsageFocus(count)
{
	cartUsageValue = $('ca_usage_'+count).value;
}

function cartUsageBlur(lang, count)
{
	var usage = $('ca_usage_'+count).value;
	if (usage != cartUsageValue)
		ajaxCartUpd(lang, count);	
}



function updateCartTotals(text)
{
	$('sc').innerHTML = text;
}

function noCredits_Preview()
{
	alert("Only users with PiCredits may download the previews\n\nSorry, but you do not have credits.\nThe free previews are only available\nfor customers with credits.\n\nBuy PiCredits now to save money and get access\nto additional content.");
}

function noCredits_Story()
{
	alert("Only users with PiCredits may download the model stories/interviews\n\nSorry, but you do not have credits.\nThe free model stories/interviews are only available\nfor customers with credits.\n\nBuy PiCredits now to save money and get access\nto additional content.");
}

function noCredits_BHS()
{
	alert("Only users with PiCredits may download behind the scene images\n\nSorry, but you do not have credits.\nThe free behind the scene images are only available\nfor customers with credits.\n\nBuy PiCredits now to save money and get access\nto additional content.");
}


function logout(redirect, lang) {
	try{
	  var agt=navigator.userAgent.toLowerCase();
	  if (agt.indexOf("msie") != -1) {
	    // IE clear HTTP Authentication
	    document.execCommand("ClearAuthenticationCache");
	  } 
	  else {
	    var xmlhttp = createXMLObject();
	    xmlhttp.open("GET",".force_logout_offer_login_mozilla",true,"logout","");
	    xmlhttp.send("");
	    xmlhttp.abort();
	  }
	  if (redirect)
	  	window.location = "/" + lang + "/?logout";
	} catch(e) {
	
	}
}

function createXMLObject() {
	try {
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		}
		// code for IE
		else if (window.ActiveXObject) {
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	} catch (e) {
		xmlhttp=false
	}
	return xmlhttp;
}