// JavaScript Document
	function showLogin(callbackFunc,redirecturl) {
	
	  s = '';
	  s += '';
	  s += '<div id="formLogin">';
	  s += '  <p><a href="javascript:void(0);" name="btnCancel" id="btnCancel">x</a></p><br />';
	  s += '  <form name="newSubscribeForm" id="newSubscribeForm" method="post">';
	  s += '  Your Email<br><input id="e" name="e" type="text" maxlength="30"/><br /><br />';
	  s += '  Your Password<br><input id="p" name="p" type="password" maxlength="20" /><br /><br />';
	  s += '  <input id="redirecturl" name="redirecturl" type="hidden" value="'+redirecturl+'"/>';
	  s += '  <p><a href="javascript:void(0);" name="btnSave" id="btnSave">LOGIN</a></p>';
	  s += '  </form>';
	  s += '</div>';
	  s += '';
	  
	  s += '<script type="text/javascript">';
	  s += '  formInfo = "";';
	  s += '  $("#btnCancel").click(function(){';
	  s += '    $("#formLogin").remove();';
	  s += '  });';
	  s += '  $("#btnSave").click(function(){';
	  s += '    formInfo = new Object;';
	  s += '    formInfo.e = $("#e");';
	  s += '    formInfo.p = $("#p");';
	  s += '    formInfo.redirecturl = $("#redirecturl");';
	  s += '    returnResponse(formInfo);';
	  s += '  });';
	  s += '  function returnResponse(fI){';
	  s += '    ' + callbackFunc + '(fI);';
	  s += '  }';
	  s += '</script>';
	  $("body").append(s);
	}
    function processLogin(formData){
	
	  e = formData != "Cancelled" ? formData.e : formData;
	  p = formData != "Cancelled" ? formData.p : formData;
	  redirecturl = formData != "Cancelled" ? formData.redirecturl : formData;
	  
	  if (e.val().length!=0 && p.val().length!=0) {
		new Ajax.Updater("mlist","checklogin.php?e="+e.val()+"&p="+p.val(),
			{
				onComplete:function(req)
				{
					if(req.responseText==1)
					{ 
						$("#formLogin").remove();
						window.location = redirecturl.val();	
						
					} else {
						alert("Invalid Login!");
					}
				}
			}
			);
	  } else {
		  var err;
		  if (p.val().length==0) { p.focus(); err=true; }
		  if (e.val().length==0) { e.focus(); err=true; }
 		  if (err) { alert("All fields are required!"); return false;}
	  }
    }


	function showRegister(callbackFunc,redirecturl) {
	
	  s = '';
	  s += '';
	  s += '<div id="formRegister">';
	  s += '  <p><a href="javascript:void(0);" name="btnCancel" id="btnCancel">x</a></p><br />';
	  s += '  <form name="newSubscribeForm" id="newSubscribeForm" method="post">';
	  s += '  Your Name<br><input id="n" name="n" type="text" maxlength="30"/><br /><br />';
	  s += '  Your Email<br><input id="e" name="e" type="text" maxlength="30"/><br /><br />';
	  s += '  Your Password<br><input id="p" name="p" type="password" maxlength="20" /><br /><br />';
	  s += '  Confirm Password<br><input id="c" name="c" type="password" maxlength="20" /><br /><br />';
	  s += '  <input id="redirecturl" name="redirecturl" type="hidden" value="'+redirecturl+'"/>';
	  s += '  <p><a href="javascript:void(0);" name="btnSave" id="btnSave">SEND</a></p>';
	  s += '  </form>';
	  s += '</div>';
	  s += '';
	  
	  s += '<script type="text/javascript">';
	  s += '  formInfo = "";';
	  s += '  $("#btnCancel").click(function(){';
	  s += '    $("#formRegister").remove();';
	  s += '  });';
	  s += '  $("#btnSave").click(function(){';
	  s += '    formInfo = new Object;';
	  s += '    formInfo.n = $("#n");';
	  s += '    formInfo.e = $("#e");';
	  s += '    formInfo.p = $("#p");';
	  s += '    formInfo.c = $("#c");';
	  s += '    formInfo.redirecturl = $("#redirecturl");';
	  s += '    returnResponse(formInfo);';
	  s += '  });';
	  s += '  function returnResponse(fI){';
	  s += '    ' + callbackFunc + '(fI);';
	  s += '  }';
	  s += '</script>';
	  $("body").append(s);
	}

    function processRegister(formData){
	
      n = formData != "Cancelled" ? formData.n : formData;
	  e = formData != "Cancelled" ? formData.e : formData;
	  p = formData != "Cancelled" ? formData.p : formData;
	  c = formData != "Cancelled" ? formData.c : formData;
	  redirecturl = formData != "Cancelled" ? formData.redirecturl : formData;
	  
	  if (n.val().length!=0 && e.val().length!=0 && p.val().length!=0 && c.val().length!=0 && p.val()==c.val() && echeck(e.val())) {
		  //$('#AjaxResult').load("register.php?n="+n.val()+"&e="+e.val()+"&p="+p.val());
		new Ajax.Updater("mlist","register.php?n="+n.val()+"&e="+e.val()+"&p="+p.val(),
			{
				onComplete:function(req)
				{
					if(req.responseText==1)
					{ 
						alert("Thank you for Registering!");
						$("#formRegister").remove();
						window.location = redirecturl.val();
					}
					else if (req.responseText==4) {
						alert("Email already registered!");
					}
					else {
						alert("An error occured while processing request. Please try again!");
					}
				}
			}
			);
	  } else {
		  var err;
		  if (c.val().length==0) { c.focus(); err=true; }
		  if (p.val().length==0) { p.focus(); err=true; }
		  if (e.val().length==0) { e.focus(); err=true; }
		  if (n.val().length==0) { n.focus(); err=true; }		  
		  if (err) { alert("All fields are required!"); return false;}
		  if ((p.val().length!=0 && c.val().length!=0) && p.val()!=c.val()) { alert("Passwords does not match!"); return false; }
	  }
    }
	
	function showShare(callbackFunc,aid,redirecturl) {
	
	  s = '';
	  s += '';
	  s += '<div id="formShare">';
	  s += '  <p><a href="javascript:void(0);" name="btnCancel" id="btnCancel">x</a></p><br />';
	  s += '  <form name="newSubscribeForm" id="newSubscribeForm" method="post">';
	  s += '  Your Name<br><input id="n" name="n" type="text" maxlength="30"/><br /><br />';
	  s += '  Your Email<br><input id="e" name="e" type="text" maxlength="30"/><br /><br />';
      s += '  Recipient\'s Email<br><input id="r" name="r" type="text" maxlength="30"/><br /><br />';
	  s += '  <input id="aid" name="aid" type="hidden" value="'+aid+'"/>';
	  s += '  <input id="redirecturl" name="redirecturl" type="hidden" value="'+redirecturl+'"/>';
	  s += '  <p><a href="javascript:void(0);" name="btnSave" id="btnSave">SEND</a></p>';
	  s += '  </form>';
	  s += '</div>';
	  s += '';
	  
	  s += '<script type="text/javascript">';
	  s += '  formInfo = "";';
	  s += '  $("#btnCancel").click(function(){';
	  s += '    $("#formShare").remove();';
	  s += '  });';
	  s += '  $("#btnSave").click(function(){';
	  s += '    formInfo = new Object;';
	  s += '    formInfo.n = $("#n");';
	  s += '    formInfo.e = $("#e");';
	  s += '    formInfo.r = $("#r");';
	  s += '    formInfo.aid = $("#aid");';	
	  s += '    formInfo.redirecturl = $("#redirecturl");';
	  s += '    returnResponse(formInfo);';
	  s += '  });';
	  s += '  function returnResponse(fI){';
	  s += '    ' + callbackFunc + '(fI);';
	  s += '  }';
	  s += '</script>';
	  $("body").append(s);
	}

    function processShare(formData){
	
      n = formData != "Cancelled" ? formData.n : formData;
	  e = formData != "Cancelled" ? formData.e : formData;
	  r = formData != "Cancelled" ? formData.r : formData;
	  aid = formData != "Cancelled" ? formData.aid : formData;
	  redirecturl = formData != "Cancelled" ? formData.redirecturl : formData;

	  
	  if (n.val().length!=0 && e.val().length!=0 && r.val().length!=0 && aid.val().length!=0 && echeck(e.val()) && echeck(r.val())) {
		new Ajax.Updater("mlist","share.php?aid="+aid.val()+"&n="+n.val()+"&e="+e.val()+"&r="+r.val(),
			{
				onComplete:function(req)
				{
					if(req.responseText==1)
					{ 
						alert("Thank you for Sharing Action!");
						$("#formShare").remove();
						window.location = redirecturl.val();	
					} else {
						alert("An error occured while processing request. Please try again!");
					}
				}
			}
			);
	  } else {
		  var err;
		  if (r.val().length==0) { r.focus(); err=true; }
		  if (e.val().length==0) { e.focus(); err=true; }
		  if (n.val().length==0) { n.focus(); err=true; }		  
		  if (err) { alert("All fields are required!"); return false;}
	  }
    }
	
	function showShareLogged(callbackFunc,aid,redirecturl) {
	
	  s = '';
	  s += '';
	  s += '<div id="formShareLogged">';
	  s += '  <p><a href="javascript:void(0);" name="btnCancel" id="btnCancel">x</a></p><br />';
	  s += '  <form name="newSubscribeForm" id="newSubscribeForm" method="post">';
      s += '  Recipient\'s Email<br><input id="r" name="r" type="text" maxlength="30"/><br /><br />';
	  s += '  <input id="aid" name="aid" type="hidden" value="'+aid+'"/>';
	  s += '  <input id="redirecturl" name="redirecturl" type="hidden" value="'+redirecturl+'"/>';
	  s += '  <p><a href="javascript:void(0);" name="btnSave" id="btnSave">SEND</a></p>';
	  s += '  </form>';
	  s += '</div>';
	  s += '';
	  
	  s += '<script type="text/javascript">';
	  s += '  formInfo = "";';
	  s += '  $("#btnCancel").click(function(){';
	  s += '    $("#formShareLogged").remove();';
	  s += '  });';
	  s += '  $("#btnSave").click(function(){';
	  s += '    formInfo = new Object;';
	  s += '    formInfo.r = $("#r");';
	  s += '    formInfo.aid = $("#aid");';	
	  s += '    formInfo.redirecturl = $("#redirecturl");';
	  s += '    returnResponse(formInfo);';
	  s += '  });';
	  s += '  function returnResponse(fI){';
	  s += '    ' + callbackFunc + '(fI);';
	  s += '  }';
	  s += '</script>';
	  $("body").append(s);
	}

    function processShareLogged(formData){
	
	  r = formData != "Cancelled" ? formData.r : formData;
	  aid = formData != "Cancelled" ? formData.aid : formData;
	  redirecturl = formData != "Cancelled" ? formData.redirecturl : formData;

	  
	  if (r.val().length!=0 && aid.val().length!=0 && echeck(r.val())) {
		new Ajax.Updater("mlist","share.php?aid="+aid.val()+"&r="+r.val(),
			{
				onComplete:function(req)
				{
					if(req.responseText==1)
					{ 
						alert("Thank you for Sharing Action!");
						$("#formShareLogged").remove();
						window.location = redirecturl.val();	
					} else {
						alert("An error occured while processing request. Please try again!");
					}
				}
			}
			);
	  } else {
		  var err;
		  if (r.val().length==0) { r.focus(); err=true; }
		  if (err) { alert("All fields are required!"); return false;}
	  }
    }
	
    function updateAction(aid,type,redirecturl){
	
	  
	  if (aid.length!=0 && type.length!=0 && redirecturl.length!=0) {
		new Ajax.Updater("mlist","updateaction.php?t="+type+"&aid="+aid,
			{
				onComplete:function(req)
				{
					//alert(req.responseText);
					if(req.responseText==1)
					{ 
						alert("Action Saved!");
						window.location = redirecturl;	
					} else {
						alert("An error occured while processing request. Please try again!");
					}
				}
			}
			);
	  } else {
		  alert("Invalid request. Please try again!");
		  return false;
	  }
    }
	
    function suggestAction(){
	
	  var title = document.getElementById('suggest_message');
	  if (title.value.length!=0) {
		new Ajax.Updater("mlist","savesuggest.php?t="+title.value,
			{
				onComplete:function(req)
				{
					//alert(req.responseText); exit;
					if(req.responseText==1)
					{ 
						alert("Suggestion Sent!");
						window.location = "actions.php";			
					} else {
						alert("An error occured while processing request. Please try again!");
					}
				}
			}
			);
	  } else {
 		 alert("Please enter your suggestion!"); 
		 title.focus();
		 return false;
	  }
    }

	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					
}

function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}

