//script to auto tab to next feild for Phone enteries


<!-- This script is based on the javascript code of Roman Feldblum (web.developer@programmer.net) -->
<!-- Original script : http://javascript.internet.com/forms/format-phone-number.html -->
<!-- Original script is revised by Eralper Yilmaz (http://www.eralper.com) -->
<!-- Revised script : http://www.kodyaz.com -->

var zChar = new Array(' ', '(', ')', '-', '.');
var maxphonelength = 13;
var phonevalue1;
var phonevalue2;
var cursorposition;

function ParseForNumber1(object){
phonevalue1 = ParseChar(object.value, zChar);
}
function ParseForNumber2(object){
phonevalue2 = ParseChar(object.value, zChar);
}

function backspacerUP(object,e) {
if(e){
e = e
} else {
e = window.event
}
if(e.which){
var keycode = e.which
} else {
var keycode = e.keyCode
}

ParseForNumber1(object)

if(keycode >= 48){
ValidatePhone(object)
}
}

function backspacerDOWN(object,e) {
if(e){
e = e
} else {
e = window.event
}
if(e.which){
var keycode = e.which
} else {
var keycode = e.keyCode
}
ParseForNumber2(object)
}

function GetCursorPosition(){

var t1 = phonevalue1;
var t2 = phonevalue2;
var bool = false
for (i=0; i<t1.length; i++)
{
if (t1.substring(i,1) != t2.substring(i,1)) {
if(!bool) {
cursorposition=i
bool=true
}
}
}
}

function ValidatePhone(object){

var p = phonevalue1

p = p.replace(/[^\d]*/gi,"")

if (p.length < 3) {
object.value=p
} else if(p.length==3){
pp=p;
d4=p.indexOf('(')
d5=p.indexOf(')')
if(d4==-1){
pp="("+pp;
}
if(d5==-1){
pp=pp+")";
}
object.value = pp;
} else if(p.length>3 && p.length < 7){
p ="(" + p;
l30=p.length;
p30=p.substring(0,4);
p30=p30+")"

p31=p.substring(4,l30);
pp=p30+p31;

object.value = pp;

} else if(p.length >= 7){
p ="(" + p;
l30=p.length;
p30=p.substring(0,4);
p30=p30+")"

p31=p.substring(4,l30);
pp=p30+p31;

l40 = pp.length;
p40 = pp.substring(0,8);
p40 = p40 + "-"

p41 = pp.substring(8,l40);
ppp = p40 + p41;

object.value = ppp.substring(0, maxphonelength);
}

GetCursorPosition()

if(cursorposition >= 0){
if (cursorposition == 0) {
cursorposition = 2
} else if (cursorposition <= 2) {
cursorposition = cursorposition + 1
} else if (cursorposition <= 5) {
cursorposition = cursorposition + 2
} else if (cursorposition == 6) {
cursorposition = cursorposition + 2
} else if (cursorposition == 7) {
cursorposition = cursorposition + 4
e1=object.value.indexOf(')')
e2=object.value.indexOf('-')
if (e1>-1 && e2>-1){
if (e2-e1 == 4) {
cursorposition = cursorposition - 1
}
}
} else if (cursorposition < 11) {
cursorposition = cursorposition + 3
} else if (cursorposition == 11) {
cursorposition = cursorposition + 1
} else if (cursorposition >= 12) {
cursorposition = cursorposition
}

var txtRange = object.createTextRange();
txtRange.moveStart( "character", cursorposition);
txtRange.moveEnd( "character", cursorposition - object.value.length);
txtRange.select();
}

}

function ParseChar(sStr, sChar)
{
if (sChar.length == null)
{
zChar = new Array(sChar);
}
else zChar = sChar;

for (i=0; i<zChar.length; i++)
{
sNewStr = "";

var iStart = 0;
var iEnd = sStr.indexOf(sChar[i]);

while (iEnd != -1)
{
sNewStr += sStr.substring(iStart, iEnd);
iStart = iEnd + 1;
iEnd = sStr.indexOf(sChar[i], iStart);
}
sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);

sStr = sNewStr;
}

return sNewStr;
}


// JavaScript Document

//script to auto tab to next feild for Phone enteries
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
// List some of this nominee's biggest professional accomplishments between October 2006 and July 2007
keytotal1 = 750;
function changed1 (form, mytext1) {
var s = mytext1.name;
var index;
if (s.indexOf('[') == -1) {
index = 0;
} else {
index = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
checkit1(mytext1,index);
}

function checkit1(mytext1,zindex) {
if (!(zindex >= 0)) {
zindex = '';
}
var s = mytext1.name;
var zindex;
if (s.indexOf('[') == -1) {
zindex = 0;
}
else
{
zindex = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
if (mytext1.value.length > keytotal1) {
mytext1.value = mytext1.value.substring(0,keytotal1);
}
if (document.getElementById('charCountA'+zindex)) {
document.getElementById('charCountA'+zindex).innerHTML = mytext1.value.length
}
}
// **********
// List any industry or in-house recognition that the nominee has received between October 2006 and July 2007
keytotal2 = 750;
function changed2 (form, mytext2) {
var s = mytext2.name;
var index;
if (s.indexOf('[') == -1) {
index = 0;
} else {
index = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
checkit2(mytext2,index);
}

function checkit2(mytext2,zindex) {
if (!(zindex >= 0)) {
zindex = '';
}
var s = mytext2.name;
var zindex;
if (s.indexOf('[') == -1) {
zindex = 0;
}
else
{
zindex = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
if (mytext2.value.length > keytotal2) {
mytext2.value = mytext2.value.substring(0,keytotal2);
}
if (document.getElementById('charCountB'+zindex)) {
document.getElementById('charCountB'+zindex).innerHTML = mytext2.value.length
}
}
// **********
// List any charitable or civic-minded organizations that the nominee is involved with
keytotal3 = 500;
function changed3 (form, mytext3) {
var s = mytext3.name;
var index;
if (s.indexOf('[') == -1) {
index = 0;
} else {
index = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
checkit3(mytext3,index);
}

function checkit3(mytext3,zindex) {
if (!(zindex >= 0)) {
zindex = '';
}
var s = mytext3.name;
var zindex;
if (s.indexOf('[') == -1) {
zindex = 0;
}
else
{
zindex = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
if (mytext3.value.length > keytotal3) {
mytext3.value = mytext3.value.substring(0,keytotal3);
}
if (document.getElementById('charCountC'+zindex)) {
document.getElementById('charCountC'+zindex).innerHTML = mytext3.value.length
}
}
// **********
// List any thoughts, predictions, trends or interesting notions the nominee may have in regards to Southern California’s commercial real estate market
keytotal4 = 500;
function changed4 (form, mytext4) {
var s = mytext4.name;
var index;
if (s.indexOf('[') == -1) {
index = 0;
} else {
index = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
checkit4(mytext4,index);
}

function checkit4(mytext4,zindex) {
if (!(zindex >= 0)) {
zindex = '';
}
var s = mytext4.name;
var zindex;
if (s.indexOf('[') == -1) {
zindex = 0;
}
else
{
zindex = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
if (mytext4.value.length > keytotal4) {
mytext4.value = mytext4.value.substring(0,keytotal4);
}
if (document.getElementById('charCountD'+zindex)) {
document.getElementById('charCountD'+zindex).innerHTML = mytext4.value.length
}
}
// **********
// List any thoughts, predictions, trends or interesting notions the nominee may have in regards to Southern California’s commercial real estate market
keytotal5 = 500;
function changed5 (form, mytext5) {
var s = mytext5.name;
var index;
if (s.indexOf('[') == -1) {
index = 0;
} else {
index = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
checkit5(mytext5,index);
}

function checkit5(mytext5,zindex) {
if (!(zindex >= 0)) {
zindex = '';
}
var s = mytext5.name;
var zindex;
if (s.indexOf('[') == -1) {
zindex = 0;
}
else
{
zindex = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
if (mytext5.value.length > keytotal5) {
mytext5.value = mytext5.value.substring(0,keytotal5);
}
if (document.getElementById('charCountE'+zindex)) {
document.getElementById('charCountE'+zindex).innerHTML = mytext5.value.length
}
}
// **********
// List any thoughts, predictions, trends or interesting notions the nominee may have in regards to Southern California’s commercial real estate market
keytotal6 = 750;
function changed6 (form, mytext6) {
var s = mytext6.name;
var index;
if (s.indexOf('[') == -1) {
index = 0;
} else {
index = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
checkit6(mytext6,index);
}

function checkit6(mytext6,zindex) {
if (!(zindex >= 0)) {
zindex = '';
}
var s = mytext6.name;
var zindex;
if (s.indexOf('[') == -1) {
zindex = 0;
}
else
{
zindex = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
if (mytext6.value.length > keytotal6) {
mytext6.value = mytext6.value.substring(0,keytotal6);
}
if (document.getElementById('charCountF'+zindex)) {
document.getElementById('charCountF'+zindex).innerHTML = mytext6.value.length
}
}
// **********
// List any thoughts, predictions, trends or interesting notions the nominee may have in regards to Southern California’s commercial real estate market
keytotal7 = 750;
function changed7 (form, mytext7) {
var s = mytext7.name;
var index;
if (s.indexOf('[') == -1) {
index = 0;
} else {
index = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
checkit7(mytext7,index);
}

function checkit7(mytext7,zindex) {
if (!(zindex >= 0)) {
zindex = '';
}
var s = mytext7.name;
var zindex;
if (s.indexOf('[') == -1) {
zindex = 0;
}
else
{
zindex = s.substring( s.indexOf('[')+1,s.indexOf(']') );
}
if (mytext7.value.length > keytotal7) {
mytext7.value = mytext7.value.substring(0,keytotal7);
}
if (document.getElementById('charCountG'+zindex)) {
document.getElementById('charCountG'+zindex).innerHTML = mytext7.value.length
}
}
// **********


// VALIDATE FORM

function validateform()
{
	formerrors = "";
    valid = true;

	if (document.women.firstname.value=="")
    {
        formerrors=formerrors + "- Nominee First Name is missing \n";
        valid=false;
    }
	if (document.women.lastname.value=="")
    {
        formerrors=formerrors + "- Nominee Last Name is missing \n";
        valid=false;
    }
	if (document.women.title.value=="")
    {
        formerrors=formerrors + "- Title is missing \n";
        valid=false;
    }
	if (document.women.company.value=="")
    {
        formerrors=formerrors + "- Company is missing \n";
        valid=false;
    }
	if (document.women.address1.value=="")
    {
        formerrors=formerrors + "- Address is missing \n";
        valid=false;
    }
	if (document.women.city.value=="")
    {
        formerrors=formerrors + "- City is missing \n";
        valid=false;
    }
	if (document.women.state.value=="")
    {
        formerrors=formerrors + "- State is missing \n";
        valid=false;
    }
		if (document.women.zip.value=="")
    {
        formerrors=formerrors + "- Zip is missing \n";
        valid=false;
    }
			if (document.women.telephone.value=="")
    {
        formerrors=formerrors + "- Telephone is missing \n";
        valid=false;
    }

	if (document.women.yearsInBusiness.value=="")
    {
        formerrors=formerrors + "- Years in Business is missing \n";
        valid=false;
    }
	if (document.women.yearsInCurrentPosition.value=="")
    {
        formerrors=formerrors + "- Years in Current Position is missing \n";
        valid=false;
    }
	if (document.women.geographicFocus.value=="")
    {
        formerrors=formerrors + "-  Geographic Focus is missing \n";
        valid=false;
    }
		if (document.women.businessSpecialty.value=="")
    {
        formerrors=formerrors + "- Type of Business/Specialty is missing \n";
        valid=false;
    }
			if (document.women.propertyCategory.value=="")
    {
        formerrors=formerrors + "- Type Property Category is missing \n";
        valid=false;
    }

		if (document.women.currentResponsibilities.value=="")
    {
        formerrors=formerrors + "- Current Responsibilities is missing \n";
        valid=false;
    }
	if (document.women.accomplishments.value=="")
    {
        formerrors=formerrors + "- Greatest Professional Accomplishments Over the Past 12 Months is missing \n";
        valid=false;
    }
	if (document.women.inhouseIndustryAccomplishments.value=="")
    {
        formerrors=formerrors + "- In-House or Industry Accomplishments or Recongnitions Over the Past 12 Months is missing \n";
        valid=false;
    }
	if (document.women.careerOrientedOrganizations.value=="")
    {
        formerrors=formerrors + "- Membership/Activity in Business or Career-Oriented Organizations is missing \n";
        valid=false;
    }
		if (document.women.civicMindedOrganizations.value=="")
    {
        formerrors=formerrors + "- Membership/Activity in Charitable or Civic-Minded Organizations is missing \n";
        valid=false;
    }
		if (document.women.overallCareerGoals.value=="")
    {
        formerrors=formerrors + "- Overall Career Goals is missing \n";
        valid=false;
    }
			if (document.women.overviewMajorTrends.value=="")
    {
        formerrors=formerrors + "- Major Trends is missing \n";
        valid=false;
    }

	if (document.women.cname.value=="")
    {
        formerrors=formerrors + "- Submitter Contact Name is missing \n";
        valid=false;
    }
	if (document.women.ctitle.value=="")
    {
        formerrors=formerrors + "- Submitter Title is missing \n";
        valid=false;
    }
	if (document.women.ccompany.value=="")
    {
        formerrors=formerrors + "- Submitter Company is missing \n";
        valid=false;
    }
	if (document.women.caddress1.value=="")
    {
        formerrors=formerrors + "- Submitter Address is missing \n";
        valid=false;
    }
	if (document.women.ccity.value=="")
    {
        formerrors=formerrors + "- Submitter City is missing \n";
        valid=false;
    }
	if (document.women.cstate.value=="")
    {
        formerrors=formerrors + "- Submitter State is missing \n";
        valid=false;
    }
	if (document.women.czip.value=="")
    {
        formerrors=formerrors + "- Submitter Zip Code is missing \n";
        valid=false;
    }
    if (document.women.cphone=="")
    {
        formerrors=formerrors + "- Submitter Phone is missing \n";
        valid=false;
    }
	    if (document.women.email.value=="" || valEmail(document.women.email)==null)
    {
        formerrors=formerrors + "- Nominee Email is missing or invalid \n";
        valid=false;
    }

    if (document.women.cemail.value=="" || valEmail(document.women.cemail)==null)
    {
        formerrors=formerrors + "- Submitter Email is missing or invalid \n";
        valid=false;
    }

	if (formerrors!="")
	{
		alert("Please correct the following errors: \n" + formerrors);
	}
    return valid;
}
function valEmail(eml) {
	if (eml.value.indexOf("@")<1) return null;
	else return 1;
}
function valForm()
{
	formerrors2 = "";
    valid = true;
		if (document.women.initials.value=="")
    {
        formerrors2=formerrors2 + "- Please put in your initals before submitting \n";
        valid=false;
    }

	if (formerrors2!="")
	{
		alert("Please correct the following errors: \n" + formerrors2);
	}

    return valid;
}
