Ext.onReady(function(){

    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

   // var bd = Ext.getBody();

    /*
     * ================  Simple form  =======================
     */
	//var getParams = document.URL.split("?");
    //var params = Ext.urlDecode(getParams[getParams.length - 1]);
	
   var pos_id= Ext.get('pos_id').dom.value;	 
   var eid= Ext.get('eid').dom.value;
   var jobtitle = Ext.get('JobTitle').dom.value;
   var zipcode =  Ext.get('zipcode').dom.value;
   var employer_email = Ext.get('employer_email').dom.value;
   
   var termsString = '<p><span class="redbold">Terms <br/ ></span>By accessing this web site, you are agreeing to be bound by these web site Terms and Conditions of Use, all applicable laws and regulations, and agree that you are responsible for compliance with any applicable local laws. If you do not agree with any of these terms, you are prohibited from using or accessing this site. The materials contained in this web site are protected by applicable copyright and trademark law. </p><p><span class="redbold">Use License <br/ ></span>Permission is granted to temporarily download one copy of the materials (information or software) on Job Alarm\'s web site for personal, non-commercial transitory viewing only. This is the grant of a license, not a transfer of title, and under this license you may not: </p><ul><li>Modify or copy the materials; </li><li>Use the materials for any commercial purpose, or for any public display (commercial or non-commercial); </li><li>Attempt to decompile or reverse engineer any software contained on Job Alarm\'s web site; </li><li>Remove any copyright or other proprietary notations from the materials; or </li><li>Transfer the materials to another person or "mirror" the materials on any other server. </li></ul><p><br />This license shall automatically terminate if you violate any of these restrictions and may be terminated by Job Alarm at any time. Upon terminating your viewing of these materials or upon the termination of this license, you must destroy any downloaded materials in your possession whether in electronic or printed format. </p><p><span class="redbold">Disclaimer <br/ ></span>The materials on Job Alarm\'s web site are provided "as is". Job Alarm makes no warranties, expressed or implied, and hereby disclaims and negates all other warranties, including without limitation, implied warranties or conditions of merchantability, fitness for a particular purpose, or non-infringement of intellectual property or other violation of rights. Further, Job Alarm does not warrant or make any representations concerning the accuracy, likely results, or reliability of the use of the materials on its Internet web site or otherwise relating to such materials or on any sites linked to this site. </p><p><span class="redbold">Limitations <br/ ></span>In no event shall Job Alarm or its suppliers be liable for any damages (including, without limitation, damages for loss of data or profit, or due to business interruption,) arising out of the use or inability to use the materials on Jobalarm.com, even if Job Alarm or a Job Alarm authorized representative has been notified orally or in writing of the possibility of such damage.  Because some jurisdictions do not allow limitations on implied warranties, or limitations of liability for consequential or incidental damages, these limitations may not apply to you. </p><p><span class="redbold">Revisions and Errors <br/ ></span>The materials appearing on Job Alarm\'s web site could include technical, typographical, or photographic errors. Job Alarm does not warrant that any of the materials on its web site are accurate, complete, or current. Job Alarm may make changes to the materials contained on its web site at any time without notice. Job Alarm does not, however, make any commitment to update the materials. </p><p><span class="redbold">Links <br/ ></span>Job Alarm has not reviewed all of the sites linked to its Internet web site and is not responsible for the contents of any such linked site. The inclusion of any link does not imply endorsement by Job Alarm of the site. Use of any such linked web site is at the user\'s own risk.</p><p><span class="redbold">Short Message Service (SMS) Policy <br/></span>If you optin to our SMS Services, you thereby agree to receive SMS Service messages at the address you provide for such purposes. Such messages will come from Jobalarm.com.  Participation in our service is free of charge but standard carrier text messaging charges will apply. You may change your mind at any time by following the opt-out instructions in your User Profile. You represent that you are the owner or authorized user of the wireless device you use to sign up for the SMS Service, and that you are authorized to approve the applicable service. </p><p><span class="redbold">Assumption of Risk<br/ ></span>You use the Internet solely at your own risk and subject to all applicable local, state, national, and international laws and regulations. While Jobalarm.com has endeavored to create a secure and reliable Site, please be advised that the confidentiality of any communication or material transmitted to/from this Site over the Internet cannot be guaranteed. Accordingly, Jobalarm.com and its affiliates are not responsible for the security of any information transmitted via the Internet, the accuracy of the information contained on the Site, or for the consequences of any reliance on such information. You assume the sole and complete risk for using this Site. Site Terms of Use Modifications Job Alarm may revise these terms of use for its web site at any time without notice. By using this web site you are agreeing to be bound by the then current version of these Terms and Conditions of Use. </p><p><span class="redbold">Indemnity<br/ ></span>You agree to defend, indemnify, and hold harmless Job Alarm and its affiliates and all of their employees, directors, officers, agents, partners, representatives, shareholders, attorneys, and assigns, from and against any and all claims, proceedings, damages, injuries, liabilities, losses, costs, and expenses (including reasonable attorney fees and litigation expenses), relating to or arising from your use of the Site or any breach by you of this Agreement. </p><p><span class="redbold">Governing Law <br/ ></span>Any claim relating to Job Alarm\'s web site shall be governed by the laws of the State of Texas without regard to its conflict of law provisions. </p>';
 
 
 var myField = new Ext.form.TextArea({
    id: 'txtNotes',
	name:'txtNotes',
	anchor:'100%',
	maxLength:'140',
    autoCreate: {tag: 'textarea', style:'width:390px;height:200px;', wrap:'hard', autocomplete: 'off',maxLength:140}
});
 
	
    var carriers = new Ext.data.ArrayStore({
    fields: ['carrier', 'cid'],
    data:[['AT&T', '31001'],['Boost','31008'],['Cingular','31002'],['Cricket','90002'],['Dobson','31006'],['Nextel','31007'],['Sprint','31005'],['T-Mobile','31004'],['US Cellular','31012'],['Verizon','31003'],['Virgin Mobile','90001'],['All Others','99999']]
	
	
  });

    var simple = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        url:'http://www.jobalarm.com/applicant_email_ext.php',
        frame:true,
        title: 'Employer Direct',
        bodyStyle:'padding:5px 5px 0',
        width: 730,
		id:'appform',
		fileUpload: true,
        defaults: {width: 700},
        defaultType: 'textfield',
        waitMsg: 'Loading Form',
        monitorValid:true,

        items: [ {
            xtype:'fieldset',
  
            title: 'Required Information',
            autoHeight:true,
            defaults: {width: 210},
            defaultType: 'textfield',
            
            items :[{
                    fieldLabel: 'First Name*',
                    name: 'first',
					id:'first',
                    allowBlank:false
                },{
                    fieldLabel: 'Last Name*',
                    name: 'last',
					id:'last',
					allowBlank:false
                },{
                    fieldLabel: 'Email*',
                    name: 'emailopt',
					id:'emailopt',
					
					vtype:'email',
					allowBlank:false
                },
				
				{
                    fieldLabel: 'Mobile Phone',
                    name: 'phone',
					id:'phone'
                    
                },{
				  xtype : "checkbox",
				  name : "optin",
				  id: "optin",
				  width: 550,
				  inputValue : "cbvalue",
				  boxLabel : "It's ok for Employers to send text messages about jobs to my phone. Standard rates apply"
			  }, { xtype: "label",
			       html: "<h5>To Opt-in to JobAlarm's text messaging service simply text: JOIN JOBALARM to 88147.  We will also send you an email with opt-in instructions</span></h5>"
				   }/*,        {
				  xtype : "combo",
				  fieldLabel : "Carrier",
				  name : "xcarrier",
				  hiddenname:"carrier",
				  id:"carrier",
				  store: carriers,
				  valueField:'cid',
				  displayField:'carrier',
				  typeAhead: true,
	              triggerAction: 'all',
				  mode: 'local',
			editable: false

			  } */
            ]
        },{
            xtype:'fieldset',
            title: 'Resume',
            
           // autoHeight: true,
       // bodyStyle: 'padding: 10px 10px 0 10px;',
        labelWidth: 50,
        

                       
            items :[{
                 xtype: 'fileuploadfield',
            id: 'resume',
			width:210,
			fieldLabel:'',
			allowBlank:true,
            emptyText: 'Select your resume',
            
			name: 'resume',
            buttonText: '',
            buttonCfg: {
                iconCls: 'upload-icon'
            }

					
          }
            ]
        },{
            xtype:'fieldset',
            title: 'Terms',
			collapsible: true,
			collapsed: true,
            
            items :[{
                     xtype:'label',
				     name : 'varea',
					  width: 600,
					 html : termsString
					 
                }
            ]
        },{
            xtype:'fieldset',
            title: 'Confirm *',
            
            items :[{
                     xtype:'checkbox',
				     name : 'confcb',
					  id: "confcb",
				  width: 550,
				  validateValue: function(){
						return this.getValue();
					},
                  

				   boxLabel : "* I agree to JobAlarm terms and conditions. "
										 
                }
            ]
        }],

        buttons: [{
            text: 'Submit',
			formBind:true,
			 handler: function() {
				win = new Ext.Window({
						title: 'JobAlarm Quick Message',
						layout: 'fit',
						modal: true,
						width: 400,
						height: 200,
						items:[{
							     xtype:'label',
								 html:'<span style="text-align:center"><h5>140 Characters for you to emphasize your value to this Employer.</h5><br/><h4>Make yourself stand out!!</h4></span>',
								 anchor:'100%'
							   },
							   //myField
							   {
								 
                                 name: 'txtNotes',
								 id:'txtNotes',
								 xtype:'textarea',
								 width:400,
								 height:200,								 
								 anchor:'100%',
								 enableKeyEvents:true,
								 listeners: {
										// imposes a max length on this textarea even if the value is pasted in.
										'keyup' : function(){
											var value = this.getValue();
											var max = 140;
											if(value.length >= max) {
												this.setValue( value.slice(0, value.length-(value.length-max)) );
											}
										} //function
									}//listeners
							   }],
						 buttons: [{
								  text: 'Send',
								  
								  handler: function() {
									 Ext.getCmp('appform').getForm().submit({params:{
																				   pos_id:pos_id,
																				   eid: eid,
																				   JobTitle: jobtitle,
																				   zipcode:zipcode,
																				   emp_email:employer_email,
																				   txtNotes: Ext.getCmp('txtNotes').getValue()
																				   //carrier: Ext.getCmp('carrier').getValue()
																				   //optin: Ext.getCmp('optin').getValue()
																			   },
																			   waitMsg: 'Saving...',		// Wait Message
																			 /*	success: function () {		// When saving data success
																					
																					Ext.MessageBox.alert ('Status','Notes have been saved');
																					win.hide();
																					
																				},
																				*/
																				success:function()	{
																					win.hide();
																				Ext.Msg.alert('Status', 'Your Application was submitted', function(btn, text)
																				{
																				 
																					if (btn == 'ok'){
																						var redirect = 'applicant.php?a=search3&zip='+zipcode+'&txtKeyWord='+jobtitle+'&TravelFromZip_List_ID_fk=100';
																						window.location = redirect;
																						}
																				})},
																				
																				failure: function (form, action) {		// when saving data failed
																				  
																				  if(action.failureType == 'server'){
																						
																						Ext.Msg.alert('Save Failed!', action.result.response);
																				  }	

																				}
					                                                            ,
																				previous: function (form, action) {		// when saving data failed
																				Ext.MessageBox.alert ('Message','Previous submitted ');
																				}
																				  
																			   });
								  }
								},
								{
								   text: 'No Thanks',
								   handler: function() {
									 Ext.getCmp('appform').getForm().submit({params:{
																				   pos_id:pos_id,
																				   eid: eid,
																				   JobTitle: jobtitle,
																				   zipcode:zipcode,
																				   emp_email:employer_email,
																				   txtNotes: Ext.getCmp('txtNotes').getValue()
																				   //carrier: Ext.getCmp('carrier').getValue()
																				   //optin: Ext.getCmp('optin').getValue()
																			   },
																			   waitMsg: 'Saving...',		// Wait Message
																			 /*	success: function () {		// When saving data success
																					
																					Ext.MessageBox.alert ('Status','Notes have been saved');
																					win.hide();
																					
																				},
																				*/
																				success:function()	{
																					win.hide();
																				Ext.Msg.alert('Status', 'Your Application was submitted', function(btn, text)
																				{
																				 
																					if (btn == 'ok'){
																						var redirect = 'applicant.php?a=search3&zip='+zipcode+'&txtKeyWord='+jobtitle+'&TravelFromZip_List_ID_fk=100';
																						window.location = redirect;
																						}
																				})},
																				
																				failure: function (form, action) {		// when saving data failed
																				  
																				  if(action.failureType == 'server'){
																						
																						Ext.Msg.alert('Save Failed!', action.result.response);
																				  }	

																				}
					                                                            ,
																				previous: function (form, action) {		// when saving data failed
																				Ext.MessageBox.alert ('Message','Previous submitted ');
																				}
																				  
																			   });
								  }
							   }]
						
						}).show(); 
			 }
        }]
    });


    simple.render('message-dialog');

    
    
});
