
Ext.namespace('Applewood');

/*** Reference local blank image ***/
Ext.BLANK_IMAGE_URL = 'images/s.gif';

//Phone===================
Ext.form.VTypes["phoneVal"] = /^((\d{3}[-])|(\(\d{3}\)[ ]?))(\d{3}[-])(\d{4})$/;
    Ext.form.VTypes["phoneMask"] = /[() \d-]/;
    Ext.form.VTypes["phoneText"] = 'Please enter a valid phone number in the format: (303) 123-4567 or (303)123-4567 or 303-123-4567';
    Ext.form.VTypes["phone"]=function(v){
        return Ext.form.VTypes["phoneVal"].test(v);
};
//Zipcode===================
Ext.form.VTypes["zipVal"] = /^\d{5}$/;
Ext.form.VTypes["zipMask"] = /[\d-]/;
Ext.form.VTypes["zipText"] = 'Not a valid US zipcode. Must be in the format of 12345';
Ext.form.VTypes["zip"]=function(v){
    return Ext.form.VTypes["zipVal"].test(v);
};

Ext.onReady(function(){
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'qtip';
        
    var url = window.document.URL;
    var docName = url.substr(url.lastIndexOf('/'));
    switch(docName.replace('/',''))
    {
        case 'employment-application.html':        
            convertText('first-name', 100, '', 'First Name', true);
            convertText('last-name', 150, '', 'Last Name', true);
            convertText('email', 200, 'email', 'Ex: user@domain.com', true); //Email validation is built into ext
            convertText('home-phone', 200, 'phone', 'Ex: 123-456-7890', true);
            convertText('work-phone', 200, 'phone', 'Ex: 123-456-7890', true);
            convertText('address', 200, '', '', true);
            convertText('address2', 200, '', '', true);
            convertText('city', 200, '', '', true); 
            convertCombo('states', 125, 'Select or type', Applewood.states);
            convertText('zips', 100, 'zip', '', true);     
            convertCombo('positions', 125, 'Select or type', Applewood.positions);        
            convertText('experience', 30, '', '', true);
            convertCombo('licensed', 125, 'Select or type', Applewood.yesNo); 
            convertTextArea('license-list', 300, '', 'What licenses do you hold?', true);
            convertText('desired-pay', 50, '', '', true);
            convertTextArea('comments', 300, '', 'Do you have any questions for us?', true);
            break;
        case 'contact-us.html':
            convertText('name', 200, '', '', true);
            convertText('email', 200, 'email', 'Ex: user@domain.com', true); //Email validation is built into ext
            convertText('phone', 200, 'phone', 'Ex: 123-456-7890', true);
            convertText('address', 200, '', '', true);
            convertText('address2', 200, '', '', true);
            convertText('city', 200, '', '', true);
            convertText('zips', 100, 'zip', '', true);
            convertCombo('states', 125, 'Select or type', Applewood.states);
            convertTextArea('comments', 300, '', 'How can we help you?', true);    
            break;
        case '12in12.html':
            convertText('name', 200, '', '', true);
            convertText('email', 200, 'email', 'Ex: user@domain.com', true); //Email validation is built into ext
            convertText('phone', 200, 'phone', 'Ex: 123-456-7890', true);
            convertText('phone2', 200, 'phone', 'Ex: 123-456-7890', true);
            convertText('address', 200, '', '', true);
            convertText('address2', 200, '', '', true);
            convertText('city', 200, '', '', true);
            convertText('zips', 100, 'zip', '', true);
            convertCombo('states', 125, 'Select or type', Applewood.states);
            convertTextArea('comments', 300, '', 'How can we help you?', true);  
            convertText('np-name', 200, '', '', true);
            convertText('np-phone', 200, 'phone', 'Ex: 123-456-7890', true); 
            convertText('np-url', 250, '', 'http://www.nonprofit.org', true);   
            break;
    };    

    /* FOLLOWING FIELD TRAMSFORMS ARE ON ALL PAGES WITHIN THE SITE */
    //Convert schedule service form    
    convertText('service-name', 150, '', '', true);
    convertText('service-email', 150, 'email', 'Ex: user@domain.com', true); //Email validation is built into ext
    convertText('service-phone', 150, 'phone', 'Ex: 123-456-7890', true);
    convertText('service-address', 150, '', '', true);
    convertText('service-city', 150, '', '', true);
    convertTextArea('service-comments', 150, '', 'How can we help you?', true); 
    convertText('service-zips', 150, '', '', true);   
    
    //Convert email newsletter form
    convertText('newsletter-name', 150, '', '', true);
    convertText('newsletter-email', 150, 'email', 'Ex: user@domain.com', true);

    function convertCombo(fieldId,width,emptyText,data){
        new Ext.form.ComboBox({
            width:width,
            store:data,
            typeAhead:true,
            triggerAction:'all',
            applyTo:fieldId,
            emptyClass:'form-field-empty',
            forceSelection: true,
            emptyText:emptyText
        });
    }

    function convertText(fieldName, width, validation, emptyText, required){
        new Ext.form.TextField({
            width:width,
            allowBlank:required,
            applyTo:fieldName,
            vtype:validation,
            emptyText:emptyText,
            emptyClass:'form-field-empty',
            cls:'form-field',
            height:21
        });
    }
    
    function convertTextArea(fieldName, width, validation, emptyText, required){
        new Ext.form.TextArea({
            width:width,
            allowBlank:required,
            applyTo:fieldName,
            vtype:validation,
            emptyText:emptyText,
            emptyClass:'form-field-empty',
            cls:'form-field',
            height:50
        });
    }
       
});

Applewood.zipsCO = [80001,80002,80003,80004,80005,80006,80007,80010,80011,80012,80013,80014,80015,80016,80017,80018,80019,80020,80021,80022,80024,80025,80026,80027,80028,80030,80031,80033,80034,80035,80036,80037,80038,80040,80041,80042,80044,80045,80046,80047,80101,80102,80103,80104,80105,80106,80107,80108,80109,80110,80111,80112,80113,80116,80117,80118,80120,80121,80122,80123,80124,80125,80126,80127,80128,80129,80130,80131,80132,80133,80134,80135,80136,80137,80138,80150,80151,80154,80155,80160,80161,80162,80163,80165,80166,80201,80202,80203,80204,80205,80206,80207,80208,80209,80210,80211,80212,80214,80215,80216,80217,80218,80219,80220,80221,80222,80223,80224,80225,80226,80227,80228,80229,80230,80231,80232,80233,80234,80235,80236,80237,80238,80239,80241,80243,80244,80246,80247,80248,80249,80250,80251,80252,80254,80255,80256,80257,80259,80260,80261,80262,80263,80264,80265,80266,80270,80271,80273,80274,80275,80279,80280,80281,80285,80290,80291,80292,80293,80294,80295,80299,80301,80302,80303,80304,80305,80306,80307,80308,80309,80310,80314,80321,80322,80323,80328,80329,80401,80402,80403,80419,80420,80421,80422,80423,80424,80425,80426,80427,80428,80429,80430,80432,80433,80434,80435,80436,80437,80438,80439,80440,80442,80443,80444,80446,80447,80448,80449,80451,80452,80453,80454,80455,80456,80457,80459,80461,80463,80465,80466,80467,80468,80469,80470,80471,80473,80474,80475,80476,80477,80478,80479,80480,80481,80482,80483,80487,80488,80497,80498,80501,80502,80503,80504,80510,80511,80512,80513,80514,80515,80516,80517,80520,80521,80522,80523,80524,80525,80526,80527,80528,80530,80532,80533,80534,80535,80536,80537,80538,80539,80540,80541,80542,80543,80544,80545,80546,80547,80549,80550,80551,80553,80601,80602,80603,80610,80611,80612,80614,80615,80620,80621,80622,80623,80624,80631,80632,80633,80634,80638,80639,80640,80642,80643,80644,80645,80646,80648,80649,80650,80651,80652,80653,80654,80701,80705,80720,80721,80722,80723,80726,80727,80728,80729,80731,80732,80733,80734,80735,80736,80737,80740,80741,80742,80743,80744,80745,80746,80747,80749,80750,80751,80754,80755,80757,80758,80759,80801,80802,80804,80805,80807,80808,80809,80810,80812,80813,80814,80815,80816,80817,80818,80819,80820,80821,80822,80823,80824,80825,80826,80827,80828,80829,80830,80831,80832,80833,80834,80835,80836,80840,80841,80860,80861,80862,80863,80864,80866,80901,80903,80904,80905,80906,80907,80908,80909,80910,80911,80912,80913,80914,80915,80916,80917,80918,80919,80920,80921,80922,80925,80926,80928,80929,80930,80931,80932,80933,80934,80935,80936,80937,80940,80941,80942,80943,80944,80945,80946,80947,80949,80950,80960,80962,80970,80977,80995,80997,81001,81002,81003,81004,81005,81006,81007,81008,81009,81010,81011,81012,81013,81014,81015,81019,81020,81021,81022,81023,81024,81025,81027,81029,81030,81033,81034,81036,81038,81039,81040,81041,81043,81044,81045,81046,81047,81049,81050,81052,81054,81055,81057,81058,81059,81062,81063,81064,81067,81069,81071,81073,81074,81076,81077,81081,81082,81084,81087,81089,81090,81091,81092,81101,81102,81120,81121,81122,81123,81124,81125,81126,81127,81128,81129,81130,81131,81132,81133,81134,81135,81136,81137,81138,81140,81141,81143,81144,81146,81147,81148,81149,81151,81152,81153,81154,81155,81157,81201,81210,81211,81212,81215,81220,81221,81222,81223,81224,81225,81226,81227,81228,81230,81231,81232,81233,81235,81236,81237,81239,81240,81241,81242,81243,81244,81246,81247,81248,81251,81252,81253,81290,81301,81302,81303,81320,81321,81323,81324,81325,81326,81327,81328,81329,81330,81331,81332,81334,81335,81401,81402,81410,81411,81413,81414,81415,81416,81418,81419,81420,81421,81422,81423,81424,81425,81426,81427,81428,81429,81430,81431,81432,81433,81434,81435,81501,81502,81503,81504,81505,81506,81520,81521,81522,81523,81524,81525,81526,81527,81601,81602,81610,81611,81612,81615,81620,81621,81623,81624,81625,81626,81630,81631,81632,81633,81635,81636,81637,81638,81639,81640,81641,81642,81643,81645,81646,81647,81648,81649,81650,81652,81653,81654,81655,81656,81657,81658];

Applewood.states = ['AL','AK','AZ','AR','CA','CO','CT','DE','DC','FL','GA','HI','ID','IL','IN','IA','KS','KY','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY'];

Applewood.positions = ['Plumber','Electrician','HVAC','Drain Cleaning','Accounting','Human Resources','Customer Service','Dispatcher','Driver','Warehouse','Marketing'];

Applewood.yesNo = ['Yes','No'];