﻿/*'----------------------------------------------------
'Copyright © 2010, Southern Cross Ceramics
'All rights reserved.
'http://www.scceramics.com

'Redistribution and use in source and binary forms, 
'with or without modification, are not permitted
'----------------------------------------------------*/

//JavaScript Document

var arrayCookieItems = new Array();

function callAllFavoriteItems() {
       
    //call web service to add favorite item
    var ret = Authentication.AddToFavorite.AllFavoriteItems(OnAllItemComplete, OnAlltemTimeOut, OnAllItemError);
    
} //end callAllFavoriteItems Authentication

        
function OnAllItemComplete(args) {
   // alert(args.split("/"));
    document.getElementById("ctl00_ContentPlaceHolder1_hdfCookieValues").innerText = ""
    document.getElementById("ctl00_ContentPlaceHolder1_hdfCookieValues").textContent = ""
                
    var count = 0;
    arrayCookieItems = args.split("/");
    
    for (k = 0; k < arrayCookieItems.length; k++) {
        if ( arrayCookieItems[k].length < 5 ) {
            arrayCookieItems.splice(k, 1);
        }         
    }
    
    if (arrayCookieItems[0] == "") {
        count = 0;
    }
    else {
        count = arrayCookieItems.length;
        //copy all favorite item values to hidden text
        if (document.getElementById("ctl00_ContentPlaceHolder1_hdfCookieValues") != null ) {  //from Step4
            for (k = 0; k < count; k++) {
                document.getElementById("ctl00_ContentPlaceHolder1_hdfCookieValues").innerHTML +=  arrayCookieItems[k] + " ";          
            } 
        }
        
    }
    
//    if ( count == 0 ) {
//        document.getElementById("ctl00_lnkMyFavorite").disabled = true; 
//    }
//    else {
//        document.getElementById("ctl00_lnkMyFavorite").disabled = false;
//    }
    
    if ( count == 0 ) {
        document.getElementById("spanLnkMyFavourite").onclick = function (evt) { }
    }
    else {
        document.getElementById("spanLnkMyFavourite").onclick = function (evt) {
            window.location = "MyFavourites.aspx";
        }
        document.getElementById("spanLnkMyFavourite").onmouseover = function (evt) {
            this.style.cursor='pointer';
            this.style.color = "#666666";
        }
        document.getElementById("spanLnkMyFavourite").onmouseout = function (evt) {
            this.style.cursor='default';
            this.style.color = "#333333";
        }
    }        
        
    document.getElementById("itemcount").innerText = count;
    document.getElementById("itemcount").textContent = count;
    return arrayCookieItems
}

function OnAlltemTimeOut(args) {
    alert("UNEXPECTED ERROR: Service call timed out.\nPlease wait for a while or clear the cookies \non your browser and try again.");
}
        
function OnAllItemError(args) {
    alert("UNEXPECTED ERROR: Error calling service method.\nPlease wait for a while or clear the cookies \non your browser and try again.");
} 
