$(function(){
	inputValue();
	confirmDelete();
});


function confirmDelete(){
	$('a.delete').click(function(){
		if(confirm('Наистина ли да се изтрие?')){
			return true;
		}else{
			return false;
		}
	});	
}

function formSubmit(){
		var value = $('input#url').val();
		var alias = $('input#alias').val();
		var pass = $('input#pass').val();
		var expire = $('input#expire').val();
		
		var url = $.domain+'createCode/'
		
		$('#loader').css({"display":"block"});
		
		$.post(url, {url:value, alias:alias, pass:pass, expire:expire}, 
				function(data){
					$('#loader').css({"display":"none"});
					$('#result').html(data);
				}
		);
		return false;
}

function remoteDo(href){
		var url = $.domain+'createCode/';		
		$('#loader').css({"display":"block"});
		
		$.post(url, {url:href}, 
				function(data){
					$('#loader').css({"display":"none"});
					$('#result').html(data);
				}
		);
}

function inputValue(){
	$('input#url').click(function(){
		if($(this).val()=='http://'){$(this).val('');}
	});
}

$.curentForm='basic';
function switchForm(){
	var newForm = '';
	var buton = '';
	var display = '';
	if($.curentForm=='basic'){
		newForm='advanced';
		buton = 'Basic options';
		display = 'block';
	}else{
		newForm='basic';
		buton = 'Advanced options';
		display = 'none';
	}
	
	$('form.'+$.curentForm).removeAttr('class').attr('class', newForm);
	$('a#options_button').html(buton);
	$('#advanced_options_container').css({"display":display});
	if(newForm=='basic'){
		$('input#pass').val('');
		$('input#expire').val('');
	}
	$.curentForm = newForm;
}

function enterPass(code){
	var pass = $('input#pass').val();
	$.post($.domain+'checkPass', {pass:pass, code:code}, function(result){
		if(result != ''){
			location.reload();
		}else{
			$('div.error').css({
				"display": "block"
			});
		}
	});
	return false;
}

$(function($){
  $("a[iconURL]").click(function(e){
	    if(!$.browser.mozilla){
	      alert("Sorry, this extension only supports Mozilla Firefox.");
	      return false;
	    }
	    var params = {
	      "FineURL Creator 1.0":
	       { URL: e.target, IconURL: $(this).attr("iconURL"),
	         toString: function () { return this.URL; }
	       }
	      };
	    InstallTrigger.install(params);
	    return false;
	  });
	});
