/*
   Two functions which changes the background color of an object
*/
function highlight_table_field(oObject, sStyle) {
	oObject.className = sStyle;
	}

function highlight_table_field_off(oObject, sStyle) {
	oObject.className = sStyle;
	}


 function chkMinQuantity(id)
  {
    if (document.getElementById('min_quantity'+id).value > document.getElementById('item_'+id).value)
    {
        alert('Du kan ikke bestille mindre end '+document.getElementById('min_quantity'+id).value+' stk af denne vare.');
        document.getElementById('item_'+id).value = document.getElementById('min_quantity'+id).value;
        document.getElementById('item_'+id).focus();
        return false;
    }
return true;
  }

function isArray(obj)
{
	return(typeof(obj.length)=="undefined") ? false : true;
}

function submitbasketform()
{
	var form = document.forms[0].elements['quantity[]'];
	if (!isArray(form))
	{
		if (parseInt(document.getElementById('minquantity0').value) > parseInt(document.getElementById('quantity0').value))
		{
		    alert('Du kan ikke bestille mindre end '+document.getElementById('minquantity0').value+' stk af dette produkt.');
		    document.getElementById('quantity0').value = document.getElementById('minquantity0').value;
		    document.getElementById('quantity0').focus();
		    return false;
		}
		return true;
	}
	else
	{
		for (var i = 0;i < form.length;i++)
		{
		    if (parseInt(document.getElementById('minquantity'+i).value) > parseInt(document.getElementById('quantity'+i).value))
		    {
			alert('Du kan ikke bestille mindre end '+document.getElementById('minquantity'+i).value+' stk af dette produkt.');
			document.getElementById('quantity'+i).value = document.getElementById('minquantity'+i).value;
			document.getElementById('quantity'+i).focus();
			return false;
		    }
		}
	return true;
	}
	return true;
}


/*
   Three functions which are used to control an infobox which follows the mouse
*/
var iHoverY = 10;
var iHoverX = 30;
var outInfobox;

function infobox_init(oEvent, sElementName, sMessage) {
	clearTimeout(outInfobox);
	var oElement = document.getElementById(sElementName);
	oElement.innerHTML = '<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="200"><TBODY><TR><TD>' + sMessage + '</TD></TR></TBODY></TABLE>';
	oElement.style.visibility = "visible";
	return infobox_move(oEvent, sElementName);
	}

function infobox_shutdown(sElementName) {
	var oElement = document.getElementById(sElementName);
	outInfobox = setTimeout('var oElement = document.getElementById("' + sElementName + '"); oElement.style.visibility = "hidden";', 50);
	return true;
	}

function infobox_move(oEvent, sElementName) {
	clearTimeout(outInfobox);
	var oElement = document.getElementById(sElementName);
	if (oEvent.pageY != undefined && oEvent.pageX != undefined) {
		oElement.style.top = oEvent.pageY + iHoverY + 'px';
		oElement.style.left = oEvent.pageX + iHoverX + 'px';
		} else {
		oElement.style.top = oEvent.clientY + iHoverY + oElement.offsetParent.scrollTop + 'px';
		oElement.style.left = oEvent.clientX + iHoverX + oElement.offsetParent.scrollLeft + 'px';
		}
	return true;
	}





/*
   Function which opens a new browser window
*/
function window_popup(sUrl, sTitle, iWidth, iHeight) {
	if (iWidth < 100) {iWidth = 300;}
	if (iHeight < 100) {iHeight = 100;}
	if (iWidth > 800) {iWidth = 800;}
	if (iHeight > 600) {iHeight = 600;}
	sWindowFeatures = "width=" + iWidth + ", height=" + iHeight + ", menubar=yes, personalbar=no, resizable=yes, scrollbars=yes, status=no, titlebar=yes, toolbar=no";
	window.open(sUrl, sTitle, sWindowFeatures);
	}

	
function updateValue(objCheck, objInput) {
	if(objCheck.checked == true) {
		objInput.value = 1;
	} else {
		objInput.value = 0;
	}
	objInput.form.submit();
}

