/**
 * @author jleineweber
 */

function OpenEmail(url) {
	emailWind=window.open("/home/email.asp?URLemail="+escape(window.location)+"&Title="+escape(document.title),"Email","status=no,toolbar=no,resizable=yes,location=no,width=350,height=350");
	emailWind.focus();
}


// --- START ROTATING BANNER CODE ---

var siteFeatures = null;
var featureIndex = 0;
var isFocused = 0;
var featureProductDelay = 8000;	

//$(document).ready(function() {
//aigLoadObjects.push(function() {
$(document).ready(function() {
    siteFeatures = $("div.featuredProdList div.prod").hide().size();
    $("div.featuredProdList div.prod:eq(" + featureIndex + ")").show();
    $("div.featuredProdList").hover(function() {
    	isFocused = 1;
    }, function() {
    	isFocused = 0;
    });
    setInterval(updateFeatureProduct, featureProductDelay);
});

function updateFeatureProduct() {
	// alert(featureIndex);
	if (isFocused) return;
    $("div.featuredProdList div.prod:eq(" + featureIndex + ")").fadeOut('slow', function() {
    	$(this).hide();
    	featureIndex = (featureIndex + 1) % siteFeatures;
    	$("div.featuredProdList div.prod:eq(" + featureIndex + ")").show().fadeIn('slow');
    });
}

// --- START SHOW DISCLAIMER CODE ---

//aigLoadObjects.push(function() {
$(document).ready(function() {
	$('#disclaimer').hide();
    $('#disclaimerLink').click( function() {
		$('#disclaimer').toggle('normal');
	});
});

// --- END SHOW DISCLAIMER CODE ---

// --- START COUPON ENTRY CODE ---
function toUppercaseNoSpace(formField) {
  formField.value = formField.value.toUpperCase().replace(/([^0-9.\-A-Z])/g,"");
}

var lastFieldValue = null;
var cachedCouponButton = null;
function toUppercaseNoSpaceAndLabelChange(formField) {
  if (formField.value == 'Limit 1 coupon per order') formField.value = '';
  if (formField.value == lastFieldValue) return;
  if (cachedCouponButton == null) cachedCouponButton = $(".applyCoupon");
  
  lastFieldValue = formField.value;
  formField.value = formField.value.toUpperCase().replace(/([^0-9.\-A-Z])/g,"");
  
  if (formField.value == "") {
	cachedCouponButton.val("Clear Coupon");	
  } else {
	cachedCouponButton.val("Apply Coupon");
  }
}

// used for coupon code input box and possibly others
function selectText(formField){
	//formField.focus();
	formField.select();
}

function selectDonationAmtText(){
	this.select();
}


function toNumeric(el) {
  var newVal = $(el).val().toUpperCase().replace(/([^0-9])/g,"").substring(0,16);
  $(el).val(newVal);
  //el.val = newVal;
}


function disallowAngleBrackets(formField) {
  formField.value = formField.value.replace(/[<>]/g,"");
}
// --- END COUPON ENTRY CODE ---



// --- BEGIN DONATION STORE CART BOX ---

  //formField.value = formField.value.toUpperCase().replace(/([^0-9][^0-9]{0,2})/g,"").substring(0,15);
function toMoney() {
	var incString = $(this).val().toUpperCase().replace(/([^0-9.])/g,"");
	var dotOneLoc = incString.indexOf('.');

	if (dotOneLoc > -1) {
		var centString = incString.substring(dotOneLoc + 1);
		var dotTwoLoc = centString.indexOf('.');
		
		// ensure that the value only contains a single decimal character
		if (dotTwoLoc > -1) {
			incString = incString.substring(0, incString.length - 1);
		
		// ensure that only two numbers can follow a decimal character
		} else if (centString.length > 2) {
			incString = incString.substring(0, incString.length - 1);
		}
	}
		
	$(this).val(incString);
}


// use toMoney to clean input on each of the following events
$(document).ready(function() {
	$("#donateAmount").change( toMoney ).keyup( toMoney ).focus( selectDonationAmtText );

    // submit the donation via ENTER keypress
    $("#donateAmount").keypress(function(e) {
	    if (e.which == 13){
	        var amt = ($("#donateAmount").val()) * 100;
	        window.location.assign("/PublicStore/addtocart/3143," + amt + ",atc.aspx");
	        return false; 
	    }      
    });

    // submit the donation via BUTTON press
    $("#donateBtn").click(function() {
	    var amt = ($("#donateAmount").val()) * 100;
	    window.location.assign("/PublicStore/addtocart/3143," + amt + ",atc.aspx");
	    return false;
    });
	
});

// --- END DONATION STORE CART BOX ---


// --- DANIEL'S GET HELP BOX ---
/*
$(document).ready(function() {
   $(".help").toggle(function() {
   alert(1);
     $("#helpBox").show('slow');
   },function(){
   alert(2);
     $("#helpBox").hide('slow');
   });
 });
*/
 
 // --- COLORBOX AUTO-OPEN ON HASH URL ---
$(document).ready(function() {
var hash=location.hash;
if (hash){
var hashParts = hash.split('-');
if (hashParts.length > 1 && hashParts[0] == '#media') {
var num = hashParts[1];
var $el = $('.sampleMediaBox .thickbox').eq(num);
var href = $el.attr('href');
var urlparts = queryStringParts( href );
var iframe = false,
height, width;
for (var i=0; i<urlparts.length; i++) {
var item = urlparts[i];
if (item.attr == 'TB_iframe' && item.val == 'true') iframe = true;
else if (item.attr == 'width') width = Number(item.val);
else if (item.attr == 'height') height = Number(item.val);
}
$.colorbox({ href: href, iframe:iframe, innerHeight:height+6, innerWidth:width+6 });
}
}
});

