// JavaScript Document
//Written by Rupak Kharel
// Use function validate such that the form elements are checked if they are filled or not.. Required field are given id value of 
// form element this way =>  <input type=text name=username id=Username_required>
// here first part of id before underscore ie, Username is used to display on alert and _required part is to know if the element is required or not....
// if an element is optional then just ignore this convention...
// id is used, because this way you just have to change your working code by changing id, not the name attribute of field...
function validate(thisform)
        {
        returnval=true;
        for (var j=0; j<(thisform.elements.length); j++)
                {
                indx = thisform.elements[j].id.indexOf('_required');
                if (indx != -1)
                        {
						display=thisform.elements[j].id.substring(0,indx);
                        fieldname=thisform.elements[j].name;
                        if (thisform.elements[fieldname].value.length == 0)
                                {
                                alert(display+" can not be empty!!!");
                                thisform.elements[j].focus();
                                returnval = false;
								break;
                                }
                        }
                }
        return returnval;
        }
		
function IsNumeric(sText)
{  //alert('sfsdf');
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   if(!IsNumber)
    alert("This should be numeric value!!!")
	
   return IsNumber;
   
   }

function checknumber(obj,form){
var x=obj.value
var anum=/(^\d+$)|(^\d+\.\d+$)/
if (anum.test(x))
testresult=true
else{
alert("Please input a valid number!")
obj.focus()
testresult=false
}
return (testresult)
}

function confirmreset(){
	return confirm('This will clear the form!!!, Are u sure to continue???');
}

function noimage(obj)
{
    obj.src="images/nopic.jpg";
}
