function a() // kill javascript button links
{	}
function ppcconversion(total) {
var iframe = document.createElement('iframe');
iframe.style.width = '0px';
iframe.style.height = '0px';
document.body.appendChild(iframe);
iframe.src = 'https://www.canadawideflowers.ca/cart-express/thank-you.php?total='+total;
};
var total_val;
$(document).ready(function(){
	// Slide flower titles
function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}
function checkVersion() {
    var ver = getInternetExplorerVersion();
    if (ver > -1) {
        if (ver >= 8.0){
            return 1;}
        else{
		return 0;}
        }
	return 0;
}
	$('.flower').hover(function(){
		$("h6", this).stop().animate({bottom:'40px'},{queue:false,duration:160});
	}, function() {
		$("h6", this).stop().animate({bottom:'-70px'},{queue:false,duration:160});
	});
	$('.flower-cbcf').hover(function(){
		$("h6", this).stop().animate({bottom:'40px'},{queue:false,duration:160});
	}, function() {
		$("h6", this).stop().animate({bottom:'-70px'},{queue:false,duration:160});
	});
		// Fast Checkout - Delivery AJAX
	$("#delivery").submit(function(){
		$("input[name='lballoon_h']").val($("select[name='lballoon']").val());
		$("input[name='mballoon_h']").val($("select[name='mballoon']").val());
		$("input[name='chocolate_h']").val($("select[name='chocolate']").val());
		$("input[name='animal_h']").val($("select[name='animal']").val());
		$("input[name='price_h']").val($("input[name='price']:checked").val());
		//alert($("input[name='price']:checked").val());
		//alert($("input[name='price_h']").val()+' '+$("select[name='lballoon']").attr('value')+' '+$("input[name='mballoon_h']").val()+' '+$("input[name='chocolate_h']").val()+' '+$("input[name='animal_h']").val());
		var str = $(this).serialize();
		var objSaved;
	   	$.ajax({
		   type: "POST",
		   url: "https://www.canadawideflowers.ca/cart-express/checkout.php",
		   cache: false,
		   data: str,
		   success: function(msg){
				$("#delivery_message").ajaxComplete(function(event, request, settings){
					if((msg.length) > '800'){
					    $("#facebook").contents().find("div.connect_button_slider div a").click();
						$("#totals").html(msg);
						$("#delivery_message").html('');
						if($('#iframe-billing')){
							$("#iframe-billing").stop().animate({height:'1px',width:'1px'},{duration:60});
						}
						if(!checkVersion()){
							
							$("#checkout").stop().animate({marginLeft:'-740px'},{duration:160});}
						else{
							$("#billing-wrapper").css('position','absolute');
							$("#billing-wrapper").stop().animate({top:'0',left:'0'},{duration:160});}
						total_val = $("#total-check").text();
					} else {
						$("#delivery_message").html(msg);
						if($('#iframe-billing')){
							$("#iframe-billing").stop().animate({height:'280px',width:'350px'},{duration:60});
						}
						$("#totals").html('');
						
						
						$("#checkout").stop().animate({marginLeft:'0px'},{duration:160});
					}
					$("#delivery_message").stop().animate({top:'20px'},{duration:60});
					
				});
			}
		});
	return false;
	});
	// Fast Checkout - Delivery error message hide
	$("#delivery_message").click(function () {
		$(this).stop().animate({top:'380px'},{duration:60});
		if($('#iframe-billing')){			
			$('#iframe-billing').stop().animate({height:'1px',width:'1px'},{duration:60});
		}
	});
	// Fast Checkout - Previous Step
	$('#previous-step').click(function(){
		if(!checkVersion()){
			$("#checkout").animate({marginLeft:'0px'},{duration:160});}
		else{

			$("#billing-wrapper").stop().animate({top:'390px',left:'740px'},{duration:160});	
		}
		$("#totals").html('');
		$("#thank_you").html('');
	});
	$("#coupon").click(function(){
		$("input[name='promo']").val($('#couponHolder').val());		
		var form_data = $('#delivery').serialize();
		$.ajax({
		   type: "POST",
		   url: "https://www.canadawideflowers.ca/cart-express/checkout.php",
		   cache: false,
		   data: form_data,
		   success:function(msg){
			$("#totals").ajaxComplete(function(event, request, settings){
				if(settings.url == "https://www.canadawideflowers.ca/cart-express/checkout.php"){
					$('#thank_you').empty();
					$("#totals").html(msg);
					total_val = $("#total-check").text();
				}
			});
		   }
		})
	});
	
	$('#express').click(function(){		
		$("#description").fadeOut('fast');
		$("#delivery-wrapper").fadeIn('slow');
		return false;
	});
	$('#descBack').click(function(){		
		$("#description").fadeIn('slow');
		$("#delivery-wrapper").fadeOut('fast');
		return false;
	});
	// Fast Checkout - Billing AJAX
	$("#billing").submit(function(){
		var str = $(this).serialize();
	   	$.ajax({
		   type: "POST",
		   url: "https://www.canadawideflowers.ca/cart-express/confirm.php",
		   cache: false,
		   data: str,
		   success: function(msg){
		    //alert(msg.length);
				$("#billing_message").ajaxComplete(function(event, request, settings) {
					if(settings.url == "https://www.canadawideflowers.ca/cart-express/confirm.php"){
						
					if((msg.length) == '291'){
						$("#totals").empty();
						$("#thank_you").html(msg);
						ppcconversion(total_val);
						$("#thank_you").stop().animate({height:'379px',width:'745px'},{duration:60});
						$("#billing_message").html('');
						if($('#iframe-billing')){
							$("#iframe-billing").stop().animate({height:'1px',width:'1px'},{duration:60});
						}
					} else if ((msg) == ''){
					} else {						
						$("#thank_you").html('');
						$("#billing_message").html(msg);
						$("#billing_message").stop().animate({top:'20px'},{duration:60});
						if($('#iframe-billing')){
							$("#iframe-billing").stop().animate({height:'280px',width:'350px'},{duration:60});
						}
						
					}
					msg = '';
					}
				});
			}
		});
	return false;
	});
	// Fast Checkout - Billing error message hide
	$("#thank_you").click(function(){
		$("#thank_you").hide();
		$("#checkout").css('marginLeft','0px');
		$("#description").fadeIn('slow');
		$("#delivery-wrapper").fadeOut('fast');
		$("#thank_you").css('height','1px');
		$("#thank_you").css('width','1px');
		$("#occasion").val('');
		$("input[name='message']").empty();
		$("input[name='signature']").val('');
		$("input[name='instructions']").empty();
		$("input[name='first_name']").val('');
		$("input[name='last_name']").val('');
		$("input[name='street']").val('');
		$("input[name='apt']").val('');
		$("input[name='city']").val('');
		$("input[name='postal_code']").val('');
		$("input[name='phone1']").val('');
		$("input[name='ext']").val('');
		$("#card_number").val('');
		$("select[name='expmonth']").val('');
		$("select[name='expyear']").val('');
	});
	$("#billing_message").click(function () {
		$(this).stop().animate({top:'380px'},{duration:60});
		if($('#iframe-billing')){
			$("#iframe-billing").stop().animate({height:'1px',width:'1px'},{duration:60});
		}
	});
	// Fast Checkout - Show hide location_name
	$("#location_type").change(function () {
		if ($("option:selected", this).val()!='Residence'){
	  		$(".location_name").show();
			$("#delivery-wrapper").css('height','380px');
		} else {
	  		$(".location_name").hide();
			$(".location_name").val('');
			$("#delivery-wrapper").css('height','360px');
		}
  	});
	// Fast Checkout - Change cart item
	$(".flower-selection").click(function(){
		if ($(this).attr('id')=='0'){
			$("input[name='price']:nth(0)").attr("checked","checked");
		} else if ($(this).attr('id')=='1'){
			$("input[name='price']:nth(1)").attr("checked","checked");
		} else if ($(this).attr('id')=='2'){
			$("input[name='price']:nth(2)").attr("checked","checked");
		}
		if(!checkVersion()){
			$("#checkout").animate({marginLeft:'0px'},{duration:160});}
		else{

			$("#billing-wrapper").stop().animate({top:'390px',left:'740px'},{duration:160});	
		}
  	});
	$(".add_gift").change(function(){
		if($("#delivery-wrapper").css('height')!='1px'){
		$("#billing-wrapper").animate({left:'740px'},{duration:160});
		}		
	});
	$('div').removeClass('hidder-cl');
	if(window.attachEvent){
		$('#navbar ul li ul').css('display','block');
		$('#navbar ul li ul').css('position','absolute');
		$('#navbar ul li ul').css('z-index','100000');
		$('#navbar ul li ul').css('height','100%');
		$('.headline a').css('overflow','visible');
		$('.headline img').css('overflow','visible');
	}	
});

