﻿/*************************************************************************************************/
/*************************************************************************************************/
/***
/***  Web Services
/***
/*************************************************************************************************/
/*************************************************************************************************/

var G_Service = new Array();

/**************
/* Method used to add item to wishlist
/***/
function AddItemToWishlist(obj)
{
    if (obj.id)
    {
        var arIds = obj.id.split('_');
        G_Service[arIds[0]] = new Commerce().AddItemToWishlist(arIds[0],arIds[1], _AddItemToWishlist_OnComplete, _MSAjax_OnError, _MSAjax_OnTimeOut);   
    }
}

function _AddItemToWishlist_OnComplete(arg)
{
	var ReturnObj = eval('('+arg+')');

	if (!ReturnObj.Error)
	{
        var Plant = ReturnObj.Item.Plant;
        var imagePath = WG.BasePath + '/images/layout/noimageavailable.gif';
        for (i = 0; i < Plant.MediaFiles.length; i++)
        {
            if (Plant.MediaFiles[i].MediaType.match(/thum/gi))
                imagePath = WG.BasePath + '/images/lib/plants/' + Plant.MediaFiles[i].FileName;
        }
        
        var str = '<div><h1 style="font-size:10pt">' + Plant.Name.AsHtml + ' was added to your wishlist</h1>';        
        str += '<img src="' + imagePath + '" alt="' + Plant.Name.AsText + '" Title="' + Plant.Name.AsText + '"';
        str += ' class="plant" style="width:75px;height:75px;float:left;margin-right:15px;" />';
        
        str += '<div style="float:left; width: 375px;font-size:11px">';
        
        str += '<strong>Common Name: </strong>' + Plant.Common + '<br />';
		if (typeof(PR) == "undefined")
		{
			str += '<strong>Sizes Offered:<br /></strong>';
			for (i = 0; i < Plant.SizesOffered.length; i++)
				str += '&nbsp; ' + Plant.SizesOffered[i].Name + '<br />';
        }
        
        str += '<strong>Hardiness Zone:</strong> ' + Plant.HardinessZone + '<br />';
        str += '<strong>Height:</strong> ' + Plant.Height + '<br />';
        str += '<strong>Spread:</strong> ' + Plant.Spread + '<br />';
        str += '<strong>Exposure:</strong> ' + Plant.Exposure + '<br />';
        str += '<strong>Bloom Time:</strong> ' + Plant.BloomTime + '<br />';
 
        str += '</div></div>';
        
        str += '<div style="clear:both">';
        str += '<br /><br/ ><div style="padding: 8px 5px 0 0; text-align:right; background: #d7bb98">';
        str += ' <img src="' + WG.BasePath + '/images/buttons/close.gif" onclick="PR.Dialog.Close();" style="cursor:pointer;border:0px none" />'; 
        str += ' &nbsp; <a href="' + PR.BasePath + '/wishlist"><img src="' + WG.BasePath + '/images/buttons/proceedtowishlist.gif"';
        str += ' border="0" /></a></div>';
        
	    PR.Dialog.Create(str);
	    PR.Dialog.ToggleOverlay(true);
	}
}

/*************************************************************************************************/
/*************************************************************************************************/
/***
/***  Common Services
/***
/*************************************************************************************************/
/*************************************************************************************************/

var G_HasAborted = false;
function _MSAjax_Abort(i)
{
    if (G_Service[i] && G_Service[i].get_executor().get_started())
    {
        G_HasAborted = true;
        G_Service[i].get_executor().abort();
        G_Service[i] = false;
    }
}

function _MSAjax_OnComplete(arg)
{
    //alert(arg);
    return true;
}
function _MSAjax_OnError(arg)
{
    if (! G_HasAborted)
    {
        alert("error has occured: " + arg.get_message());//_message);
        G_HasAborted = false;
    }
}
function _MSAjax_OnTimeOut(arg)
{
   alert("timeout has occured");
}
