//registration link
function register() {
    window.location = '/Loginregistration.aspx';
};
function actionIconsListings() {
    if (isIE6()) {
        $('.actionIcons li a:not(li.facebookIcon a, li.twitterIcon a, li.diggitIcon a), .saveListing a, .bubble a').each(function() {
            $(this).hover(function() {
                $(this).addClass('iconHover');
            }, function() {
                $(this).removeClass('iconHover');
            });
        });
    }
    $('.actionIcons li.heartIcon, .actionIcons li.shareIcon').each(function() {
        $(this).hover(function() {
            $(this).children('ul').css('display', 'block');
        }, function() {
            $(this).children('ul').css('display', 'none');
        });
    });
    $('li.shareThis ul li').each(function() {
        $(this).hover(function() {
            $(this).css('background-color', '#f2f0b8');
        }, function() {
            $(this).css('background-color', 'transparent');
        });
    });

    // Clearing the default values out of the text fields
    var tmpObj = {};
    $('li.formLoveItSayIt textarea').each(function(obj) {
        tmpObj[$(this).attr('id')] = { defaultValue: $(this).val() };
        $(this).focus(function() {
            if ($(this).val() == tmpObj[$(this).attr('id')].defaultValue) {
                $(this).val("");
            }
        });
        $(this).blur(function() {
            if ($(this).val() == "") {
                $(this).val(tmpObj[$(this).attr('id')].defaultValue);
            }
        });
    });
    $('.formLoveItSayItSubmit').mouseover(function() {
        $(this).css('background-position', 'left bottom');
    }).mouseout(function() {
        $(this).css('background-position', 'left top');
    });
}

function actionIconsConfirmation () {
    // Hearting Confirmation
    var heartMyNY = window.location.pathname;
    if (heartMyNY != '/MyNy.aspx') {
        $('.formLoveItSayItSubmit').each(function() {
            $(this).click(function() {
                if (!($('li.formLoveItSayIt .checkbox').attr('checked'))) {
                    $('li.formLoveItSayIt .emptyCheckbox').css('display', 'block');
                    $('li.formLoveItSayIt label').addClass('checkboxError');
                    $('li.formLoveItSayIt .checkbox').blur(function() {
                        if ($(this).attr('checked')) {
                            $('li.formLoveItSayIt .emptyCheckbox').css('display', 'none');
                            $('li.formLoveItSayIt label').removeClass('checkboxError');
                        }
                    });
                    return false;
                } else {
                    $('li.formLoveItSayIt .emptyCheckbox').css('display', 'none');
                    $('li.formLoveItSayIt label').removeClass('checkboxError');
                }
                $('li.formLoveItSayIt .checkbox').focus(function() {
                    if ($(this).attr('checked')) {
                        $('li.formLoveItSayIt .emptyCheckbox').css('display', 'none');
                    }
                });
            });
        });
    }

    // Save listing Confirmation
    $('.saveListing').each(function() {
        $(this).hover(function() {
            $(this).css('background-position', 'bottom left');
        }, function() {
            if ($(this).children('a').hasClass('disabled')) {
                $(this).css('background-position', 'left bottom').css('cursor', 'default');
                $(this).children('a').css('display', 'none');
                $(this).children('a').children('span.saveSuccess').hide();
            } else {
                $(this).css('background-position', 'top left');
            }
        }).click(function() {
            $(this).children('a').children('span.saveDefault').hide();
            $(this).children('a').children('span.saveSuccess').show();
            $(this).children('a').addClass('disabled');
        });
    });
}

$(document).ready(function() {
    // User tool / action functionality
    if (isIE6()) {
        actionIconsListings();
        actionIconsConfirmation();
    }

    // Clearing the default values out of the text fields
    var tmpObj = {};
    $('li.formLoveItSayIt textarea').each(function(obj) {
        tmpObj[$(this).attr('id')] = { defaultValue: $(this).val() };
        $(this).focus(function() {
            if ($(this).val() == tmpObj[$(this).attr('id')].defaultValue) {
                $(this).val("");
            }
        });
        $(this).blur(function() {
            if ($(this).val() == "") {
                $(this).val(tmpObj[$(this).attr('id')].defaultValue);
            }
        });
    });
    $('.actionIcons li.heartIcon:not(.disabled), .actionIcons li.shareIcon').each(function() {
        $(this).hover(function() {
            $(this).children('a:first').css('background-position', 'left -13px');
        }, function() {
            $(this).children('a:first').css('background-position', 'left top');
        });
    });
    $('.formLoveItSayItSubmit').mouseover(function() {
        $(this).css('background-position', 'left bottom');
    }).mouseout(function() {
        $(this).css('background-position', 'left top');
    });
    $('li.heartIcon a.heartRegister').each(function() {
        $(this).css('display', 'none');
    });
    $('li.heartIcon.disabled a.heartRegister').each(function() {
        $(this).css('display', 'block');
    });

    setSharePanelZ();
});

function toggleRegPanels(nextPanel) {
    switch (nextPanel) {
        case "step1":
            $("#step1").show();
            $("#step2").hide();
            $("#step3").hide();
            break;
        case "step2":
            $("#step1").hide();
            $("#step2").show();
            $('#step2 input:visible:first').focus();
            $("#step3").hide();
            break;
        case "step3":
            $("#step1").hide();
            $("#step2").hide();
            $("#step3").show();
            $('.zipStep3').val($('.zipStep1').val());
            $('#step3 input:visible:first').focus();
            break;
    }
}

function setSharePanelZ() {
    $('.actionIcons').each(function(i) {
        $(this).css('z-index', (500 - i));
    });
}
