function Trim(value)
{
	value = value.replace(/^\s+/g, "");
	value = value.replace(/\s+$/g, "");
	return value;
}

function notempty()
{
	var specchar = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|\"\']/;
	var firstpart=document.frm_reply.email.value.substr(0,document.frm_reply.email.value.indexOf('@'));
	var secondpart=document.frm_reply.email.value.substr(document.frm_reply.email.value.indexOf('@')+1, document.frm_reply.email.value.length-document.frm_reply.email.value.indexOf('@'));
	var email1=new RegExp('[^a-zA-Z0-9.\_]');
	var email2=new RegExp('[^a-zA-Z0-9.]');
    	var emailFilter=/^.+@.+\..{2,3}$/;
	var name1=new RegExp('[0-9]');
	if ((name1.test(document.frm_reply.name.value))) 
	{
		alert('Please enter a valid name');
		document.frm_reply.name.focus();
		return false;
	}
	if(document.frm_reply.name.value.search(specchar) == -1) 
	{	}
	else {
		alert("Please use valid characters");
		document.frm_reply.name.focus();
		return false;
	}
	if ((Trim(document.frm_reply.name.value) == "")||(Trim(document.frm_reply.name.value) == 'Enter your Name'))
	{
		alert ("Enter your Name");
		document.frm_reply.name.focus();
		return false;
	}
	if ((Trim(document.frm_reply.email.value) == "")||(Trim(document.frm_reply.email.value) == 'Enter your Email Id'))
	{
		alert ("Enter your Email Id");
		document.frm_reply.email.focus();
		return false;
	}
     if(firstpart.length<3)
	{
		alert('Please enter valid email id');
		document.frm_reply.email.focus();
		return false;
	}
	if((email2.test(secondpart)))
	{
		 alert('Please enter a valid email address');
		 document.frm_reply.email.focus();
		 return false;
	}
	if((email1.test(firstpart)))
	{
		 alert('Please enter a valid email address');
		 document.frm_reply.email.focus();
		 return false;
	}
	if ((!(emailFilter.test(document.frm_reply.email.value))))
	{
		 alert('Please enter a valid email address');
		 document.frm_reply.email.focus();
		 return false;
	}
	if (Trim(document.frm_reply.comments.value) == "")
	{
		alert ("Enter the Comments");
		document.frm_reply.comments.focus();
		return false;
	}
	if (document.frm_reply.comments.value.length >2000)
	{
		alert(" Maximum characters allowed - 2000 ");
		document.frm_reply.comments.focus();
		document.frm_reply.comments.select();
		return false;
	}
	//document.frm_reply.action="clive_fullstory.php?id="+document.fullstory.fullstory_id.value+"&cid="+document.fullstory.cid.value;
	//document.frm_reply.submit();
	querystr="name="+document.frm_reply.name.value+"&email="+document.frm_reply.email.value+"&comments="+document.frm_reply.comments.value+"&fullstory_id="+document.frm_reply.fullstory_id.value+"&ctid="+document.frm_reply.ctid.value;
	getResponse("comments", "http://sify.com/fullstory/comments_submit.php", querystr);
}
function validate_abuse_form()
{
	frm=document.frmAbuse;
	//frm= eval("document.frmAbuse"+document.getElementById('reply_id').value);
//alert(frm);
//frm=frm_obj;
	var name=Trim(frm.name.value);
	if (name== "")
	{
		alert ("Please enter name");
		frm.name.focus();
		return false;
	}
	if(!isValidName(name))
	{
		alert("Please enter valid name."); 
		frm.name.focus(); 
		return false;
	}
	var email=Trim(frm.email.value);
	if (email=="")
	{
		alert ("Please enter email id");
		frm.email.focus(); 
		return false;
	}
	if (!isValidEmail(email))
	{
		alert ("Please enter valid email id");
		frm.email.focus();
		return false;
	}
	var reason=Trim(frm.reason.value);
	if (reason== "")
	{
		alert ("Please enter reason for abuse");
		frm.reason.focus();
		return false;
	}
	if(!inString(reason))
	{
		alert("Please enter valid reason for abuse."); 
		frm.reason.focus(); 
		return false;
	}
	if (frm.reason.value.length >2000)
	{
		alert(" Maximum characters allowed - 2000 ");
		frm.reason.focus();
		frm.reason.select();
		return false;
	}
	querystr = "msg_id="+frm.msg_id.value+"&name="+name+"&email="+email+"&reason="+reason+"&reply_id="+frm.reply_id.value;
//alert ("abuse"+frm.reply_id.value);
	getResponse ("abuse"+frm.reply_id.value, "http://sify.com/fullstory/abuse_submit.php", querystr);
}

function notempty_reply()
{
	var specchar = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|\"\']/;
	var firstpart=document.frmMailer.email.value.substr(0,document.frmMailer.email.value.indexOf('@'));
	var secondpart=document.frmMailer.email.value.substr(document.frmMailer.email.value.indexOf('@')+1, document.frmMailer.email.value.length-document.frmMailer.email.value.indexOf('@'));
	var email1=new RegExp('[^a-zA-Z0-9.\_]');
	var email2=new RegExp('[^a-zA-Z0-9.]');
    	var emailFilter=/^.+@.+\..{2,3}$/;
	var name1=new RegExp('[0-9]');
	if ((name1.test(document.frmMailer.name.value))) 
	{
		alert('Please enter a valid name');
		document.frmMailer.name.focus();
		return false;
	}
	if(document.frmMailer.name.value.search(specchar) == -1) 
	{	}
	else {
		alert("Please use valid characters");
		document.frmMailer.name.focus();
		return false;
	}
	if ((Trim(document.frmMailer.name.value) == "")||(Trim(document.frmMailer.name.value) == 'Enter your Name'))
	{
		alert ("Enter your Name");
		document.frmMailer.name.focus();
		return false;
	}
	if ((Trim(document.frmMailer.email.value) == "")||(Trim(document.frmMailer.email.value) == 'Enter your Email Id'))
	{
		alert ("Enter your Email Id");
		document.frmMailer.email.focus();
		return false;
	}
     if(firstpart.length<3)
	{
		alert('Please enter valid email id');
		document.frmMailer.email.focus();
		return false;
	}
	if((email2.test(secondpart)))
	{
		 alert('Please enter a valid email address');
		 document.frmMailer.email.focus();
		 return false;
	}
	if((email1.test(firstpart)))
	{
		 alert('Please enter a valid email address');
		 document.frmMailer.email.focus();
		 return false;
	}
	if ((!(emailFilter.test(document.frmMailer.email.value))))
	{
		 alert('Please enter a valid email address');
		 document.frmMailer.email.focus();
		 return false;
	}
	if (Trim(document.frmMailer.comments.value) == "")
	{
		alert ("Enter the Comments");
		document.frmMailer.comments.focus();
		return false;
	}
	if (document.frmMailer.comments.value.length >2000)
	{
		alert(" Maximum characters allowed - 2000 ");
		document.frmMailer.comments.focus();
		document.frmMailer.comments.select();
		return false;
	}
	//document.frmMailer.action="clive_fullstory.php?id="+document.fullstory.fullstory_id.value+"&cid="+document.fullstory.cid.value;
	//document.frmMailer.submit();
	querystr = "msg_id="+document.frmMailer.msg_id.value+"&name="+document.frmMailer.name.value+"&email="+document.frmMailer.email.value+"&comments="+document.frmMailer.comments.value+"&reply_id="+document.frmMailer.reply_id.value;
	getResponse("reply"+document.frmMailer.reply_id.value, "http://sify.com/fullstory/reply_submit.php", querystr);
}

function checksize(obj)
{  
  obj = eval(obj);
  if (obj)
  {
	  var str = obj.value;
  	  if (str.length >= 2000)
	  {
		obj.value = str.substr(0, 2000);
		return false;
	  }
	  else
	  {
		return true;
	  }
  }
}
function validateEmail(email)
{ 
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) 
	{
		return false;
	}
    if (splitted[1] != null)
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null)
      {
		return false;
	  }
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null)
      {
		var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
		if(splitted[2].match(regexp_ip) == null)
		{
			return false;
		}
      }
      return true;
    } 
	return false;
}
function Validate_Save()
{
	/* From validations */
	//alert ("Inside");
	if(document.frmMailer.mailfrom.value == "")
	{
		alert ("Please enter your e-mail address");
		document.frmMailer.mailfrom.focus();
		return false;
	}
	if (! validateEmail(document.frmMailer.mailfrom.value))
	{
		alert("Invalid Email Id.");
		document.frmMailer.mailfrom.focus();
		return false;
	}
	if (Trim(document.frmMailer.mailfrom.value) == '' )
	{
		alert("Email Address should not be a whitespace.");
		document.frmMailer.mailfrom.value = "";
		document.frmMailer.mailfrom.focus();
		return false;
	}
	/* To validations */
	if(document.frmMailer.mailto.value == "")
	{
		alert ("Please enter the e-mail address of your friend.");
		document.frmMailer.mailto.focus();
		return false;
	}
	var temp=0;
	var pattern = /,/; 
	var mailList = new Array();
    mailList = document.frmMailer.mailto.value.split(pattern);
    for (var i=0; i<mailList.length; i++){
        if (! validateEmail(mailList[i]))
		    temp=1;
	}    
	if (temp==1)
	{
		alert("Invalid Email Id.");
		document.frmMailer.mailto.focus();
	 	return false;
 	}
	if (Trim(document.frmMailer.mailto.value) == '' )
	{
		alert("Email Address should not have whitespaces.");
		document.frmMailer.mailto.value = "";
		document.frmMailer.mailto.focus();
		return false;
	}
	/* Cc validations 
	if (document.frmMailer.mailcc.value != "" )
	{
		if (! validateEmail(document.frmMailer.mailcc.value))
		{
			alert("Invalid Email Id.");
			document.frmMailer.mailcc.focus();
			return false;
		}
		if (Trim(document.frmMailer.mailcc.value) == '' )
		{
			alert("Email Address should not have whitespaces.");
			document.frmMailer.mailcc.value = "";
			document.frmMailer.mailcc.focus();
			return false;
		}
	}*/
	/* Comments validations*/
	if (document.frmMailer.comments.value == "" )
	{
		alert("Please enter your comments .");
		document.frmMailer.comments.focus();
		return false;
	}	
	if (document.frmMailer.comments.value.length >2000)
	{
		alert(" Maximum characters allowed - 2000 ");
		document.frmMailer.comments.focus();
		document.frmMailer.comments.select();
		return false;
	}
    document.frmMailer.linkto.value = parent.location;
	querystr = "msg_id="+document.frmMailer.msg_id.value+"&mailfrom="+document.frmMailer.mailfrom.value+"&mailto="+document.frmMailer.mailto.value+"&mailcc="+document.frmMailer.mailcc.value+"&comments="+document.frmMailer.comments.value+"&linkto="+document.frmMailer.linkto.value+"&reply_id="+document.frmMailer.reply_id.value;
	getResponse("forward"+document.frmMailer.reply_id.value, "http://sify.com/fullstory/mail_submit.php", querystr);
//    return true;
}