function buyNow(){
    $.cookie("apex__BuyNow","true",{ path: '/' });
    $(location).attr('href',location.href.split('#')[0]);
}

if({!SkuIdToSkuBuyingInfoMap[currentSKU].QuantityInStock} == -1){
    $('.sizeSelect[charch-id='+$('.charcChoose').val()).addClass('select-error');
}

$('.sizeSelect').on('SELECT_SELECTED', function(event, choice, choiceValue)
{
    var selectedPickList;
    var unSelectedPickList;
    $('.sizeSelect').each(function(){

	if($(event.target).attr('charch-Id')==$(this).attr('charch-Id')){
	    selectedPickList={
		    charcId :$(this).attr('charch-Id') ,
		    val: $(this).find("span.currentChoice").text().trim().split(' ')[0]}
	}
	
	else{
	    unSelectedPickList={
		    charcId :$(this).attr('charch-Id') ,
		    val: $(this).find("span.currentChoice").text().trim().split(' ')[0]}
	}
    });
    $('.charcChoose').val(selectedPickList.charcId);
    $('.valueChoose').val(selectedPickList.val);
    if($('.sizeSelect').size()==2){
	$('.charcNotChoose').val(unSelectedPickList.charcId);
	$('.valueNotChoose').val(unSelectedPickList.val);

    }

    changeInPickList();
});

function ValidQuntity(){		

    var inStock =  {!SkuIdToSkuBuyingInfoMap[currentSKU].QuantityInStock};
    var clientQunt = parseInt($('.quantityInput').val());
    var LimitCustomSetting = parseInt($('#maxAmountPerOrder').text());
    var ErrorQuantityMSG = $('.InputText_errorLabel.popinError.popinErrorQuantity');
    var IsNumbers = !(isNaN(clientQunt) || isNaN(inStock));
    if(IsNumbers && (inStock >= clientQunt)){
	$('.quantityInput').parent().removeClass('InputText-error');
       // $('.popinErrorNotify').hide();
	$('.popinErrorQuantity').hide();
	AddToCart();
    }
    else if(IsNumbers && !isNaN(LimitCustomSetting)){
	$('.quantityInput').focus();
	$('.quantityInput').parent().addClass('InputText-error');
	$('.popinErrorNotify').hide();
	$('.popinErrorQuantity').show();

	if(LimitCustomSetting >= clientQunt)
	    ErrorQuantityMSG.text('Quantity not available remains in stock ='+inStock);
	else{
	    ErrorQuantityMSG.text('Quantity not available remains in stock value ='+LimitCustomSetting);
	    console.log('DONT HAVE ENOUGTH FROM THAT! Or put NaN in input');
	}
    }
}
