
///////// FUNCTION FIRES ON CLICK OF SUBMIT BUTTON

function checkWholeForm(theForm) {
	
    var why = "";
	
   
	why += isEmpty1(theForm.username.value, 'username');
		
	why += isEmpty(theForm.password.value, 'password');
	why += checkDropdown(theForm.usertype.value, 'usertype');	
	
	/////////// OTHE INFORMATION VALIDATION ENDS HERE
   
    if (why != "") {
       alert(why);
       return false;
    }
	else
	{
		//alert("Well done! Data is Valid");
	}
return true;
}





/**********************  VALIDATION FUNCTIONS BELOW ********************
/**********************                              *******************/

function isEmpty1(strng, nm) {
	   document.getElementById(nm).style.background="#ffffff";
var error = "";
  if (strng.length == 0) {
     error = " ";
	 if(nm=='cp')
	 { error += 'Contact Person';
	 }
	 else
	 {
	 error += nm;
	 }
	 error += "  has not been filled in.\n";
	  document.getElementById(nm).style.background="#ffbeaa";
  }
return error;	  
}


// email

// non-empty textbox

function isEmpty(strng, nm) {
	   document.getElementById(nm).style.background="#ffffff";
var error = "";
  if (strng.length == 0) {
     error = "";

	 if(nm=='minarea')
	 { error += 'Minimum Area';	 }
	 else if(nm=='maxarea')
	 { error += 'Maximum Area';	 }
	  else if(nm=='cname')
	 { error += 'Contact Person Name';	 }
	 else if(nm=='cphone')
	 { error += 'Contact Phone';	 }
	 else if(nm=='cmobile')
	 { error += 'Contact Mobile';	 }
	 else if(nm=='cemail')
	 { error += 'Contact Email';	 }
 	 else if(nm=='maxprice')
	 { error += 'Maximum Price';	 }
 	 else if(nm=='minprice')
	 { error += 'Minimum Price';	 }


	 else
	 {
	 error += nm;
	 }
	 error += "  has not been filled in.\n";
	  document.getElementById(nm).style.background="#ffbeaa";
  }
return error;	  
}



// valid selector from dropdown list

function checkDropdown(choice, nm) {
	   document.getElementById(nm).style.background="#ffffff";
var error = "";
    if (choice == '')
	{
    error = "Pls choose from the drop-down ";
	error += nm;
	error += "\n";
	 document.getElementById(nm).style.background="#ffbeaa";
    } 

		
		
	
return error;
}    




////////////////////////////////////////
/////////////////////////////////////

// Text Field Validation Functions



var numb = '0123456789 ';
var lwr = 'abcdefghijklmnopqrstuvwxyz ';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ';

function isValid(parm,val) {
  if (parm == "") return true;
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}

function isNum(parm) {return isValid(parm,numb);}
function isLower(parm) {return isValid(parm,lwr);}
function isUpper(parm) {return isValid(parm,upr);}
function isAlpha(parm) {return isValid(parm,lwr+upr);}
function isAlphanum(parm) {return isValid(parm,lwr+upr+numb);}
function isDecimal(parm) {return isValid(parm,numb+'.');}

           