/*************** Form Validations *************************/
function Trim(value)
{
	value = value.replace(/^\s+/g, "");
	value = value.replace(/\s+$/g, "");
	return value;
}

function notempty() // comments form validation
{
	frm = eval("document.frm_reply");
	var specchar = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|\"\']/;
	var firstpart=frm.email.value.substr(0,frm.email.value.indexOf('@'));
	var secondpart=frm.email.value.substr(frm.email.value.indexOf('@')+1, frm.email.value.length-frm.email.value.indexOf('@'));
	var email1=new RegExp('[^a-zA-Z0-9.\_]');
	var email2=new RegExp('[^a-zA-Z0-9.]');
    var emailFilter=/^.+@.+\..{2,3}$/;
	if (Trim(frm.textname.value)=="" || Trim(frm.textname.value)== "Enter your name" ) 
	{
		alert ("Please enter the Name");
		frm.textname.focus();
		return false;
	 }
	var name1=new RegExp('[0-9]');
	if ((name1.test(frm.textname.value))) 
	{
		alert('Enter a valid Name');
		frm.textname.focus();
		return false;
	}
	if(frm.textname.value.search(specchar) == -1) 
	{	}
	else {
		alert("Use valid characters");
		frm.textname.focus();
		return false;
	}
	if (Trim(frm.email.value)=="" || Trim(frm.email.value)=="Enter your email id") 
	 { 
		alert ("Please Enter the Email Id");
		frm.email.focus();
		return false;
	 }
    if(firstpart.length<3)
	{
		alert('Enter valid Email Id');
		frm.email.focus();
		return false;
	}
	if((email2.test(secondpart)))
	{
		 alert('Enter valid Email Id');
		 frm.email.focus();
		 return false;
	}
	if((email1.test(firstpart)))
	{
		 alert('Enter  valid Email Id');
		 frm.email.focus();
		 return false;
	}
	if ((!(emailFilter.test(frm.email.value))))
	{
		 alert('Enter  valid Email Id');
		 frm.email.focus();
		 return false;
	}
	if (Trim(document.frm_reply.comments.value) == "")
	{
		alert ("Enter the Comments");
		document.frm_reply.comments.focus();
		return false;
	}
	getcommentformdata();
	setVisibility("player","none");
	screenVisibility("bgscreen", 'inline');
	setVisibility('thankuscreen','inline');
}

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()   //Mailform validation
{
	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.mailcomments.value == "" )
	{
		alert("Please enter your comments .");
		document.frmMailer.mailcomments.focus();
		return false;
	}	
     getmailformdata();
	 hideMailform();	
	setVisibility("player","none");
	screenVisibility("bgscreen", 'inline');
	setVisibility('thankuscreen','inline');

}

function rateValidate()  /// Rate form validation
{
	with(document.FRate)
	{
		var chk = false;
		len = radiobutton.length;
		for (count = 0; count < len; count++)
		{
                        if (radiobutton[count].checked)
                        {
                                chk = true;
								document.FRate.chkval.value=count+1;
                                break;
                        }
                }
                if (!chk)
                {
                        alert("Select an answer");
                        return;
                }
				getrateformdata();
				setVisibility("player","none");
				screenVisibility("bgscreen", 'inline');
	}
}
function checksize()
{
  var str = document.frm_reply.comments.value;
  if (str.length >= 1000)
  {
	document.frm_reply.comments.value = str.substr(0, 1000);
	return false;
  }
  else
  {
	return true;
  }
}

