//-------------------//
// Submit other form //
//-------------------//
function doOther(f){
	f.submit();
	return(false);
}
//----------------------------------------//
// Verify string array has at least 1 "Y" //
//----------------------------------------//
function checkArray(x){
	var i;
	var array=x.value;
	for(i=0;i<array.length;i++){
		if(array.charAt(i)=="Y"){
			return(true);
		}
	}
	alert("Please select one or more catigories.")
	return(false);
}
//-----------------------------------------------//
// Toggal char in string array between "." & "Y" //
//-----------------------------------------------//
function setFlagAt(x, n){
	var j=n-1;
	var xin=x.value;
	var out=String("");
	for(i=0;i<xin.length;i++){
		if(i==j){
			if(xin.charAt(i)=="Y")
				out=out+".";
			else
				out=out+"Y";
		}else
			out=out+xin.charAt(i);
	}
	x.value=out;
}
//-------------------//
// Set a field value //
//-------------------//
function setField(x, y){
	x.value=y;
}
//------------------------//
// submit form validation //
//------------------------//
function searchVal(theObj, sndxObj){
  if(theObj.value==""){
    alert("Please enter at least a partial search name.");
    theObj.focus();
    return(false);
  }
  if(sndxObj.value==""){
    phonetic(sndxObj, theObj);
  }
  return(true);
}
//-----------------------//
// Search key generation //
//-----------------------//
function searchInit(keyObj, nameObj, ctlObj, ctlConst) {
  ctlObj.value=ctlConst;
  phonetic(keyObj, nameObj);
}
//---------------------------------//
// phonetic/soundex key generation //
//---------------------------------//
function phonetic(keyObj, nameObj) {
  var i = 0;
  var j = 0;
  var chSoundexCode = '0';
  var chPrevSoundexCode = '0';
  var strResult = '';
  var chSwitch = '0';
  if (nameObj.value == "") {
	keyObj.value="";
	return(false);
  }	
  else {
	//Convert name to uppercase, and remove non-alpha characters
	var chAlphaName = toAlphax(nameObj);
	//For each character in name, set appropriate Soundex value
	for (i = 0; (i < chAlphaName.length && j < 4); i++) {
	    chSwitch = chAlphaName.charAt(i);
	    if (chSwitch == 'R') {
	       chSoundexCode = '6'}
	    else
	    if (chSwitch == 'M' ||
	        chSwitch == 'N') {
	       chSoundexCode = '5'}
	    else
	    if (chSwitch == 'L') {
	       chSoundexCode = '4'}
	    else
	    if (chSwitch == 'D' ||
	        chSwitch == 'T') {
	       chSoundexCode = '3'}
	    else
	    if (chSwitch == 'C' ||
 	        chSwitch == 'S' ||
	        chSwitch == 'K' ||
	        chSwitch == 'G' ||
	        chSwitch == 'J' ||
	        chSwitch == 'Q' ||
	        chSwitch == 'X' ||
	        chSwitch == 'Z') {
	       chSoundexCode = '2'}
	    else
	    if (chSwitch == 'B' ||
	        chSwitch == 'P' ||
	        chSwitch == 'F' ||
	        chSwitch == 'V') {
	       chSoundexCode = '1'};
	    if (chSoundexCode > '0' || j == 0) {
	       if (j == 0 || chSoundexCode != chPrevSoundexCode) {
	          strResult += chSoundexCode ;
		  j++
	       }
	    }
	    if (j == 0) {
	       j++ }
	    chPrevSoundexCode = chSoundexCode;
	    chSoundexCode = '0';
	}

	//Append zeroes to the end of the number
	for (i = j; i <= 4; i++) {
	    strResult += '0' }
	keyObj.value = chAlphaName.charAt(0) + strResult.substring(1,4);
  }
  return(true);
}
//---------------------------------------//
// This function receives an input box.  //
// It returns the alpha characters only, //
// in uppercase.						 //
//---------------------------------------//
function toAlphax(n) {
	var chAlpha = "";
	var inStr = n.value.toUpperCase();
	var inLen = inStr.length;
	for(var i = 0; i < inLen; i++) {
		var ch = inStr.charAt(i);
                if (ch >= "A" && ch <= "Z") {
                   chAlpha += ch;
		}
	}
	return chAlpha;
}
//-----//
// End //
//-----//

