
function log(m){ 
   try {
   if (typeof console != 'undefined') { console.log(m); }  
   }catch(e){
      //alert(e.message);
   }
   
}


//**************************************************************
//Event handlers for styling input fields on hover, blur, focus

$('.input').live('focus', function(){
	$(this).removeClass('inputHover');
	$(this).addClass('inputFocus');
	$('#scrollcover').css('background-position', '0 96px');
});

$('.input').live('blur', function(){
	$(this).removeClass('inputFocus');
	$('#scrollcover').css('background-position', '0 0');
});

$('.input').live('mouseenter', function(){
	if(!($(this).hasClass('inputFocus'))){
		$(this).addClass('inputHover');
	    $('#scrollcover').css('background-position', '0 -96px');
	}
});

$('.input').live('mouseout', function(){
	if($(this).hasClass('inputHover')){
		$(this).removeClass('inputHover');
		$('#scrollcover').css('background-position', '0 0');
	}
});


//**************************************************************
//Preloading of images

$.fn.preload = function() {
    this.each(function(){
        $('<img/>')[0].src = this;
    });
}


//**************************************************************
//Cheeseball generic ajax request 
function createRequest() {
  try {
    request = new XMLHttpRequest();
  } catch (tryMS) {
    try {
      request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (otherMS) {
      try {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (failed) {
        request = null;
      }
    }
  }	
  return request;
}


//**************************************************************
// Animation function for fading preview images in and out. Excludes IE7 and lower
function dtFade(elemId, toOpacity, duration){
	if (!$('html').hasClass('ie7')){
		$('#'+elemId).fadeTo(duration,toOpacity);
	}
}

//**************************************************************
//Cheezeball function for showing and hiding UI elements on DT composer page. codesdlg function and emaildlg_simple functions use this.
function hideshow(id, action){
	//log('in hideshow function, theme is '+theme+' and id is '+id);
			
		
			if (action == 'hide'){
				//log('					in hideshow function, hiding');
				if (!$('html').hasClass('ie7')){
					setTimeout(function(){
					$('.dt-fadeable').fadeTo(300,0);
						setTimeout(function(){
							$('#'+id).show();
							$('#'+id).css('opacity', 0);
							$('#'+id).fadeTo(300, 1);
						},300);
	
					},0);
				}else{
					$('.dt-fadeable').css('visibility','hidden');					
					$('#'+id).css('display', 'block');
				}
			

			}else if(action == 'show'){
				//log('					in hideshow function, showing');
			
				if (!$('html').hasClass('ie7')){
					setTimeout(function(){
						$('#'+id).fadeTo(300, 0);
						$('#'+id).hide();
						setTimeout(function(){
							$('.dt-fadeable').fadeTo(300,1);
						},300);
				
					},0);
			    }else{
				    $('.dt-fadeable').css('visibility','visible');
					$('#'+id).css('display', 'none');
				}
			}else{
		 		//log('					id undefined, doing nothing');
			}
}


