var RA = new Array();

function loaded()
{
	totalProductQuantity();
	checkWrongAccount();
}

function checkWrongAccount()
{
	if ($("#loginError")[0] != null && $("#loginError")[0].value == "True")
	
/*	$("span[errorlabel='ok']").css("display", "");*/
        $.modaldialog.warning('Forkert brugernavn eller adgangskode!');
	return;		
}

function ClearStorage()
{
	RA = new Array();
}

function getParent(element, parent)
{
	if (typeof(element) == "string")
	{
		element = document.getElementById(element);
	};
	if (!element)
	{
		return null;
	};
	
	var elements = [];
	
	if (typeof(parent) != "string")
	{
		/*no parent: gets all parents till #document*/
		while (element.parentNode)
		{
			element=element.parentNode;
			elements.unshift(element);
			if	(element == parent)
			{
				return elements;
			};
		}
	}
	else
	{
		/*string, presumes you want to locate the first parent node that is such TAG*/
		parent=parent.toUpperCase();
		
		while (element.parentNode)
		{
			element = element.parentNode;
			elements.unshift(element);
			if (element.nodeName && element.nodeName.toUpperCase() == parent)
			{
				return elements;
			};
		}
	};
	return elements;
}

//
// Redirects ti search page
//
function redirect(searchButton)
{
	var location = searchButton.form.redirectValue.value;
	var txtFunctionLine = "", txtProductLine = "", txtDesigner = "";
	
	// Function Line
	if (searchButton.form.selectFunctionLine.selectedIndex != 0)
	{
	    txtFunctionLine = searchButton.form.selectFunctionLine.options[searchButton.form.selectFunctionLine.selectedIndex].value;
	}
	
	// Product Line
	if (searchButton.form.selectProductLine.selectedIndex != 0)
	{
	    txtProductLine = searchButton.form.selectProductLine.options[searchButton.form.selectProductLine.selectedIndex].value;
	}
	
	// Designer
	if (searchButton.form.selectDesigner.selectedIndex != 0)
	{
	    txtDesigner = searchButton.form.selectDesigner.options[searchButton.form.selectDesigner.selectedIndex].value;
	}
	
	var priceRange = searchButton.form.priceRange;
	
	if (txtFunctionLine != "")
		location = location + "&Function=" + escape(txtFunctionLine);
	if (txtProductLine != "")
		location = location + "&ProductLine=" + escape(txtProductLine);
	if (txtDesigner != "")
		location = location + "&Designer=" + escape(txtDesigner);
		
	location = location + "&PriceRange=" + priceRange.options[priceRange.selectedIndex].id;
	window.location = location;
}

function checkEMail(email)
{
    //var exp = "([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})";
    var reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
    return email.match(reg);
}

function escapeHTML(str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
};

function unescapeHTML(str)
{
   return str.replace(/&lt;/g, '<').replace(/&gt;/g, '>');
};

/* Trim functions */

function trim(str, chars)
{
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars)
{
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars)
{
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}



