//kuvaurlin vaihto (mm. nappien efektit)
function imgSrc(el,url){
	document.getElementById(el).src = url;
}

//tarkistetaan kirjautuminen
function checkLoginFields(){
	
	if(document.loginform.lemail.value=="" && document.loginform.lpass.value==""){
		alert("Tunnus ja salasana on pakollinen");
		return false;
	}
	return true;
}

//henkilötietojen tarkistus muokattaessa ja lisättäessä
function checkUserInfo(type){

	if(document.tiedot.etunimi.value==""){
		alert("Etunimi on pakollinen");
		document.tiedot.etunimi.focus();
		return false;
	}
	else if(document.tiedot.sukunimi.value==""){
		alert("Sukunimi on pakollinen");
		document.tiedot.sukunimi.focus();
		return false;
	}
	else if(document.tiedot.katuosoite.value==""){
		alert("Katuosoite on pakollinen");
		document.tiedot.katuosoite.focus();
		return false;
	}
	else if(document.tiedot.postinumero.value==""){
		alert("Postinumero on pakollinen");
		document.tiedot.postinumero.focus();
		return false;
	}
	else if(document.tiedot.toimipaikka.value==""){
		alert("Toimipaikka on pakollinen");
		document.tiedot.toimipaikka.focus();
		return false;
	}
	else if(document.tiedot.puhelin.value==""){
		alert("Puhelin on pakollinen");
		document.tiedot.puhelin.focus();
		return false;
	}
	else if(document.tiedot.email.value==""){
		alert("Email on pakollinen");
		document.tiedot.email.focus();
		return false;
	}

	if(type=="1" || type==null && document.tiedot.salasana.value!="" || type==null && document.tiedot.salasana2.value!=""){

		if(document.tiedot.salasana.value==""){
			alert("Salasana on pakollinen");
			document.tiedot.salasana.focus();
			return false;
		}
		else if(document.tiedot.salasana2.value==""){
			alert("Syötä salasana uudelleen");
			document.tiedot.salasana2.focus();
			return false;
		}	
		else if(document.tiedot.salasana.value!=document.tiedot.salasana2.value){
			alert("Tarkista salasana!\nSyötä salasana uudelleen.");
			document.tiedot.salasana2.value = "";
			document.tiedot.salasana2.focus();
			return false;
		}
	}

	return true;
}

/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
/**
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
		var index = $(this).attr("id").split("_");
		carousel.scroll(jQuery.jcarousel.intval(index[1]));
        //carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		$(".jcarousel-control a").removeClass("active"); //Remove any "active" class
		$(this).addClass("active");
        return false;
    });
    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });
**/
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
		var index = $(this).attr("id").split("_");
		carousel.scroll(jQuery.jcarousel.intval(index[1]));
        //carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		$(".jcarousel-control a").removeClass("active"); //Remove any "active" class
		$(this).addClass("active");
        return false;
    });


    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
    	wrap: 'circular',
        scroll: 1,
        initCallback: mycarousel_initCallback,
        auto: 5,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null,
        itemVisibleInCallback: {
            onAfterAnimation: function(c, o, i, s) {
            --i;
              jQuery('.jcarousel-control a').removeClass('active').addClass('inactive');
              jQuery('.jcarousel-control a:eq('+i+')').removeClass('inactive').addClass('active');
            }
          }

    });
});
