﻿/* Namespace setting */
if (typeof expediaNS === "undefined"){
	var expediaNS = {};
}
if (typeof expediaNS.namespace === "undefined"){
	expediaNS.namespace = function() {
		var a=arguments, o=null, i, j, d;
		for (var i=0; i<a.length; i=i+1) {
			d=a[i].split(".");
			o=expediaNS;
			for (var j=(d[0] == "expediaNS") ? 1 : 0; j<d.length; j=j+1) {
				o[d[j]]=o[d[j]] || {};
				o=o[d[j]];
			}
		}
		return o;
	};
}
expediaNS.namespace("expediaNS.header");
/* End of Namespace setting */

expediaNS.header.Actions = function() {
    var obj = {};

    var _getElementValue = function(attributeName, id) {
        try {
            var attrValue = document.getElementById(id).getAttribute(attributeName);
            if(attrValue) {
                return attrValue;
            }
            else {
                return "";
            }
        }
        catch(ex){ return ""; }
    }
    
    var _getHrefFromId = function(id) {
        return _getElementValue("href", id);
    };
    
    var _getRUrlFromId = function(id) {
        return _getElementValue("returnurl", id);
    };
    
    var _getRfrrFromId = function(id) {
        return _getElementValue("rfrr", id);
    };
    
    /**
    Gets the full href value the element specified with the id passed
    */
    var _formatFinalHrefFromId = function(id) {
        var href = _getHrefFromId(id);
        var Rfrr = _getRfrrFromId(id);
        var RUrl = _getRUrlFromId(id);
        var finalHref = "";
        if (typeof(href) !== "undefined"){
            finalHref = href + ((href.indexOf('?')>-1) ? '&' : '?') + 'rfrr=' + Rfrr + RUrl;
            return finalHref ;
        }
        else {
            return "";
        }
    };
    
    /**
    Naviguates page to the specific url for the element passed.
    */
    obj.LinkToLocationFromElt = function(elt) {
        if (elt) {
            var finalHref = _formatFinalHrefFromId(elt.id);
            if (finalHref != "") {
                window.parent.location.href = finalHref;
            }
        }
        return false;
    };
    
    /**
    Opens a popup window to the specific url for the passed element
    */
    obj.PopUpToLocationFromElt = function(elt) {
        if (elt) {
            var finalHref = _formatFinalHrefFromId(elt.id);
            if (finalHref != "") {
                window.open(finalHref ,'popup','height=650,width=630,scrollbars=yes,menubar=no,resizable=no,status=no,toolbar=no,top=223,left=160');            
            }
        }
        return false;
    };
    
    return obj;
}();