/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function wishList(event,prodId,userId)
{
    var classname = jQuery( "#"+prodId+"_"+userId ).attr('class');

    if(userId == 0)
    {
        alert("You need to perform login to use this feature");

        return false;
    }
    
    //ajax function
    /*if(classname == "AddToWishList")
        addToWishList(event,prodId,userId);
    else
        removeFromWishList(event,prodId,userId)*/
        
        addToWishList(event,prodId,userId);
        return true;
}

function addToWishList(event,prodId,userId)
{
    url = "addToWishList.php";
    data = "product_id="+prodId+"&user_id="+userId+"&type=add";

        var result = jQuery.ajax({
            type: "POST",
            url: url,
            dataType: "text",
            data: data,
            async:false
        }).responseText;

        //alert(result);

        var obj = eval("( "+result+" );");

        if(obj.success == "true")
        { 
            jQuery( "#"+prodId+"_"+userId ).attr('class', "RemoveFromWishList");
            jQuery( "#"+prodId+"_"+userId ).attr("src" , "images/wishlist_in.gif");
        }

}

function removeFromWishList(event,prodId,userId)
{
     url = "addToWishList.php";
    data = "product_id="+prodId+"&user_id="+userId+"&type=remove";

        var result = jQuery.ajax({
            type: "POST",
            url: url,
            dataType: "text",
            data: data,
            async:false
        }).responseText;

        var obj = eval("( "+result+" );");

        if(obj.success == "true")
        {

            jQuery( "#"+prodId+"_"+userId ).attr('class',"AddToWishList");
            jQuery( "#"+prodId+"_"+userId ).attr("src" , "images/wishlist_add.gif");

        }
}
