/**
* Form validation for adding cart items.
* @param string url
**/
function rd_addCartItem(form)
{
	check(form, form.elements.length);
}

/**
* Form validation for adding cart items.
* @param string url
**/
function rd_removeCartItem(url)
{
	rd_setURL(url);
}

/**
* @param string url
**/
function rd_checkOutConfirm(url, form)
{
	if(form != null && typeof(form) == 'object')
	{
		form.action = url;
		form.submit();
	}
	else
	{
		rd_setURL(url);
	}
}

/**
* @param string url
**/
function rd_checkOut(url)
{
	rd_setURL(url);
}

/**
* @param string url
**/
function rd_setURL(url)
{
	window.location.href = url;
}

/**
* Utility Classes
*
**/
/**
* Set any attibute on any element
* @return void
**/
var __debug__ = false;

function setElementAttribute(element, attribute_name, attribute_value, create_new_attribute)
{
	if(element != null)
	{
		if(element[attribute_name] != null || create_new_attribute == true)
		{
			if(typeof(element[attribute_name]) == 'object' && element[attribute_name].value != null)
			{
			 element[attribute_name].value = attribute_value;
			}
			else
			{
			 element[attribute_name] = attribute_value;
			}
		}
		else if(__debug__ == true)
		{
			 alert('Element Attribute '+attribute_name+' does not exist');
		}
	}
	else if(__debug__ == true)
	{
		 alert('Element does not exist');
	}
}

/**
* Return element by element name
* @return object return null if element was not found
**/
function rd_getElement(element_name)
{
	var element = null;
	element = document.getElementById(element_name);
	return element;
}

/**
* Sets/Adds a element attribute "initial_value" to the current value
* Use onFocus attribute
**/
function rd_setInitialValue(element)
{
	setElementAttribute(element, 'initial_value', element.value, true);
}

/**
* Function resticts an input to a specific range
* Use onBlur attribute of inputs
* @param object tag/element
* @param number number cannot be smaller to this
* @return number number cannot be larger to this
**/
function rd_restrictElementNumberValue(element, restrict_min, restrict_max)
{
	if(element != null)
	{
		var element_value = element.value;
		var set_initial_value = false;
		var element_initial_value = '';
		if(element_value < restrict_min)
		{
			element_initial_value = restrict_min;
			set_initial_value = true;
		}
		else if(restrict_min > restrict_max)
		{
			element_initial_value = restrict_max;
			set_initial_value = true;
		}
		if(set_initial_value == true)
		{
			if(element.initial_value != null)
			{
				element.value = element.initial_value;
			}
			else		
			{
				element.value = element_initial_value;
			}	
		}
	}
}