

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

function checkWholeForm(theForm) {
	
    var why = "";
	
   

//alert(document.getElementById('Cities').value);
	//  why += checkDropdown(theForm.country.value, 'country');
	 why += checkDropdown(theForm.category.value, 'category');
	why += checkDropdown(theForm.States.value, 'States');
	why += checkDropdown(theForm.Cities.value, 'Cities');
	
	  //why += checkDropdown(theForm.budget.value, 'budget');
	 
     
//    why += isDifferent(theForm.different.value);
    /////// IF OTHER INFORMATION IS DISPLAY THEN DO CHECK OTHER VALIDATIONS
		
	
	
	/////////// OTHE INFORMATION VALIDATION ENDS HERE
   
    if (why != "") {
       alert(why);
       return false;
    }
	else
	{
		//alert("Well done! Data is Valid");
	}
return true;
}





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


// email

function checkEmail (strng, nm) {
	document.getElementById(nm).style.background="#ffffff";
var error="";
if (strng == "") {
  // error = "You didn't enter an email address.\n";
    document.getElementById(nm).style.background="#ffbeaa";
}
else
{

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
	    document.getElementById(nm).style.background="#ffbeaa";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
}
return error;    
}





// 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;	  
}


// exactly one radio button is chosen

function checkRadio(checkvalue, nm) {
	   document.getElementById(nm).style.background="#ffffff";
var error = "";
   if (!(checkvalue)) {
       error = "Please choose category.\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 = "You didn't choose an option from the drop-down ";
	error += nm;
	error += "\n";
	 document.getElementById(nm).style.background="#ffbeaa";
    } 
	else if(choice == 0)
	{	//alert("Hi I am 0");
		if(nm=='Country')
		{			}
		if(nm=='States')
		{	
			document.getElementById(nm).style.background="#ffbeaa";
			error = "You should not choose  'Other State' \n ";
			
		}
		if(nm=='Cities')
		{
			error = "You should not 'other City' \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+'.');}

           