﻿// JScript File

//the functions provided in this file are mainly for the pages displaying product information(products.aspx, product_sub.aspx and product_details.aspx). 

    //emails a product specified by a product id 
	function mailToWithPID(pid)
	{
        openNewWindow('EmailFriend.aspx?pid=' + pid ,'Email_to_friend','width=500,height=450,status=no,scrollbars=no,resizable=no,toolbar=no');	    
	}
	
	//emails a product specified by a product size id 
	function mailToWithPSID(psid)
	{
        openNewWindow('EmailFriend.aspx?psid=' + psid ,'Email_to_friend','width=500,height=450,status=no,scrollbars=no,resizable=no,toolbar=no');	    
	}
	
	//adds a product specified by a product id to favourites. the pid added will be converted into a product size id on the server
	function addPidToFavourite(pid)
    {
	    Holdfast3.Service.AddPIDToFavourite(pid, showAddingResult);
    }
    
    //adds a product specified by a product size id to favourites 
	function addPsidToFavourite(psid)
    {
	    Holdfast3.Service.AddToFavourite(psid, showAddingResult);
    }
    
    //displays the container where customers can enter the quantity of a product they want to order
    function showCart(evnt, pId)
    {
        _showCartContainer(evnt, pId);
    }

    //displays feedback to users for adding a product 
    function showAddingResult(result)
    {
        var msg = "";
        switch (result)
        {
        case 1:
            msg = "Item has been added to your favourites";
            break;
        
        case 0:
            msg = "The item is already in your favourites";
            break;
        
        case -1:
            msg = "Failed to added the item to your favourites. Invalid parameters passed";
            break;
        
        case -2:
            msg = "Failed to add the item to your favourites. \r\nThis may happend when your sesssion has been timeout or you haven't logged in";
            break;
        
        default :
            msg = "Failed to add the item to your favourite. Please try again later";
        
        }
        
        alert(msg);
    }
    
	function iniPage()
	{
	    var tags = document.getElementsByTagName("div");
	    var display = "";
	    var count = 0;

        //checks if users have logged in. If they do, displays the sticky tags providing functions for logged in users
	    if (_hasLoggedIn())
	    {
	        display ="inline";
	    }
	    else
	    {
	        display="none";
	    }
	    
	    for (var i = 0; i < tags.length; i++)
	    {
	        if (tags[i].className == "restrictedArea") 
	        {
	            tags[i].style.display=display;
	        }
	    }
	    
	}

