
//JQUERY FUNCTION
(function($){
		  $(document).ready(function(){
	//Top Navigation Menu

/************************************PRINT/EMAIL FUNCTIONALITY************************************************************/
	if($('.articleTools').length) {
		$('.articleTools li.signin').click(function(e){
			e.preventDefault();
			$('#signinPage').modal({
				close: false,
				overlayId: 'email-overlay',
				containerId: 'email-container',
				onOpen: email.open,
				onShow: email.show,
				onClose: email.close
			});
		});
		var email = {
			message: null,
			open: function (dialog) {
				dialog.container.draggable();
				dialog.overlay.fadeIn(100, function(){
					dialog.container.fadeIn(100, function () {
						dialog.data.fadeIn(100, function () {
							$('#email-container #signinPage').animate({
								height:290 
								}, function () {
									$('#email-container #signinPage').fadeIn(100, function () {
										$('#signinPage #sender_name').focus();
									});
							});
						});
					});
				});
			},
			show: function (dialog) {
				$('#signinPage input.submit').click(function (e) {
					if (email.validate()) {
						$('#signinPage').submit();
						return true;
					}
					else {
						e.preventDefault();
						$('#email-container #signinPage').css({'height':'340px'});
						if ($('#email-container .email-message:visible').length > 0) {
							var msg = $('#email-container .email-message div');
							msg.fadeOut(100, function () {
								msg.empty();
								email.showError();
								msg.fadeIn(100);
							});
						}
						else {
							$('#email-container .email-message').animate({
								height: '60px'
							}, email.showError);
						}
					}
				});
			},
			close: function(dialog) {
				$('#signinPage form').fadeOut(100);
				$('#email-container #signinPage').animate({
					height: 10
					}, function () {
						dialog.data.fadeOut(100, function () {
						dialog.container.fadeOut(100, function () {
							dialog.overlay.fadeOut(100, function () {
								$.modal.close();
							});
						});
					});
				});
			},
			error: function (xhr) {
				alert(xhr.statusText);
			},
			validate: function () {
				email.message = '';
				if (!$('#email-container #mem_type_login').val()) {
					email.message += 'Login Type is required.<br/> ';
				}
		
				var email_id = $('#email-container #email').val();
				if (!email_id) {
					email.message += 'Please Enter Your Email-Id.<br/> ';
				}
				else {
					if (!email.validateEmail(email_id)) {
						email.message += 'Please enter a valid email-Id.<br/> ';
					}
				}
				if (!$('#email-container #pass').val()) {
					email.message += 'Password is required.<br/> ';
				}
				if (email.message.length > 0) {
					return false;
				}
				else {
					return true;
				}
			},
			validateEmail: function (email) {
				var at = email.lastIndexOf("@");
		
				// Make sure the at (@) sybmol exists and  
				// it is not the first or last character
				if (at < 1 || (at + 1) === email.length)
					return false;
		
				// Make sure there aren't multiple periods together
				if (/(\.{2,})/.test(email))
					return false;
		
				// Break up the local and domain portions
				var local = email.substring(0, at);
				var domain = email.substring(at + 1);
		
				// Check lengths
				if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
					return false;
		
				// Make sure local and domain don't start with or end with a period
				if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
					return false;
		
				// Check for quoted-string addresses
				// Since almost anything is allowed in a quoted-string address,
				// we're just going to let them go through
				if (!/^"(.+)"$/.test(local)) {
					// It's a dot-string address...check for valid characters
					if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
						return false;
				}
		
				// Make sure domain contains only valid characters and at least one period
				if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
					return false;	
		
				return true;
			},
			showError: function () {
				$('#email-container .email-message').focus().css({'background-Color':'#FDFBD7','border':'1px solid #FFCC00','padding':'2px 5px','margin':'0px 0px 5px 0px'})
					.phpl($('<div class="error">').append(email.message))
					.fadeIn(200).fadeOut(200).fadeIn(200).fadeOut(200).fadeIn(200);
			}
		};
	} 
	
});
		  })(jQuery);




