// JavaScript Document
function validatePetition()
{
	var regexp1 = new RegExp("\\S");
	var emailexp =  new RegExp("/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/");
	petition= document.petitionBoard;
	
	if (!regexp1.test(petition.user_name.value) || petition.user_name.value=='Enter your Name')
	{
		alert("Enter Your Name");
		petition.user_name.focus();
		return false;
	}
	var specchar = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|\"\']/;
	var name1=new RegExp('[0-9]');
	if ((name1.test(petition.user_name.value))) 
	{
		alert('Please enter a valid name');
		petition.user_name.focus();
		return false;
	}
	if(petition.user_name.value.search(specchar) == -1) 
	{	}
	else {
		alert("Please use valid characters");
		petition.user_name.focus();
		return false;
	}
	if (petition.user_emailid.value=='Enter your email id') 
	{
		alert('Please enter your email id');
		petition.user_emailid.focus();
		return false;
	}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(petition.user_emailid.value)==false)
	{
		alert("Enter Valid Email ID");
		petition.user_emailid.focus();
		return false;
	}
	if (!regexp1.test(petition.user_message.value))
	{
		alert("Enter Message");
		petition.user_message.focus();
		return false;
	}
	
	if (petition.user_message.value.length >1000)
	{
		alert(" More than 1000 characters are not allowed ");
		petition.user_message.focus();
		petition.user_message.select();
		return false;
	}
	if(petition.user_message.value.search(/http/) != -1)
	{
		alert(" Links are not allowed in the comments ");
		petition.user_message.focus();
		return false;
	}	
	if (petition.user_message.value.indexOf(">")!=-1 || petition.user_message.value.indexOf("<")!=-1)
	{
		alert(" < and > characters are not allowed ");
		petition.user_message.focus();
		return false;
	}
}
function onChangeSelect()
{
	document.petitionBoard.action='index.php';
	document.petitionBoard.submit();
}

function checksize()
{
  var str = document.petitionBoard.user_message.value;
  if (str.length >= 1000)
  {
	document.petitionBoard.user_message.value = str.substr(0, 1000);
	return false;
  }
  else
  {
	return true;
  }
}
// Abuse form Validation
function abuseFormValidate(){
	frm=document.frmAbuse;
	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}$/;
	var name1=new RegExp('[0-9]');
	if ((name1.test(frm.name.value))){
		alert('Please enter a valid name');
		frm.name.focus();
		return false;
	}
	if(frm.name.value.search(specchar) == -1){	}
	else {
		alert("Please use valid characters");
		frm.name.focus();
		return false;
	}
	if (Trim(frm.name.value) == ""){
		alert ("Enter your Name");
		frm.name.focus();
		return false;
	}
	if (Trim(frm.email.value) == ""){
		alert ("Enter your Email Id");
		frm.email.focus();
		return false;
	}
    if(firstpart.length<3){
		alert('Please enter valid email id');
		frm.email.focus();
		return false;
	}
	if((email2.test(secondpart))){
		 alert('Please enter a valid email address');
		 frm.email.focus();
		 return false;
	}
	if((email1.test(firstpart))){
		 alert('Please enter a valid email address');
		 frm.email.focus();
		 return false;
	}
	if ((!(emailFilter.test(frm.email.value)))){
		 alert('Please enter a valid email address');
		 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(reason.search(/http/) != -1)
	{
		alert(" Links are not allowed in the comments ");
		frm.reason.focus();
		return false;
	}	
	if (reason.indexOf(">")!=-1 || reason.indexOf("<")!=-1)
	{
		alert(" < and > characters are not allowed ");
		frm.reason.focus();
		return false;
	}
	if (reason.length >1000){
		alert("More than 1000 characters are not allowed ");
		document.frmAbuse.reason.focus();
		document.frmAbuse.reason.select();
		return false;
	}
	
	frm.action="http://sify.com/news/election/citizencharter/abuse_form.php";
	return true;
}
// Functions

function Trim(value){
	value = value.replace(/^\s+/g, "");
	value = value.replace(/\s+$/g, "");
	return value;
}