﻿var url = 'http://lafcheta.info/';
function reload(divid) { document.getElementById(divid).src = 'source/image.php?' + Math.random(); }
function add_smile(div,smile) { document.getElementById(div).value = document.getElementById(div).value + ' ' + smile; } 
function vote(vid) { $.post(url + "source/validate.php?validate=vote&id=" + vid,function(result){ if (result != false) { $('.voters').html(result); } }); }
function addfav(vid) { $.post(url + "source/validate.php?validate=addfav&id=" + vid,function(result){ if (result != false) { $('#info').html(result).fadeIn(1000).fadeOut(5000); } } )}
function send(vid) { $.post(url + "source/validate.php?validate=send&id" + vid,{ from: $("#from").val(), to: $("#email").val(), id: vid },function(result) { if (result != false) $("#info").html(result).fadeIn(1000).fadeOut(5000); })}
$(document).ready(function(){
	 $("#birthday").datepicker();
	 $("#editprofile_result,#editpassword_result,#editemail_result").hide();
	 $("#sidebar h2,#content h2,.post").corners("top 10px");
	 $("#contact input,#contact textarea,#contact select").click( function() { $(this).css("border","1px solid #4A2922"); });
	 $("#contact input,#contact textarea,#contact select").blur( function() { $(this).css("border","1px solid #A5ACB2"); });
	 $("#members tr:not(.extlink),#contact tr:not(.extlink)").hover(function() { $(this).css('background-color', '#D6E6CC'); }, function() { $(this).css('background-color', '#FFFFFF'); });
	 $("#successfull > #timer").countdown({ until: 10,compact: true, format: 'S',layout: '{sn}',expiryUrl: url + 'index.php' });
	 $(".checkbox").click(function(){
		 if ($(this).attr("alt") == "checked") { $(this).attr({ alt: 'unchecked', src: 'images/checkbox-unchecked.gif' }); }
		 else { $(this).attr({ alt: 'checked', src: 'images/checkbox-checked.gif' }); }
	 });
	 $("#contact_submit").click(function(){
		 var selected = $("#about :selected").text();
		 $.post(url + "source/validate.php?validate=send_contact", { author: $("#author").val(), message: $("#message").val(), category: selected },
		 function(data) { $("#info").html(data).fadeIn(1000).fadeOut(5000); });
	 });
	 $("#editcontact").click(function(){ 
		 $.post(url + "source/validate.php?validate=update&mode=contact", {
			 icq : $("#icq").val(),
			 skype : $("#skype").val(),
			 city : $("#city").val(),
			 birthday : $("#birthday").val()
		 }, function(data) { $("#editprofile_result").slideToggle('slow').html(data).slideToggle(2000); });
	 });
	 $("#editpassword").click(function(){ 
		 $.post(url + "source/validate.php?validate=update&mode=newpass", {
			 oldpass : $("#oldpass").val(),
			 newpass : $("#newpass").val(),
			 conpass : $("#conpass").val()
		 }, function(data) { $("#editpassword_result").slideToggle('slow').html(data).slideToggle(3000); });
	 });	 
	 $("#editemail").click(function(){
		 $.post(url + "source/validate.php?validate=update&mode=email", { email: $("#email").val() },
		 function(data) { $("#editemail_result").slideToggle('slow').html(data).slideToggle(2000); });
	 });
	 $("a.send").click(function() { $("form.form_send").slideToggle('slow'); });
	 $(".delete").click(function(){ $(this).parents(".fav").animate({ opacity: 'hide' }, "slow"); $.ajax({ url: 'source/validate.php?validate=delfav&id=' + $(this).attr('alt') }); });
	 $("#do_loggin").click(function(){
		 var save = $(".checkbox").attr("alt");
		 $.post(url + "source/loggin.php",{ username: $("#user").val(), password: $("#pass").val(), saveme: save },
		 function (response) { 
			 if (response == true) { window.location = url + 'index.php'; }
			 else { $("#error_loggin").empty().fadeIn(2000).append(response).slideToggle(3000); }
		 });
	 });
	 $("#do_register").click(function(){
		 $.post(url + "source/validate.php?validate=register",{
			 rusername: $("#ruser").val(),
			 rpassword: $("#rpass").val(),
			 rpasswd: $("#rpswd").val(),
			 remail: $("#remail").val(),
			 captcha: $("#code").val(),
			 icq: $("#icq").val(),
			 skype: $("#skype").val(),
			 city: $("#city").val(),
			 bd: $("#birthday").val()
		 },function(validate) {
			 if (validate == true) { window.location = url + 'index.php?page=success&y=register'; }
			 else { $("#information").empty().fadeIn('slow').append('Възникна следната грешка:<br />» ' + validate); }
		 });		 
	 });
	 $("#addcontent").click(function(){
		 $.post(url + "source/validate.php?validate=addcontent",{ author: $("#name").val(),category: $("#cat").val(), message: $("#msg").val() }
		 ,function(validate) {
			 if (validate == true) { window.location = url + 'index.php?page=success&y=addcontent'; }
			 else { $("#information").empty().fadeIn('slow').append('Възникна следната грешка:<br />» ' + validate); }
		 });		 
	 });
	 $("#add_guestbook").click(function(){
		 $.post(url + "source/validate.php?validate=add_guestbook",{ author: $("#author").val(),message: $("#message").val(), captcha: $("#captcha").val() },
		 function (data) { $("#info").empty().html(data).slideToggle(1000).slideToggle(5000); });
	 });
	 $("#accordion").accordion();	 
});
