function checkOptions(myForm)
{
  if (myForm.idOption1)
	{
	if (myForm.idOption1.value == "")
		{
		myForm.idOption1.focus();
		return false;
		}
	if (myForm.idOption2)
		{
		if (myForm.idOption2.value == "")
			{
			myForm.idOption2.focus();
			return false;
			}
		if (myForm.idOption3)
			{
			if (myForm.idOption3.value == "")
				{
				myForm.idOption3.focus();
				return false;
				}
			}
		}
	}
	return true;
}

function validateCartNumber(thisButton, fromForm)
{
  thisForm = thisButton.form;
  vn_pcount = 0;
  antalForm = "";
  antalForm = antalForm.concat("quantity", thisButton.name.substring(3));
  thisForm.elements['idProduct'].value = thisButton.name.substring(3);
  vn_pcount = parseInt(thisForm.elements[antalForm].value);
  thisForm.elements["quantity"].value = vn_pcount;

  if (!fromForm)
	{
	if (!checkOptions(thisForm))
		{
		alert("Du skal vælge variant før du kan tilføje varen til indkøbskurven. Vælg variant fra drop-down boksen.");
		return false;
		}
	}
	
  if (isNaN(vn_pcount))
    {
    vn_pcount = 0;
    }

  if (vn_pcount < parseInt(1))
    {
    thisForm.elements[antalForm].value = 1;
    alert("Du skal angive et antal som er større end nul.");
    }
  else
    {
    thisForm.action="comersus_additem.asp";
    thisForm.target="";
	if (fromForm)
		{
		thisForm.submit();
		}
	else
		{
		return true;
		}
    }
	if (!fromForm)
		{
		return false;
		}
}

function validateCompare(thisButton)
{
thisForm = thisButton.form;

elementsChecked = 0;
elementsOnForm = thisForm.elements.length;

for (i=0; i<elementsOnForm; i=i+1)
  {
  if (thisForm.elements[i].type == "checkbox")
    {
    checkboxName=thisForm.elements[i].name;
    if ( (checkboxName.substring(0,7) == "compare") && thisForm.elements[i].checked )
      {
      elementsChecked = elementsChecked + 1;
      }
    }
  }
  
if (elementsChecked < 2) 
  {
  alert("Du skal vælge minimum 2 produkter for at lave sammenligning");
  }
else
  {
  thisForm.action="productCompare.asp"
  thisForm.target="keasProdComp";
  window.open("","keasProdComp","width=800,height=600,scrollbars=Yes,resizable=Yes,menubar=No");
  thisForm.submit();
  }
}
