function update(ss){var old = document.feedback.counter.value;var limit=ss;document.feedback.counter.value=document.feedback.comment.value.length;
if(document.feedback.counter.value > limit && old <= limit){alert('Limit Exceeds (Max 300 Char). Please Enter Short Description upto 300 Characters only.');document.feedback.counter.value=document.feedback.counter.value-1;}}
function limitText(limitField, limitCount, limitNum){if (limitField.value.length > limitNum){limitField.value = limitField.value.substring(0, limitNum);}else{limitCount.value = limitNum - limitField.value.length;}}
function textCounter(fieldname, maxlimit) {var field;for(i=0; i < document.forms.length; ++i) {var obj = document.forms[i].elements[fieldname];if (obj) field = obj;}
if (field == null) return false;var results = field.value.match(/\{keyword:[^\}]+\}/i);if (results) {maxlimit += "{keyword:}".length;}results = field.value.match(/\{keyword\}/);if (results) {maxlimit += "{keyword}".length - 1;}if (field.value.indexOf("{") == -1 ) {if (field.value.length > maxlimit) {field.value = field.value.substring(0, maxlimit);}} else {if (field.value.length > maxlimit) {field.style.color = 'red';return true;} else {field.style.color = 'black';return false;}}}
function modifyText(id, text) {if (document.getElementById) {obj = document.getElementById(id);obj.childNodes[0].data = text;}}

function validate()
{
   if(!(rate() && interface()   && commenttype()  && name() && email() && checksum()))
  {
// alert ("error")
   return false;
  }
  return true;
}

var FirstNo=get_randomfirst();var SecondNo=get_randomsecond();var mynoone = new Array(8);mynoone[0] = 1;mynoone[1] = 2;mynoone[2] = 3;mynoone[3] = 4;mynoone[4] = 5;mynoone[5] = 6;mynoone[6] = 7;mynoone[7] = 8;mynoone[8] = 9;var mynosecond = new Array(8);mynosecond[0] = 1;mynosecond[1] = 2;mynosecond[2] = 3;mynosecond[3] = 4;mynosecond[4] = 5;mynosecond[5] = 6;mynosecond[6] = 7;mynosecond[7] = 8;mynosecond[8] = 9;var ranNum1;var ranNum2;var totno;function get_randomfirst(){ranNum1= Math.floor(Math.random()*9);return ranNum1;}function get_randomsecond(){ranNum2= Math.floor(Math.random()*9);return ranNum2;}function getnumbers(){totno=parseInt(mynoone[FirstNo])+parseInt(mynosecond[SecondNo]);document.getElementById('divno').innerHTML="<b><font color='#990000' style='font-size:15px'>"+mynoone[FirstNo]+" + "+mynosecond[SecondNo]+" = </font></b>";return totno;}

function checksum(){if (document.feedback.getsumtxt.value==""){alert("Please Enter Sum of Numbers to submit your form. This is to avoid automated queries.");document.feedback.getsumtxt.focus();return false;}var getsum= document.getElementById('getsumtxt').value;if (totno!=getsum){alert('Entered Number is not correct. The correct answer is "'+totno+'". Enter this number to submit the form.');return false;}return true;}

function rate(){
if(!(document.feedback.rate[0].checked || document.feedback.rate[1].checked ||document.feedback.rate[2].checked || document.feedback.rate[3].checked)){
        document.feedback.rate[1].focus()
        alert ("Select Rating of the site")
        return false;
       }
    return true;
}

function interface(){
if(!(document.feedback.interface[0].checked || document.feedback.interface[1].checked ||document.feedback.interface[2].checked || document.feedback.interface[3].checked)){
        document.feedback.interface[2].focus()
        alert ("Select interface of the site")
        return false
       }
    return true
}

function commenttype(){
if(!(document.feedback.commenttype[0].checked || document.feedback.commenttype[1].checked ||document.feedback.commenttype[2].checked || document.feedback.commenttype[3].checked)){
        document.feedback.commenttype[2].focus()
        alert ("Select your kind of comments")
        return false
       }
    return true
}


function comment() {
  if(document.feedback.comment.value == "") {
        alert("Enter your comments")
        document.feedback.comment.focus()
        return false
     }
     return true
}

function name()
{
    if(document.feedback.name.value =="")
    {
      alert ("Please enter Name")
      document.feedback.name.focus()
      return false
    }
    return true
}


function email()
{ 

 str=document.feedback.email.value; 
 if(CharValidity(str,"email",2))  
 {	
	i=0;
    while((i<str.length)&&(str.charAt(i) != '@'))
	 i++;

     if(i==str.length)
	  {
	alert("'@'  is required in the email address");	 
	document.feedback.email.focus();		
        return false	      	 
    }
   else
   {	
     if(str.charAt(0) == '.')	 
   {
    alert("' . ' can not be the first character of email address.");	
    document.feedback.email.focus();	     
    return false;	
  }
   else
   {
      i=0;       	 
  while((i<str.length)&&(str.charAt(i) != '.'))  
      i++;
   if(i==str.length)	 
   {	 
     alert("' . '  is required in the email address");		
     document.feedback.email.focus();	   
     return false;	      
    }
     else
    {
  if(str.charAt(i-1) == '@')
    {	
    alert("Character(s) are needed between  ' @ ' and  ' . '");	           document.feedback.email.focus();	
    return false;	
    }
  else 
   {
    if(i==str.length-1)	 
     {
    alert("' . '  can't be the last character of email address");	
    document.feedback.email.focus();  	 
    return false;	  
      }
  else
  {	
    i=0;count=0;
    while((i<str.length)&&(count<2))
    {
      if(str.charAt(i)=='@')
      count++;i++;
    }
      if(count>1)
    {	
    alert("'@'  can't be entered more than one");	
    document.feedback.email.focus();	
    return false;
    }
   else
    {
   i=0;
   while(i<str.length-1)	
   {
    if((str.charAt(i)=='.')&&(str.charAt(i+1)=='.'))
    {	
   alert("Character(s) are needed between  ' . ' and  ' . '");
   document.feedback.email.focus();
    return false;
    }
  else i++;	
     }
  if(str.charAt(str.length-1)=='.')
    {
  alert("' . '  can't be the last character of email address");
  document.feedback.email.focus();  
  return false;	
  }
  else
   return true;	
  	}
        }
       }
       }
     }
  }
//if charval()}
}
}


function CharValidity(str,entry,ele)
{ 
 if(str == '') 
 {	
  alert("Please enter the "+entry);
  document.feedback.email.focus();
    return false;
  }	
  else 
 {  
    i=0;
    while(i < str.length)
   {  
  if((str.charAt(i)<'a')||(str.charAt(i) >'z'))
    if((str.charAt(i)!='_')&&(str.charAt(i)!='.')&&(str.charAt(i)!='-')&& (str.charAt(i)!='@')&&((str.charAt(i)<'A')||(str.charAt(i)>'Z'))) 
     { 
   if((str.charAt(i) < '0') || (str.charAt(i) > '9'))
    {	
  if(str.charAt(i) == ' ')
       {   
       alert("Space is not allowed in "+entry);
       document.feedback.elements[ele].focus();
       return false;	
       }
  else
   if(ele != 1)
   {
    alert("' "+str.charAt(i)+" '"+"  is not allowed in "+entry);
     document.feedback.elements[ele].focus();	
     return false; 
    }
   else
  if((str.charAt(i) != '@')&&(str.charAt(i) != '.'))
   {
   alert("' "+str.charAt(i)+" '"+"  is not allowed in "+entry);
   document.feedback.elements[ele].focus();
   return false;
     }
     }// <'0' || >'9'
     else
    return true;
   }//1st if 
      i++;
    }//while  
  return true;
  }//else (str!='')
}

