﻿// Just always load this one first

////////// JQUERY LINK HI-JAXING
// Disable JQuery Cache
$.ajaxSetup({
    cache: false
});
$(".seekerProfileLink").live("click", function() {
    LoadSeeker($(this).attr("href"));
    return false;
});
function LoadSeeker(url) {
    $("#aj").html("Loading...");
    $('.btnTxt').hide();
    $("#_seeker").load(url, null, function() {
        var hash=url.match(/^.*\/([^\/]+)$/);
        var ca = $("#CartAdd");
        if (hash && ca) {
            hash = hash[1];
            ca.attr("href", "/Lists/CartAdd/" + hash).show();
        }
        $("#aj").html("");
    });
}
$(".cartAction").live("click", function() {
    var ajax_load = "Working...";
    var me = $(this);
    $("#aj").html(ajax_load).load(me.attr('href'), null, function() { me.parent().children().show(); me.hide(); });
    return false;
});
function SaveCart() {
    if ($.trim($("#title").val()) == "") {
        PopInfo('MeetSeeker', 'Please specify list title.');
        $("#title").focus();
        return false;
    }
    var ajax_load = "Working...";
    $("#aj").html(ajax_load).load($("#frmSaveCart").attr("action"), { title: $("#title").val() });
    return false;
}

$(".ViewPhoto").live("click", function() {
    $("#PhotoDiv").toggle();
    $("#VideoDiv").toggle();
});
$(".ViewVideo").live("click", function() {
    $("#PhotoDiv").toggle();
    $("#VideoDiv").toggle();
});

////////////////////////////////

String.prototype.trim = function() { return this.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); }; // apparently very quick

// Keep track of which js files are loaded
var loadedJs = ['MeetSeeker'];
var loadingJs = 0;

function ElId(id) { return document.getElementById(id); }

function jsLoaded(jsFile) {
    for (var i = 0; i < loadedJs.length; i++) {
        if (loadedJs[i] == jsFile) return true;
    }
    return false;
}

function jsStartLoad(jsFile) {
    if (!jsLoaded(jsFile)) {
        loadedJs[loadedJs.length] = jsFile;
        loadingJs = jsFile;
        return true;
    }
    return false;
}

function jsRequire(jsFile) {
    if (!jsLoaded(jsFile)) {
        alert(loadingJs + '.js needs ' + jsFile + '.js');
    }
}

// confirm exit for unsaved changes
var checkSaved = 0;
var unsaved = 0;
//window.onbeforeunload = function() { if (unsaved) return 'You have made changes that haven\'t been saved' };

function bunload() {
    if (checkSaved && unsaved) return 'You have made changes that haven\'t been saved';
}
function CheckSaved() {
    checkSaved = 1;
}
function Saved() {
    unsaved = 0;
}
function Unsaved() {
    unsaved = 1;
}

window.onbeforeunload = bunload;

