function suositteleYC(){
	if($('select[name=milla]').attr('value') == 'sposti'){
		$('#valSana').html('Sähköpostiosoite');
	}else{
		$('#valSana').html('Puhelinumero');
	}

	/*time = new Date();

	$.post('includes/suositteleAjax.php?anticache='+time.getTime(), {key: 'suosittele', value: uId }, function(data){

		$('#popupTable #include').html(data);
	});*/
}

$(document).ready(function(){
    $(function() { $(".lavaLampWithImage,.lavaLampWithImage2").lavaLamp({ fx: "backout", speed: 700 }); });

    $('.l_nick_cl, .l_pass_cl').click(function(){$(this).select();}).focus(function(){$(this).select();});

	function GETvalue( name ){
    	var results = new RegExp( "[\\?&]"+name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]")+"=([^&#]*)" ).exec( window.location.href );
    	return ( results ) ? results[1] : "";
	}

	function numbersonly(tthis,e,decimal) {
  		var key  = window.event ? window.event.keyCode : e ? e.which : true;
  		var keychar = String.fromCharCode(key);
  		if ( ('|0|8|9|13|27|').indexOf('|'+key+'|')>-1 || ('0123456789').indexOf(keychar) > -1 || key===true )   return true;
  		else if ( ('.,0123456789').indexOf(keychar) > -1 && tthis.value!='' && decimal && tthis.value.indexOf(',')==-1 && tthis.value.indexOf('.')==-1 ) return true;
  		else return false;
 	}

	function getFileExt(filename)
	{
		if(filename.length == 0)
			return false;

		var dot = filename.lastIndexOf('.');

		if(dot == -1)
			return false;

		var ext = filename.substr(dot, filename.length);

		return ext;
	}

	function allowExt(ext)
	{
		if(ext == false)
			return false;

		var validExt = new Array();

		validExt[0] = '.jpg';
		validExt[1] = '.jpeg';
		validExt[2] = '.gif';
		validExt[3] = '.png';

		for(i=0;i<validExt.length;i++)
		{
			if(validExt[i] == ext)
				return true;
		}

		return false;
	}

	$('.min_dropDown').change(function(){
		var dd_html = '';
		var currentVal = $(this).val();
		var maxVal = $('.kpl_val').val();

		for(var i = 1; i <= maxVal; i++){
			if(i >= currentVal)
				dd_html += '<option value='+i+'>'+i+'</option>';
		}

		$(this).parent().parent().next().children().next().children().html(dd_html);
	});

	$('#haku_input_search').click(function()
		{
			if($(this).val() == 'Haku')
				$(this).val('');
		}
	);

	$('.custom_tooltip').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		extraClass: "pretty",
		fixPNG: true,
		left: 35,
		top:-25
	});

	$(".kohde_item_over").live('mouseover',function(){
		$(this).css('background-image', 'url(images/kohde_over.png)');
	});

	$(".kohde_item_over").live('mouseout',function(){
		$(this).css('background-image', 'url(images/lp.gif)');
	});

	$(".kohde_img_over").mouseover(function(){
		$(this).css('background-image', 'url(kohde_images/no_image.jpg)');
	});

	$(".kohde_img_over").mouseout(function()
		{
			$(this).css('background-image', 'none');
		}
	);

	$(".tyyppi").click(
		function(){
			if ( $(this).attr("value") == 1 )
				$(".kt").hide();
			else
				$(".kt").show();
		}
	);

	$(".v_kuva").toggle(
		function()
		{
			$(".l_kuva").slideDown("slow");
		},
		function()
		{
			$(".l_kuva").slideUp("slow");
		});

	$(".kys_but").toggle(function()
		{
			$("#kysymys").fadeIn();
		},function()
		{
			$("#kysymys").fadeOut();
		}
	);

	$(".vast").toggle(function()
		{
			$(this).parent().parent().parent().parent().parent().parent().parent().parent().next().fadeIn();
		},function()
		{
			$(this).parent().parent().parent().parent().parent().parent().parent().parent().next().fadeOut();
		}
	);

	$(".onlyNums").keypress(function(e){return numbersonly(this,e,false);});
	$(".onlyNums2").keypress(function(e){return numbersonly(this,e,true);});
	$(".onlyNumsChk").keypress(function(e){return numbersonly(this,e,false);});
	$(".onlyNumsChk2").keypress(function(e){return numbersonly(this,e,true);});

	$("#kohden_nimi").keyup(function()
		{
			if($(this).val().length >= 3 && $(this).val().length <= 50)
				$(this).next().fadeOut();
			else
				$(this).next().fadeIn();
		}
	).trigger('keyup');

	$(".onlyNums").keyup(function()
		{
			if($(this).val()*1 > 0)
				$(this).next().hide();
			else
				$(this).next().show();
		}
	).trigger('keyup');

	$(".onlyNumsChk").keyup(function()
		{
			if($(this).val()*1 > 0)
				$(this).parent().next().next().hide();
			else
				$(this).parent().next().next().show();
		}
	).trigger('keyup');

	$(".onlyNums2").keyup(function()
		{
			var inputValue = $(this).val();

			if(inputValue.search(',') != -1)
				inputValue = $(this).val().replace(',','.');

			if(inputValue*1 >= 0.1)
				$(this).next().hide();
			else
				$(this).next().show();
		}
	).trigger('keyup');

	$(".onlyNumsChk2").keyup(function()
		{
			var inputValue = $(this).val();

			if(inputValue.search(',') != -1)
				inputValue = $(this).val().replace(',','.');

			if(inputValue*1 > 0)
				$(this).parent().next().next().hide();
			else
				$(this).parent().next().next().show();
		}
	).trigger('keyup');

	$("#kohde_kuva").change(function()
		{
			if(allowExt(getFileExt($(this).val())))
				$(this).next().hide();
			else
				$(this).next().show();
		}
	);

	$(".selArea").click(function()
		{
			if(($(".toimitus_tapa1").attr('checked') == true) || ($(".toimitus_tapa2").attr('checked') == true) || ($(".toimitus_tapa5").attr('checked') == true) ||
					($(".toimitus_tapa3").attr('checked') == true) || ($(".toimitus_tapa4").attr('checked') == true)) {
				$(".valita1").fadeOut();
			}else {
				$(".valita1").fadeIn();
			}

			if(($(".maksu_tapa1").attr('checked') == true) || ($(".maksu_tapa2").attr('checked') == true) ||
					($(".maksu_tapa3").attr('checked') == true) || ($(".maksu_tapa4").attr('checked') == true)) {
				$(".valita2").fadeOut();
			}else{
				$(".valita2").fadeIn();
			}
	});

    /* osasto menun keskiosa hover käsittely */
    var timer;
	$('.alaosasto').hover(
		function(){
			$('.alahovermenu').hide(0);
            if ( $.browser.msie )   $(this).prev().fadeIn(200);
			else                    $(this).prev().css('left',$(this).offset().left*1+156+'px').fadeIn(200);

		},function(){
			tama = $(this).prev();
			timer = setTimeout('tama.fadeOut(200);',100);
		}
	);
    $('.alahovermenu').hover( function(){ clearTimeout(timer); },function(){ $(this).fadeOut(200); });
    /* hover end */

    $('#infospan').show(0).css('opacity','0.0');
    $('#huuto_tarjous').keyup(function(){
        ms = 250;
        if ( $(this).val() >= $('#minimi_hinta').val() )
            $('#infospan').stop().animate({opacity:0.0},ms);
        else
            $('#infospan').stop().animate({opacity:1.0},ms).animate({opacity:0.2},ms).animate({opacity:1.0},ms).animate({opacity:0.2},ms).animate({opacity:1.0},ms);
    });
//  KOHTEEN KUVAUKSEN LISÄYS
    $('#lisaa_kuvaukseen').toggle(
        function(){ $(this).next().slideDown(500); },
        function(){ $(this).next().slideUp(500); }
    );

    /*
	function tarkista_ytunnus(yt){ /* y-tunnuksen tarkistusfunktio
        yt.replace(/^\s+|\s+$/g, '');
        tnum = yt.substr(yt.length-1,1);
        yt = ( (yt.substr(0,(yt.length-2))).length==6 ? 0 : '' )+yt.substr(0,(yt.length-2));
        sum = 0;
        if ( yt.length == 7 )
            for( var i in numarr = Array(7,9,10,5,8,4,2)  )
                sum += yt[i] * numarr[i];
        return ( sum%11!=1 && sum!=0 && (sum%11==0 && sum%11==tnum || 11-sum%11==tnum ) ? true : false );
    }
	*/

	$(".uutinen_plus").toggle(
		function(){$(this).css('background-image',"url('images/minus.png')");$(this).parent().next().children().children().slideDown(700)},
		function(){$(this).css('background-image',"url('images/plus.png')");$(this).parent().next().children().children().slideUp(700)}
	);
	$(".uutinen_plus:first").trigger('click');

	$("#checkbox_korotusautomaatti").click(function(){
		if ( $(this).attr('checked') )
			$("#kohdeInfo_huuda").html('Maksimi huutohinta');
		else
			$("#kohdeInfo_huuda").html('Huuda');
	});

	//Mikä kuva laitataan kohteeseen "ilmoita kohde uudelleen" sivulla?
 if($('.kuvaToupload2').attr('checked') == true){
  $('.kuvaToupload').hide();
 }else{
  $('.kuvaToupload').show();
 }

 $('.kuvaToupload2').click(function(){
  if($('.kuvaToupload').css('display') == 'inline'){
   $('.kuvaToupload').hide();
  }else{
   $('.kuvaToupload').show();
  }
 });

    /*if ( $('#huudot').height() > 400 ) /* HUUTAJAT kentän korkeuden hallinta kohde_info sivulla
        $('#huudot').css({'height':'400px','overflow':'auto'});            */
});