
/**
 * This method is just used to verify that the
 * JavaScript is properly included on pages that
 * that it needs to be.  It can be deleted if need be.
 */
function testJS ()
{
	alert("index.js Included");
}

//---------------------------------------------------------------------//


/**
 * This method is just used to verify that the product 
 * option and quantity were selected
 */
function  pullTrigger ()
{
	var objOption = document.getElementById('option_code').value;
	var objQuantity = document.getElementById('quantity');
/*
	var intCurrentLimit = document.getElementById('current_quantity');
	var intPurchaseLimit = document.getElementById('purchase_limit');
	intCurrentLimit = parseInt(intCurrentLimit.value);
	intPurchaseLimit = parseInt(intPurchaseLimit.value);
  var totalItemQuantity = (intCurrentLimit + parseInt(objQuantity.value));
  var totalLimit = (intPurchaseLimit - intCurrentLimit);
*/  
  var objOptionCurrentOption = objOption.split("-");
  objOption = objOptionCurrentOption[0];
	
	//Check to make sure the totalItemQuantity does not exceed the Purchase limit
/*
  if(parseInt(totalItemQuantity) > intPurchaseLimit)
  {
    alert('You cannot purchase more than the allowed limit.\n Currently in your cart you have ' + intCurrentLimit + ' you can only choose ' + totalLimit + ' more.' );
    return false;
  }
*/
  if ((objOption).length <= 0 || (objQuantity.value).length <= 0)
	{
		alert("You must select an option and a quantity to order this item!");
	}
	else
	{
		if (isNaN(objOption) || isNaN(objQuantity.value))
		{
			alert("You must select an option and a quantity to order this item!");
		}
		else
		{
			document.getElementById('addToCart').submit();
		}
	}
}

//---------------------------------------------------------------------//

function changeImage(largeImage)
{
  if(largeImage == '')
  {
    return;
  }
  else
  {
      document.getElementById('mainProduct').innerHTML = '<img src="/Uploads' + largeImage + '" />';
  }
}


function checkUpdateQuantity()
{
    
    var objOption = document.getElementById('option_code').value;
    var objPurchaseLimit = document.getElementById('purchase_limit').value;
    var quantityOptions = document.getElementById('qty1');
    var objOptionCurrentInventory = objOption.split("-");
    var tempString = '';
    var counter = 1;
    
    if(parseInt(objOptionCurrentInventory[1]) < objPurchaseLimit)
    {
        tempString += '<select name="quantity" id="quantity">';
        tempString += '<option>How Many</option>';
        for(var i =0; i < objOptionCurrentInventory[1]; i++)
        {
            tempString += '<option value="'+counter+'">'+ counter +'</option>';
            counter++;
        
        }
        tempString += '</select>';
        quantityOptions.disabled=false;
        quantityOptions.innerHTML=tempString;
        
    }
    else
    {
        counter = 1;
        tempString += '<select name="quantity" id="quantity">';
        tempString += '<option>How Many</option>';
        for(var i = 0; i < objPurchaseLimit; i++)
        {
          tempString += '<option value="'+counter+'">'+ counter +'</option>';
          counter++;
        }
        tempString += '</select>';
        quantityOptions.innerHTML=tempString;
    }
}


//---------------------------------------------------------------------//


/**
 * Macromedia generated script for validating forms
 */
function MM_validateForm() {
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }


