﻿// CASE SENSITIVE FOR CONTROL NAMES!!

function getContent(url, callback) {
    var request = new Sys.Net.WebRequest();
    request.set_url(url);
    request.set_httpVerb("GET");
    var del = Function.createCallback(getContentResults, callback);
    request.add_completed(del);
    request.invoke();
}

function getContentResults(executor, eventArgs, callback) {
    if (executor.get_responseAvailable()) {
        callback(eval("(" + executor.get_responseData() + ")"));
    }
    else {
        if (executor.get_timedOut())
            alert("Timed Out");
        else if (executor.get_aborted())
            alert("Aborted");
    }
}
// jquery
// slideUp, show, hide, animate (via css prop)
// addClass, removeClass instead of manual css here
function BoxStuff() {
    $('#box').stop().hide('slow');
    $('#img').click(DoImage1);

}
function Opaq() {
    $(this).stop().animate({ 'opacity': 1 });

}
function Opaq5() {
        $(this).stop().animate({ 'opacity': .75 });

}
function LoadStuff() {

    alert("running");
    $('<div id="info" />').load("/list.htm #num", function() {
        $(this).hide();
        $(this).appendTo('#extra');
        $(this).slideDown(1500);
    });

}
function DoImage1() {
    $('#box').stop().show('slow');
    $('#box').click(DoImage2);
}
function DoImage2() {
    $(this).stop().animate({ 'left': '300px' });
    $(this).stop().animate({ 'width': '50px' });
    // fade, hide, toggleClass
}
function ListStuff() {
//    $('<li>ok</li>').appendTo('#ul1');
//    $('li:even').toggleClass('green');
//    $('li[id^="q"').toggleClass('green');
//    var x = $('#ul1')[0];
//    alert(x);
    CreateCollection();
}
function LoadCallback() {
    alert("callback running");
}
function ShowPopup(e) {
//    alert("popup running");
//    alert(e.toString());
//    alert(this);
    var img = $(this).attr['alt'];
    $('<img src="' + img + '" alt="image" />')
//    .css('top', e.PageY)
//    .css('left', e.PageX)
//    .appendTo('body');

}
var array = [];
function CreateCollection() {

    alert("CreateCollection running");
    var x = new DataObj("me", "david");
    var y = new DataObj("you", "not");
    var ar = new Array();
    ar[0] = x;
    ar[1] = y;
    array = ar;
}
function DataObj(Key, Value) {
    this.Key = Key;
    this.Value = Value;
}
function ShowCollection() {
    for (var x = 0; x < array.length; x++)
        $('#go').append("<br />" + array[x].Key);
}

function AjaxCall(Url, type, data, callbackName) {

    $.ajax({
        url: 'page on server',
        type: 'post',
        data: 'the data as qs args or whatever the page wants ',
        success: function(result) {
        // do something on page
         }
    });

}
function Post(Url, data, callbackFunction) {

   $.post(Url, $("form").serialize(), callbackFunction);
// serialize uses the name attribute of form fields (not id)
}

function SendtoWDFAsJSON() {
    // Convert the form into an object
    var data = { title: $("#title").val(), director: $("#director").val() };

    // JSONify the data
    data = JSON.stringify(data);

    // Post it
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "WCFService.svc/MethodName",
        data: data,
        dataType: "json",
        success: insertCallback
    });
}
function ShowSelected() {

    alert($('#ul1 option:selected').val());
}
