function popup(src,scroll) {
if (scroll)
{
  win = window.open(src,"","top=20,left=20,height=440,width=450,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
}
else
{
  win = window.open(src,"","top=20,left=20,height=440,width=450,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes");
}
}

function RecalcTotal(theForm)
{
 var totalQuan = 0;
 for ( var i = 0; i < theForm.elements.length; i++ )
 { 
  if (theForm.elements[i].type == "text" && theForm.elements[i].id.match("Quantity")) 
  {
    if (theForm.elements[i].value != "")
    {
      var qty = parseInt(theForm.elements[i].value);
      if (isNaN(qty))
      {
        alert("Please enter a number for quantity");
        theForm.elements[i].focus();
        return(false);
      }
      else
      {
        totalQuan += qty;
      }
    }
  }
 }
 if (theForm.vwquantity0 && totalQuan > 0)
 {
   theForm.vwquantity0.value = totalQuan;
 }
 else
 {
   if (theForm.vwquantity && totalQuan > 0)
   {
     theForm.vwquantity.value = totalQuan;
   }
 }

 return(true);
}

function CheckOrderForm(theForm)
{
    if (theForm['Approved'] || theForm['vwattr0_Approved'])
    {
        var isApproved;
        if (theForm['Approved'])
            isApproved = theForm['Approved'].checked;
        else
            isApproved = theForm['vwattr0_Approved'].checked;
        if (!isApproved)
        {
            alert("Please click the box at the bottom of this form indicating that you have reviewed and approve all spelling for your engraving.");
            return(false);
        }
    }

 var emptySelections = new Array("None-Selected Yet", "None Selected", "None Selected Yet", "Click on Arrow to Select");
 
 var totalQuan = 0;

 for ( var i = 0; i < theForm.elements.length; i++ )
 { 
  if (theForm.elements[i].type == "select-one")
  {
   for (var j = 0; j < emptySelections.length; j ++ )
   {
     if (theForm.elements[i].options[theForm.elements[i].selectedIndex].text == emptySelections[j])
     {
      alert('Please make a selection');
      theForm.elements[i].focus();
      return(false);
     }
   }
  }
  
  if (theForm.elements[i].type == "text" && theForm.elements[i].id.match("Quantity")) 
  {
    if (theForm.elements[i].value != "")
    {
      var qty = parseInt(theForm.elements[i].value);
      if (isNaN(qty))
      {
        alert("Please enter a number for quantity");
        theForm.elements[i].focus();
        return(false);
      }
      else
      {
        totalQuan += qty;
      }
    }
  }
 }
 if (totalQuan > 0)
 {
    if (theForm.vwquantity0)
    {
      theForm.vwquantity0.value = totalQuan;
    }
    else
    {
      if (theForm.vwquantity)
      {
        theForm.vwquantity.value = totalQuan;
      }
    }
 }
 if (theForm.vwquantity0 || theForm.vwquantity)
 {
   if (theForm.vwquantity0)
   {
     var q = parseInt(theForm.vwquantity0.value);
   }
   else
   {
     var q = parseInt(theForm.vwquantity.value);
   }

   var MinQuan;
   if (eval("typeof " + theForm.name + "_MinimumQuantity") != 'undefined')
   {
     MinQuan = eval(theForm.name + "_MinimumQuantity") - 1;
   }
   else if (typeof MinimumQuantity != 'undefined')
   {
       MinQuan = MinimumQuantity - 1;
   }
   else
   {
       MinQuan = 0;
   }
   if (!isNaN(q) && q <= MinQuan )
   {
     alert("The minimum quantity for this product is " + (MinQuan + 1) + ". Please enter a quantity of " + (MinQuan + 1) + " or more." );
     return(false);
   }
 }

  // remove hidden option blocks
  var remove = new Array();
  for (var i = 0; i < 100; i++)
  {
    var opt = document.getElementById("opt" + i);
    if (opt)
    {
      if(opt.style.display=='none')
      {
        remove[remove.length] = opt;
      }
    }
  }
  if (remove.length > 0)
  {
    for (var i = 0; i < remove.length; i++)
    {
      var opt = remove[i];
      opt.parentNode.removeChild(opt)
    }
  }

 return (true);
}

function submitToEngrave(frm)
{
   if (!CheckOrderForm(frm))
     return(false);

   frm.action = "http://photosplash.com/tc/engraving.aspx";

   frm.submit();
}

function submitToCart(frm) {
   if (!CheckOrderForm(frm))
     return(false);

    //we have some unecessary variables in the form...
    var victims = new Array("format", "lines", "pcolor", "CHAR", "Rlogo", "rlogo");
    for(var v = 0; v < victims.length; v++) {
        if (frm[victims[v]] != undefined)
        {
            frm[victims[v]].value = '';
        }
    }
    //document.forms["prdform"].submit();
    return true;
}

var currentclass;

function SwitchClass(elem,c)
{
    if (c)
    {
        currentclass = elem.className;
        elem.className = c;
    }
    else
        elem.className = currentclass;
}
function HandlePopup(url, w, h, created)
{
    var PopupCreated = getCookie('Popupcreated');
    if (PopupCreated != created)
    {
        windowPicker = window.open(url,"MyWindow","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=" + w + ",height=" + h + ",left=75,top=75");
        windowPicker.focus();
        setCookie('Popupcreated',created,365);
    }
}



