
function ShowAllPaymentDivs(){
    //var Display = $$("([class*=displaybox])");

    if (PaymentDisplayBoxes.length > 0){
    PaymentDisplayBoxes.each(
        function(Box) {
            $(Box).show();
        }
    );
    }
}


/* alternate functions trying to fix slowdown in IE */
function ShowAllPaymentDivsNew(){
    var Display = $$("([class*=displaybox])");

//    var Display = new Array();
//    Display.push("card_0", "card_1", "card_2");


    Display.each(
        function(Box) {
            $(Box).style.display="block";
        }
    );
}
function HideAllPaymentEditDivsNew(){

    var Boxes = $$("([id*=edit_])");
//    var Boxes = new Array();

//    Boxes.push("edit_0", "edit_1", "edit_2");


    Boxes.each(
        function(Box) {
          //$(Box).style.display="none;";
          $(Box).hide();
        }
    );
}



function ShowCardEditNew(Which){

//alert("doing ShowCardEdit");
    //Step 1:  make sure all payment divs are showing
    //these are the normal showing of payment info
    ShowAllPaymentDivsNew();
//alert("done with ShowAllPaymentDivs");

    //step 2:  make sure all the edit boxes are hidden
    //these are the "edit" boxes for each payment method
    HideAllPaymentEditDivsNew();
//alert("done with HideAllPaymentEditDivs");
    
    //step 3: hide the display of the one we want to edit
    if (document.getElementById("card_" + Which)){
        document.getElementById("card_" + Which).hide();
        //document.getElementById("card_" + Which).style.display="none;";
        }
    else{ }

    //don't need to see the add box if we're editing
    HideAddPaymentMethodDiv();
//alert("done with HideAddPaymentMethodDiv");

    //step 4: show the edit for the card in question
    
    //document.getElementById("edit_" + Which).style.display="block";
    document.getElementById("edit_" + Which).show();
}


/////////end alternate functions for IE fix trial */



function ShowAllAddressDivs(){
    //var Display = $$("([class*=addressdisplaybox])");
    if (AddressDisplayBoxes.length > 0){
    AddressDisplayBoxes.each(
        function(Box) {
            $(Box).show();
        }
    );
    }
}


function HideAllPaymentEditDivs(){

    //var Boxes = $$("([class*=editbox])");
    PaymentEditBoxes.each(
        function(Box) {
          //$(Box).style.display="none;";
          $(Box).hide();
        }
    );
}

function HideAllAddressEditDivs(){

    if (AddressEditBoxes.length > 0 ) {
    //var Boxes = $$("([class*=addresseditbox])");
    AddressEditBoxes.each(
        function(Box) {
          //$(Box).style.display="none;";
          $(Box).hide();
        }
    );
    }
}


function ResetPaymentDivs(){
    HideAddPaymentMethodDiv();
    HideAllPaymentEditDivs();
    ShowAllPaymentDivs();
}

function HideAddPaymentMethodDiv(){

    //$("AddNewCard").style.display="none";
    $("AddNewCard").hide();
}

function HideAddAddressDiv(){

    //$("AddNewCard").style.display="none";
    $("AddNewAddress").hide();
}


function ShowCardEdit(Which){

    //Step 1:  make sure all payment divs are showing
    //these are the normal showing of payment info
    ShowAllPaymentDivs();


    //step 2:  make sure all the edit boxes are hidden
    //these are the "edit" boxes for each payment method
    HideAllPaymentEditDivs();

    
    //step 3: hide the display of the one we want to edit
    if (document.getElementById("card_" + Which)){
        document.getElementById("card_" + Which).hide();
        //document.getElementById("card_" + Which).style.display="none;";
        }
    else{ }

    //don't need to see the add box if we're editing
    HideAddPaymentMethodDiv();
//alert("done with HideAddPaymentMethodDiv");

    //step 4: show the edit for the card in question
    
    //document.getElementById("edit_" + Which).style.display="block";
    document.getElementById("edit_" + Which).show();
}

/* this function used on the my account page.  A slightly different
	version is used on th econfirm page, since we don't have the
	same number of boxes.*/
function ShowAddNewCard(){

    HideAllPaymentEditDivs();
    ShowAllPaymentDivs();
    document.getElementById("AddNewCard").style.display="block";

}

/* this function used on the my account page.  A slightly different
	version is used on th econfirm page, since we don't have the
	same number of boxes.*/
function ShowAddNewAddress(){

    HideAllAddressEditDivs();
    ShowAllAddressDivs();
    document.getElementById("AddNewAddress").style.display="block";

}

function ValidateCC(MyForm){

    var CardType = MyForm.CCType.value;
    var CCNumber = MyForm.CCNumber.value;
    var CCExpMonth = MyForm.CCExpMonth.value;
    var CCExpYear = MyForm.CCExpYear.value;


    if (CardType = ""){
        alert("You must select a card type.");
        return(false);
    }
    if (CCNumber = "" || ! CCNumber.match("^[0-9]+$")){
        alert("You must enter a valid card number.");
        return(false);
    }
    if (CCExpMonth = ""){
        alert("You must select an expiration month.");
        return(false);
    }
    if (CCExpYear = ""){
        alert("You must select an expiration year.");
        return(false);
    }
    return (true);
}

function ShowAddPayment(){

    var Type = $("AddPaymentSelect").value;

    if (Type == "CC"){
        $("BmlFields").style.display="none";        
        $("AddCCFields").style.display="block";
    }
    if (Type == "BML"){
        $("AddCCFields").style.display="none";
        $("BmlFields").style.display="block";        
    }

}

function VerifyCCDelete(){


    var msg = "Are you sure you wish to delete this credit card?";

    if (confirm(msg)){
        return(true);
    }
    else{
        return(false);
    }

}

function ResetAddressDivs(){
    ShowAllAddressDivs();
    HideAllAddressEditDivs();
    HideAddAddressDiv();
}

function ShowAddressEdit(Which){

    //Step 1:  make sure all payment divs are showing
    //these are the normal showing of payment info
    ShowAllAddressDivs();


    //step 2:  make sure all the edit boxes are hidden
    //these are the "edit" boxes for each payment method
    HideAllAddressEditDivs();
    
    //step 3: hide the display of the one we want to edit
    if (document.getElementById("address_" + Which)){
        document.getElementById("address_" + Which).hide();
        //document.getElementById("card_" + Which).style.display="none;";
        }
    else{ }

    //don't need to see the add box if we're editing
    HideAddAddressDiv();

    //step 4: show the edit for the card in question
    
    //document.getElementById("edit_" + Which).style.display="block";
    document.getElementById("editaddress_" + Which).show();
}


function ValidateAddress(MyForm){

    var FirstName = MyForm.FirstName.value;
    var LastName = MyForm.LastName.value;
    var Address1 = MyForm.Addr1.value;
    var Address2 = MyForm.Addr2.value;
    var City = MyForm.City.value;
    var Zip = MyForm.Zip.value;
    var Count = MyForm.Count.value;


    //State validation depends on the country
    var MyCountry = document.getElementById("Country_" + Count);
    var StateText = document.getElementById("State_text_field_" + Count);
    var StateDropdown = document.getElementById("State_" + Count);
    var StateCanadian = document.getElementById("CanadianState_" + Count);

    if (FirstName == ""){
        alert("Please enter your first name.");
        return(false);
    }
    if (LastName == ""){
        alert("Please enter your last name.");
        return(false);
    }

    if (Address1 == ""){
        alert("Please enter a street address.");
        return(false);
    }
    if (City == ""){
        alert("Please enter a city.");
        return(false);
    }
    if (MyCountry.value == ""){
        alert("Please select a country.");
        return(false);
    }


    if (MyCountry.value == "United States"){
        if (StateDropdown.value == ""){
            alert("You must select a state.");
            return(false);
        }
    }
    if (MyCountry.value == "Canada"){
        if (StateCanadian.value == ""){
            alert("You must select a state.");
            return(false);
        }
    }


    if (Zip == ""){
        alert("You must enter a postal code.");
        return(false);
    }

    return (true);
}

function ToggleStateInput(Which){

    var MyCountry = document.getElementById("Country_" + Which);
    
    if (MyCountry.value == "United States"){
        ToggleStateText(Which, "off");
        ToggleStateDropdown(Which, "on");
        ToggleStateCanadian(Which, "off");
    }
    else if (MyCountry.value == "Canada"){
        ToggleStateText(Which, "off");
        ToggleStateDropdown(Which, "off");
        ToggleStateCanadian(Which, "on");

    }
    else{
        ToggleStateText(Which, "on");
        ToggleStateDropdown(Which, "off");
        ToggleStateCanadian(Which, "off");

    }
    return(true);
}

function ToggleStateText(Which, Dir){
    var StateText = document.getElementById("State_text_" + Which);

    

    if (Dir == "on"){
        //StateText.style.display="block";
        StateText.show();

    }
    else{
        //StateText.style.display="none";
        StateText.hide();
    }
}

function ToggleStateDropdown(Which, Dir){
    var StateDropdown = document.getElementById("State_dropdown_" + Which);
    
    if (Dir == "on"){
        StateDropdown.style.display="block";

    }
    else{
        StateDropdown.style.display="none";
    }
}
function ToggleStateCanadian(Which, Dir){
    var StateCanadian = document.getElementById("Canadian_State_dropdown_" + Which);
    

    if (Dir == "on"){
        StateCanadian.style.display="block";

    }
    else{
        StateCanadian.style.display="none";
    }
}

function HideOneClickPaymentDisplay(){

}

function ToggleOneClickPaymentEdit(Which){
    if (Which == "on"){
        $("One_click_payment_edit").show();
    }
    else{
        $("One_click_payment_edit").hide();
    }
}

function ToggleOneClickPaymentDisplay(Which){
    if (Which == "on"){
        $("One_click_payment_display").show();
    }
    else{
        $("One_click_payment_display").hide();
    }
}

function ToggleOneClickBillingDisplay(Which){
    if (Which == "on"){
        $("BillingAddressDisplay").show();
    }
    else{
        $("BillingAddressDisplay").hide();
    }
}

function ToggleOneClickBillingEdit(Which){
    if (Which == "on"){
        $("BillingAddressEdit").show();
    }
    else{
        $("BillingAddressEdit").hide();
    }
}

function DoOneClickChangeBilling(){
    ToggleOneClickBillingDisplay("off");
    ToggleOneClickBillingEdit("on");
    ToggleOneClickShippingEdit("off");
	ToggleOneClickShippingDisplay("on");


}
function DoOneClickChangeShipping(){
    ToggleOneClickShippingDisplay("off");
    ToggleOneClickShippingEdit("on");
    ToggleOneClickBillingEdit("off");
    ToggleOneClickBillingDisplay("on");


}


function DoOneClickChangePayment(){
    ToggleOneClickPaymentEdit("on");
    ToggleOneClickPaymentDisplay("off");
}

function ResetOneClickChangePayment(){
    ToggleOneClickPaymentEdit("off");
    ToggleOneClickPaymentDisplay("on");
}

function ResetOneClickDivs(){
    ToggleOneClickBillingDisplay("on");
    ToggleOneClickBillingEdit("off");
    ToggleOneClickShippingDisplay("on");
    ToggleOneClickShippingEdit("off");

}

function ToggleOneClickShippingDisplay(Which){
    if (Which == "on"){
        $("ShippingAddressDisplay").show();
    }
    else{
        $("ShippingAddressDisplay").hide();
    }
}

function ToggleOneClickShippingEdit(Which){
    if (Which == "on"){
        $("ShippingAddressEdit").show();
    }
    else{
        $("ShippingAddressEdit").hide();
    }
}

function ShowDetailsEdit(){
    ToggleDetailsDisplay("off");
    ToggleDetailsEdit("on");

}
function ToggleDetailsDisplay(Which){
    if (Which == "on"){
        $("DetailsDisplay").show();
    }
    else{
        $("DetailsDisplay").hide();
    }
}
function ToggleDetailsEdit(Which){
    if (Which == "on"){
        $("DetailsEdit").show();
    }
    else{
        $("DetailsEdit").hide();
    }
}



function ValidateInfo(MyForm){
    var FirstName = MyForm.FirstName.value;
    var LastName = MyForm.LastName.value;
    var Email = MyForm.Email.value;
    var Email2 = MyForm.Email2.value;
    var Phone = MyForm.PhoneNumber.value;

    if (Email == "") { alert("Please enter your email address.");  return(false);}
    if (Email2 == "") { alert("Please confirm your new email address.");  return(false);}
    if (Email != Email2){ alert("Email addresses do not match.  Please try again."); return (false);}


    return(true);

}





function ValidatePasswordChange(MyForm){
    var Password1 = MyForm.Password1.value;
    var Password2 = MyForm.Password2.value;

    if (Password1 == "") { alert("Please type a new password."); return(false);}
    if (Password2 == "") { alert("Please confirm your new password.");  return(false);}

    if (Password1 != Password2){ alert("Passwords do not match.  Please try again."); return (false);}


	if (Password1.length < 5  ){
		alert("Your password must be at least five characters in length.");
		return(false);
	}

    return(true);
}

function VerifyAddressDelete(){
    var msg = "Are you sure you want to delete this address?";

    if (confirm(msg)){ return(true);}
    else{ return(false); }
}

function ShowAddNewAddressConfirm(which){
    document.getElementById("AddNewAddress").style.display="block";

	document.AddNewAddress.AddressTarget.value = which;

}

function ShowAddNewCardConfirm(){
    document.getElementById("AddNewCard").style.display="block";
}

function CancelEditDetails(){
	$("DetailsEdit").hide();
	$("DetailsDisplay").show();
}