﻿// JScript File

var reload = true;
	
$(document).ready(function() 
{
    
    $("#fraga").blur(cleanTextArea);
	$("#fraga").focus(cleanTextArea);
	//doChatRequest();
	$('.scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 16, maintainPosition: true});
    /* reload1();*/
});


/*function reload1()
{	
	
	setTimeout("window.location.href = window.location.href; reload1()", 5 * 1000);
	
}*/

/*
var alreadyshown = new Array();

function doChatRequest() 
{
	
	if(reload)
	{
		
		// Initiate Chat
		var numRand = Math.random() * 1001;
		
		
		
		$.getJSON("chatresults.aspx?rand=" + numRand, function(data){
			
			alert("fsdad");
			var lastadded = new Array();
	        
			$.each(data.items, function(i,item){
				
				if (!alreadyshown[item.id])
				{
					//$("<div>Läggs till: " + alreadyshown[item.id+""] + "</div>").appendTo("#chatresults").fadeIn(200);
	                
					$("<div id=\"chat"+item.id+"\">" + 
						"<p class=\"question\"><span>" + item.name + ":</span> " + item.question + "</p>" + 
						"<p class=\"answer\"><span>Ulf:</span> " + item.answer + "</p>" + 
						"</div>").prependTo("#chatresults").slideDown(200);
				}
				alreadyshown[item.id] = true;
				lastadded[item.id] = true;
			});
			
			for (var i=0 ; i<alreadyshown.length ; i++)
			{
			   if (alreadyshown[i] && !lastadded[i]) 
			   {
					// $("<div>Tas bort: " + i + "</div>").appendTo("#chatresults").fadeIn(200);
					$("div#chat" + i ).slideUp(function() { $(this).remove() });
					alreadyshown[i] = null;
				}
	            
			}
			
		});
		
    }
    $.chatTimer = setTimeout(function () 
    {
			
        doChatRequest();
    }, 5000);
}
*/
function doNewQuestion()
{
    $.post(
        "chatnewquestion.aspx", 
        { question: $("#fraga").attr("value") , name: $("#ditt-namn").attr("value") },
        function(data) 
        {
            showQuestionOkDiv('questionok');
        });
}
    
function showSendingQuestion()
{
	$("#input-container").slideUp();
    setTimeout("",1000);
    $("#input-container").hide();
    $("#questionsending").slideDown();
}
    
function showQuestionOkDiv(divname)
{
    $("#questionsending").slideUp();
    $("#questionsending").hide();
    $("#questionok").slideDown();
}

function showQuestionDiv(divname)
{
    $("#questionok").slideUp();
    setTimeout("",1000);
    $("#questionok").hide();
    
    $("#input-container").slideDown();
}
    
    
function cleanText(event) 
{
    var element = this;
    if ($(element).attr("value") == $(element).attr("title")) 
    {
        $(element).attr("value", "");
    }
    else if ($(element).attr("value") == "" && event.type != "click")
    {
        $(element).attr("value", $(element).attr("title"));
    }
}

function cleanTextArea(event) {

    var element = this;
    if ($(element).val() == $(element).attr("title"))
    {
        $(element).val("");
    }
    else if ($(element).val() == "" && event.type != "click")
    {
        $(element).val($(element).attr("title"));
    }
}

function stopAjax(event)
{
	if(event.type == "mousedown")
	{
		reload = false;
	}
	else if(event.type == "mouseup")
	{
		reload = true;
	}

}