jQuery(document).ready(function($){

	var beforeValidation = function() {};
    var onSuccess = function() {};
    var onPostSuccess = function() {};
    var onFailure = function() {};
    var afterValidation = function() {}; 
	
	
	$('.dropdown li').each(function(){
		$(this).hover(function(){
			next = $(this).children('.dropdown');
			next.removeClass('off');
		}, function(){
			next = $(this).children('.dropdown');
			next.addClass('off');
		});
	});
	
	// investor information package step1
	if ( $('#investorPackage1').length > 0 ) {
		$('#submitStep1').click(function() {
			var n = $("input:checked").length;
			if (n >= 1) {
				document.package1.submit();
			} else {
				alert('Please select at least one document before continuing');
			}
		});
	}
	
	// investor information package step2
	if ( $('#step2FormContainer').length > 0 ) {  
	  $('#step2FormContainer > form').ketchup(
	  	{ 
	  		onFailure : onFailure,
	        beforeValidation : beforeValidation,
	        onSuccess : onSuccess,
	        afterValidation : afterValidation,
	        useFormSubmit : true
	  	}
	  );
  	}
  	
  	// resume submission via modal
	if ( $('#resumeContainer').length > 0 ) {  
	  $('#resumeContainer > form').ketchup(
	  	{ 
	  		onFailure : onFailure,
	        beforeValidation : beforeValidation,
	        onSuccess : onSuccess,
	        afterValidation : afterValidation,
	        useFormSubmit : true
	  	}
	  );
  	}
  	
  	// email contact submission via modal
	if ( $('#emailContainer').length > 0 ) {  
	  $('#emailContainer > form').ketchup(
	  	{ 
	  		onFailure : onFailure,
	        beforeValidation : beforeValidation,
	        onSuccess : onSuccess,
	        afterValidation : afterValidation,
	        useFormSubmit : true
	  	}
	  );
  	}
  	
  	// header search box - keypress enter
  	$('#searchInput').bind('keypress', function(e) {
	        if(e.keyCode==13){
	              var field = $(this);
				  var val = $.trim(field.val());  
				  if (val.length < 3) {
				  	alert('Minimum of 3 characters are required for searching');
				  	return false;
				  } else {
				  	$('#headerSearch').submit();
				  }
	        }
	});
	
	// header search box - label click
	$('#searchLabel').click(function() {
		var field = $('#searchInput');
		var val = $.trim(field.val());
		if (val.length < 3) {
		  	alert('Minimum of 3 characters are required for searching');
		  	return false;
		} else {
		  	$('#headerSearch').submit();
		}
	});

	
});

function disableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}


Shadowbox.init({
    // let's skip the automatic setup because we don't have any
    // properly configured link elements on the page
    skipSetup: true
});

function resumeModal(path) {
	Shadowbox.open({
			        content:    path,
			        player:     "iframe",
			        height:     830,
			        width:      700
			    });
}


function changeRatingTab(tab, filter) {
		$('#ratingsContainer').load('/ajax/ratings_router/'+Math.random()*99999, { ratingsTab: tab, ratingsFilter: filter });
}

function submitRatingsRedirect() {
	document.ratingRedirect.submit();
}

function changePresentationTab(theFilter) {
		$('#presentationContainer').load('/ajax/presentation_router/'+Math.random()*99999, { filter: theFilter });
}

function submitPresentationRedirect() {
	document.presentationRedirect.submit();
}

function requestArchive(type) {
	$('#list').load('/ajax/by_company_archive/'+type+'/'+Math.random()*99999);
}
