﻿// JavaScript Document

		var havequestion = '<div class="havequestion"><h1>Do you have any questions or concerns?</h1><p>Please contact us if you should have a non-clinical related question or would like information about any of our products or procedures.</p><div class="hqForm"><form method="post" action="_self"><fieldset><label for="e-mail">Your E-mail: <span>*</span></label><input type="text" name="email" id="email" /><br style="clear:both" /><br /><label for="question">Your question:</label><textarea id="question" name="question"></textarea></fieldset></form></div><div class="buttons"><div class="text">* This is a required field</div><div class="btns"><input type="image" id="submit" class="submit" src="img/submit.png"/><input type="image" id="maybelater" class="maybelater" src="img/maybelater.png"/></div></div></div>';
		var emaillist = '<div class="eList"><div class="elistForm"><form method="post" action="_self"><fieldset><label for="e-mail">Your E-mail:</label><input type="text" name="email" id="email" /></fieldset></form></div><div class="buttons"><div class="btns"><input type="image" id="joinnow" class="joinnow" src="img/joinnow.png"/><input type="image" id="maybelater" class="maybelater" src="img/maybelater.png"/></div></div></div>';
		var share = '<div class="swfriend"><h1>Share this with a friend</h1><div class="swfForm"><form method="post" action="_self"><fieldset><label for="name">Your Name:</label><input type="text" name="name" id="name" /><label for="e-mail">Your E-mail: <span>*</span></label><input type="text" name="email" id="email" /><label for="recipient">Recipient: <span>*</span></label><input type="text" name="recipient" id="recipient" /></fieldset></form></div><div class="buttons"><div class="text">* This is a required field</div><div class="btns"><input type="image" id="sharenow" class="sharenow" src="img/sharenow.png"/><input type="image" id="maybelater" class="maybelater" src="img/maybelater.png"/></div></div></div>';
		var shareb = '<div class="swfriend swfbottom"><h1>Share this with a friend</h1><div class="swfForm"><form method="post" action="_self"><fieldset><label for="name">Your Name:</label><input type="text" name="name" id="name" /><label for="e-mail">Your E-mail: <span>*</span></label><input type="text" name="email" id="email" /><label for="recipient">Recipient: <span>*</span></label><input type="text" name="recipient" id="recipient" /><br /><br /></fieldset></form></div><div class="buttons"><div class="text">* This is a required field</div><div class="btns"><input type="image" id="sharenow" class="sharenow" src="img/sharenow.png"/><input type="image" id="maybelater" class="maybelater" src="img/maybelater.png"/></div></div></div>';
		var swfmsg = "I hope you find this useful";

		$(document).ready(function() {
								   
			$("#maybelater").live('click', function() {
				$(this).parent().parent().parent().fadeOut(500, function(){ $(this).remove(); });
			});
								   
			$("#question").click(function() {
				if($(".havequestion").length == 0) {										  
					var pos = $(this).position();
					var left = pos.left - 520;
					var top = pos.top - 115;
					$(".wrapper").after(havequestion);
					$('.havequestion').css('top', top).css('left', left).fadeIn(500);
				} else {
					$('.havequestion').fadeOut(500, function(){ $(this).remove(); });
				}
			});

			$("#email_list").click(function() {
				if($(".eList").length == 0) {										  
					var pos = $(this).position();
					var left = pos.left - 330;
					var top = pos.top - 42;
					$(".wrapper").after(emaillist);
					$('.eList').css('top', top).css('left', left).fadeIn(500);
				} else {
					$('.eList').fadeOut(500, function(){ $(this).remove(); });
				}
			});
			
			$("#submit").live('click', function() {
				if($('.hqForm #email:input').val() == "") { alert("Please enter your email!");	}
				if($('.hqForm textarea#question').val() == "") { alert("Please enter your message!"); }
				if($('.hqForm #email:input').val() != "" && $('.hqForm textarea#question').val() != "") {
					var formdata = "type=havequestion&" + $(".hqForm form").serialize();
					$.ajax({
					  url: "ajaxsubscriptions.php",
					  async: true,
					  type: "POST",
					  data: formdata,
					  success: function(html){
						  $(".havequestion").html(html);
						  setTimeout('$(".havequestion").fadeOut(500, function(){ $(this).remove(); })', 2000);
					  }
					});
				}
			});
			
			$("#joinnow").live('click', function() {
				if($('.elistForm #email:input').val() == "") { 
					alert("Please enter your email!");	
				} else {
					var formdata = "type=emaillist&" + $(".elistForm form").serialize();
					$.ajax({
					  url: "ajaxsubscriptions.php",
					  async: true,
					  type: "POST",
					  data: formdata,
					  success: function(html){
						  $(".eList").html(html);
						  setTimeout('$(".eList").fadeOut(500, function(){ $(this).remove(); })', 2000);
					  }
					});
				}
			});	
			
			$("#sharenow").live('click', function() {
				if($('.swfForm #name:input').val() == "" || $('.swfForm #email:input').val() == "" || $('.swfForm #recipient:input').val() == "") { 
					alert("Please enter the required fields!");	
				} else {
					var currentUrl = window.location.href;
					var formdata = "type=sharewebsite&url=" + currentUrl + "&swfmsg=" + swfmsg +"&" + $(".swfForm form").serialize();
					$.ajax({
					  url: "ajaxsubscriptions.php",
					  async: true,
					  type: "POST",
					  data: formdata,
					  success: function(html){
						  $(".swfriend").html(html);
						  setTimeout('$(".swfriend").fadeOut(500, function(){ $(this).remove(); })', 2000);
					  }
					});
				}
			});				
			
			$(".sharelink").click(function() {
				if($(".swfriend").length == 0) { 
					var pos = $(this).position();
					var left = pos.left - 260;
					var top = pos.top + 20;
					$(".wrapper").after(share);
					$('.swfriend').css('top', top).css('left', left).fadeIn(500);
				} else {
					$('.swfriend').fadeOut(500, function(){ $(this).remove(); });
				}
			});
			
			$(".sharelinkb").click(function() {
				if($(".swfbottom").length == 0) {										  
					var pos = $(this).position();
					var left = pos.left - 30;
					var top = pos.top - 210;
					$(".wrapper").after(shareb);
					$('.swfbottom').css('top', top).css('left', left).fadeIn(500);
					$.scrollTo(".sharelinkb", {speed:1});
				} else {
					$.scrollTo(".sharelinkb", {speed:1});
					$('.swfbottom').fadeOut(500, function(){ $(this).remove(); });
				}
			});			
			

		});
