$(document).ready(function(){
  //IE background flickering
  if(jQuery.browser.msie && jQuery.browser.version==6.0) 
    document.execCommand("BackgroundImageCache",false,true);
    
  $('a[rel=external]').bind('click',function(){$(this).attr('target','_blank')});
   
  // FirstChild and LastChild class
  var FirstAndLastChild = function(){
    if($.browser.msie || $.browser.opera){
      $('li:first-child').addClass('FirstChild');
      $('li:last-child').addClass('LastChild');
    }
    if($.browser.safari){
	     $('li:last-child').addClass('LastChild');
    }
  }
  FirstAndLastChild();
  Cufon.replace('h1,h2,h3,h5,h6');
  Cufon.replace('h4', {ignore: {span: 1}}); 
  Cufon.replace('.quote h3',{fontStyle:'italic'});
  $('.tabularData1 tr:odd').addClass('odd');
  $('.tabularData2 tr:odd').addClass('odd');
  
	 //auto text handler
	 $('.nav0search #s')
	.each(function(){
		var autoText = "";
		 var defaultText = $(this).val();
		 $(this).bind('focus',function(){
		   autoText = $(this).val();
		   if(autoText == defaultText) $(this).val("");
		 })
		.bind('blur',function(){
			if($(this).val() == "")
			   $(this).val(defaultText);
		  });
	});
	
	$('.back').click(function() {
	 window.history.back();
	 return false;
    });
	
	$('select[name=programme],select[name=register-now]').change(function(){
		if($('select[name=register-now]').val() == 'Enrol me' && $("select[name=programme]").val() == 'talking Presentations'){ 
			document.location.href = '/shop/product-category/talking-presentations/';
		}
	});
	
	
	
	
	SubscribeMe();
	   
}); 

function SubscribeMe(){
	$('.textwidget .Submit1').click(function() {
        if(!isValidEmail($('#SubscribeEmailId').val())){
			$(".textwidget label").show();
		}else{
			document.location.href = '/register-now/?email='+ $('#SubscribeEmailId').val();
			$(".textwidget label").hide();
		}
	 return false;
    });
}

//function to check valid email address
function isValidEmail(strEmail){
 
 validRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
 
 var Email = strEmail;

  // search email text for regular exp matches
  if (Email.search(validRegExp) == -1 || Email.length == 0) 
  {
     return false;
  } 
   return true; 
}
