function matrimSearchCheckAdNo (form) {
	if (form.AdID.value == "" || form.AdID.value.match(/\D/)) {
		alert ('Please enter a valid Ad Id.  Please remember our Ad Ids consist of only numbers and not other alphabets.  If you are entering alphabets, it is perhaps an Ad Id of another website.');
		return false;
	}
	return true;
}

function addNoCastePref () {
	document.getElementById('NoCastePref').style.display	='block';
	document.getElementById('NoCastePrefHelp').style.display	='none';
	document.getElementById('NoCasteBtn').checked = true;
}
function removeNoCastePref () {
	document.getElementById('NoCastePref').style.display	='none';
	document.getElementById('NoCastePrefHelp').style.display	='block';
	document.getElementById('NoCasteBtn').checked = false;
}

// Taken out the Mangalik, CasteMatch for now.  Need to add to sql in search also
function addAdvSearchOptions (theForm)
{
	document.getElementById('AdvSearchOptions1').style.display	='inline';
	document.getElementById('AdvSearchOptions2').style.display	='inline';
	//document.getElementById('AdvSearchOptions3').style.display	='inline';
	document.getElementById('RemoveAdvSearchOpt').style.display	='inline';
	document.getElementById('AddAdvSearchOpt').style.display	='none';
}

function removeAdvSearchOptions (theForm)
{
	document.getElementById('AdvSearchOptions1').style.display	='none';
	document.getElementById('AdvSearchOptions2').style.display	='none';
	//document.getElementById('AdvSearchOptions3').style.display	='none';
	document.getElementById('RemoveAdvSearchOpt').style.display	='none';
	document.getElementById('AddAdvSearchOpt').style.display	='inline';
	document.getElementById('Complexion').selectedIndex = -1;
	document.getElementById('Build').selectedIndex = -1;
	document.getElementById('PhysicalStatus').selectedIndex = 0;
	document.getElementById('Diet').selectedIndex = -1;
	//document.getElementById('ComplexionList').value = ""; use if IE causes a problem
}

// If a user selects a specific brahmin caste and not the general brahmin caste, we select the
// general brahmin for him as well
function selectBrahmin (theForm) {

	var specBrahminSelected = 0;
	var brahminPos;
    var brahminSelected = 0;

	// Loop through the caste list to see if a specific brahmincaste is selected and the
	// general caste is not selected.  While at it determin the postion of the general brahmin caste
	// as we need it to select the item if needed
	for (var i = 0; i < theForm.Caste.length; i++){

		if (theForm.Caste.options[i].selected == true) {
			if (theForm.Caste.options[i].text.match(/Brahmin-/)) { // Is a specific brahmin caste selected ?
				specBrahminSelected = 1;
				continue; // Continue on, as the specific brahmin caste will also match the next if statement
			}

			// The following if stament must be after the preceding if, as it is meant only for general barhmin caste
			if (theForm.Caste.options[i].text.match(/Brahmin/)) { // Is a general brahmin caste selected ?
				brahminSelected = 1;
			}
		}

		// Record the position of the general brahmin caste, but not of specific ones
		if (theForm.Caste.options[i].text.match(/Brahmin/) && !theForm.Caste.options[i].text.match(/Brahmin-/)) {
			brahminPos = i;
		}
	}

	// Alert user
	if (specBrahminSelected && !brahminSelected) {
		alert ('You have selected a specific Brahmin caste.  Specific Brahmin caste have been introduced recently.  Therefore, some profiles posted previously under general Brahmin may come under your caste.  We will therefore automatically added general Brahmins to your search criteria. ');
		theForm.Caste.options[brahminPos].selected = true;
	}
}

function matrimSearchCheck (theForm)
{
	if (theForm.Type.options[theForm.Type.selectedIndex].text == "Pick One")
  	{
    	alert("Need to pick the \"Type\" (Bride or Groom).");
    	theForm.Type.focus();
    	return (false);
  	}

  if (theForm.MinAge.value.length > 2)
  {
    alert("Please enter at most 2 characters in the \"Minimum Age\" field.");
    theForm.MinAge.focus();
    return (false);
  }

  var checkOK = "0123456789-";
  var checkStr = theForm.MinAge.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Minimum Age\" field.");
    theForm.MinAge.focus();
    return (false);
  }

  if (theForm.MaxAge.value.length > 2)
  {
    alert("Please enter at most 2 characters in the \"Maximum Age\" field.");
    theForm.MaxAge.focus();
    return (false);
  }

  var checkOK = "0123456789-";
  var checkStr = theForm.MaxAge.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Maximum Age\" field.");
    theForm.MaxAge.focus();
    return (false);
  }

  if (theForm.MinHt.options[theForm.MinHt.selectedIndex].value != "" &&
   theForm.MaxHt.options[theForm.MaxHt.selectedIndex].value != "")
	{
    if (theForm.MaxHt.options[theForm.MaxHt.selectedIndex].value <
        theForm.MinHt.options[theForm.MinHt.selectedIndex].value) {
        alert("Maximum height cannot be less that Minimum height");
        theForm.MinHt.focus();
        return (false);
    }
  }

  return (true);
}

