$(document).ready(function($) {
	// handle new window links
	$('a[href^="#"]').bind('click', function(){ return false; });
	$('a.external, a[rel="external"]').attr('target', '_blank');


	$('#ad_size_name_listing').change(function(){
						$('#ad_name_listing').val('Name Listing in Program Book as:\''+$('#ad_size_name_listing').val()+'\'');
				});


 /* $('input[type="text"]').each(function(){

	this.value = $(this).attr('title');
	$(this).addClass('defaultText');

	$(this).focus(function(){
		if(this.value == $(this).attr('title')) {
			this.value = '';
			$(this).removeClass('defaultText');
		}
	});

	$(this).blur(function(){
		if(this.value == '') {
			this.value = $(this).attr('title');
			$(this).addClass('defaultText');
		}
	});
});
*/

$("#ad_form, #auction_form").validate({
	errorPlacement: function(error,element){
							if(element.attr('id') == 'item_for_silent_auction') {
								error.appendTo('#auctionType');
							} else if(element.attr('id') == "ad_size_full" || element.attr('id') == "ad_size_half" || element.attr('id') == "ad_size_qtr" || element.attr('id') == "ad_name_listing") {
								error.insertAfter('#ad_size_name_listing');
							} else {
								error.insertAfter(element);
							}
			},
			
			/*rules: {
				Ad_Type: {
					required: true
				}
			},*/
			messages: {
					Ad_Type: "Please select at least (1) advertisement size"
			
			},
			
			
		 submitHandler: function(form) { 
		 
				var formName = form.id;
   	var ajaxResponse = $('#'+formName).find('.response');
				var loader = '<div class="spinner right">&nbsp;</div>';
				var formAction = $('#'+formName).attr('action');
				var dataString = $("#"+formName+"").serialize();		
				
				ajaxResponse.hide();
				 
   $.ajax({
    type: "POST",
    cache: false,
    url: formAction,
    data: dataString,
   	dataType: "json",
   	beforeSend: function(){
						$('#'+formName+' .spinner').show();
						$('#'+formName+' .submitBtn').hide();				
	   	},
	   		error: function(XMLHttpRequest, textStatus, errorThrown) {
							ajaxResponse.html("<p>Ajax error: "+textStatus+" "+errorThrown+"</p>").fadeIn();
							},
	   success:  function(data){
		   	scroll(0,0);
	    	$('#'+formName+' .spinner').hide();
						$('#'+formName+' .submitBtn').show();			
						
						if (data.STATUS == 'success') {
					   			ajaxResponse.html('<p class="'+data.STATUS+'">'+data.MESSAGE+'</p>').fadeIn();
											$('#'+formName+' fieldset').hide();
		 		  } else {
 			   			ajaxResponse.html('<p class="'+data.STATUS+'">'+data.MESSAGE+'</p>').fadeIn();
		 		  }     
							}
			                
			  });

    
    		}

			  });


	/*
	 $('.ajaxForm').submit(function() {

				var ajaxResponse = $(this).find('.response');
				var loader = '<div class="spinner right">&nbsp;</div>';
				var formAction = $(this).attr('action');
				var formName = $(this).attr('id');
				var dataString = $("#"+formName+"").serialize();

				ajaxResponse.hide();
				 
   $.ajax({
    type: "POST",
    cache: false,
    url: formAction,
    data: dataString,
   	dataType: "json",
   	beforeSend: function(){
						$('#'+formName+' .spinner').show();
						$('#'+formName+' .submitBtn').hide();				
	   	},
	   		error: function(XMLHttpRequest, textStatus, errorThrown) {
							ajaxResponse.html("<p>Ajax error: "+textStatus+" "+errorThrown+"</p>").fadeIn();
							},
	   success:  function(data){
		   	scroll(0,0);
	    	$('#'+formName+' .spinner').hide();
						$('#'+formName+' .submitBtn').show();			
						
						if (data.STATUS == 'success') {
					   			ajaxResponse.html('<p class="'+data.STATUS+'">'+data.MESSAGE+'</p>').fadeIn();
											$('#'+formName+' table').hide();
		 		  } else {
 			   			ajaxResponse.html('<p class="'+data.STATUS+'">'+data.MESSAGE+'</p>').fadeIn();
		 		  }     
							}
			                
			  });
			return false;
			
		//	e.preventDefault();
			 
				});
	
	*/
	
	
	

});


var win = null;
function launchVideo(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}

