var Sears = {
	/*
	 * Obtains the page html and window information
	 */
	getWindowSize : function(){
		var xScroll, yScroll, windowWidth, windowHeight;
		if (window.innerHeight && window.scrollMaxY) {
			xScroll = document.body.scrollWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else {
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		if (self.innerHeight) {
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}
		if(xScroll < windowWidth){
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
		return {'pageWidth':pageWidth, 'pageHeight':pageHeight, 'windowWidth':windowWidth, 'windowHeight':windowHeight};
	},
	/**
	 *
	 */
	showHideRecentlyView: function(e){
		if(e)
			$("#recentlyView").fadeIn("slow");
		else
			$("#recentlyView").fadeOut("slow");

	},

	preloadImages : function(){
		if(document.images){
			document.myImages = new Array();
			for (var i = 0; i < preloadImages.arguments.length; i++){
				document.myImages[i] = new Image;
				document.myImages[i].src = preloadImages.arguments[i];
			}
		}
	}
};


$(window).resize(function(){
	var windowWidth = Sears.getWindowSize().windowWidth;
	if (!window.XMLHttpRequest){
		if(windowWidth < 1000){
			$("#content").css("width", "980px");
			$("#footer").css("width", "1000px");
			$("#header").css("width", "1000px");
		}  else {
			$("#content").css("width", "auto");
			$("#footer").css("width", "auto");
			$("#header").css("width", "auto");
		}

	}
});

function showHideContainer(element){
	if (document.all) {
		if (element.style.display == "none")
			$("#" + element.id).fadeIn("slow");
		else
			$("#" + element.id).fadeOut("slow");
	}
}
/* We are commenting this part as the below mentioned files are already included from the dyna header.
if (document.all)
{
	if (window.XMLHttpRequest) //IE7
	{
		document.write("<link href=\"css/ie7fixes.css\" rel=\"stylesheet\" type=\"text/css\" media=\"screen\">");
	}
	else //IE6
	{
		document.write("<link href=\"css/ie6fixes.css\" rel=\"stylesheet\" type=\"text/css\" media=\"screen\">");
	}
}
*/
//Ajax call
var httpRequestSupported = true;

function _liquid_ajaxCall(url,callbackFunction,returnData,linkId)
{


    var httpRequest = false;

    // Exit if this function is not supported
    if (!httpRequestSupported) {
        return;
    }

    // check if supported
    httpRequest = _liquid_isHttpRequestSupported();

    if (!httpRequest) {
        httpRequestSupported = false;
        return false;
    }

    // Map the response to the callback function
    httpRequest.onreadystatechange = function() {
        if (httpRequest.readyState == 4) {

            if (httpRequest.status == 200) {
                if (returnData) {
                    eval(callbackFunction + '(httpRequest.responseXML,linkId)');
                } else {
                    eval(callbackFunction + '(httpRequest.responseText,linkId)');
                }
            } else {
                // TODO:  Keep this line commented in production.  The user will have no idea what this means.
                //('The AJAX request was made to our backend server and the following error occurred: ' + httpRequest.status);
                eval(callbackFunction + '(httpRequest.responseText)');

            }
        }
        else{
            if(callbackFunction == 'displayTabContent'){

                htmlValue = "<img src= '"+ imagePath + "img/backgrounds/loading.gif' />";
                document.getElementById(linkId).innerHTML = htmlValue;
            }
            if(callbackFunction == 'browseSpecialOffer'){
                htmlValue = "<img src= '"+ imagePath + "img/backgrounds/loading.gif' />";
                linkId.innerHTML = htmlValue;
            }
        }
    }

    httpRequest.open('GET', url, true);
    httpRequest.send(null);
}

function _liquid_isHttpRequestSupported() {

    if (window.XMLHttpRequest) {
        // Test if the Gecko engine is running.  Gecko supports AJAX
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) {
            httpRequest.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) {
        // Test if an IE engine is running
        try {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!httpRequest) {
        httpRequestSupported = false;
    }
    return httpRequest;
}
function RecentlyViewedWide(value){

	var DivRef = document.getElementById('recentlyView');
 	DivRef.style.display = "block";
 	DivRef.innerHTML = value;
 	Sears.showHideRecentlyView(true);
}
function showHideContainer(element){
	if (document.all) {
		if (element.style.display == "none")
			$("#" + element.id).fadeIn("slow");
		else
			$("#" + element.id).fadeOut("slow");
	}
}

