﻿function fixIE(e) {
    if (typeof e == 'undefined') e = window.event;
    if (typeof e.target == 'undefined') e.target = e.srcElement;
    if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
    if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
    if ((typeof e.which == 'undefined') && e.keyCode) e.which = e.keyCode;

    if (!e.preventDefault) e.preventDefault = function() {
	    e.returnValue = false;
    }
    if (!e.stopPropagation) e.stopPropagation = function() {
	    window.event.cancelBubble = true;				
	    window.event.returnValue = false;	
    }

    return e;
}

function favorite(obj, e, idItem){
    var parentDiv = obj.parentNode;
    //$('historyIframe').src="Thumb.ashx/full/" + idItem;
    
    if (Element.hasClassName(parentDiv,"favorite")){
        Element.removeClassName(parentDiv,"favorite");
        $('NoOfFavorites').innerHTML --;
        if ($('favoritesView')!= null) new Effect.DropOut(parentDiv);       
        }
    else{            
        Element.addClassName(parentDiv,"favorite");            
        $('NoOfFavorites').innerHTML ++;            
    }
    
    //var i = obj.children[0];
    var i = obj.firstChild;
    if (i.src.indexOf("on=") == -1 && i.src.indexOf("add=") == -1) 
        i.src = "favorites.ashx?add=" + idItem; //obj.href;
    else
        i.src = "favorites.ashx?remove=" + idItem; //obj.href;
    
    e = fixIE(e);
    e.stopPropagation();
    e.preventDefault();
}
