function show_popup(){
	centerPopup('cart_popup');
	loadPopup('cart_popup');
}
function add_to_cart(pid){
    qty = jQuery("#qty_field").val();
    if(isNaN(qty)){
        qty = 1;
    }
    if(qty==0 || qty == undefined){
        qty = 1;
    }
    show_popup();
    jQuery("#popup_matter").html("Please wait. <br/>Processing.....")
    jQuery.post("ajax_request.php?action=addtocart", {pid:pid,qty:qty}, function(data){
        if(data=="msg"){
            jQuery("#popup_matter").html("Welcome to \"My Style\" : the shopping destination of products recommended by YST. Shopping from this section starts on the 6th of June.... please return and make sure you pick your favorite stuff before it is Sold Out cause everything is in limited quantity...because we believe in bringing you Quality.");
        }
        else if(data=="exists"){
            jQuery("#popup_matter").html("Product already added in cart");
        }
        else if(data=="stock"){
            jQuery("#popup_matter").html("Product stock not available");
        }
        else if(data=="invalid"){
            jQuery("#popup_matter").html("Invalid request, please check");
        }else{

            
            jQuery("#popup_matter").html("<br/>Product added to cart. <br/><br/>Pls click on <a class='link1' href='cart.php'>Shopping Cart</a> if you want to Checkout Now");
            jQuery("#cart_content").html(data);
        }
        //window.setTimeout(hidepopup, 2000);
    });
    
}

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

function hidepopup(){
    disablePopup('cart_popup');
}
//loading popup with jQuery magic!
function loadPopup(div_id){
	//loads popup only if it is disabled
	if(popupStatus==0){
		jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery("#"+div_id).fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(div_id){
    jQuery("#popup_matter").html("");
	//disables popup only if it is enabled
	if(popupStatus==1){
		jQuery("#backgroundPopup").fadeOut("slow");
		jQuery("#"+div_id).fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(div_id){
	//request data for centering
	var windowWidth = jQuery(window).width();
	var windowHeight = jQuery(window).height();
	var popupHeight = jQuery("#"+div_id).height();
	var popupWidth = jQuery("#"+div_id).width();
    var scrollTop = jQuery(window).scrollTop();
	//centering
	jQuery("#"+div_id).css({
		"position": "absolute",
		"top": scrollTop + windowHeight/2-popupHeight/2-70,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	jQuery("#backgroundPopup").css({
		"height": windowHeight,
		"width": windowWidth
	});
	
}
function forceNumber(ev){
    if(!ev)
        var ev = window.event;
    
    if((ev.keyCode>=48 && ev.keyCode<=57) || (ev.keyCode>=35 && ev.keyCode<=40) || (ev.keyCode>=96 && ev.keyCode<=105) || (ev.keyCode==46 || ev.keyCode==8 || ev.keyCode==9)){
        return true;
    }
    return false;
}
