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;
	}	
    document.frmMailer.linkto.value = parent.location;
	//document.frmMailer.action = parent.location;
   // document.frmMailer.submit();
	querystr = "img_name="+document.frmMailer.img_name.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;
    getResponse("viewcard", "clive_sendmail_submit.php", querystr);
//    return true;
}
function Trim(value)
{
	value = value.replace(/^\s+/g, "");
	value = value.replace(/\s+$/g, "");
	return value;
}
