/*
 * Ext JS Library 1.1.1
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://www.extjs.com/license
 */
 
 

Ext.onReady(function(){
	
    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

    /*
     * ================  Register form  =======================
     */
    var register_user = new Ext.form.Form({
        //labelWidth: 147, // label settings here cascade unless overridden
        //url:'insert_user.php',
		labelAlign: 'top'
    });

    
	register_user.column({width:342, labelWidth:250}); // open column, without auto close



        var stName = new Ext.form.TextField({
            fieldLabel: 'Name',
            name: 'txtName',
            width:250,
            allowBlank:false
        });
		
        var stEmail = new Ext.form.TextField({
            fieldLabel: 'E-mail address',
            name: 'txtEmail',
            width:250,
            allowBlank:false,
	        vtype:'email'
        });
		
        var stTel = new Ext.form.TextField({
            fieldLabel: 'Telephone, incl. area and country code',
            name: 'txtTel',
            width:250,
            allowBlank:false
        });
		
        var stFax = new Ext.form.TextField({
            fieldLabel: 'Telefax, incl. area and country code',
            name: 'txtFax',
            width:250
        });
		
	
	
	    register_user.fieldset(
        {legend:'Your info'},
		stName,
		stEmail,
		stTel,
		stFax
		)
		

register_user.end();


    register_user.column({width:332, style:'margin-left:10px; padding-bottom:60px;', clear:true}); // open column, without auto close

		var stusername = new Ext.form.TextField({
            fieldLabel: 'Username',
            name: 'username',
            width:250,
            allowBlank:false
        });

        var stpassword = new Ext.form.TextField({
            fieldLabel: 'Password',
            name: 'password',
            width:250,
			inputType:'password',
            allowBlank:false
        });
		
		var strep_password = new Ext.form.TextField({
            fieldLabel: 'Please repeat Password',
            name: 'rep_password',
            width:250,
			inputType:'password',
            allowBlank:false
        });
		
	    register_user.fieldset(
        {legend:'Username and Password'},
		stusername,
		stpassword,
		strep_password
		)		

register_user.end();

	register_user.column({width:342, labelWidth:250}); // open column, without auto close

		var stCompany = new Ext.form.TextField({
            fieldLabel: 'Company/organisation',
            name: 'txtCompany',
            width:250,
            allowBlank:false
        });

        var stVat= new Ext.form.TextField({
            fieldLabel: 'VAT no., if within EU',
            name: 'txtVat',
            width:250
        });

        var stDepartment = new Ext.form.TextField({
            fieldLabel: 'Department',
            name: 'txtDepartment',
            width:250
        });

        var stSection = new Ext.form.TextField({
            fieldLabel: 'Section/Sub-department',
            name: 'txtSection',
            width:250
        });

        var stInvoice = new Ext.form.TextField({
            fieldLabel: 'Invoice marking/code',
            name: 'txtInvoice',
            width:250
        });

        var stContact = new Ext.form.TextField({
            fieldLabel: 'Contact/reference person',
            name: 'txtContact',
            width:250
        });

        var stContactTel = new Ext.form.TextField({
            fieldLabel: 'Contact/reference person telephone',
            name: 'txtContactTel',
            width:250
        });

        var stContactFax = new Ext.form.TextField({
            fieldLabel: 'Contact/reference person telefax',
            name: 'txtContactFax',
            width:250
        });

        var stAddress = new Ext.form.TextArea({
            fieldLabel: 'Address',
            name: 'txtAddress',
            width:250,
            allowBlank:false
        });

        var stCity = new Ext.form.TextField({
            fieldLabel: 'City',
            name: 'txtCity',
            width:250,
            allowBlank:false
        });

        var stPostalcode = new Ext.form.TextField({
            fieldLabel: 'Postal Code',
            name: 'txtPostalcode',
            width:250,
            allowBlank:false
        });

        var stState = new Ext.form.TextField({
            fieldLabel: 'State/province',
            name: 'txtState',
            width:250
        });

        var stCountry = new Ext.form.TextField({
            fieldLabel: 'Country',
            name: 'txtCountry',
            width:250,
            allowBlank:false
        });

	    register_user.fieldset(
        {legend:'Invoice to'},
		stCompany,
		stVat,
		stDepartment,
		stSection,
		stInvoice,
		stContact,
		stContactTel,
		stContactFax,
		stAddress,
		stCity,
		stPostalcode,
		stState,
		stCountry
		)	
		
		var stButton = register_user.addButton('Copy from invoice address', function() {
		stShipCompany.setValue(stCompany.getValue());
		stShipDepartment.setValue(stDepartment.getValue());
		stShipSection.setValue(stSection.getValue());
		stShipContact.setValue(stContact.getValue());
		stShipContactTel.setValue(stContactTel.getValue());
		stShipContactFax.setValue(stContactFax.getValue());
		stShipAddress.setValue(stAddress.getValue());
		stShipCity.setValue(stCity.getValue());
		stShipPostalcode.setValue(stPostalcode.getValue());
		stShipState.setValue(stState.getValue());
		stShipCountry.setValue(stCountry.getValue());
		});
		
register_user.end(); // closes the last container element (column, layout, fieldset, etc) and moves up 1 level in the stack



    register_user.column({width:332, style:'margin-left:10px;, margin-bottom:50px;', clear:true}); // open column, without auto close

	
		var stShipCompany = new Ext.form.TextField({
            fieldLabel: 'Company/organisation',
            name: 'txtShipCompany',
            width:250,
            allowBlank:false
        });

        var stShipDepartment = new Ext.form.TextField({
            fieldLabel: 'Department',
            name: 'txtShipDepartment',
            width:250
        });

        var stShipSection = new Ext.form.TextField({
            fieldLabel: 'Section/Sub-department',
            name: 'txtShipSection',
            width:250
        });

        var stShipGoods = new Ext.form.TextField({
            fieldLabel: 'Goods marking/code',
            name: 'txtShipGoods',
            width:250
        });

        var stShipContact = new Ext.form.TextField({
            fieldLabel: 'Contact/reference person',
            name: 'txtShipContact',
            width:250
        });

        var stShipContactTel = new Ext.form.TextField({
            fieldLabel: 'Contact/reference person telephone',
            name: 'txtShipContactTel',
            width:250
        });

        var stShipContactFax = new Ext.form.TextField({
            fieldLabel: 'Contact/reference person telefax',
            name: 'txtShipContactFax',
            width:250
        });

        var stShipAddress = new Ext.form.TextArea({
            fieldLabel: 'Address',
            name: 'txtShipAddress',
            width:250,
            allowBlank:false
        });

        var stShipCity= new Ext.form.TextField({
            fieldLabel: 'City',
            name: 'txtShipCity',
            width:250,
            allowBlank:false
        });

        var stShipPostalcode = new Ext.form.TextField({
            fieldLabel: 'Postal Code',
            name: 'txtShipPostalcode',
            width:250,
            allowBlank:false
        });

        var stShipState= new Ext.form.TextField({
            fieldLabel: 'State/province',
            name: 'txtShipState',
            width:250
        });

        var stShipCountry = new Ext.form.TextField({
            fieldLabel: 'Country',
            name: 'txtShipCountry',
            width:250,
            allowBlank:false
        });

		
    register_user.fieldset(
        {legend:'Ship to'},
		stButton,
		stShipCompany,
		stShipDepartment,
		stShipSection,
		stShipGoods,
		stShipContact,
		stShipContactTel,
		stShipContactFax,
		stShipAddress,
		stShipCity,
		stShipPostalcode,
		stShipState,
		stShipCountry
		)

register_user.end();

    register_user.column({width:332, style:'margin-left:0px;', clear:true}); // open column, without auto close

		var stNewsletter1 = new Ext.form.Checkbox({
            boxLabel: 'Lipids',
            name: 'newscheck[]',
			width:250,
			inputValue:1
		});

		var stNewsletter2 = new Ext.form.Checkbox({
            boxLabel: 'Stable Isotopes',
            name: 'newscheck[]',
			width:250,
			inputValue:2
		});

		
		var stNewsletter3 = new Ext.form.Checkbox({
            boxLabel: 'NMR products',
            name: 'newscheck[]',
			width:250,
			inputValue:3
		});

		var stNewsletter4 = new Ext.form.Checkbox({
            boxLabel: 'Radiochemicals',
            name: 'newscheck[]',
			width:250,
			inputValue:4
		});

		var stNewsletter5 = new Ext.form.Checkbox({
            boxLabel: 'Environmental standards',
            name: 'newscheck[]',
			width:250,
			inputValue:5
		});

		var stNewsletter6 = new Ext.form.Checkbox({
            boxLabel: 'Certified standards',
            name: 'newscheck[]',
			width:250,
			inputValue:6
		});

		var stNewsletter7 = new Ext.form.Checkbox({
            boxLabel: 'Immunochemicals',
            name: 'newscheck[]',
			width:250,
			inputValue:7
		});

		var stNewsletter8 = new Ext.form.Checkbox({
            boxLabel: 'Recombinant Proteins',
            name: 'newscheck[]',
			width:250,
			inputValue:8
		});

		var stNewsletter9 = new Ext.form.Checkbox({
            boxLabel: 'Organics',
            name: 'newscheck[]',
			width:250,
			inputValue:9
		});

		var stNewsletter10 = new Ext.form.Checkbox({
            boxLabel: 'Forensics',
            name: 'newscheck[]',
			width:250,
			inputValue:10
		});

		
	    register_user.fieldset(
        {legend:'Newsletter',hideLabels:true},
		stNewsletter1,
		stNewsletter2,
		stNewsletter3,
		stNewsletter4,
		stNewsletter5,
		stNewsletter6,
		stNewsletter7,
		stNewsletter8,
		stNewsletter9,
		stNewsletter10
		)		

	
		register_user.addButton('Register', function(){
			if (register_user.isValid()) {
                register_user.submit({url:'insert_user.php', 
                    //waitMsg:'Please wait...', 
                    failure:function(form, action){ 
                        Ext.MessageBox.alert('', action.result.msg);
                      },
                        success:
                        function() {
													location.href = 'reg_complete.php';
												}
                }); 
			}else{
				Ext.MessageBox.alert('Errors', 'Please fix the errors noted.');
			}
		}, register_user);


    register_user.render('form-ct');

	
})
