//Function for Character Validation----------------------------------------------------------------------
//Allows only abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.  
function charValidation(fieldValue) {

  var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. "
  var ok = "yes";
  var temp;

  for (var i=0; i<fieldValue.length; i++) {
    temp = "" + fieldValue.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
  }

/*  if(fieldValue == "")
	{
	  alert("Please type your name:");
	  document.feedback_form.textfield.focus();
	  document.feedback_form.textfield.select();
	  return false;
	}*/

  if (ok == "no") {
    alert("Invalid entry!  Only Characters, Space and . are accepted!");
    document.feedback_form.textfield.focus();
	document.feedback_form.textfield.select();
    return false;
  }
  return true;
}
//End Caharacter Validation-----------------------------------------------------------------------------
//Function for empy validation--------------------------------------------------------------------------
	function emptyVal(){
		
		/*if (document.feedback_form.textfield.value == 0)
			{
				alert("Invalid entry! Please Enter Your Name");
				document.feedback_form.textfield.focus();
				document.feedback_form.textfield.select();
				return false;
			}*/

		if (document.feedback_form.textfield3.value == 0)
			{
				alert("Invalid entry! Please Enter Your Email Address");
				document.feedback_form.textfield3.focus();
				document.feedback_form.textfield3.select();
				return false;
			}
      return true;
	}
//End Empty Validation----------------------------------------------------------------------------------
//Email Validation--------------------------------------------------------------------------------------
function emailCheck(emailStr) {

   eMailIdFlag = 'yes';
  /* The following variable tells the rest of the function whether or not to verify that the address ends in a two-letter country or well-known TLD.  1 means check it, 0 means don't. */
  var checkTLD=1;
  /* The following is the list of known TLDs that an e-mail address must end with. */
  var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
  /* The following pattern is used to check if the entered e-mail address fits the user@domain format.  It also is used to separate the username from the domain. */
  var emailPat=/^(.+)@(.+)com$/;
  /* The following string represents the pattern for matching all special characters.  We don't want to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ] */
  var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
  /* The following string represents the range of characters allowed in a username or domainname.  It really states which chars aren't allowed.*/
  var validChars="\[^\\s" + specialChars + "\]";
  /* The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com is a legal e-mail address. */
  var quotedUser="(\"[^\"]*\")";
  /* The following pattern applies for domains that are IP addresses, rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
  /* The following string represents an atom (basically a series of non-special characters.) */
  var atom=validChars + '+';
  /* The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string. */
  var word="(" + atom + "|" + quotedUser + ")";
  // The following pattern describes the structure of the user
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
  /* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
  /* Finally, let's start trying to figure out if the supplied address is valid. */
  /* Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze. */

  
  var matchArray=emailStr.match(emailPat);

  if (matchArray==null) {

   //Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. 

    alert("Email address  is incorrect (check @ and .'s)");
	eMailIdFlag = "no";
    document.feedback_form.textfield3.focus();
    document.feedback_form.textfield3.select();
    return false;
  }
  var user=matchArray[1];
  var domain=matchArray[2];

  // Start by checking that only basic ASCII characters are in the strings (0-127).

  for (i=0; i<user.length; i++) {
    if (user.charCodeAt(i)>127) {
      alert("An email address contains Invalid characters.\n Eg: user@domain.com ,user@domain.eng.sun.com etc.");
	  eMailIdFlag = "no";
	  document.feedback_form.textfield3.focus();
      document.feedback_form.textfield3.select();
      return false;
    }
  }
  for (i=0; i<domain.length; i++) {
    if (domain.charCodeAt(i)>127) {
      alert("Ths domain name contains Invalid characters.\n Eg: user@domain.com ,user@domain.eng.sun.com etc.");
	  eMailIdFlag = "no";
      document.feedback_form.textfield3.focus();
      document.feedback_form.textfield3.select();
	  return false;
    }
  }

// See if "user" is valid 

  if (user.match(userPat)==null) {

// user is not valid

    alert( user+" is an invalid email address.\n Eg: user@domain.com ,user@domain.eng.sun.com etc.");
	eMailIdFlag = "no";
	document.feedback_form.textfield3.focus();
    document.feedback_form.textfield3.select();
    return false;
  }

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

  var IPArray=domain.match(ipDomainPat);
  if (IPArray!=null) {

// this is an IP address
    for (var i=1;i<=4;i++) {
      if (IPArray[i]>255) {
        alert("Destination IP address is Invalid!\n Eg: user@domain.com ,user@domain.eng.sun.com etc.");
		eMailIdFlag = "no";
        document.feedback_form.textfield3.focus();
		document.feedback_form.textfield3.select();
		return false;
      }
    }
    return true;
  }

// Domain is symbolic name.  Check if it's valid.
 
  var atomPat=new RegExp("^" + atom + "$");
  var domArr=domain.split(".");
  var len=domArr.length;
  return true;
}
//End Email alidation-----------------------------------------------------------------------------------
//Function Other RadionButton and Text Field Validation-------------------------------------------------
function radio_val(){
	
		if(document.feedback_form.radiobutton1[0].checked == true){
			document.feedback_form.textfield4.value = "";
		}

		if(document.feedback_form.radiobutton1[1].checked == true){
			document.feedback_form.textfield4.value = "";
		}

		if(document.feedback_form.radiobutton1[2].checked == true){
			document.feedback_form.textfield4.focus();
		}
}
//End Other RadionButton and Text Field Validation-------------------------------------------------------
//Function to make other text null when i $2 radio button selected--------------------------------------
function radio_empty(){
if (document.feedback_form.radiobutton1[2].checked == 0 && document.feedback_form.textfield4.value != 0)
		{
	alert("Check");
			document.feedback_form.textfield4.value = "";
			return false;
		}
return true;
}
//End Function null------------------------------------------------------------------------------------
//Text Other Validation----------------------------------------------------------------------------------
function text_other(){
	if(document.feedback_form.textfield4.value == 0 && document.feedback_form.radiobutton1[2].checked == 1){
				document.feedback_form.textfield4.focus();
				document.feedback_form.textfield4.select();
				alert("Please specify here the other");
				return false;
	}
	return true;
}
//end Text Other Validation------------------------------------------------------------------------------
function name_mailVal(){
	if (document.feedback_form.textfield.value == 0) 
		{
				alert("Invalid entry! Please Enter Your Name And Your Email");
				document.feedback_form.textfield.focus();
				document.feedback_form.textfield.select();
				return false;
		}
		if (document.feedback_form.textfield3.value == 0)
		{
			alert("Invalid entry! Please Enter Your Name And Your Email");
				document.feedback_form.textfield3.focus();
				document.feedback_form.textfield3.select();
				return false;
		}
		return true;
}