function validate()
{
	form = document.Complaint;
	flag =0;
	str ="";
	

	//obj = form.frmCTyp
	//sel = obj[obj.selectedIndex].value
	
	//if(sel == 0)
	//{
	//	str += " Please select customer type.  \n"
	//}
	
	if(form.frmCRNNo.value == "")
	{
		str += " Please enter the CRN No.  \n"
	}
	
	//if(form.frmName.value == "")
	//{
	//	str += " Please enter the Name.  \n"
	//}

	//if(form.frmAddr.value == "")
	//{
	//	str += " Please enter the Address  \n"
	//}

	//if(form.frmTel.value == "")
	//{
	//	str += " Please enter the Telephone No.  \n"
	//}
	//else
	
	if(form.frmTel.value != "")
	{
		i = validateNo(form.frmTel.value);
		if(i)
		{
			str += " Enter a valid Telephone No. \n";
		}
	}

	//if(form.frmEmail.value == "")
	//{
	//	str += " Please enter the email address.  \n"
	//}
	//else
	if(form.frmEmail.value != "")
	{
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.frmEmail.value))) 
			str +=  " Please enter a valid email address. \n";
		
	}
	
	/*
	len = form.frmCSub.length
	chk = 0
	
	for(i=0;i<len;i++)
	{
		if(form.frmCSub[i].checked == true)
			chk = 1
	}

	if(chk==0)
	{
		str += " You must provide at least one complaint subject. \n"   
	}
	
	*/
	obj = form.frmCat
	sel = obj[obj.selectedIndex].value
	
	if(sel == 0)
	{
		str += " Please select Category.  \n"
	}



	if(form.frmComplaint.value == "")
	{
		str += " Please enter the complaint details.  \n"
	}

	if(str)
	{
		alert(str)
		return false
	}
	else 
	{
		return true;
	}	
}	


function validateNo(s) 
{
      ctr = 0;	
      Chars = "0123456789-";
      flag=0;


      for (i = 0; i < s.length; i++)
      {   
          // Check that current character is number.
          var c = s.charAt(i);
  
          if (Chars.indexOf(c) == -1) 
          	flag = 1;
      }

      if(flag)
	  return true;    
} 


function checkCust()
{
	form = document.Complaint;
	//alert("hey ")
	
	obj = form.frmCTyp
	sel = obj[obj.selectedIndex].value
	
	
	if(sel == 0)
	{
	   alert(" Please select the Customer type first")
	   form.frmCTyp.focus();
	}	
	if(sel == 'r')
	{
	   form.frmCRNNo.value=""
	   //form.frmName.value=""
	   form.frmName.readOnly = false;
	}		
	
}	

function setName()
{
	form = document.Complaint;
	obj = form.frmCTyp
	sel = obj[obj.selectedIndex].value
	
	if(sel == "c")
	{
		no = form.frmCRNNo.value;
		cnt = document.Complaint["cnt"].value;	
		//alert(cnt)
		
		if(document.Complaint["ID"+no])
		{
			form.frmName.value = document.Complaint["ID"+no].value
			form.frmName.readOnly = true
		}
		else
		{
			form.frmName.value=""
			alert(" ERROR!!!\n CRN No. does not exist.\n Please re-enter the CRN No.")
		}
	}
}


 function resetForm(fname)
 {
     //alert(fname);
      eval('window.document.' + fname + '.reset()'); 
      return false;
   
 }



 function emptyDD(tmp_str_name,thisDoc)
 {
 	/* get the currrent no of options  */	
 	tmp_int_pLen = thisDoc[tmp_str_name].length;
 
 	/* empty the  drop down */
 	for(i=tmp_int_pLen;i>=0;i--)
 	{
 		thisDoc[tmp_str_name].options[i] = null;
 	}
}