
Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
    var i;
    for (i=0; i < this.length; i++) {
        // Matches identical (===), not just similar (==).
        if (this[i] === value) {
            return true;
        }
    }
    return false;
};
function externalLinks() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") &&
        anchor.getAttribute("rel") == "external")
      anchor.target = "_blank";
    }
}

window.onload = externalLinks;


$(document).ready(function(){
 
	 if( $('input[name=submit_form]').val()=='Send Gift Bag Pre-Order' ) {
		//$('input[id^="gift_bag_"]').val(0);		
		$('input[name=submit_form]').click(function(){
			total = 0;
			errors = [];
			$('input[id^="gift_bag_"]').each(function(){
				$input = $(this);
				val = $input.val();
				if(val!=''){
					if(isNaN(val)){
						errors.push($('label[for="'+$input.attr('id')+'"]').text()+" must be a number");
						$input.css('color','#c00').val(0).focus();
					} else {
						total += Math.floor(val);
					}
				}
			});
			if(errors.length){				
				alert('The form produced the following errors, please correct them and try again:\n\n\t'+errors.join('\n\t')+'\n');
				return false;
			} else {
				if(total < 12){
					alert("There is a 12 unit minumum order (any combination) of gift bags");
					return false;
				}	
			}
		});// close click 	
	}	
		

	$('#submitforfoodtest').click(function(){
		
		if(checkFormConcessions(document.getElementById('application'))){
			$('.food-concessions-app').hide('slow');	
			$('.foodtest').show('slow');
			$.scrollTo('a[name="top"]', 500 );

		}else{
			return false;
		}
	
	});




});// close document ready

