// Checks if a passed string is empty
function searchSubmit(frm)
{
	var validForm = true;
	if ( (!isStringEmpty(frm.pfrom.value) && !isNum(frm.pfrom.value)) || (!isStringEmpty(frm.pto.value) && !isNum(frm.pto.value))) 
	{
		alert("Price must be a numeric value");
		validForm = false;
	}
	if ( (!isStringEmpty(frm.pfrom.value) && (isStringEmpty(frm.pto.value))) || (!isStringEmpty(frm.pto.value) && (isStringEmpty(frm.pfrom.value))) ) 
	{
		alert("Please enter values for both from and to values");
		validForm = false;
	}
	
	if ( (!isStringEmpty(frm.pfrom.value) && isNum(frm.pfrom.value)) || (!isStringEmpty(frm.pto.value) && isNum(frm.pto.value))) 
	{
		if (parseInt(frm.pto.value) < parseInt(frm.pfrom.value))
		{
			alert("Price from value cannot be greater than to value");
			validForm = false;
		}
	}
	return validForm;
}

function isStringEmpty(str)
{
	var tmpString;
	
	tmpString = str;
	// Trim the string in a while loop
	while(''+ tmpString.charAt(0)==' ')
	{
		tmpString = tmpString.substring(1,tmpString.length);
	}
	if (tmpString == '')
	{
		return true; // Yes the text is empty
	}
	return false; // No The text is not empty
}

//Checks if a value is numeric
function isNum(passedVal)
{
	for (i=0; i<passedVal.length; i++)
	{
		if ((passedVal.charAt(i) != "0") &&
		    (passedVal.charAt(i) != "1") &&
		    (passedVal.charAt(i) != "2") &&
		    (passedVal.charAt(i) != "3") &&
	 		 (passedVal.charAt(i) != "4") &&
			 (passedVal.charAt(i) != "5") &&
			 (passedVal.charAt(i) != "6") &&
			 (passedVal.charAt(i) != "7") &&
			 (passedVal.charAt(i) != "8") &&
			 (passedVal.charAt(i) != "9") )
  			return false;
	}
	return true;
}

function isNumeric(strString)
   //  check for valid numeric strings	
{
	var strValidChars = "0123456789.";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
		 	blnResult = false;
		}
	}
	return blnResult;
}

function uncheck(cur_field, list_field) 
{
  var checkflag = "true";
  for (i = 0; i < cur_field.length; i++) 
	{
		 if (cur_field[i].checked == false)
		 {
 	      checkflag = "false";
				break; 
		 }
	 }
	 if (checkflag == "false")
	 {
   	  list_field.checked = false;
	 }
	 else
	 {
      list_field.checked = true;
	 }
}

function check(source_field, list_field) 
{
  if (source_field.checked == true) 
	{
	 	 for (i = 0; i < list_field.length; i++) 
		 {
		 	 list_field[i].checked = true;
		 }
  }
	else 
	{
		for (i = 0; i < list_field.length; i++) 
		{
		 		list_field[i].checked = false; 
		}
	}
}

