/**
 * 
 * @author Artod for ООО "Экспресс лаб"
 * http://MoiaVizitka.ru/Artod, http://artod.ru
 *
 * Copyright (c) 2009 ООО "Экспресс лаб" http://expresslab.ru
 *
 */

 function setStartPage(obj)
{



	

  if (document.all)
  {
    obj.style.behavior='url(#default#homepage)';
    obj.setHomePage('http://newsufa.ru');
  }
/*   else
    if(!document.layers)
    {
      netscape.security.PrivilegeManager.enablePrivilege­("UniversalPreferencesWrite");
      navigator.preference("browser.startup.homepage", "http://newsufa.ru"); 
    } */
}
 
 
 function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
 
function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}


$(document).ready(function(){

	
	
	$("a.fancybox").fancybox({
		'zoomOpacity' : false,
		'overlayShow' : true,
		'hideOnContentClick' : false,
		'overlayOpacity' : '0.8',
		'zoomSpeedIn' : '200',
		'zoomSpeedOut' : '200',
		'centerOnScroll' : true,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	//$('a.a-native').click(function(){
	

	$('.news_world').hide();
	

	$('a.a-native').click(function(){
		$(this).css('font-weight', 'bold');
		$('a.a-world').css('font-weight', 'normal');
		var parent = $(this).parents('div.news_samples');
		parent.find('.news_world').hide();
		parent.find('.news_native').fadeIn('fast');
		return false;
	});
	$('a.a-world').click(function(){
		$(this).css('font-weight', 'bold');
		$('a.a-native').css('font-weight', 'normal');
		var parent = $(this).parents('div.news_samples');
		parent.find('.news_native').hide();
		parent.find('.news_world').fadeIn('fast');
		return false;
	});
	
	
	$('.errorMessage').live('click',
		function(){
			$(this).fadeOut('slow', function(){$(this).remove();});
		}
	);
	
	$('.successMessage').live('click',
		function(){
			$(this).fadeOut('slow', function(){$(this).remove();});
		}
	);
	
	

	$('#calculation').click(
		function(){
			removeMess();
			
			var court = parseInt($("select#court option:selected").val());
			var price = parseFloat($("#price").val().replace(',', '.').replace(' ', ''));

			if (!court) {
				errMess('Выберите суд');
				return false;
			}
			else if (!price) {
				errMess('Введите цену иска');
				return false;
			}
			
			var res = 0;
			
			if (court == 2) {
				if (price <= 10000) {
					//до 10 000 рублей - 4 процента цены иска, но не менее 200 рублей;
					res = price/100*4;
					res = (res<200 ? 200 : res);
				}
				else if (price > 10000 && price <= 50000) {
					//от 10 001 рубля до 50 000 рублей - 400 рублей плюс 3 процента суммы, превышающей 10 000 рублей;
					res = 400 + (price-10000)/100*3;
				}
				else if (price > 50000 && price <= 100000) {
					//от 50 001 рубля до 100 000 рублей - 1 600 рублей плюс 2 процента суммы, превышающей 50 000 рублей;
					res = 1600 + (price-50000)/100*2;
				}
				else if (price > 100000 && price <= 500000) {
					//от 100 001 рубля до 500 000 рублей - 2 600 рублей плюс 1 процент суммы, превышающей 100 000 рублей;
					res = 2600 + (price-100000)/100*1;
				}
				else if (price > 500000) {
					//свыше 500 000 рублей - 6 600 рублей плюс 0,5 процента суммы, превышающей 500 000 рублей, но не более 20 000 рублей;
					res = 6600 + (price-500000)/100*0.5;
					res = (res>20000 ? 20000 : res);
				}
			}
			else if (court == 1) {

				if (price <= 50000) {
					//до 50 000 рублей - 4 процента цены иска, но не менее 500 рублей;
					res = price/100*4;
					res = (res<500 ? 500 : res);
				}
				else if (price > 50000 && price <= 100000) {
					//от 50 001 рубля до 100 000 рублей - 2 000 рублей плюс 3 процента суммы, превышающей 50 000 рублей;
					res = 2000 + (price-50000)/100*3;
				}
				else if (price > 100000 && price <= 500000) {
					//от 100 001 рубля до 500 000 рублей - 3 500 рублей плюс 2 процента суммы, превышающей 100 000 рублей;
					res = 3500 + (price-100000)/100*2;
				}
				else if (price > 500000 && price <= 1000000) {
					//от 500 001 рубля до 1 000 000 рублей - 11 500 рублей плюс 1 процент суммы, превышающей 500 000 рублей;
					res = 11500 + (price-500000)/100*1;
				}
				else if (price > 1000000) {
					//свыше 1 000 000 рублей - 16 500 рублей плюс 0,5 процента суммы, превышающей 1 000 000 рублей, но не более 100 000 рублей;
					res = 16500 + (price-1000000)/100*0.5;
					res = (res>100000 ? 100000 : res);
				}

			}
			else {
				succMess('O_o');
			}
			
			succMess('Размер госпошлины: '+res+' руб.');
			
			return false;
		}
	);
	
	$('#reset').click(
		function(){
			removeMess();
		}
	);

});

function removeMess() {
	$(".successMessage").fadeOut('slow', function(){$(this).remove();});
	$(".errorMessage").fadeOut('slow', function(){$(this).remove();});
}

function errMess(mess) {
	if (!mess)
		return;
	var id = 'errorMessage';
	$("#duty").prepend("<div class='"+id+"'>"+mess+"</div>");
	$("."+id+"").hide();
	$("."+id+"").fadeIn();
}


function succMess(mess) {
	if (!mess)
		return;
	var id = 'successMessage';
	$("#duty").prepend("<div class='"+id+"'>"+mess+"</div>");
	$("."+id+"").hide();
	$("."+id+"").fadeIn();
}
