﻿var findCareerDestinationUrl = "http://search6.smartsearchonline.com/amf/jobs/process_jobsearch.asp?job_type={0}&location={1}&k1={2}&UrlPrefix=http://www.amf.com/corporate";

function checkBirthDate(sender, args) {
    if (sender._selectedDate > new Date()) {
        alert("You cannot select a future date!");
        sender._selectedDate = new Date();
        // set the date back to the current date
        sender._textbox.set_Value(sender._selectedDate.format(sender._format))
    }
}

function ChangeCalendarView(sender, args) {
    sender._switchMode("years", true);
}

function watermarkInputFocus(obj, defVal) {
    if (obj.value == defVal) {
        obj.value = "";
    }
}

function watermarkInputBlur(obj, defVal) {
    if (obj.value == "") {
        obj.value = defVal;
    }
}

function maphover(map, bInout) {
    if (typeof isIe7  != "undefined") {
        if (bInout) {
            map.style.backgroundImage = "url(../img/design/mapDropBigActive.png)";
        } else {
            map.style.backgroundImage = "url(../img/design/mapDropBig.png)";
        }
    } else {
        if (bInout) {
            map.style.backgroundPosition = "2px -617px";
        } else {
            map.style.backgroundPosition = "2px -489px";
        }
    }
}

var animating = false;

function doSlide(idToSlide, UrlForExpandedStateSaving, moduleVar) {

	if (!animating) {

		var itemToSlide = $("#" + idToSlide);
		animating = true;

		if ($.browser.msie && parseFloat($.browser.version) < 9) {
			var cor_bot = $("#" + idToSlide).next('.bottomCorners1IE');

			if (cor_bot.is(':visible')) {

				if (cor_bot.height() == 0) {
					itemToSlide.slideDown("slow", function () {
						cor_bot.animate({ 'bottom': '-5px', 'height': '5px' }, 'fast', function () { animating = false; });
					});
				} else {
					itemToSlide.slideUp("slow", function () {
						cor_bot.animate({ 'bottom': '0px', 'height': '0px' }, 'fast', function () { animating = false; });
					});
				}
			} else {
				itemToSlide.slideToggle("slow", function () { animating = false; });
			}
		} else {
			itemToSlide.slideToggle("slow", function () { animating = false; });
		}


		if (itemToSlide.is(":hidden")) {
			sendState("1", UrlForExpandedStateSaving, moduleVar);
		}
		else {
			sendState("0", UrlForExpandedStateSaving, moduleVar);
		}
	}
}

function sendState(newState, UrlForExpandedStateSaving, moduleVar) {
    var urlForSavingState = UrlForExpandedStateSaving + "&" + moduleVar + "=" + newState;
    $.get(urlForSavingState);
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

function ControlVisibility(obj, controlToModify) {
    if (obj.checked) {
        $("#" + controlToModify).css("display", "block");
    } else {
        $("#" + controlToModify).css("display", "none");
    }
}

function copyPhoneNumber(sourceId, destinationId) {
    $("#" + destinationId).val(
                            $("#" + sourceId).val()
                        );
}

/*popup*/
window.onload = function () { resizeOverlay(); }
window.onresize = function () { resizeOverlay(); }
function showPopup() {
	resizeOverlay();
    $('.overlay').show();
    $('.popup').fadeIn(600);
}
function showPopupId(id) {
	resizeOverlay();
	$('#overlay_' + id).show();
	$('#popup_' + id).fadeIn(600);
	$('html, body').animate({
		scrollTop: ($('#popup_' + id).offset().top - 20)
	}, 700);

}
function closePopup() {
    $('.popup').fadeOut(600);
    setTimeout(function () { $('.overlay').hide(); }, 600);
}
function resizeOverlay() {
    $('.overlay').height('auto');
    var w = $(document).width();
    var h = $(document).height();
    if (w > 990) { $('.overlay').width('100%'); } else { $('.overlay').width('990px'); }
    $('.overlay').height(h);
}
/*end popup*/


function proceedAmfFindCareerButton_click(jobCategory, location, keywords) {
    var temp = findCareerDestinationUrl;
    temp = temp.replace(/\{0\}/gi, jobCategory);
    temp = temp.replace(/\{1\}/gi, location);
    temp = temp.replace(/\{2\}/gi, keywords);

    window.open(temp, "_self");
}

function mozillaStatesCutOffHack(id) {
    $(document).ready(function () {
        if ($.browser.mozilla) {
            $("#" + id + " > option + option").each(function () {
                $(this).append("&nbsp;");
            });
        }
    });
}

