﻿function ViewProduct(PId) {
    var win = window.open('ProductDetail.aspx?PID=' + PId, null, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=550,height=400,top=10,left=10', 'true');
    win.focus();
    return false;
}

function ViewProductdetail(PId) {
    var loaction = parent.location.href;
    var sitestatus = 'live' //local,live
    var locationpath = loaction.split("?")
    if (sitestatus == 'local') {
        if (locationpath[0].toLowerCase() == "http://localhost/popatstore/product.aspx") {
            parent.location.href = "http://localhost/popatStore/product.aspx?PID=" + PId;
        }
        else if (locationpath[0].toLowerCase() == "http://localhost/popatstore/subcategory.aspx") {
            var win = window.open('productdetail.aspx?PID=' + PId, null, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=550,height=400,top=10,left=10', 'true');
            win.focus();
            return false;
        }
        else {
            parent.location.href = "http://localhost/popatstore/productdesc.aspx?PID=" + PId;
        }
    }
    else {
        if (locationpath[0].toLowerCase() == "http://www.worldkitchen.co.uk/product.aspx") {
            parent.location.href = "http://www.worldkitchen.co.uk/product.aspx?PID=" + PId;
        }
        else if (locationpath[0].toLowerCase() == "http://www.worldkitchen.co.uk/subcategory.aspx") {
            var win = window.open('productdetail.aspx?PID=' + PId, null, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=550,height=400,top=10,left=10', 'true');
            win.focus();
            return false;
        }
        else {
            parent.location.href = "http://www.worldkitchen.co.uk/Productdesc.aspx?PID=" + PId;
        }
    }
}

function OutofStock1(PId) {
    var win = window.open('OutOfStock.aspx?chk=chk&PID=' + PId, null, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=320,height=195,top=10,left=10', 'true');
    win.focus();
    return false
}

function OutofStock(PId) {
    var win = window.open('OutOfStock.aspx?PID=' + PId, null, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=320,height=195,top=10,left=10', 'true');
    win.focus();
}

function openlifestyle(id) {
    var win = window.open('lifestyleimage.aspx?id=' + id, null, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=620,height=495,top=10,left=10', 'true');
    win.focus();
    return false
}

function ViewCart(PId, ddlval, qty, cid, strstock) {
    var count = 0;

    if (emptyField(cid)) {
        alert('Please Enter Quantity');
        cid.focus();
        return false;
    }

    if (cid.value < 1) {
        alert('Quantity Must Be Greater Then Zero.');
        cid.focus();
        return false;
    }

    if (!isInt(cid.value)) {
        alert('Please enter Integer value.');
        cid.focus();
        return false;
    }

    if (cid.value > strstock) {
        alert('Only ' + strstock + ' of this product in stock');
        return false;
    }
}

function refreshCart(id,action) {
    var height = $('#'+ id).height();
    var width = $('#' + id).width();
    leftVal = 600 + "px";
    topVal = 0 + "px";
    $('#' + id).css({ left: leftVal, top: topVal }).show().fadeOut(7500);
    if (action = 'cart') {parent.CartList.location.replace("cartcontrol.aspx?" + Math.floor(Math.random() * 200));}
}

function UpdateCart(id, action) {
    var height = $('#' + id).height();
    var width = $('#' + id).width();
    leftVal = 0 + "px";
    topVal = 0 + "px";
    $('#' + id).css({ left: leftVal, top: topVal }).show().fadeOut(7500);
    if (action = 'cart') { parent.CartList.location.replace("cartcontrol.aspx?" + Math.floor(Math.random() * 200)); }
}

function ShowCart(id, action) {
    var height = $('#' + id).height();
    var width = $('#' + id).width();
    leftVal = 560 + "px";
    topVal = 210 + "px";
    $('#' + id).css({ left: leftVal, top: topVal }).show().fadeOut(7500);
    if (action = 'cart') { parent.CartList.location.replace("cartcontrol.aspx?" + Math.floor(Math.random() * 200)); }
}

function showproductdescription(cartid, productid) {
    parent.location.href = "categoryproduct.aspx?catid=" + cartid + "&pid=" + productid;
    return false;
}

function emailtofriend(PID) {
    var win = window.open('Mailafriend.aspx?PID=' + PID, null, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=yes,width=500,height=400,top=10,left=10', 'true');
    win.focus();
    return false;
}

function showrealdedproduct(productid) {
    parent.location.href = "product.aspx?pid=" + productid;
    return false;
}


//-----for custom ur pages---------------------------------------------

function updateusercart(target, productid, parameter, mode) {
    $.ajax({
        type: "POST",
        url: "inserttocart.aspx",
        data: "PID=" + productid + "&ddlval=" + parameter + "&mode=" + mode,
        success: function(msg) {
            if (msg == 'cart') { ShowCart(target, 'cart'); }
            else if (msg == 'wishlist') { ShowCart('popuup_div1', ''); }
            else if (msg == 'wishexist') { ShowCart('popuup_div2', ''); }
            else { if (msg != "") { location.href = msg; } }
        }
    });
}

function emailtofriendcustom(PID) {
    var win = window.open('mailafriend.aspx?PID=' + PID, null, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=yes,width=500,height=400,top=10,left=10', 'true');
    win.focus();
    return false;
}

function ViewProductcustom(PId) {
    var win = window.open('productdetail.aspx?PID=' + PId, null, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=550,height=400,top=10,left=10', 'true');
    win.focus();
    return false;
}

function outof_stock_custom(PId) {
    var win = window.open('outofstock.aspx?PID=' + PId, null, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=320,height=195,top=10,left=10', 'true');
    win.focus();
}

function view_disc_custom(Subpageid) {
    var win = window.open('viewdiscription.aspx?subpageid=' + Subpageid, null, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=550,height=400,top=10,left=10', 'true');
    win.focus();
    return false;
}

function shoppingBasket(basket) {
    document.getElementById("innerHeader1_ltrshoppingbasket").innerHTML = basket;
}

function iframeshoppingBasket(basket) {
    parent.document.getElementById("innerHeader1_ltrshoppingbasket").innerHTML = basket;
}

//------------------whats New---------------------------------------
    function checkbasket(id) {
        var trigger = $('.trigger', this);
        var height = $('#' + id).height();
        var width = $('#' + id).width();
        leftVal = 890 - (width / 2) + "px";
        topVal = 230 - (height / 2) + "px";
        $('#' + id).css({ left: leftVal, top: topVal }).show().fadeOut(9500);
    }
//------------------------------------------------------------------