// JavaScript Document
var win;
var mymodel='';
var fullname = new Ext.form.TextField({
          fieldLabel: 'Full Name',
		  blankText:'Please enter your Full Name.',
		  allowBlank:false,
          anchor : '90%'
          });

var address = new Ext.form.TextField({
          fieldLabel: 'Address',
		  blankText:'Please enter your COMPLETE Address.',
		  allowBlank:false,
          anchor : '90%'
          });

var contact = new Ext.form.TextField({
          fieldLabel: 'Contact No.',
		  blankText:'Please enter your Contact Number.',
		  allowBlank:false,
          anchor : '90%'
          });


var email = new Ext.form.TextField({
          fieldLabel: 'Email',
		  allowBlank:true,
          anchor : '90%',
		  vtype:'email'
          });

var brand = new Ext.form.TextField({

            name: "brand",
            id:'brand',
			blankText:"Please select a motorcycle brand",
            fieldLabel: 'Brand',
			readOnly:true,
            allowBlank: false,
            anchor: "90%",
			bodyStyle:'background-color:transparent; border-style:none',
			//displayField:'value',
			//emptyText:'No table to select',
			//valueField: 'value',
			//forceSelection: true,
			//store: new Ext.data.SimpleStore({fields:['id','value'],data:[], autoLoad:true}),
			autoWidth: false
			//mode:'local',
			//triggerAction: 'all'
});

var model = new Ext.form.TextField({

            name: "model",
            id:'cmb_model',
			blankText:"Please select a motorcycle model",
            fieldLabel: 'Model',
			readOnly:true,
            allowBlank: false,
            anchor: "90%",
			//displayField:'value',
			bodyStyle:'background-color:transparent;  border-style:none',
			//emptyText:'No table to select',
			//bodyStyle:'width:100%; float:left; margin-left:0px; padding-left:0px;',
			//valueField: 'value',
			//forceSelection: true,
			//store: new Ext.data.SimpleStore({fields:['id','value'],data:[], autoLoad:true}),
			autoWidth: false
			//mode:'local',
			//triggerAction: 'all'
});



var additional = new Ext.form.TextArea({
          fieldLabel: 'Notes',
		  allowBlank:true,
          anchor : '90%'
          });
		  

var message = new Ext.form.TextArea({
          fieldLabel: 'Message',
		  blankText:'Please enter your Message',
		  allowBlank:false,
          anchor : '90%'
          });



var loginform = Ext.extend(Ext.form.FormPanel, {
						   
		initComponent: function(){
			Ext.apply(this, {
				frame:false,
				border:false,
				buttonAlign:'right',
				bodyStyle:'background-color:transparent; padding:10px;',
				monitorValid:true,
				loadMask: true,
				standardSubmit: true,
				waitMsg:'Processing...',
				items:[
					fullname,
					address,
					contact,
					email,
					brand,
					model,
					additional
				],
				buttons:[{
					 text:'Cancel'
					,scope:this
					,handler:this.onCancelClick
				},{
					 text:'Submit'
					//,formBind:true
					,scope:this
				//,handler:this.submit
					,handler:this.onSubmit
				}]
			});
		loginform.superclass.initComponent.apply(this, arguments);
		this.onCancelClick;
		}  // eo function initComponent
		
		,onRender:function() {
 
        loginform.superclass.onRender.apply(this, arguments);
		//this.getForm().waitMsgTarget = this.getEl();
 
    	}  // eo function onRender

		,onCancelClick:function() {
			this.getForm().reset();
			win.hide();
			//win.close();
			//username.setValue('');
			//password.setValue('');
			//hiddentext.setValue('');
			//remember.setValue(false);
			
		}  // eo function onCancelClick
		

		,onSubmit:function() {
			Ext.MessageBox.show({
           msg: 'Please wait...',
           progressText: 'Saving...',
           width:200,
           wait:true,
           waitConfig: {interval:100}/*,
           icon:'ext-mb-download', //custom class in msg-box.html
           animEl: 'mb7'*/
       		});
			Ext.Ajax.request({   
        		waitMsg: 'Processing...',
        		url: 'mailer/mailme.php',
        		params: {
          		task: "GETTABLES",
		  		name: fullname.getValue(),
		  		address: address.getValue(),
		  		contact: contact.getValue(),
		  		email: email.getValue(),
				brand: brand.getValue(),
				model: model.getValue(),
				notes: additional.getValue()
       		 	},success: function(response,mymsg,myuser){              
          			var result=eval(response.responseText); 
					 Ext.MessageBox.hide();
					 if(result=='1'){
						 //loginform.getForm().reset();
						 win.hide();
						 Ext.MessageBox.show({
           				title: 'Success!',
           				msg: 'Your inquiry has been sent to Transcycle. Please check your email later or we will call you on the contact number that you have provided. Thank you!',
           				buttons: Ext.MessageBox.OK,
           				icon:Ext.MessageBox.INFO,
						animEl: 'logwin'
       					});
						 //document.getElementById('conn').src='../100_02/'+result+'.gif';
						 //document.getElementById('mb7').innerHTML="Sign Out";
						 //getUser();
					}else if(result=='2'){
						 //loginform.getForm().reset();
						 //win.hide();
						 Ext.MessageBox.show({
           				title: 'Error!',
           				msg: 'Invalid Email Address!',
           				buttons: Ext.MessageBox.OK,
           				icon:Ext.MessageBox.WARNING,
						animEl: 'logwin'
       					});
					}else if(result=='3'){
						 //loginform.getForm().reset();
						 //win.hide();
						 Ext.MessageBox.show({
           				title: 'Error!',
           				msg: 'Please enter your full name!',
           				buttons: Ext.MessageBox.OK,
           				icon:Ext.MessageBox.WARNING,
						animEl: 'logwin'
       					});
					}else if(result=='4'){
						 //loginform.getForm().reset();
						 //win.hide();
						 Ext.MessageBox.show({
           				title: 'Error!',
           				msg: 'Please enter your complete address!',
           				buttons: Ext.MessageBox.OK,
           				icon:Ext.MessageBox.WARNING,
						animEl: 'logwin'
       					});
					}else if(result=='5'){
						 //loginform.getForm().reset();
						 //win.hide();
						 Ext.MessageBox.show({
           				title: 'Error!',
           				msg: 'Please enter the contact number so that we can call you!',
           				buttons: Ext.MessageBox.OK,
           				icon:Ext.MessageBox.WARNING,
						animEl: 'logwin'
       					});
					}else{
						Ext.MessageBox.show({
           				title: 'Sorry',
           				msg: 'Your inquiry did not reach to transcycle due to an error, please try again later.',
           				buttons: Ext.MessageBox.OK,
           				icon:Ext.MessageBox.INFO,
						animEl: 'logwin'
       					});
						}
					}
					
      		});
			
			
		} // eo function submit
});  // eo function loginform


var inquire_form = Ext.extend(Ext.form.FormPanel, {
						   
		initComponent: function(){
			Ext.apply(this, {
				frame:false,
				border:false,
				buttonAlign:'right',
				bodyStyle:'background-color:transparent; padding:10px;',
				monitorValid:true,
				loadMask: true,
				standardSubmit: true,
				waitMsg:'Processing...',
				items:[
					fullname,
					address,
					contact,
					email,
					message
				],
				buttons:[{
					 text:'Reset'
					,scope:this
					,handler:this.onCancelClick
				},{
					 text:'Submit'
					//,formBind:true
					,scope:this
				//,handler:this.submit
					,handler:this.onSubmit
				}]
			});
		loginform.superclass.initComponent.apply(this, arguments);
		this.onCancelClick;
		}  // eo function initComponent
		
		,onRender:function() {
 
        loginform.superclass.onRender.apply(this, arguments);
		//this.getForm().waitMsgTarget = this.getEl();
 
    	}  // eo function onRender

		,onCancelClick:function() {
			this.getForm().reset();
			//win.hide();
			//win.close();
			//username.setValue('');
			//password.setValue('');
			//hiddentext.setValue('');
			//remember.setValue(false);
			
		}  // eo function onCancelClick
		

		,onSubmit:function() {
			Ext.MessageBox.show({
           msg: 'Please wait...',
           progressText: 'Saving...',
           width:200,
           wait:true,
           waitConfig: {interval:100}/*,
           icon:'ext-mb-download', //custom class in msg-box.html
           animEl: 'mb7'*/
       		});
			Ext.Ajax.request({   
        		waitMsg: 'Processing...',
        		url: 'mailer/mailme2.php',
        		params: {
          		task: "INQUIRE",
		  		name: fullname.getValue(),
		  		address: address.getValue(),
		  		contact: contact.getValue(),
		  		email: email.getValue(),
				message: message.getValue()
       		 	},success: function(response,mymsg,myuser){              
          			var result=eval(response.responseText); 
					 Ext.MessageBox.hide();
					 if(result=='1'){
						 //loginform.getForm().reset();
						 //win.hide();
						 Ext.MessageBox.show({
           				title: 'Success!',
           				msg: 'Your inquiry has been sent to Transcycle. Please check your email later or we will call you on the contact number that you have provided. Thank you!',
           				buttons: Ext.MessageBox.OK,
           				icon:Ext.MessageBox.INFO,
						animEl: 'logwin'
       					});
					}else if(result=='2'){
						 //loginform.getForm().reset();
						 //win.hide();
						 Ext.MessageBox.show({
           				title: 'Error!',
           				msg: 'Invalid Email Address!',
           				buttons: Ext.MessageBox.OK,
           				icon:Ext.MessageBox.WARNING,
						animEl: 'logwin'
       					});
					}else if(result=='3'){
						 //loginform.getForm().reset();
						 //win.hide();
						 Ext.MessageBox.show({
           				title: 'Error!',
           				msg: 'Please enter your full name!',
           				buttons: Ext.MessageBox.OK,
           				icon:Ext.MessageBox.WARNING,
						animEl: 'logwin'
       					});
					}else if(result=='4'){
						 //loginform.getForm().reset();
						 //win.hide();
						 Ext.MessageBox.show({
           				title: 'Error!',
           				msg: 'Please enter your complete address!',
           				buttons: Ext.MessageBox.OK,
           				icon:Ext.MessageBox.WARNING,
						animEl: 'logwin'
       					});
					}else if(result=='5'){
						 //loginform.getForm().reset();
						 //win.hide();
						 Ext.MessageBox.show({
           				title: 'Error!',
           				msg: 'Please enter your message!',
           				buttons: Ext.MessageBox.OK,
           				icon:Ext.MessageBox.WARNING,
						animEl: 'logwin'
       					});
					}else{
						Ext.MessageBox.show({
           				title: 'Sorry',
           				msg: 'Your inquiry did not reach to transcycle due to an error, please try again later.',
           				buttons: Ext.MessageBox.OK,
           				icon:Ext.MessageBox.INFO,
						animEl: 'logwin'
       					});
						}
					}
					
      		});
			
			
		} // eo function submit
});  // eo function loginform


		function getUser(){
				Ext.Ajax.request({   
        		waitMsg: 'Processing...',
        		url: 'process.php',
        		params: {
          		get_user: "1"
       		 	},success: function(myuser){              
          			var result_name=eval(myuser.responseText); 
					document.getElementById('username').innerHTML=result_name;
				}});
		
		}

		function logOut(){
				Ext.Ajax.request({   
        		waitMsg: 'Processing...',
        		url: 'process.php'
				});
		
		}
		
var logwin = new Ext.Window({
	height:200,
	width:400,
	closeAction :'hide',
	frame:true,
	title:'Log In',
	id:'logwin',
	layout:'fit',
	bodyStyle:'padding:5px; padding-top:30px;',
	closable:false,
	minimizable:false,
	resizable:false,
	iconCls:'key',
	modal:true,
	items:[new loginform()],
	animEl: 'mb7',
	animate:true
});


