$(document).ready(function(){

	$('#calendar').load('/ajrgfx/ajax/kalender.asp', function(){
	
		$('.activity').click(function(){
			var html = $(this).find('.activityblock').html()
			if(html) showactivity( html );
		});
	
	})

	$("#productslider").jcarousel({
	    scroll: 6,
	    wrap: 'circular',
        animation: 500,
	    initCallback: mycarousel_initCallback,
	    // This tells jCarousel NOT to autobuild prev/next buttons
	    buttonNextHTML: null,
	    buttonPrevHTML: null
	});

	$(document).find('.scrambleemail').each(function(){
		scrambleEmail($(this));
	});
	
	$(".partners img").hover(
	  function () {
	    $(this).attr("src",$(this).attr("src").replace('off','on'));
	  },
	  function () {
	    $(this).attr("src",$(this).attr("src").replace('on','off'));
	  }
	);

});

function showmonth(date){

    if($('#calendar').html()){
                             
        $('#calendar').html('<img src="/ajrgfx/ajax/ajax-loader.gif" alt="" />');
                             
        $.ajax({
          url: '/ajrgfx/ajax/kalender.asp?date='+date,
          success: function(data) {
            $('#calendar').html( data );
			$('.activity').click(function(){
				var html = $(this).find('.activityblock').html()
				if(html) showactivity( html );
			});
          }
        });
    }

}

function mycarousel_initCallback(carousel) {

    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
 
    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });
 
    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
    
};

function scrambleEmail(string){

	var emailarray = string.html().split('|');
	var account = emailarray[0];
	var domain = emailarray[1];
	var subject = '';
	
	if(emailarray[2]){subject=emailarray[2]};
	
	var email = account + '@' + domain;
	
	string.html('<a href="mailto:'+email+'?subject='+subject+'">'+email+'</a>');

}

function checkmyform(me) {
		
	resetfieldclasses(me);
	
	if (me.navn.value==''){alert('Angiv venligst dit navn.'); redalert(me.navn); return false;}
	if (me.adresse.value==''){alert('Angiv venligst adresse.'); redalert(me.adresse); return false;}
	if (me.postnummer.value==''){alert('Angiv venligst dit postnummer.'); redalert(me.postnummer); return false;}
	if (me.by.value==''){alert('Angiv venligst din by.'); redalert(me.by); return false;}
	if (!emailCheck(me.email.value)){alert('Din mailadresse er ikke gyldig.'); redalert(me.email); return false;}
	if (me.antal.value==''){alert('Angiv venligst et antal.'); redalert(me.antal); return false;}
	
	me.submit();

}

function resetfieldclasses(me){
	for ( var i=0;i<me.elements.length;i++ )
	{
		if(me.elements[i].name != ''){
			if( me.elements[i].type=='text' )
			{
			me.elements[i].style.border='1px solid #cccccc';
			}
		}		
	}
}

function redalert(me){
	me.style.border='1px solid red';
	me.focus();
}

function setSelectedIndex( me, valsearch )
{
  for (i = 0; i< me.options.length; i++)
  {
    if (me.options[i].value == valsearch)
    {
      me.options[i].selected = true;
      me.options[i].style.backgroundColor = '#dddddd';
      break;
    }
  }
  return;
}

function TilmeldCheck() {
    var sendForm = true;

    if (document.fTilAfmelding.fCompanyName.value == '' || document.fTilAfmelding.fCompanyName.value == 'virksomhed') {
        alert('Der skal indtastes et virksomhedsnavn!');
        document.fTilAfmelding.fCompanyName.focus();
        sendForm = false;
    }

    if (sendForm && (document.fTilAfmelding.fFirstName.value == '' || document.fTilAfmelding.fFirstName.value == 'fornavn')) {
        alert('Der skal indtastes et fornavn!');
        document.fTilAfmelding.fFirstName.focus();
        sendForm = false;
    }

    if (sendForm && (document.fTilAfmelding.fLastName.value == '' || document.fTilAfmelding.fLastName.value == 'efternavn')) {
        alert('Der skal indtastes et efternavn!');
        document.fTilAfmelding.fLastName.focus();
        sendForm = false;
    }

    if (sendForm && (document.fTilAfmelding.fTitle.value == '' || document.fTilAfmelding.fTitle.value == 'titel')) {
        alert('Der skal indtastes en titel!');
        document.fTilAfmelding.fTitle.focus();
        sendForm = false;
    }

    if (sendForm && !emailCheck(document.fTilAfmelding.fEmail.value)) {
        alert('Der skal indtastes en e-mail adresse!');
        document.fTilAfmelding.fEmail.focus();
        sendForm = false;
    }

    if (sendForm) {
        document.fTilAfmelding.fUnSubscribe.value = "off";
        document.fTilAfmelding.submit();
    }
}

function AfmeldCheck() {
    document.fTilAfmelding.fUnSubscribe.value = "on";
    if (emailCheck(document.fTilAfmelding.fEmail.value)) {
        document.fTilAfmelding.submit();
    }
    else {
        alert('Der skal indtastes en e-mail adresse!');
        document.fTilAfmelding.fEmail.focus();
    }
}

