var wfo = {
    
    contactTitle : Object(),
    myvar : "test",
    
    init : function() {

	this.contactTitle["Corporate Office"] = new Array("Jay Smolin", "erequest@wilmingtonfamilyoffice.com");
        this.contactTitle["California"] = new Array("Alan Bonde", "erequest@wilmingtonfamilyoffice.com");
        this.contactTitle["Connecticut"] = new Array("Jay Smolin", "erequest@wilmingtonfamilyoffice.com");
        this.contactTitle["Delaware"] = new Array("Jack Garniewski", "erequest@wilmingtonfamilyoffice.com");
        this.contactTitle["New Jersey"] = new Array("Jay Smolin", "erequest@wilmingtonfamilyoffice.com");
        this.contactTitle["New York"] = new Array("Jay Smolin", "erequest@wilmingtonfamilyoffice.com");

    },
    
    setOfficeLoc : function(evt) {
        evt = (evt) ? evt : ((window.event) ? window.event : "")
        if (evt) {
            var elem
            if (evt.target) {
                elem = (evt.target.nodeType == 3) ? evt.target.parentNode : evt.target;
            } else {
                elem = evt.srcElement;
            }
            if (elem) {
                //alert(elem.id);
                var theElement = elem;
                var theForm = theElement.form;
                var tval = wfo.getRadioVal(theForm[theElement.name]);
                
                if (wfo.contactTitle[tval]) {
                    //alert(this.contactTitle[tval][0]);
                    theForm.appt_to.value=wfo.contactTitle[tval][0];
                    theForm.appt_to_email.value=wfo.contactTitle[tval][1];
                }
            }
        }
    },
    
    setOfficeLoc2 : function(theElement) {
        //alert(theElement.id)
        var theForm = theElement.form;
        var tval = this.getRadioVal(theForm[theElement.name]);
        if (this.contactTitle[tval]) {
            //alert(this.contactTitle[tval][0]);
            theForm.appt_to.value=this.contactTitle[tval][0];
            theForm.appt_to_email.value=this.contactTitle[tval][1];
        }
    },
    
    setOfficeTriggers : function() {
        var myElement = document.getElementById("appt_officeselect_main");
        var myForm = myElement.form;
        var myTarget = myForm.elements[myElement.name];

        if (typeof(myTarget.length) != "undefined") {
            for (i=0;i<myTarget.length;i++) {
                myTarget[i].onclick = wfo.setOfficeLoc;
    	    }
        } else {
            myTarget.onclick = wfo.setOfficeLoc;
        }
    },
    
    setFirstClick : function() {
        myElement = document.getElementById("appt_officeselect_main");
        myForm = myElement.form;
        myTarget = myForm.elements[myElement.name];

        var tval = wfo.getRadioVal(myForm[myElement.name]);
            
        if (tval=="") { 
            myElement.checked = true;
            tval = wfo.getRadioVal(myForm[myElement.name]);
        }
        
        if (wfo.contactTitle[tval]) {
            //alert(this.contactTitle[tval][0]);
            myForm.appt_to.value=wfo.contactTitle[tval][0];
            myForm.appt_to_email.value=wfo.contactTitle[tval][1];
        }
    },
    
    getRadioVal : function(theObject) {
        var tval = "";    
        
        //alert(theObject.name + ":" + theObject.id + ":" + theObject.length);
        if (typeof(theObject.length) != "undefined") {
            for (i=0;i<theObject.length;i++) {
    		    if (theObject[i].checked==true) {
    			    tval = theObject[i].value;
    			    break;
    		    }
    	    }
        } else {
            tval = theObject.value;
        }
        return tval;
    }, 
    
    setRadio:function(theElement, theValue) {
        var i;
        for (i=0;i<theElement.length;i++) {
            //alert(theElement.name+":"+theElement[i].value +":"+theValue)
    		if (theElement[i].value == theValue) {
    			theElement[i].checked=true;
    			break;
    		}
    	}
    },
    
    checkForm:function(theElement){
        //this.setOfficeLoc(document.getElementById("appt_officeselect"))
        //required field checking to go here.
        var theForm = theElement.form;
        var formOK = true;
        
        if (theForm.appt_firstname.value=="") {
            formOK = false;
            alert("Please enter your firstname.");
            theForm.appt_firstname.focus();
        } else if (this.getRadioVal(theForm.appt_replypref)=="") {
            formOK = false;
            alert("Please select a contact method preference.");
            theForm.appt_replypref[0].focus();
        }
        return formOK;
    },
    
    cancelClick:function(theElement){
        //this.setOfficeLoc(document.getElementById("appt_officeselect"))
        //required field checking to go here.
        var theForm = theElement.form;
        var formOK = true;
        
        theForm.reset();
        this.setFirstClick();
    }
    
}

wfo.init();
