﻿function IsProductQty() {
    var otxtQty = document.getElementById('txtQty');

    if (Trim(otxtQty.value).length == 0) {
        alert("Please enter a valid quantity.");
        otxtQty.focus();
        otxtQty.select();
        return false;
    }

    if (!IsInteger(otxtQty)) {
        alert("Please enter a valid quantity.");
        otxtQty.focus();
        otxtQty.select();
        return false;
    }

    //  myLightWindow  is current request page 
    //  it define in the lightWindow.js 
    var Request = new QueryString(myLightWindow.contentToFetch);
    var productID = Request["id"];
    var qty = otxtQty.value;

    AjaxData.AjaxAddCartItem(productID, qty, fnAddCartItem_CallBack);
}
//call back handle after excute AjaxData.AjaxAddCartItem
function fnAddCartItem_CallBack(response) 
{
    if (response.error != null) 
    {
        alert(response.error);
        return;
    }
    // if add success, return > 0 
    // else  return  -1 
    var reVal = response.value;
    if (parseInt(reVal) > 0) 
    {
        SetOrderItemAndValue();
        //ShowItAd(1);
    }
    if (document.all) 
    {
        $('lightwindow_title_bar_close_link').click();
    }
    else 
    {
        var evt = document.createEvent("MouseEvents");
        evt.initEvent("click", true, true);
        $('lightwindow_title_bar_close_link').dispatchEvent(evt);
    }
}
function SetOrderItemAndValue() 
{
    AjaxData.AjaxGetItemCount(fnItemCount_CallBack);
}

 //Reload orderItem and OrderCount
function fnItemCount_CallBack(response) 
{

     if (response.error != null)
     {
        alert(response.error); 
        return;
     }  
     var ds = response.value;  
     if (ds == null || typeof(ds) != "object") return;

     var objItemCount ,objItemValueCount ;
     objItemCount =  document.getElementById("lblItemCount");
     objItemValueCount =  document.getElementById("lblItemValueCount");
   
    if(objItemCount!= null)
    {
        objItemCount.innerHTML = ds.Tables[0].Rows[0].itemCount;
        objItemValueCount.innerHTML = ds.Tables[0].Rows[0].itemValueCount;
    }
}


//2010-12-28
function f_Login() {
    window.location.href = "Login.aspx";
}

function IsProductQty() {
    var otxtQty = document.getElementById('txtQty');

    if (trim(otxtQty.value).length == 0) {
        alert("Please enter a valid quantity.");
        otxtQty.focus();
        otxtQty.select();
        return false;
    }

    if (!isInteger(otxtQty.value)) {
        alert("Please enter a valid quantity.");
        otxtQty.focus();
        otxtQty.select();
        return false;
    }

    //  myLightWindow  is current request page 
    //  it define in the lightWindow.js 
    var Request = new queryString(myLightWindow.contentToFetch);
    var productID = Request["id"];
    var qty = otxtQty.value;

    AjaxData.AjaxAddCartItem(productID, qty, fnAddCartItem_CallBack);
}

function fnAddCartItem_CallBack(response) {
    if (response.error != null) {
        alert(response.error);
        return;
    }
    // if add success, return > 0 
    // else  return  -1 
    var reVal = response.value;
    if (parseInt(reVal) > 0) {
        //AjaxData.AjaxGetItemCount(fnItemCount_CallBack);
        SetOrderItemAndValue();

        if (document.all) {
            $('lightwindow_title_bar_close_link').click();
        }
        else {
            var evt = document.createEvent("MouseEvents");
            evt.initEvent("click", true, true);
            $('lightwindow_title_bar_close_link').dispatchEvent(evt);
        }

        $("MainNav").focus();
    }
}
