function updItemTotal(unitPrice,quantity,total){if(unitPrice==null||quantity==null||total==null){return-1;}
if(!isNaN(parseInt($(quantity).val()))){if(parseInt($(quantity).val())<0){$(quantity).val(1);}
else{$(quantity).val(parseInt($(quantity).val()));}
total.text(parseFloat(unitPrice).toFixed(2)*parseInt($(quantity).val()));}
return 0;}
function updTotalCart(pricesByItem,totalInvoice,discount){if(pricesByItem==null||totalInvoice==null){return false;}
var oldTotal=$(totalInvoice).text();var total=0.0;if($(pricesByItem).length==1)
{total=parseFloat($(pricesByItem).text());}
else
{pricesByItem.each(function(){total+=parseFloat($(this).text());});}
if(!isNaN(discount)&&parseFloat(discount)>0)
{discount=parseFloat(discount);if(discount>=1)
{total=Math.max(total-discount,0);}
else
{total=total*(1-discount);}}
$(totalInvoice).text('Total Price : $'+total.toFixed(2));if(oldTotal=='Total Price : $'+total.toFixed(2))
{return false;}
else
{return true;}}
function carouselSoftMenuOn(carousel,item,position,state)
{var titles=$("#carouselSoftwareTitle li");$(titles.get(position-1).firstChild).addClass('active');return 0;}
function carouselSoftMenuOff(carousel,item,position,state)
{var titles=$("#carouselSoftwareTitle li");$(titles.get(position-1).firstChild).removeClass('active');return 0;}
function carouselSoftInit(carousel)
{$('#carouselSoftwareTitle li a').bind('click',function(){carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('rel')));carousel.options.auto=0;return false;});}
function accordeon(lastBlock,blocks,maxWidth,minWidth){blocks.hover(function(){if($(this).width()<maxWidth){$(lastBlock).animate({width:minWidth+"px"},{queue:false,duration:400});$(this).animate({width:maxWidth+"px"},{queue:false,duration:400});lastBlock=this;}});}
function replaceStoreAction()
{var total=$('#totalPrice').text();total=total.substring(total.indexOf("$",0)+1,total.length);if($('#cartItems tbody tr').length>0&&parseFloat(total)==0)
{$('#paysecurelynow').css({"background-position":"0 -88px"});$('#paysecurelynow').hover(function(){$(this).css({"background-position":"0 -132px"});},function(){$(this).css({"background-position":"0 -88px"});});$('#step3 div p').html("Click on 'Free download' to download the free demo of MapInXL.");}
else
{$('#paysecurelynow').css({"background-position":"0 0"});$('#paysecurelynow').hover(function(){$(this).css({"background-position":"0 -44px"});},function(){$(this).css({"background-position":"0 0"});});$('#step3 div p').html("Click on '<span id=\"paysecurelynowlink\">Pay Securely Now</span>' to complete your purchase through PayPal.<br/>Both Credit Card and PayPal accounts are accepted.");}}
function changeQuantity(elem)
{var val=parseInt($(elem).val());if(isNaN(val)||val==0||val==parseInt($(elem).attr('rel'))){return false;}
jQuery.ajax({type:'POST',dataType:'json',data:$(elem).attr('name')+'='+val,beforeSend:function(XMLHttpRequest){$(elem).next().show();},complete:function(XMLHttpRequest,textStatus){$(elem).next().hide();},success:function(data,textStatus){var temp=readJsonCart(data);},url:'/store/updateCart'});$('#totalPrice').effect("highlight",{'color':'#cce6c5'},1000);replaceStoreAction();}
function changeDiscount(elem)
{var val=jQuery.trim($(elem).val());if(val==""){return false;}
jQuery.ajax({type:'POST',dataType:'json',data:'name='+val,beforeSend:function(XMLHttpRequest){$('#indicatorCoupon').show();},complete:function(XMLHttpRequest,textStatus){$('#indicatorCoupon').hide();},success:function(data,textStatus){var temp=readJsonCart(data);},url:'/store/discount/'});$('#totalPrice').effect("highlight",{'color':'#cce6c5'},1000);replaceStoreAction();}
function changeVersion(elem)
{var val=$(elem).val();jQuery.ajax({type:'POST',dataType:'json',data:$(elem).attr('name')+'='+val,beforeSend:function(XMLHttpRequest){},complete:function(XMLHttpRequest,textStatus){},success:function(data,textStatus){var temp=readJsonCart(data);},url:'/store/updateCart/'});$('#totalPrice').effect("highlight",{'color':'#cce6c5'},1000);replaceStoreAction();}
function readJsonCart(datas){var data=datas[0];var cart='';var total='';$.each(data.products,function(i,product){cart+='<tr rel="'+product.id+'"';cart+=(i%2==1)?'class="alt">':'>';cart+='<td><span class="product-'+product.alias+'">'+product.name+"</span></td>";if(product.versions&&typeof product.versions==='object'){cart+='<td class="version"><select id="version_'+product.id+'" name="version_'+product.id+'" onchange="javascript:changeVersion(this)">';for(i=0;i<product.versions.length;i++){cart+='<option value="'+product.versions[i].id+'"';if(product.versions[i].id==product.version){cart+=' selected ';}
cart+='>'+product.versions[i].name+'</option>';}
cart+='</select></td>';}
else{cart+='<td class="version">'+product.version+'</td>';}
cart+='<td class="platform">'+product.platform+'</td>';cart+='<td class="unitPrice" style="text-align:right">';if(product.priceOriginal!=product.price){cart+='<del>'+product.priceOriginal+'</del> <ins>'+product.price+'</ins>';}
else{cart+=product.price;}
cart+='</td>';cart+='<td class="quantity">';cart+='<input class="text span-1" id="quantity_'+product.id+'" name="quantity_'+product.id+'" type="text" value="'+product.quantity+'" rel="'+product.quantity+'" onkeyup="javascript:changeQuantity(this)" />';cart+='<span id="indicatorQuantity'+i+'" class="indicator16">&nbsp;</span>';cart+='</td>';cart+='<td class="total" style="text-align:right">'+product.total+'</span>';cart+='<td><a href="'+data.urlStore+'/store/removeItem/id/'+product.id+'" title="Remove this item" class="ui-icon ui-icon-closethick">remove</a></td>';cart+='</tr>';})
cart+='<tr id="couponCart">';cart+='<td class="deco" colspan="3">';cart+='<label for="coupon">Coupon : </label>'
cart+='<input id="coupon" class="text span-3" onchange="javascript:changeDiscount(this)" name="coupon" value="';if(data.discount.valid==1){cart+=data.discount.name+'"/>&nbsp;<span id="indicatorCoupon" class="indicator16">&nbsp;</span>'+data.discount.message+'</td>';cart+='<td id="couponValue" colspan="3">'+data.discount.value+'</td>';}
else if(data.discount.valid==-1){cart+=data.discount.name+'"/>&nbsp;<span id="indicatorCoupon" class="indicator16">&nbsp;</span>'+data.discount.message+'</td>';cart+='<td id="couponValue" colspan="3">&nbsp;</td>';}
else{cart+='optional"/>&nbsp;<span id="indicatorCoupon" class="indicator16">&nbsp;</span></td>';cart+='<td id="couponValue" colspan="3">&nbsp;</td>';}
cart+='<td>&nbsp;</td></tr>';total='<tr id="totalCart">';total+='<td colspan="6" id="totalPrice">Total Price : '+data.total+'</td>';total+='<td class="nobg">&nbsp;</td>';total+='</tr>';$('#cartItems tbody').html(cart);$('#cartItems tfoot').html(total);}
$(document).ready(function(){if($("#tabs").length>0){$("#tabs").tabs({event:'mouseover'});}
if($("#accordion").length>0){$("#accordion").accordion({autoHeight:false,collapsible:true,header:'dt'});}
if($("#accordeonHomepage").length>0){accordeon($("#discover .visible"),$(".visible"),749,96);}
$("#carouselSoftwareImages").jcarousel({vertical:true,scroll:1,auto:4,wrap:"both",itemVisibleInCallback:{onBeforeAnimation:carouselSoftMenuOn},itemVisibleOutCallback:{onBeforeAnimation:carouselSoftMenuOff},initCallback:carouselSoftInit,buttonNextHTML:null,buttonPrevHTML:null});$(".lightbox").colorbox();$(".mediaobject a").colorbox();$(".videobox").colorbox({fixedWidth:800,fixedHeight:502});$(".qtipMap").each(function(){$(this).qtip({content:'<img src="'+$(this).attr('href')+'"/>',style:{background:'#1e8300',border:{color:'#1e8300',radius:2,width:2},tip:'bottomMiddle',width:67},position:{corner:{target:'topMiddle',tooltip:'bottomMiddle'}}});$(this).click(function(e){e.stopPropagation();return false;});});$("#statisticalDisplay div").each(function(){$(this).qtip({content:$(this).children('p').eq(0).html(),style:{background:'#e0f6d9',border:{color:'#1e8300',radius:2,width:2},tip:'bottomMiddle',width:300},position:{corner:{target:'topMiddle',tooltip:'bottomMiddle'}}});});$(".downloadMapsDesc").each(function(){$(this).qtip({content:$(this).children('div').eq(0).html(),style:{background:'#e0f6d9',border:{color:'#1e8300',radius:2,width:2},tip:'leftMiddle',width:200},position:{corner:{target:'rightMiddle',tooltip:'leftMiddle'}}});});$("#step1 input[type=submit]").hide();if($("#step1").length==1){replaceStoreAction();}
$("#step3 form").submit(function(){if($("#login").hasClass("logged")&&$("#step1 form").length==0){return true;}
else{return false;}});$("#multilicenses").dialog({bgiframe:true,resizable:false,height:250,width:400,modal:true,autoOpen:false,overlay:{backgroundColor:'#000',opacity:0.8},buttons:{'OK':function(){$(this).dialog('close');}}});$('#quantityInfo').click(function(e){$("#multilicenses").dialog('open');});$('#purchaseyouritems, #paysecurelynowlink').click(function(e){$('#paysecurelynow').click();});});