﻿jQuery.noConflict();

function inquiry() {
    if(!location == "https://my.campminder.com/family/inquiry2.aspx?c=zlhlt")
        location = "https://my.campminder.com/family/inquiry2.aspx?c=zlhlt"
    else
       NavigateUrl="mailto:info@campkingsmont.com"
}

// Hook up the click events of the log in and log out buttons.
if ($get('btnLognn') != null) {
    $addHandler($get('btnLogin'), 'click', loginHandler);
}
if (null != $get('btnLogout')) {
    $addHandler($get('btnLogout'), 'click', logoutHandler);
}

var ssa = Sys.Services.AuthenticationService;
loadRoles();
var profileService = Sys.Services.ProfileService;
var propertyNames = new Array();
var isLoggingIn = false;

if (ssa.get_isLoggedIn() == true) {
    HideElement('LoginMenu');
    ShowElement('LogoutMenu');
    LoadProfile();
    ShowProfileInfo();  
} else {
    ShowElement('LoginMenu');
    HideElement('LogoutMenu');
}

HideElement('LoginPanel');


function  DisplayLoginHandler() {

    if (null != $get('LoginWrapper'))
        $get('LoginWrapper').style.display = 'block'
    if (null != $get('AnonymousView'))
        $get('AnonymousView').style.display = 'block';
    
    
               
}


function loginHandler() {
    var username = $get('txtUsername').value;
    var password = $get('pwdPassword').value;
    var isPersistent = $get('chkRememberMe').checked;
    var customInfo = null;
    var redirectUrl = null;
    isLoggingIn = true;
    ShowElement('LoginPanel');
    // Log them in.
    ssa.login(username,
                          password,
                          isPersistent,
                          customInfo,
                          redirectUrl,
                          onLoginComplete,
                          onError);

}

function logoutHandler() {
    // Log them out.
    var redirectUrl = null;
    var userContext = null;
    ssa.logout(redirectUrl,
                           onLogoutComplete,
                           onError,
                           userContext);
}

function onLoginComplete(result, context, methodName) {

    if (result) {

        isAdministrator();
        loadRoles();
        // Logged in.  Hide the anonymous view.

        ShowElement('LoggedInView');
        HideElement('AnonymousView');
        HideElement('LoginPanel');
        
        HideElement('LoginMenu');
        ShowElement('LogoutMenu');


        LoadProfile();
        

    } else {
        alert('Sorry those Credentials did not work.');
        $get('txtUsername').value = '';
        $get('pwdPassword').value = '';
       
    }
}

function isAdministrator() {

    if (Sys.Services.RoleService.isUserInRole('Administrator')) {
        ShowElement('liAdmin');
    } else {
        HideElement('liAdmin');
    }

}

function onLogoutComplete(result, context, methodName) {
    // Logged out.  Hide the logged in view.
    ShowElement('LoginMenu');
    HideElement('LogoutMenu');

}


function loadRoles() {
    Sys.Services.RoleService.load(onLoadRolesCompleted, onLoadRolesFailed, null);
}

function onLoadRolesCompleted(result, userContext, methodName) {
    isAdministrator();
}

function onLoadRolesFailed(error, userContext, methodName) {
    alert(error.get_message());
}

function onError(error, context, methodName) {
    alert(error.get_message());
}


// Loads the profile of the current
// authenticated user.
function LoadProfile() {

    propertyNames[0] = "FirstName";
    propertyNames[1] = "LastName";

    Sys.Services.ProfileService.load(null,
	    OnLoadCompleted, OnProfileFailed, null);

}

// Reads the profile information and displays it.
function OnLoadCompleted(numProperties, userContext, methodName) {

    firstName = Sys.Services.ProfileService.properties.FirstName;

    if (firstName.length > 0 && isLoggingIn == true) {
        alert("Welcome " + firstName);
    }

    ShowProfileInfo();

}

function ShowProfileInfo() {

    if (null != $get('dUserName')) {

        if (undefined != Sys.Services.ProfileService.properties.FirstName &&
            undefined != Sys.Services.ProfileService.properties.LastName) {

            $get('dUserName').innerHTML =
                '<a href="../editprofile.aspx">' +
	            Sys.Services.ProfileService.properties.FirstName + ' ' +
	            Sys.Services.ProfileService.properties.LastName + '</a>';


        } else {
            $get('dUserName').innerHTML =
	            '<a href="../editprofile.aspx">Update Profile</a><BR/>';
        }
    }

}


// This is the callback function called 
// if the profile load or save operations failed.
function OnProfileFailed(error_object, userContext, methodName) {
    alert("Profile service failed with message: " +
	        error_object.get_message());
}

function ProcessEnter(btnSubmit) {

    if (event.which || event.keyCode) {
        if ((event.which == 13) || (event.keyCode == 13)) {
            $get(btnSubmit).click();
            return false;
        }
    } else {
        return true;
    };

}

function DisableElement(ElementName) {

    $get(ElementName).Enable == false;

}

function ShowLocation(Childelement, TextElement) {

    bounds = Sys.UI.DomElement.getBounds($get(Childelement));
    alert(bounds.x + ' ' + bounds.y + ' ' + bounds.width + ' ' + bounds.height);

}


function ConfirmMsg(entityName) {
    return confirm('Warning: This will delete the ' + entityName + ' from the database.');
}


function SelectAllCheckBoxes(id) {
    var frm = document.forms[0];

    for (i = 0; i < frm.elements.length; i++) {
        if (frm.elements[i].type == "checkbox") {
            frm.elements[i].checked = document.getElementById(id).checked;
        }
    }
}

function SubscribeToNewsletter() {
    var email = window.document.getElementById('NewsletterEmail').value;
    window.document.location.href = '~/Register.aspx?Email=' + email;
}

function ShowElement(ElementName) {
    if (null != $get(ElementName))
        $get(ElementName).style.display = 'block';
}

function HideElement(ElementName) {
    if (null != $get(ElementName))
        $get(ElementName).style.display = 'none';
}

function toggleDivState(divName) {
    var ctl = $get(divName);

    if (ctl.style.display == "none") {
        ShowElement(divName);
    } else {
        HideElement(divName);
    }
}

jQuery(document).ready(function() {
    var $boxes = jQuery('#TopTenWrapper li').hide()
    lix = 9;
    
    jQuery(function() {
    jQuery($boxes[lix--] || []).fadeIn(5000, arguments.callee); 
    });

});

