 
 function getHost() {
	 var a = document.URL.split("//"); // split at protocol
	 a = (a[1] ? a[1] : a[0]).split("/");
	 return a[1];
 }
 
function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID")
	   return false
	}
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail ID")
		return false
	}
	
	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail ID")
		return false
	 }
	
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail ID")
		return false
	 }
	
	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail ID")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail ID")
		return false
	 }
	
	 return true					
}
 
 
 var track = 0;							// Track the reply 
 var posted_comment = "";				// Comment text
 var click_count = 0;					// User can not click more than once
 var textFieldValue = 0;				// Can not post a blank reply 
 var ajaxPost = 0; 						// Only a single post is allowed
 var req_path = (document.location.host == 'www.effinfunny.com' || document.location.host == 'effinfunny.com') ? ( '/' ) : ( '/' + getHost() + '/' );

 
 $(document).ready(function(){
	$("#legend_store_email_button").click(function(){
	
		var posted_email = $("#edit-store-email").val();
		if(posted_email != null && posted_email != '') {
			if(echeck(posted_email)==false) {
				alert('Enter a Valid Email');
				$('#edit-store-email').addClass('form-text required error');
				return false;
			} else {
				$("#legend_store_email_button").attr('disabled',true).addClass('legend_processing');
				$.ajax({
				type: "post",
				 url: req_path + "legend_store_email/subscribed",
			     data: "sub_email=" + $('#edit-store-email').val(),
				 success: function(msg){
					
					 if(msg == "Thank you")
					 {
						
						document.getElementById('subscribed_center_return_status').innerHTML = '<h2 class="yellow_txt_small" style="font-size:12px;">Thank you for your email id. </h2>';
						 $("#legend_store_email_button").attr('enabled',true).removeClass('legend_processing').addClass('legend_submit');
						$('#subscribed_row').show('slow');
					 }
					 else
					 {
						 
						 if(msg == "You've already listed  with this email address!")
						 {
							 document.getElementById('subscribed_center_return_status').innerHTML = '';
							document.getElementById('subscribed_center_return_status').innerHTML = '<h2 class="yellow_txt_small" style="font-size:12px;">You have already listed  with this email address!</h2>';
							 $("#legend_store_email_button").attr('enabled',true).removeClass('legend_processing').addClass('legend_submit');
							
							$('#subscribed_row').show('slow');
						 }
						 else
						 {    alert(msg);
							  $('#edit-subscribed-email').addClass('form-text required error');
							$('#subscribed_row').show('slow');
							 $("#legend_store_email_button").attr('enabled',true).removeClass('legend_processing').addClass('legend_submit');
						 }
					 }
				 }
				});
			}
		}else {
			alert('You must enter an email first');
			$("#edit-store-email").addClass('form-text required error');
			return false;
		}
	  
	  	return false;
   });
   
	
	
 });
	


