
var base="/";$(document).ready(function(){$('body').ajaxStart(function(){$('div#loader').show();});$('body').ajaxStop(function(){$('div#loader').fadeOut(500);});$('.cart').hover(function(){$('.cart-details .content').show('fast');},function(){$('.cart-details .content').slideUp('fast');});loadCart();})
function loadCart(){$('#promo-cart .cart-content').load(base+'ajax.php?get_cart_content=1','',function(){$('.cart-details .content').slideUp('slow');});}
function submitForm(form,callback){callback=callback||function(){};$(form).ajaxSubmit({success:function(result){result=trim(result);if(typeof(result)=='string'&&result!=''){alert(trim(result));}
callback();}});}
function resetOrder(){$('#review-what-qty').html(1);$('#qty').val(1);}
function changeFutonColor(product_id,attribute_id){runFunction('changeColor','product_id='+product_id+'&attribute_id='+attribute_id,function(response){var attribute_id=response.data.attribute_id;var color=response.data.color;var color_title=response.data.color_title;var product_name=response.data.product_name;var bigimage=base+'images/new_futons/'+product_name+'/jfc_350/'+color+'.jpg';$('#review-what-look').html('<a class="thickbox"  href="javascript:tb_show(\''+color_title+'\',\''+bigimage+'\')"><img src="'+base+'images/new_futons/'+product_name+'/jfc_16/'+color+'.jpg" alt="'+color+'" width="14" height="14" /> '+color_title);$('#what-look-large').html('<a class="thickbox"  href="javascript:tb_show(\''+color_title+'\',\''+bigimage+'\')"> <img src="'+base+'images/image_enlarge.gif" alt=""  /> </a>');$('#color-picker li').removeClass("selected");$('#color-picker li.'+color).addClass("selected");$('#opt_id1').val(product_id);$('#futon-container').html('<img src="'+bigimage+'" alt="" width="225"  />');$('#opt_id1').val(attribute_id);});}
function changeFutonSize(product_id,attribute_id,loader){runFunction('changeSize','product_id='+product_id+'&attribute_id='+attribute_id,function(response){var attribute_id=response.data.attribute_id;var size=response.data.size;var upper_size=response.data.upper_size;var size_title=response.data.title;var html=upper_size+'<br><span style="font-size:12px;">'+size_title+'</span>';$('#review-what-size').html(html);if(loader){$("#opt_id2").selectOptions(attribute_id,true);}
$('#opt_id2').val(attribute_id);var qty=$('#qty').val();changeFutonQty(qty)});}
function changeFutonQty(qty){if(isNaN(qty)||qty<1){$('#qty').val('1');$('#review-what-qty').html('1');drawItemTotal();}else{$('#review-what-qty').html(qty);$('#review-what-qty').html(qty);drawItemTotal();}}
function drawItemTotal(){
	var qty=$('#qty').val();
	var attribute_id=$('#opt_id2').val();
	var product_id=$('#product_id').val();
	
	runFunction('getItemTotal',
				'product_id='+product_id+'&attribute_id='+attribute_id+'&qty='+qty,
				function(response){
					$('#review-total').html(response.data.total_formated);
					$('#review-our-price').html(response.data.total_our_price);
					$('#review-msrp').html(response.data.total_msrp);
				});
}
function sentenceCase(strInput)
{strInput=trim(strInput);strInput=' '+strInput;strInput=strInput.toLowerCase();var firstcharlc=strInput.charAt(1);var firstcharuc=firstcharlc.toUpperCase();firstcharuc=" "+firstcharuc;firstcharlc=" "+firstcharlc;strInput=strInput.replace(firstcharlc,firstcharuc);strInput=trim(strInput);var len=strInput.length;var spacePos=strInput.indexOf(' ');while(spacePos!=-1)
{var firstcharlc=strInput.charAt(spacePos+1);var firstcharuc=firstcharlc.toUpperCase();firstcharuc=" "+firstcharuc;firstcharlc=" "+firstcharlc;strInput=strInput.replace(firstcharlc,firstcharuc);strInput=trim(strInput);spacePos=strInput.indexOf(' ',spacePos+1);}
return strInput;}
function rtrim(strInput){while(1){if(strInput.substring(strInput.length-1,strInput.length)!=" ")
break;strInput=strInput.substring(0,strInput.length-1);}
return strInput;}
function ltrim(strInput){while(1){if(strInput.substring(0,1)!=" ")
break;strInput=strInput.substring(1,strInput.length);}
return strInput;}
function trim(strInput){var tmpstr=ltrim(strInput);return rtrim(tmpstr);}
function goTo(url){if(url=='checkout.php'){if($.ajax({url:base+"ajax.php?get_cart_count=1",async:false}).responseText>0){window.location=url;}else{alert("Your Cart is Empty.");return;}}else{window.location=url;}}