$(document).ready(function () {					

    // init create account layer so there no flash
    $("#newAcctOpts").hide();

    // enable tabs
    var $tabs = $('#tabs').tabs({

        select: function (event, ui) {
            var selected = ui.index;

            if (selected == 1) { //clicked create account
                if (typeof(edu_account_url) !== "undefined") {
                    return location.href = edu_account_url;
                }

                $("#forgotPass").hide();
                $('#wishlistSearch').hide();
                $('.createAcct').hide();
                $('#newAcct').show();

            } else { //clicked login to my account
                $('.createAcct').show();
                $('#wishlistSearch').show();
                $('#newAcct').hide();
            }
        }

    });


    //New login Layer
    $(".checkLogin").click(function (e) {
        //find mouse pos
        var eleWidth = $("#loginSection").width();
        var eleHeight = $("#loginSection").height();



        if (window.innerHeight && window.innerWidth) {
            var x = (window.innerWidth - eleWidth) / 2;
            var y = (window.innerHeight - eleHeight) / 2;
        } else if (document.documentElement.clientHeight && document.documentElement.clientWidth) {
            var x = (document.documentElement.clientWidth - eleWidth) / 2;
            var y = (document.documentElement.clientHeight - eleHeight) / 2;
        } else {
            var x = (document.body.clientWidth - eleWidth) / 2;
            var y = (document.body.clientHeight - eleHeight) / 2;
        }
        if ($.browser.msie && (parseInt(jQuery.browser.version) == 6)) { // if ie6
            var x = (e.pageX);
            var y = (e.pageY);
        }
        //set values in form hidden fields
        //show layer and position layer...turn off form submit
        $("#loginSection").show();
        $("#lbOverlay").show();
        //$("select").hide(); //for ie6
        $("#lbOverlay").css({
            'opacity': '0.4'
        });
        $("#lbOverlay").click(function () {
            $('#tabs .closeMe a').click();
        });
        $("#loginSection").css({
            'left': x + 'px',
            'top': y + 'px',
            "position": "fixed"
        }); /*$("#loginSection").css("position", "fixed");*/


        if ($.browser.msie && (parseInt(jQuery.browser.version) == 6)) { // if ie6
            $("#loginSection").css("position", "absolute");
            $("#loginSection").css({
                'left': x - eleWidth + 'px',
                'top': y - (eleHeight / 2.3) + 'px'
            });
            $("#lbOverlay").css({
                'width': document.body.clientWidth + 'px'
            });
            $("#lbOverlay").css({
                'height': document.body.clientHeight + 'px'
            });
            $("#country").hide();
        }


        if ($(this).hasClass("getCheckedLogin")) {
            $(".checkoutbutton").show();
            $(".loginsubmitequote").hide();
        }

        if ($(this).hasClass("getEqouteLogin")) {
            $(".loginsubmitequote").show();
            $(".checkoutbutton").hide();
        }

        return false;
    });

    $('#tabs .closeMe a').click(function () {
        $("#lbOverlay").hide();
        $("#loginSection").hide();
        $("select").show(); //for ie6
    });








    $('.createAcct').click(function () { // bind click event to link
        $tabs.tabs('select', 1); // switch to third tab
        $('.createAcct').hide();
        return false;
    });

    // toggle subscribe layer
    $("#subscribeNow").click(function () {
        if (this.checked == true) {
            $("#newAcctOpts").show();
        } else {
            $("#newAcctOpts").hide();
        }
    });

    //toggle password recovery
    $("#utilLogin a").click(function () {
        var $whichLink = $(this).attr("href");
        if ($whichLink == "#forgotPass") {
            //show password recovery layer
            $("#forgotPass").show().find("img").attr("src", $("#forgotPass img").attr("rel"));
			
        } else {
            //show remeber info layer
            $("#remeber").show();
        }
        return false;
    });

    //hide password recovery layer
    $("#forgotPass a.cancel").click(function () {
        $("#forgotPass").hide();
        return false;
    });


    //hide newAcct layer
    $("#newAcct .formButt a").click(function () {
        $("#lbOverlay").hide();
        $("#loginSection").hide();
        $tabs.tabs('select', 0); // switch to third tab
        return false;

    });
    //add * to required field labels
    //$("label.required").append('&nbsp;*');
    $("label.required ~ input").addClass("reqField");
/*var $tabs = $('#tabs > ul').tabs(); 
 	$('.idTabs a').click(function() { // bind click event to link
		var $whichTab = $(this).attr("href");
		 if($whichTab == "#login"){
			$tabs.tabs('select', 0); // switch to third tab
			$("#wishlistSearch").show();// add jsp conditional to see from which page it came
		 	}	
		 else if($whichTab == "#createAccount"){
			$tabs.tabs('select', 1); // switch to third tab
			$("#wishlistSearch").hide();
	 		}

	});*/

    $(".rmExplained").click(function () {
        if ($(".rmExplained2:hidden")) {
            $(".rmExplained2").show();
            return false;
        }
    });
    $(".rmExplained2 a").click(function () {
        $(".rmExplained2").hide();
        return false;
    });

    $("#passFD").focus(function () {
        $(this).replaceWith("<input name='newPassword' id='passFD2' type='password' value='' maxlength='15' size='20' />");
        $("#passFD2").focus();
    });

    //focus on email input
    var emailInput = document.getElementsByName("emailAddress");
    $(emailInput).focus();
	
	var myImg = $("#forgotPass img");
			myImg.attr("src", myImg.attr("rel") + "?refresh=" + widgets.timeStamp());
			$(".changeCaptcha").click(function(){						   
				myImg.loading().one("load", function(){$(this).parent().stopLoading();});			
				myImg.attr("src", myImg.attr("rel") + "?refresh=" + widgets.timeStamp());
				return false;	
			});
});
//moved from utility.js 
function clearDefaultSearch(el) {
	searched = true;
  	if (el.defaultValue==el.value) el.value = "";
}
