function shippingForm(element){
	element.disable();
	var shipDiv = $('ShippingForm');
	var paras = $$('.shipping');
	Effect.toggle(shipDiv,'blind',{
		afterFinish: function(){ element.enable(); if(shipDiv.visible()){paras.each(function(Element){ Element.clear();}); }}
	});
}
function showBillingElement(){
	var divEle = $('billingDetail');
	var ImgEle = $('billingIMG');
	Effect.toggle(divEle,'blind',{afterFinish: function(){ if(divEle.visible()){ ImgEle.src = '/images/resources/flex_arrow_open.gif'; }else{ ImgEle.src = '/images/resources/flex_arrow_shut.gif'; }}});
}
function showCartElement(element){
	var divEle = $('cartDetail');
	var ImgEle = $('detailsIMG');
	Effect.toggle(divEle,'blind',{afterFinish: function(){ if(divEle.visible()){ ImgEle.src = '/images/resources/flex_arrow_open.gif'; }else{ ImgEle.src = '/images/resources/flex_arrow_shut.gif'; }}});
}
function addItem(result,FormID){ 
	if(result){
		new Ajax.Request('/ajax.php', {
			method: 'post', 
			parameters: Form.serialize($(FormID)), 
			onComplete: function(data){ 
				myLightWindow.activateWindow({ href: '/addItemNotice.php',type: 'page', height: 200, width: 500 });	
				if(data.responseText.length < 25){
					$('cartDataChild').remove();
					$('cartDataWrap').appendChild(Builder.node('span',{id: 'cartDataChild'}, data.responseText));	
				}
			}
		});
	}
}
function printPage(){
	window.print();
}
function showProcessIcon(result,FormID){
	if(result){
		$('processingOrderImg').show();
		$('completeOrder').value = "Processing Order";
	}
}
function alterProductViews(e){
	$('viewOptions').submit();
}	
function clearDiscount(){
	$('coupon').clear();
}	
function cancelOrder(){
	var validate = confirm("Are you sure you want to cancel your order?\n\nAll information will be lost.");
	if(validate){ window.location = "/cart/?cancel=1"; }		
}

var ImageHighlighter = Class.create({
  initialize: function(element) {
    this.element = $(element);
    this.initEventHandlers();
  },
  initEventHandlers: function() {
    this.element.observe('mouseover', this.handleMouseOver.bind(this));
    this.element.observe('mouseout', this.handleMouseOut.bind(this));
  },
	handleMouseOver: function(e) {
    var element = e.element();
	element.addClassName('hoverEffect');
  },
	handleMouseOut: function(e) {
	var element = e.element();
	element.removeClassName('hoverEffect');
  }
});
var updateStrength = function(e) {
	var pw = $('passCheckScore').value;
	var strength = getStrength(pw);
	var width = (100/32)*strength;
	new Effect.Morph('psStrength', {style:'width:'+width+'px', duration:'0.4'}); 
}
var getStrength = function(passwd) {
	intScore = 0;
	if (passwd.match(/[a-z]/)) // [verified] at least one lower case letter
	{
	intScore = (intScore+1)
	} if (passwd.match(/[A-Z]/)) // [verified] at least one upper case letter
	{
	intScore = (intScore+5)
	} // NUMBERS
	if (passwd.match(/\d+/)) // [verified] at least one number
	{
	intScore = (intScore+5)
	} if (passwd.match(/(\d.*\d.*\d)/)) // [verified] at least three numbers
	{
	intScore = (intScore+5)
	} // SPECIAL CHAR
	if (passwd.match(/[!,@#$%^&*?_~]/)) // [verified] at least one special character
	{
	intScore = (intScore+5)
	} if (passwd.match(/([!,@#$%^&*?_~].*[!,@#$%^&*?_~])/)) // [verified] at least two special characters
	{
	intScore = (intScore+5)
	} // COMBOS
	if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/)) // [verified] both upper and lower case
	{
	intScore = (intScore+2)
	} if (passwd.match(/\d/) && passwd.match(/\D/)) // [verified] both letters and numbers
	{
	intScore = (intScore+2)
	} // [Verified] Upper Letters, Lower Letters, numbers and special characters
	if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/) && passwd.match(/\d/) && passwd.match(/[!,@#$%^&*?_~]/))
	{
	intScore = (intScore+2)
	}
	return intScore;
}
document.observe('dom:loaded', function() {
	if($('passCheckScore')){ $('passCheckScore').observe('keyup', updateStrength.bindAsEventListener(this)); }
	if($('shipit')){ new Form.Element.EventObserver('shipit', shippingForm); }
	if($('showCartBlock')){ $('showCartBlock').observe('click', showCartElement.bindAsEventListener(this)); }
	if($('removeDiscount')){ $('removeDiscount').observe('click', clearDiscount.bindAsEventListener(this)); }
	if($('cancel')){ $('cancel').observe('click', cancelOrder.bindAsEventListener(this)); }
	if($('showBillingBlock')){ $('showBillingBlock').observe('click', showBillingElement.bindAsEventListener(this)); }
	if($('productOrder')){ $('productOrder').observe('change', alterProductViews.bindAsEventListener(this)); }
	if($('ViewNum')){ $('ViewNum').observe('change', alterProductViews.bindAsEventListener(this)); }
	if($('printButton')){ $('printButton').observe('click', printPage.bindAsEventListener(this)); }
	$$('form.doformvalidation').each(function(form) { new Validation(form.id); });
  	$$('img.imageHover').each(function(image) { new ImageHighlighter(image); }); 
});