﻿$(function() {
    // Feedback Dialogue
    
    $("#dlgfeedbackok").dialog({
        bgiframe: true,
		autoOpen: false,
        modal: true,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });
		                
    $("#dlgfeedbackerror").dialog({
        bgiframe: true,
		autoOpen: false,
        modal: true,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });
		                
	$("#dlgfeedback").dialog({
		bgiframe: true,
		autoOpen: false,
		height: 300,
		width: 415,
		modal: true,
		buttons: {
			'Save': function() {
			    
			    $('#comment').hide();
                $('#feedbackloader').show();

                $.ajax({
                    type: "POST",
                    url: "default.aspx",
                    data: {pageaction:"feedback",thispageaction:$('#dlgfeedback-pageaction').val(),comment:$('#comment').val()},
                    dataType: "xml",
                    success: function(xml){
                        if($('status', xml).text()=='ok')
                        {
                            $('#dlgfeedbackok-msg').text($('message', xml).text());
		                    $('#dlgfeedbackok').dialog('open');
                        }
                        else
                        {
                            $('#dlgfeedbackerror-msg').text($('message', xml).text());
		                    $('#dlgfeedbackerror').dialog('open');
                        }
                    
                        $('#feedbackloader').hide();
                        $('#dlgfeedback').dialog('close');
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
		                $('#dlgfeedbackerror').dialog('open');
                    }
                });
			},
			Cancel: function() {
				$(this).dialog('close');
			}
		},
		close: function() {
			$('#comment').val('Enter your feedback');
			$('#comment').show();
		}
	});
	
	$('#add-feedback').click(function() {
		$('#dlgfeedback').dialog('open');
	})
	.hover(
		function(){ 
			$(this).addClass("ui-state-hover"); 
		},
		function(){ 
			$(this).removeClass("ui-state-hover"); 
		}
	)
	.mousedown(function(){
		$(this).addClass("ui-state-active"); 
	})
	.mouseup(function(){
			$(this).removeClass("ui-state-active");
	});
	
	$('#comment').mousedown(function(){
	    if($(this).val()=='Enter your feedback')
		    $(this).val(''); 
	})
	.keydown(function(){
	    if($(this).val()=='Enter your feedback')
		    $(this).val(''); 
	});

    // Add User Note Dialogue    
	
    $("#dlgaddnoteok").dialog({
        bgiframe: true,
		autoOpen: false,
        modal: true,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });
		                
    $("#dlgaddnoteerror").dialog({
        bgiframe: true,
		autoOpen: false,
        modal: true,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });
		                
	$("#dlgaddnote").dialog({
		bgiframe: true,
		autoOpen: false,
		height: 300,
		width: 415,
		modal: true,
		buttons: {
			'Save': function() {
			    
			    $('#note').hide();
                $('#addnoteloader').show();

                $.ajax({
                    type: "POST",
                    url: "default.aspx",
                    data: {pageaction:"addusernote",thispageaction:$('#dlgaddnote-pageaction').val(),note:$('#note').val(),pagetitle:$('#dlgaddnote-pagetitle').val()},
                    dataType: "xml",
                    success: function(xml){
                        if($('status', xml).text()=='ok')
                        {
                            $('#dlgaddnoteok-msg').text($('message', xml).text());
		                    $('#dlgaddnoteok').dialog('open');
                        }
                        else
                        {
                            $('#dlgaddnoteerror-msg').text($('message', xml).text());
		                    $('#dlgaddnoteerror').dialog('open');
                        }
                    
                        $('#addnoteloader').hide();
                        $('#dlgaddnote').dialog('close');
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
		                $('#dlgaddnoteerror').dialog('open');
                    }
                });
			},
			Cancel: function() {
				$(this).dialog('close');
			}
		},
		close: function() {
			$('#note').val('Enter note text');
			$('#note').show();
		}
	});
	
	$('#add-note').click(function() {
		$('#dlgaddnote').dialog('open');
	})
	.hover(
		function(){ 
			$(this).addClass("ui-state-hover"); 
		},
		function(){ 
			$(this).removeClass("ui-state-hover"); 
		}
	)
	.mousedown(function(){
		$(this).addClass("ui-state-active"); 
	})
	.mouseup(function(){
			$(this).removeClass("ui-state-active");
	});
	
	$('#note').mousedown(function(){
	    if($(this).val()=='Enter note text')
		    $(this).val(''); 
	})
	.keydown(function(){
	    if($(this).val()=='Enter note text')
		    $(this).val(''); 
	});


});




