﻿// JScript File
// Project created by Malcolm Washington
/*
 * Arrayplay(R) SoundexCalculator Analyzer.js v1.0
 *
 *    Copyright 2007-2008, Arrayplay.com
 *           ALL RIGHTS RESERVED
 *
 * All copyrights are reserved by Arrayplay.com.
 *
 * Copying, distributing, or making derivative works
 * of this source code is forbidden by U.S. and
 * international copyright law.
 *
 * Do not copy, distribute, or make derivative
 * works from this source code without first obtaining
 * expressed written permission from Arrayplay.com.
 *
 *
 *    For usage and licensing information
 *       contact: mail@downloadzombie.com
 *       or visit: www.Arrayplay.com
 * ------------------------------------------
*/
function FP_swapImg() 
{
//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) 
 { 
 elm=FP_getObjectByID(args[n]); if(elm) 
 { 
 doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; 
 } 
 }
}

function FP_preloadImgs() 
{
//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) 
 { 
 d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; 
 }
}

function FP_getObjectByID(id,o) 
{
//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) 
 { 
 el=FP_getObjectByID(id,c[n]); if(el) return el; 
 }
 f=o.forms; if(f) for(n=0; n<f.length; n++) 
 { 
 els=f[n].elements;
 for(m=0; m<els.length; m++)
 { 
 el=FP_getObjectByID(id,els[n]); if(el) return el; 
 } 
 }
 return null;
}
// 

function doSoundex() 
{
  var su = document.frm.surname.value.toLowerCase();
  if( su == "" ) 
  { 
  alert("ERROR: Please enter a word or surname."); return; 
  }
  var l = su.length;
  var x1;
  var tn = "";
  var out = "";
  var ct = 0;
  var play = document.frm.surname.value;
  for( i=0; i<l; i++ ) 
  {
    var n = "0";
    var c1 = su.charAt(i);
    if( (c1=="a")||(c1=="e")||(c1=="i")||(c1=="o")||(c1=="u")||(c1=="y") ) 
    { 
    n="-1"; 
    }
    else if( (c1=="h")||(c1=="w") ) 
    { 
    n="-2"; 
    }
    else if( (c1=="b")||(c1=="p")||(c1=="f")||(c1=="v") ) 
    { 
    n="1"; 
    }
    else if( (c1=="c")||(c1=="s")||(c1=="k")||(c1=="g")||(c1=="j")||(c1=="q")||(c1=="x")||(c1=="z") ) 
    { 
    n="2"; 
    }
    else if( (c1=="d")||(c1=="t") ) 
    { 
    n="3"; 
    }
    else if( (c1=="l") ) 
    { 
    n="4"; 
    }
    else if( (c1=="m")||(c1=="n") ) 
    { 
    n="5"; 
    }
    else if( (c1=="r") ) 
    { 
    n="6"; 
    }
    if( n==tn ) 
    { 
    tn=n; continue; 
    }
    if( (ct==0) && (n!=0) ) 
    { 
    x1 = c1.toUpperCase(); ct++; tn=n; 
    }
    else if( n>0 ) 
    { ct++; out=out+n; tn=n; 
    }
    else if( n==-1 ) 
    { 
    tn=n; 
    }
    if( ct==4 ) 
    { 
    break; 
    }
  }
  if( ct>0 ) 
  {
    var sdx = x1+out+"000";
    frm.T1.value = "Soundex Results for "+play+" = "+sdx.substring(0,4);
    
  }
  else 
  { 
    document.frm.T1.value = "";
    alert("ERROR: Please enter a word or surname."); 
  }
}
function getkeycode(e) 
{
  var keycode;
  if (e) keycode = e.which;
  if (keycode == 13) { doSoundex(); 
  }
}
function doload(frm) 
{
  document.frm.surname.focus();
}
function validateForm(frm) 
{
var surname;
var T1;
surname = frm.elements[0];
T1 = frm.elements[1];
if ((surname.value == "") || (T1.value == '')) 
{
      alert("ERROR: There is nothing to clear.");
      }
      else 
      {
      ((document.frm.surname.value == "") || (document.frm.T1.value == ''));
      } 
    }
  


