﻿//JavaScript Document

var arrayCookieItems = new Array();

function callAllFavoriteItemsStatic() {
  //  alert(navigator.appName);
    if (navigator.appName == "Microsoft Internet Explorer") {
        document.getElementById("spanOnlyForIE").style.visibility = "visible"
        document.getElementById("spanOnlyForIE").style.color = "#333333"
	    service.useService("http://www.scsplashbacks.com/Authentication/AddToFavorite.asmx?WSDL","MyMath");
	    iCallID = service.MyMath.callService("AllFavoriteItems");
    }
    else {
        document.getElementById("spanOnlyForIE").style.visibility = "hidden"
    }
   
} //end callAllFavoriteItemsStatic

        
function OnAllItemCompleteStatic() {
   // alert(args.split("/"));
   if((event.result.error)&&(iCallID==event.result.id))  
	{    
		var xfaultcode = event.result.errorDetail.code;
		var xfaultstring = event.result.errorDetail.string;    
		var xfaultsoap = event.result.errorDetail.raw;
        // alert(xfaultstring);
	}
	else
	{
		//alert("The method returned the result : " + event.result.value);
		document.getElementById("hdfCookieValues").innerText = ""
        document.getElementById("hdfCookieValues").textContent = ""
        
        var args = event.result.value;
        
        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("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 OnAlltemTimeOutStatic(args) {
    alert("UNEXPECTED ERROR: Service call timed out.\nThe item was not added to your favorite.\nPlease try again.");
}
        
function OnAllItemErrorStatic(args) {
    alert("UNEXPECTED ERROR: Error calling service method.\nThe item was not added to your favorite.\nPlease try again");
} 
