﻿

$(document).ready(function () {

    function showAddEditReferenceForm() {

        if ($("#EditReferenceForm").is(":hidden")) {
            $("#EditReferenceForm").fadeIn("slow");
            $("#EditReferenceClose").fadeIn("slow");
            $("#ReferenceName").focus();
            $("#backgroundPopup").css({ "opacity": "0.7" });
            $("#backgroundPopup").fadeIn("slow");

            $.get('AddReferenceUC', function (data) {
                $('#EditReferenceForm').html(data);
            });
        }
        else {
            $("#EditReferenceForm").fadeOut("slow");
            $("#backgroundPopup").fadeOut("slow");
        }
    }

    $(".addReferenceModal").click(function () { showAddEditReferenceForm() });
    $(".closeAddEditReference").click(function () { closeEditReference() });


        //stay on the page
        return false;

    });


        function closeEditReference() {
            $("#EditReferenceForm").fadeOut("slow");
            $("#EditReferenceClose").fadeOut("slow");
            $("#backgroundPopup").fadeOut("slow");
        }




//$(document).ready(function () {


//   alert('wtf!');
//             function ShowAddReference() {
//                // set up ajax to prevent caching of results in IE
//               // $.ajaxSetup({ cache: false });

//                alert('inside add');

////                if ($("#EditReferenceForm").is(":hidden")) {
////                    $("#EditReferenceForm").fadeIn("slow");
////                    $("#EditReferenceClose").fadeIn("slow");
////                    $("#ReferenceName").focus();
////                    $("#backgroundPopup").css({ "opacity": "0.7" });
////                    $("#backgroundPopup").fadeIn("slow");

////            //        $.get('/Reference/AddReferenceUC', function (data) {
////            //            $('#EditReferenceForm').html(data);
////            //        });
////       
////                }
////                else {
////                    $("#EditReferenceClose").fadeOut("slow");
////                    $("#EditReferenceForm").fadeOut("slow");
////                    $("#backgroundPopup").fadeOut("slow");
////                }
//            }


//               $(".closeAddEditReference").click(function () { closeEditReference() });
//                 $(".addReferenceModal").click(function () { ShowAddReference() });



//});


//    function closeEditReference() {
//        $("#EditReferenceForm").fadeOut("slow");
//        $("#EditReferenceClose").fadeOut("slow");
//        $("#backgroundPopup").fadeOut("slow");
//    }



//function AddReference() {

//    var isValid = ValidateReferenceFields();

//    if (isValid) {

//        $.get('/Reference/AddReferenceUC', function (data) {
//            $('#EditReferenceForm').html(data);
//        });
//    
//    }
//}

//function ValidateReferenceFields() {

//    var businessname = $("#ReferenceName").val();
//    var message = $("#Message").val();

//    if (businessname == "") {
//        $('.referencename-missing').show();
//    } else { $('.referencename-missing').hide(); }
//    if (message == "") {
//        $('.message-missing').show();
//    } else { $('.message-missing').hide(); }


//    if (businessname == "" || message = "")
//        return false;
//}

//function EditReference(id) {

//    // alert('id=' + id);

//    // set up ajax to prevent caching of results in IE
//    $.ajaxSetup({ cache: false });

//    if ($("#EditReferenceForm").is(":hidden")) {
//        $("#EditReferenceForm").fadeIn("slow");
//        $("#EditReferenceClose").fadeIn("slow");
//        $("#BusinessName").focus();
//        $("#backgroundPopup").css({ "opacity": "0.7" });
//        $("#backgroundPopup").fadeIn("slow");

//        $.get('/Reference/Edit/' + id, function (data) {
//            $('#EditReferenceForm').html(data);
//        });
//    }
//    else {
//        $("#EditReferenceClose").fadeOut("slow");
//        $("#EditReferenceForm").fadeOut("slow");
//        $("#backgroundPopup").fadeOut("slow");
//    }

//}



//function DeleteReference(id) {

//    alert('id=' + id);

//    // set up ajax to prevent caching of results in IE
//    $.ajaxSetup({ cache: false });

//    var agree = confirm("Are you sure you wish to delete this Reference?");
//    if (agree) {

//        $.get('/Reference/Delete/' + id, function () {
//            window.location.href = '#EditReference';
//        });

//    }
//    else
//        return false;

//}
