// JavaScript Document
var successDiv = '<div class="system_messages green"><span class="ico"></span><strong class="system_title"></strong> <a href="#" class="close">CLOSE</a></div>';
var failDiv = '<div class="system_messages red"><span class="ico"></span><strong class="system_title"></strong> <a href="#" class="close">CLOSE</a></div>';

 	   ///////////  System Message Close /////////////////
$(function(){
	 $('a.close').live('click', function(){ $(this).parent()
		.slideUp(200, function(){$(this).remove();}
		
		);
		return false; 	  
	});		   
		   
		   });
/////////// End System Message Close ////// 


$(function(){
$("#URL").focus(function(){    // Select input field contents    this.select();});
this.select();
});

});


/*Team Hover
*
*
*/
$(document).ready(function(){
	
	$(".teamImage img").hoverIntent(function() {
		
		var name = $(this).attr("title");
		var data =$(this).attr("rel");
		$('.teamImage').removeClass('teamHover');
		$(this).parent().addClass('teamHover');
		
	/*	$(this).css({opacity:'0.4',
					filter: 'alpha(opacity=40)',
					padding: '0px',
					border: '1px solid #525b63'
					});
		*/
		
		$('.teamInfo p').html(data);
		$('.teamInfo h2').html(name);
			}, 
		//function off hover	
		function() {
			
		//$('.teamInfo h3').html('');
	});
});



/*
* Login Submission
* 
* Handles login functionality using AJAX, form still submits without javascript enabled.
*/


 $(function() {
		//listens for click of loginSubmit anchor
		$('#loginSubmit').click(function() {
			
			
			//grabs username and password;	
			var username = $('#user').val();
			var password = $('#pass').val();
			
			
			var showResult = function (type, msg) {
				$('#ContentPanel').stop().animate({height: '+=40'}, 1000);
				
				var divType;
				var errorMessages;
				var message;
				
				if(type == 'error'){
					divType = failDiv;
						
				} else if (type == 'success'){
					divType = successDiv;
				} else {
					return false;	
				}
				
				$('#ContentPanel').append('<div id="loginStatus"></div>');
				$('#loginStatus').append(divType);
				$('.system_title').text(msg);
				//timeout = setTimeout(removeResult, 10000);
			}
			
			var removeResult = function(){
				$('#ContentPanel').stop().animate({height: '-=40'}, 500, function() {
    			// Animation complete.
 				$('#loginStatus').remove();	
				});

			}
			
			if($('#loginStatus').length){
				removeResult();
			} 
			
			$('#loginSubmit span').text("Logging In...");
			  
						$.ajax({
												  
						url: 'process.php',
						type: 'POST',
						data: 'user=' + username + '&pass=' + password +'&sublogin=1',
						
						success: function(result) {
							
						
							//$('body').html('');
							//$('body').append(result);
							
							//$('body').html('');
							//$('body').append(result);
							$('#loginSubmit span').text("Sign In");
							//$("#overlay").css({background: 'none'});
							
	 
							var messageDiv; 
	
							if(result == "Successful" ) {
							//alert('success'); 
							showResult('success', 'Login Successful....Redirecting.');
							setTimeout(function(){removeResult();},2000);
							setTimeout(function(){location.reload();},3000);
							}else{
							showResult('error', result);
							//$('#ContentPanel').slideDown(800, 'easeOutQuart');
							//$.scrollTo('#ContentPanel');
		
							
							
							}

							
						}
					});			  
									  
									  
			
					
					
					return false;
				});
			
		  });
 
 
 //////////// END Login Submission /////////////////
 
 
 // WYSIWYG Functions ///
 //
 //
 //
$(document).ready(function(){
	$('#clearHTML').click(function(e){
		e.preventDefault();
		location.href = 'http://www.marketingg2.com/email/wysiwyg/';
		
	});
}); 
 
 
 //
 //
 // End WYSYIWG Functions ///
 
 
 
 
 //////Client Select Drop Down Form Submission ///////// 
 $(document).ready(function(){
   $(function() {
$("#ClientSelect").change(function() {
    $('#formClientSelect').submit();
});
 });
 }); 
//////// End //////////////


/*
* slideHTML Function
* 
* Handles sliding in and out of the listHTML
*/
$(document).ready(function(){
	if($.cookie('slideOut') == 'true'){
		$('#listHTML').css({right: '-220px'});
		$('#slideHTML').removeClass();
		$('#slideHTML').addClass('slideIn');
		$('#slideHTML').css({right: '-257px'});
			
	} else {
		$('#listHTML').css({right: '-20px'});
		$('#slideHTML').css({right: '-45px'});
	}
	
});

$(function() {
		//listens for click of SlideHTML anchor
		$('#slideHTML').click(function() {
		  		
				if($(this).hasClass('slideOut')){
						
						$('#listHTML').animate({
							right:'-220px'
						});
						$('#slideHTML').animate({
							right:'-257px'
						});
						$.cookie('slideOut', 'true');
				}
				else
				{
						$('#listHTML').animate({
							right:'-20px'
						});
						$('#slideHTML').animate({
							right:'-45px'
						});
						$.cookie('slideOut', 'false');
				}
				
				$(this).toggleClass('slideIn').toggleClass('slideOut');
					 
									  
			
					
					
					return false;
				}); // end click
			
});
 
 
 //////////// END HTML Slide /////////////////
 
 
   ////////// JHTML Submission ////////////////////////



 $(function() {
			//change to loginSubmit to activate again.
			$('#submitHTML').click(function(e) {
			e.preventDefault();
			$('.system_messages').remove(); // removes any errors that were shown previously.		 
			var html = $('#txtDefaultHtmlArea').htmlarea('toHtmlString');
			var action = $('#action').val();
			var html_id = $('#html_id').val();
			var title = $('#title').val();
			var active;
			
			if(title==''){
					$('.two-thirds').prepend(failDiv);
					$('.system_title').text('Please enter a title.');
					$('.system_messages')  
            		.css({display: 'none'}).slideDown(200);
					return false;
			}
						
			if(html==''){
					$('.two-thirds').prepend(failDiv);
					$('.system_title').text('Please enter some html.');
					$('.system_messages')  
            		.css({display: 'none'}).slideDown(200);
					return false;
			}	
			
			
			if($('#active').attr('checked')){
			active = 1;	
			} else {
			active = 0;
			}
			
			
			
			
			
			$('#jhtmlLoading').css({display: 'block'});
			//$('#submitHTML').text("Submitting");
									
					$.ajax({
						
					url: 'process.php',
					type: 'POST',
					data: 'html=' + html + '&jhtml=1' + '&action=' + action + '&html_id=' + html_id + '&title=' + title + '&active=' + active,
					
					success: function(result) {
						
					$('#jhtmlLoading').css({display: 'none'});
					//$('#submitHTML span').html('<span>Submitting</span>');
										
 					var message;
					
					
					
					var messageDiv;
					if(result == 1){
					
						if(action=='insert'){
						message = 'inserted html into ';
						var html_id2;
							
							
								$.ajax({
									
								url: 'process.php',
								type: 'POST',
								data: 'html=' + html + '&subGetLastHTMLID=1' + '&title=' + title,
								
								success: function(result) {
								$('#action').val('update');
								html_id2 = result;
								$('#html_id').val(html_id2)
								//$('#listHTML ul').delegate('li','hover', function(){
								//	$(this).parent().append('<li><a href="jhtml.php?html_id=' + html_id2 + '" class="tooltip" rel="' + html_id2 + '">' + title + '</a></li>');
								//});
								$('#listHTML ul').append('<li><a href="htmleditor.php?html_id=' + html_id2 + '" class="tooltip" rel="' + html_id2 + '">' + title + '</a></li>');
								
								var url;
								url = 'http://www.' + window.location.host + '/viewhtml.php?html_id=' + html_id2;
								$('#URL').val(url);						
								} // end success
							});					//end ajax.	
							
							
							
				
						} // end action is insert
						else{
							//action is update.
							
							message = 'updated ';	
						}
						//$('#html_id').val = 	
						
						messageDiv = successDiv;
						message = 'Successfully ' + message + 'the database';
					} // end result is successful 
					else 
					{
						messageDiv = failDiv;
					}
					
					$('.two-thirds').prepend(messageDiv);
					$('.system_title').text(message);
					$('.system_messages')  
            		.css({display: 'none'}).slideDown(200).delay(4000).slideUp(200);
						
					

						
					} // end success
				});					//end ajax.	
									
									
									
									
									
				 });
			});
 
 
 ////////// End ////////////////////// 
 

/*
* slideCabinet jQuery function.
* John Scanlon
* v. 1.0.
*
*/

$.fn.betterTooltip = function(options){
		/* Setup the options for the tooltip that can be
		   accessed from outside the plugin              */
		var defaults = {
			slideOutClass: 'slideOut',
			slideInClass: 'slideIn',
			speed: 200,
			slideOffset:''
		};

		var options = $.extend(defaults, options);

		/* Create a function that builds the tooltip
		   markup. Then, prepend the tooltip to the body */



		/* Give each item with the class associated with
		   the plugin the ability to call the tooltip    */

};

//contact form submission
$(document).ready(function(){
	
	$('.frmContactUs').submit(function(e){
		e.preventDefault();
		$('.system_messages').remove();
		//grabs email and name;	
		var email = $('#email').val();
		var name = $('#name').val();
		
		if(email=='' || name==''){
		return false;
		}
		
		var form = $(this);
		var data = form.serialize();
		//alert(data);
		
		var name = '';
		$('input[type=checkbox]').each( function(){
			if ($(this).is(':checked'))
        		{
					name = name  + $(this).attr('name') + '|';
					
    		    }
		});
		//alert(name);
		data = data + '&demo='+name;
		//alert(data);
		
		

		
		$('#btnText').text('Submitting...');
		$.ajax({
												  
			url: 'process.php',
			type: 'POST',
			data: data,
			
			success: function(result) {
				$('#btnText').text('Submit');
				//alert(result);
				if(result==1){
					
					$('.contentArea').prepend(successDiv);
					$('.system_title').text('Successfully submitted your information, you should receive a confirmation email shortly.');
					$('.system_messages')  
            		.css({display: 'none',width: '800px'}).slideDown(200);
				} else {
					//alert(result);
					$('.contentArea').prepend(failDiv);
					$('.system_title').text('There was an error submitting your contact form.  Please try again.' + result);
					$('.system_messages')  
            		.css({display: 'none',width: '800px'}).slideDown(200);
				}
				
			}
		}); // end ajax	
		
		
		
	});
	
});

