$(document).ready(function(){
	formGrade('neu');
	
	if ($('input#city').length > 0) {
		var url = $("#autocomplete_url").val();
		$('input#city').jsonSuggest(
			function(text, wildCard, caseSensitive, notCharacter) {
				  $('#city').css("background", "white url("+URL_PATH+"gfx/wait.gif) no-repeat right");
		          rez = $.ajax({
		          type: 'GET',
		          url: url,
		          data: 'q=' + text,
		          dataType: 'json',
		          async: false, 
				  complete: function(e){ $('#city').css("background", "white"); }
		        });
		        return eval(rez.responseText);
			}, { ajaxResults: true, onSelect: function(item) { $('#province').val(''+(item.id)); }
		});
	}
	
	if ($('input#city_account_edit').length > 0) {
		var url = $("#autocomplete_url").val();
		$('input#city_account_edit').jsonSuggest(
		function(text, wildCard, caseSensitive, notCharacter) {
			  $('#city').css("background", "white url("+URL_PATH+"gfx/wait.gif) no-repeat right");
			  rez = $.ajax({
			  type: 'GET',
			  url: url,
			  data: 'q=' + text,
			  dataType: 'json',
			  async: false, 
			  complete: function(e){ $('#city_account_edit').css("background", "white"); }
			});
			return eval(rez.responseText);
			}, {ajaxResults: true, onSelect: function(item){$('$province').val(''+(item.id)); }
		});
	}
	
	if ($("#description").length > 0) {
		CKEDITOR.replace( 'description', { toolbar: 'Basic', height: 300, width: 600, entities: false, entities_latin: false, entities_processNumerical: false, disableNativeSpellChecker: true, scayt_sLang: 'pl', scayt_autoStartup: false });
	}
	if ($("#company_description").length > 0) {
		CKEDITOR.replace( 'company_description', { toolbar: 'Basic', height: 300, width: 490, entities: false, entities_latin: false, entities_processNumerical: false, disableNativeSpellChecker: true, scayt_sLang: 'pl', scayt_autoStartup: false });
	}
	if ($("#company_edit_profile").length > 0) {
		CKEDITOR.replace( 'company_edit_profile', { toolbar: 'Basic', height: 300, width: 490, entities: false, entities_latin: false, entities_processNumerical: false, disableNativeSpellChecker: true, scayt_sLang: 'pl', scayt_autoStartup: false });
	}
	if ($("#ad_description").length > 0) {
		CKEDITOR.replace( 'ad_description', { toolbar: 'Basic', height: 300, width: 450, entities: false, entities_latin: false, entities_processNumerical: false, disableNativeSpellChecker: true, scayt_sLang: 'pl', scayt_autoStartup: false });
	}
	
	$(".question").tipTip();
});

function formGrade(obj){
	var id = 'grade-'+obj;
	$('#grade-neu').css("fontWeight", "normal");
	$('#grade-neg').css("fontWeight", "normal");
	$('#grade-pos').css("fontWeight", "normal");
	$('#grade-neu').css("textDecoration", "none");
	$('#grade-neg').css("textDecoration", "none");
	$('#grade-pos').css("textDecoration", "none");
	$('#grade-neu').css("color", "#A4ABEE");
	$('#grade-neg').css("color", "#FE7A7A");
	$('#grade-pos').css("color", "#69F16C");
	$("#"+id).css("fontWeight", "bold");
	$("#"+id).css("textDecoration", "underline");
	if(obj=='neg'){
		$("#"+id).css("color", "#F00");
		$('#grade').val('0');
	}else if(obj=='neu'){
		$("#"+id).css("color", "#3C56D2");
		$('#grade').val('1');
	}else{
		$("#"+id).css("color", "#1BC567");
		$('#grade').val('2');
	}
	$("#"+id).blur();
}

function showForm(id){
	document.getElementById('form-start').style.display = '';
	document.getElementById('form-end').style.display = '';
	if(id=='company'){
		document.getElementById('form-company').style.display = '';
	}else{
		document.getElementById('form-company').style.display = 'none';
	}
}
