//JQUERY
$(document).ready(function() {			 
	
	
	//FORM SUCCESS/FAIL MESSAGE
	$(".msg").hide();
	$(".msg").fadeIn("slow");
	
	//BULK DISCOUNT TABLE ON CATALOG DETAIL PAGE
	
	$("#showQuant").hide();
	//$("#bulkDiscount").hide();
	//$("#hideQuant").hide();
	
	$("#showQuant").click(function(){
		$("#bulkDiscount").slideDown("slow");
		$(this).hide();
		$("#hideQuant").show();
		return false;
	});
	$("#hideQuant").click(function(){
		$("#bulkDiscount").hide();
		$(this).hide();
		$("#showQuant").show();
		return false;
	});
	
	var exposeConfig = {color: '#333',loadSpeed: 200,	opacity: 0.9 };

	$("body").append("<div class='overlay' id='overlay'><div class='overlay-wrap'></div></div>");

    window.api = $("a[rel=#overlay]").overlay({ 
	    expose: exposeConfig, 
		api:true,
		target: '#overlay',
    	closeOnClick: false ,
        onBeforeLoad: function() { 
 
            // grab wrapper element inside content 
            var wrap = this.getContent().find("div.overlay-wrap"); 
 
            // load the page specified in the trigger 
            wrap.load(this.getTrigger().attr("href")); 
        }
	,onBeforeClose:function(){
		this.getContent().find("div.overlay-wrap").empty();	
	}		
	});

	$('.showhide').click(function(){
		$(this).prev().prev().slideToggle();
		return false;
	});
	
$('#password-clear').show();
$('#password-password').hide();

$('#password-clear').focus(function() {
    $('#password-clear').hide();
    $('#password-password').show();
    $('#password-password').focus();
});
$('#password-password').blur(function() {
    if($('#password-password').val() == '') {
        $('#password-clear').show();
        $('#password-password').hide();
    }
});

$('#pw1').show();
$('#pw2').hide();

$('#pw1').focus(function() {
    $('#pw1').hide();
    $('#pw2').show();
    $('#pw2').focus();
});
$('#pw2').blur(function() {
    if($('#pw2').val() == '') {
        $('#pw1').show();
        $('#pw2').hide();
    }
});

$('#pw3').show();
$('#pw4').hide();

$('#pw3').focus(function() {
    $('#pw3').hide();
    $('#pw4').show();
    $('#pw4').focus();
});
$('#pw4').blur(function() {
    if($('#pw4').val() == '') {
        $('#pw3').show();
        $('#pw4').hide();
    }
});

$('#pw5').show();
$('#pw6').hide();

$('#pw5').focus(function() {
    $('#pw5').hide();
    $('#pw6').show();
    $('#pw6').focus();
});
$('#pw6').blur(function() {
    if($('#pw6').val() == '') {
        $('#pw5').show();
        $('#pw6').hide();
    }
});

	
	
});// document ready




//document.execCommand("BackgroundImageCache",false,true);

//AUTOTAB
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
return true;
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)
index = i;
else
i++;
return index;
}

//SAME AS
function SameAs(form) {
if (form.sameAs.checked) {
InitSaveVariables(form);
form.su_billing_firstName.value = form.su_shipping_firstName.value;
form.su_billing_lastName.value = form.su_shipping_lastName.value;
form.su_billing_address.value = form.su_shipping_address.value;
form.su_billing_address2.value = form.su_shipping_address2.value;
form.su_billing_city.value = form.su_shipping_city.value;
form.su_billing_state.selectedIndex = form.su_shipping_state.selectedIndex;
form.su_billing_zip.value = form.su_shipping_zip.value;
}
else {
form.su_billing_firstName.value = billing_firstName;
form.su_billing_lastName.value = billing_lastName;
form.su_billing_address.value = billing_address;
form.su_billing_address2.value = billing_address2;
form.su_billing_city.value = billing_city;
form.su_billing_state.selectedIndex = billing_state;
form.su_billing_zip.value = billing_zip;
}
} 

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}
