$(function() {
    hiConfig = {
        sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
        interval: 0, // number = milliseconds for onMouseOver polling interval
        timeout: 0, // number = milliseconds delay before onMouseOut
        over: function() {

		$('#submenu').html( $('#parentnode'+$(this).attr('id')).html() );
	  
		if($('#parentnode'+$(this).attr('id')).length>0){
		
			if($(this).attr('class')!='selected'){

				$(this).css('background-color','#00344a');
				$(this).css('border-bottom','1px solid #00344a');
				
			}

		}

        },
        out: function() {
        
			if($(this).attr('class')!='selected'){
        
				$(this).css('background-color','#7ac8ed');
				$(this).css('border-bottom','none');
				
			}
			
		}
    }
    $('#udm li').hoverIntent(hiConfig)
});

$(document).ready(function(){

	$(document).find('.scrambleemail').each(function(){
		scrambleEmail($(this));
	});
	
	
	$(".top").mouseleave(
	  function () {
		$('#submenu').html( '' );
	  }
	);
	
	$("#siteselect").hover(
	  function () {
		$('#Countries').stop('true','true').slideDown()
	  },
	  function () {
	    $('#Countries').slideUp('slow')
	  }
	);		
	
	
	$(".partners img").hover(
	  function () {
	    $(this).attr("src",$(this).attr("src").replace('off','on'));
	  },
	  function () {
	    $(this).attr("src",$(this).attr("src").replace('on','off'));
	  }
	);

});

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 validateform( me ){

	$(me).find('input.alert').each( function(){
	
		$(this).css('border','none');
		$(this).removeClass('alert')
	
	});
	
	var doSubmit = true;

	$(me).find('input.required').each( function(){
	
		if( $(this).attr('type') == 'checkbox' ){
		
			if( ! $(this).attr('checked') ){
			
				alert( $(this).attr('title') );
				
				doSubmit = false;
			
			}
		
		}
		
		if( $(this).attr('class').indexOf('email') > 0 ){
		
			if( !emailCheck( $(this).val() ) ){

				$(this).css('border','1px solid red');
				$(this).addClass('alert')
			
				doSubmit = false;
			
			}
		
		} else {
		
			if ( $(this).val() == '' ){
		
				$(this).css('border','1px solid red');
				$(this).addClass('alert')
				
				doSubmit = false;
		
			}
			
		}
		
	});

	$('.alert').focus( function(){
		$(this).css('border','none');
		$(this).removeClass('alert');
	})
	
	if ( doSubmit ){ me.submit() }

}



function checknewsletterform(me) {
		
	resetfieldclasses(me);
	
	if (me.AjrFmUserFirstName.value==''){alert(me.alertname.value); redalert(me.AjrFmUserFirstName); return false;}
	if (!emailCheck(me.AjrFmUserEmail.value)){alert(me.alertemail.value); redalert(me.AjrFmUserEmail); 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;
}
