// JavaScript Document
$.post('user-asynch.php', {'width':screen.width,'height':screen.height});
$(document).ready(function(){
						   
		$("a.fancybox").fancybox();
		setInterval("UpdateDateTime()", 60*1000);
		$(".lawdateblock1").css("display", "none");
		$(".lawdateblock2").css("display", "none");
		if ($("input[name=date_type1]:checked"))
		      {  		       
		       	if ($("input[name=date_type]:checked").val() == 'nodate')
		       	{
		       		$(".lawdateblock1").css("display", "none");
		       		$(".lawdateblock2").css("display", "none");
		       	}
		       	if ($("input[name=date_type]:checked").val() == 'onedate')
		       	{
		       		$(".lawdateblock1").css("display", "block");
		       		$(".lawdateblock2").css("display", "none");
		       	}
		       	if ($("input[name=date_type]:checked").val() == 'twodate')
		       	{
		       		$(".lawdateblock1").css("display", "block");
		       		$(".lawdateblock2").css("display", "block");
		       	}
		}
		
		$("input[name=date_type]").click(
		       function()
		       {  		       
		       	if ($("input[name=date_type]:checked").val() == 'nodate')
		       	{
		       		$(".lawdateblock1").css("display", "none");
		       		$(".lawdateblock2").css("display", "none");
		       	}
		       	if ($("input[name=date_type]:checked").val() == 'onedate')
		       	{
		       		$(".lawdateblock1").css("display", "block");
		       		$(".lawdateblock2").css("display", "none");
		       	}
		       	if ($("input[name=date_type]:checked").val() == 'twodate')
		       	{
		       		$(".lawdateblock1").css("display", "block");
		       		$(".lawdateblock2").css("display", "block");
		       	}
		       }
		 );
});

function dateTimeUpdateCallback(data)
{
	if (data.ok)
	{
		$("#MainDate").text(data.date);
		$("#MainTime").text(data.time);
		$("#MainDay").text(data.day);
	}
}

function UpdateDateTime()
{
	$.post("/user-asynch.php", {'getdate':1}, dateTimeUpdateCallback, 'json');
}

function pollPanelVoteClick(message, language, dest)
{	
	var value = $('#'+dest+" input[@name=radio_name]:checked").val();
	var poll_id = $('#'+dest+" input[name=poll_id]").val();	
	if (value == undefined) 
	{
		alert(message);
		return;
	}
	$.post('/user-asynch.php', {'poll_id':poll_id,'poll_answer':value});
	w = $("#"+dest).width();
	$("#"+dest).html('<div class="loading">&nbsp;<img align="absmiddle" src="design/user/images/ajax/loading.gif" alt="Wait" />&nbsp;</div>');
	$("#"+dest).load('/user-asynch.php?poll_id='+poll_id+'&poll_results&language='+language+'&dest='+dest+ '&'+Math.random());
	$("#"+dest).width(w);
}

function goPoll(id, language, dest)
{	
	w = $("#"+dest).width();
	$("#"+dest).html('<div class="loading">&nbsp;<img align="absmiddle" src="design/user/images/ajax/loading.gif" alt="Wait" />&nbsp;</div>');
	$("#"+dest).load('/user-asynch.php?poll_id='+id+'&poll&language='+language+'&dest='+dest+ '&'+Math.random());	
	$("#"+dest).width(w);
}
function goResults(id, language, dest)
{
	w = $("#"+dest).width();
	$("#"+dest).html('<div class="loading">&nbsp;<img align="absmiddle" src="design/user/images/ajax/loading.gif" alt="Wait" />&nbsp;</div>');
	$("#"+dest).load('/user-asynch.php?poll_id='+id+'&poll_results&language='+language+'&dest='+dest+ '&'+Math.random(), null);
	$("#"+dest).width(w);
}

//***********

function questionSubmit()
{
	var qString = $("#questionAddForm").formSerialize();
	$.post("/user-asynch.php?questions&submit", qString, questionSubmitCallback, 'json');
}
function questionSubmitCallback(data)
{
	if (data.ok)
	{
		$("#questionOKFormTable").css('height', $("#questionAddForm").height());		
		$("#questionOKFormTable").css('width', $("#questionAddForm").width());		
		$("#QuestionAddFormState").hide();
		$("#MessageSentText").text(data.okString);
		$("#questionAddForm").fadeOut(1000, function()
		{					
			$("#questionOKForm").fadeIn(1000);
			$("#questionAddForm").clearForm();
			$("#question_person_id").val(1);		
		}
		);				
	} else
	if (data.error)
	{
		$("#QuestionAddFormState").fadeIn(1000);
		$("#QuestionAddFormState").text(data.errorString);
		
	}
}
function showAddQuestionForm()
{
	$("#questionOKForm").fadeOut(1000, function(){
			$("#questionAddForm").clearForm();
			$("#question_person_id").val(1);		   
 			$("#questionAddForm").fadeIn(1000);
 		});
}
function searchfocus(str)
{
    if (document.forms.searchOnSite.text.value == str)
		document.forms.searchOnSite.text.value = '';
}
function searchblur(str)
{
   if (document.forms.searchOnSite.text.value.length == 0)
      document.forms.searchOnSite.text.value = str;
}

function printable() 
{
   s = new String(document.location);   
   s = s.replace(/#/,"");
   w=window.open((s.indexOf('?')>0) ? s+"&print" : s+"?print","printable","toolbar=yes,menubar=yes,resizable=1,scrollbars=1,width=800,height=600");    
   w.document.close();   
}
