
location.querystring = (function() {

		// The return is a collection of key/value pairs
		var queryStringDictionary = {};
	
		// Gets the query string, starts with '?'
		var querystring = decodeURI(location.search);
	
		// document.location.search is empty if no query string
		if (!querystring) {
			return {};
		}
	
		// Remove the '?' via substring(1)
		querystring = querystring.substring(1);
	
		// '&' seperates key/value pairs
		var pairs = querystring.split("&");
	
		// Load the key/values of the return collection
		for (var i = 0; i < pairs.length; i++) {
			var keyValuePair = pairs[i].split("=");
			queryStringDictionary[keyValuePair[0]]
					= keyValuePair[1];
		}
	
		// toString() returns the key/value pairs concatenated
		queryStringDictionary.toString = function() {
	
			if (queryStringDictionary.length == 0) {
				return "";
			}
	
			var toString = "?";
	
			for (var key in queryStringDictionary) {
				toString += key + "=" +
					queryStringDictionary[key];
			}
	
			return toString;
		};
	
		// Return the key/value dictionary
		return queryStringDictionary;
	})();
	
	var cpok = location.querystring["cpok"];
	if (cpok != "" && cpok != null){
		filterByCategory(cpok);
	}
function redirectHttpToHttps()
{

	if (window.location.protocol!='https:')
	{
    var httpURL= window.location.hostname + window.location.pathname + window.location.search;
    var httpsURL= "https://" + httpURL;
    window.location = httpsURL;
	}
}
redirectHttpToHttps();

function filterByCategory(category_pok) {
	var pathname = window.location.pathname;
	if (pathname.indexOf("products.html") != -1){
		var plugin = document.getElementById("silverlightControl_Products");
		if (plugin != null)
			plugin.content.productsBridge.FilterByCategory(category_pok);
	}
	else {
		var _updated_location = 'http://'+window.location.host + '/products.html'+'?cpok='+category_pok;
		window.location  = _updated_location;
	}
}


function updateCategoryRegion(zip,stateProvince){
	var plugin = document.getElementById("silverlightControl_Categories");
    if (plugin != null)
        plugin.content.categoriesBridge.UpdateRegion(zip,stateProvince);
}

function updateShoppingCart_Main() {
    var plugin = document.getElementById("silverlightControl_ShoppingCart");
    if (plugin != null)
        plugin.content.shoppingCartBridge.UpdateShoppingCart();
}

function transition_ShoppingCart() {
	var _updated_location = 'http://'+window.location.host + '/cart.html';
	window.location  = _updated_location;
}

function updateShoppingCart_Products(category_pok) {
    var plugin = document.getElementById("silverlightControl_Products");
    if (plugin!=null)
        plugin.content.productsBridge.UpdateShoppingCart();
}
function refreshPage()
{
	window.location.pathname='/products.html';
}
function transition_Checkout() {
	window.location.pathname='/checkout.html';
    //remove products
    /*var plugin = document.getElementById("silverlightControl_Products");
    var pluginContainer = document.getElementById("silverlightControlHost_Products");
    if (pluginContainer != null || plugin != null) {
        pluginContainer.removeChild(plugin);
    }
    //remove the cart
    plugin = document.getElementById("silverlightControl_ShoppingCart");
    pluginContainer = document.getElementById("silverlightControlHost_Display");
    if (pluginContainer != null || plugin != null) {
        pluginContainer.removeChild(plugin);
        pluginContainer.style.height = "auto";
        pluginContainer.style.width = "auto";
    
		var host = document.getElementById("silverlightControlHost_Display");
		Silverlight.createObjectEx({
			source: "ClientBin/ProjectATLAS_Checkout.xap",
			parentElement: host,
			id: "ProjectATLAS_Checkout",
			properties: {
				height: "100%",
				width: "100%"
			},
			events: {}
		}
				);
	}*/
}
function ResizeObject(object_name, height, width) {
    var objDest = document.getElementById(object_name);
    //if there is an increase in size
    //or the decrease in size is greater than 50
	if (objDest == null)
		return;
    var current_height="";	
	var current_width = "";
	try
	
	{
		//ensure height is a string
		current_height += objDest.style.height.replace("px","");
		current_width += objDest.style.width.replace("px","");
		if (objDest != null && (current_height = "auto" || (Math.abs(current_height-height)>50 )) &&
				(current_width = "auto" || (Math.abs(current_width-width)>50))) {
			objDest.style.height = height+"px";
			objDest.style.width = width+"px";
			//update child if applicable
			/*if (objDest.children.length==1)
			{
				objDest.children[0].height = height;
				objDest.children[0].width = width;
			}*/
		}
	}
	catch(ex)
	{
	}
}
