
Ext.get("findAPostcode").dom.onclick = function () {
	var stateCombo = getStateComboBox("fState");
	//var cityCombo = getCityComboBox();
	var fPostcode = new Ext.form.TextField({
		name: "fPostcode",
		id: "fPostcode",
		fieldLabel: "Postcode",
		width: "80%",
		readOnly: true
	});
	
	var newForm = new Ext.form.FormPanel({		
		baseCls: "x-plain",
		labelWidth: "75px",
		bodyStyle: "padding: 5px",
		defaultType: "textfield",
		header: false,
		height: 150,
		plain: true,
		width: "100%",		
		items:[
			stateCombo,
			{name:  "city", id: "city", fieldLabel: "City", allowBlank: false, width:"80%"},
			fPostcode
		],
		buttons: [
			{
				text: "Search",
				handler: function () {
					if (Ext.get("city").dom.value == "") {
						return false;
					}
					
					Ext.MessageBox.wait("Searching...", "Please wait...");
					/* DO AJAX */
					Ext.Ajax.request({
						url: "index.php",
						method: "POST",
						params: {page: "common", action: "getPostcode", state: stateCombo.value, city: Ext.get("city").dom.value},
						success: function (response) {
							
							var responseObj = Ext.decode(response.responseText);
							fPostcode.setValue(responseObj.postcode);
							Ext.MessageBox.hide();	
							
						},
						failure: function () {
							showErrorMessage("Request Failed");
							Ext.MessageBox.hide();	
						}
					})
					
					
				}
			}, {
				text: "Close",
				handler: function () {
					newWindow.close();
				}
			}
		]
	});
	
	//fPostcode.setDisabled(true);
	var newWindow  = new Ext.Window({
		title: "Find a Postcode",
		modal: true,
		resizeable: false,		
		width: 300,
		autoHeight: true,
		items: newForm
	});
	newWindow.show();
}

Ext.get("addBusiness").dom.onclick = function () {
	
	//Ext.QuickTips.init();    
//    Ext.form.Field.prototype.msgTarget = 'side';
    
	var stateCombo = getStateComboBox('cState');
	var categoryCombo = getCategoryComboBox('cCategory');
	var bForm = new Ext.FormPanel ({
		url: "index.php",
		method: "POST",
		baseCls: "x-plain",
		bodyStyle: "padding: 5px",
		autoHeight: true,
		width: "100%",
		plain: true,
		fileUpload: true,
		defaultType: "textfield",
		items: [
			{name: "cName", id: "cName", fieldLabel: "Company Name", allowBlank: false, width: "80%"},
			{name: "cStreet", id: "cStreet", fieldLabel: "Street", allowBlank: false, width: "80%"},
			{name: "cPostal", id: "cPostal", fieldLabel: "Postal Address", allowBlank: true, width: "80%"},
			{name: "cPostcode", id: "cPostcode", fieldLabel: "Postcode", allowBlank: false, width: "80%"},
			{name: "cCity", id: "cCity", fieldLabel: "City", allowBlank: false, width: "80%"},
			stateCombo,
			{name: "cPhone", id: "cPhoe", fieldLabel: "Phone", allowBlank: false, width: "80%"},
			{name: "cFax", id: "cFax", fieldLabel: "Fax", allowBlank: false, width: "80%"},
			{name: "cWebsite", id: "cWebsite", vtype: "url", fieldLabel: "Website", allowBlank: true, width: "80%"},
			{name: "cEmail", id: "cEmail", vtype: "email", fieldLabel: "Email", allowBlank: true, width: "80%"},
			{name: "cTagLine", id: "cTagline", fieldLabel: "Tag Line", allowBlank: true, height: 40, width: "80%"},
			categoryCombo,
			{name: "cLogo", inputType: "file", id: "cLogo", fieldLabel: "Logo", allowBlank: true, width: "80%"}
		],
		buttons: [
			{ 
				text : "Send",
				handler: function () {
					bForm.getForm().submit({						
						waitMsg: "Sending...",
						waitTitle: "Please wait",						
						success: function (bForm, callBack) {
						
							showInfoMessage("Your request successfully sent");
							
						},
						failure: function () {
							
						},
						params: {page: "business", action: "add"}
						
					});
				}
			}, {
				text: "Close",
				handler: function () {
					//Ext.QuickTips.disable();    
//					Ext.form.Field.prototype.msgTarget = '';
					newWindow.close();
				}
			}
			
		]
	});
	
	var newWindow  = new Ext.Window({
		title: "Add your Business",
		modal: true,
		resizeable: false,
		autoHeight: true,
		width: 400,	
		items: bForm
	});
	newWindow.show();
}

Ext.get("updateKeystr").dom.onclick = function () {
	var updateForm = new Ext.form.FormPanel({
		labelWidth: 75,
		baseCls: "x-plain",
		bodyStyle: "padding: 5px",
		defaultType: "textfield",
		height: 80,
		plain: true,
		width: "100%",
		bodyBorder: false,
		items: [
			{name: "updateKey", id: "updateKey", fieldLabel: "Update Key", allowBlank: false, anchor: "100%"}
			
		],
		buttons: [
        	{
        		text: "Validate",
        		handler: function () {
        			Ext.MessageBox.wait("Please wait", "Searching...");
        			Ext.Ajax.request({
        				url: "index.php",
        				method: "POST",
        				success: function (response) {
        					
        					newWindow.close();
        					
        					var record = Ext.util.JSON.decode(response.responseText);
        					
        					if (record.success) {
        						window.location.href = "profile.php";
//        						var stateCombo = getStateComboBox('uState');
//								var categoryCombo = getCategoryComboBox('uCategory');
//								
								//Ext.QuickTips.init();    
//    							Ext.form.Field.prototype.msgTarget = 'side';
//								
        						//var recForm = new Ext.FormPanel({
//        							url: "index.php",
//        							method: "post",
//        							labelWidth: 100,
//									baseCls: "x-plain",
//									bodyStyle: "padding: 5px",
//									defaultType: "textfield",								
//									plain: true,
//									width: "100%",
//									autoHeight: true,
//									bodyBorder: false,
//									fileUpload: true,
//									items: [
//										{name: "uName", id: "uName", fieldLabel: "Company Name", value: record.data.name, allowBlank: false, width: "80%"},
//										{name: "uStreet", id: "uStreet", fieldLabel: "Street", value: record.data.street, allowBlank: false, width: "80%"},
//										{name: "uPostal", id: "uPostal", fieldLabel: "Postal Address", value: record.data.postal_address, allowBlank: true, width: "80%"},
//										{name: "uPostcode", id: "uPostcode", fieldLabel: "Postcode", value: record.data.postcode, allowBlank: false, width: "80%"},
//										{name: "uCity", id: "uCity", fieldLabel: "City", value: record.data.city, allowBlank: false, width: "80%"},
//										stateCombo,
//										{name: "uPhone", id: "uPhoe", fieldLabel: "Phone", value: record.data.phone, allowBlank: false, width: "80%"},
//										{name: "uFax", id: "uFax", fieldLabel: "Fax", value: record.data.fax, allowBlank: false, width: "80%"},
//										{name: "uWebsite", id: "uWebsite", vtype: "url", value: record.data.website, fieldLabel: "Website", allowBlank: true, width: "80%"},
//										{name: "uEmail", id: "uEmail", vtype: "email", fieldLabel: "Email", value: record.data.email, allowBlank: true, width: "80%"},
//										{name: "uTagLine", id: "uTagline", fieldLabel: "Tag Line", value: record.data.about, allowBlank: true, height: 40, width: "80%"},
//										categoryCombo,
//										{name: "uLogo", inputType: "file", id: "uLogo", fieldLabel: "Logo", allowBlank: true, width: "80%"},
//										{name: "uId_so", inputType: "hidden", hideLabel: "true", value: record.data.id_so}
//									],
//									buttons: [{
//											text: "Send",
//											handler: function () {
//												categoryCombo.allowBlank = true;
											//	showInfoMessage("Successfully sent");
//												recForm.getForm().submit({
//													waitMsg: "Sending request ...",
//													waitTitle: "Please wait",
//													success: function () {
//														showInfoMessage("Successfully sent");
//													},
//													failure: function () {
//													},
//													params: {page: "business", action: "update"}
//												})
//											}
//										
//										}, {
//											text: "Close",
//											handler: function () {
//											
											//		Ext.QuickTips.disable();    
//												 Ext.form.Field.prototype.msgTarget = '';
//												recWindow.close();
//												
//											}
//										}
//									]
//									
//        						});
//        						
//        						stateCombo.setValue(record.data.state);
        						//categoryCombo.allowBlank = t;
//        						
//        						if (record.data.cat_2 > 0) {
//        							
//									categoryCombo.setValue(record.data.cat_2);									
//									categoryCombo.setRawValue(record.data.category_name);
//									
//								}
//								
//        						var recWindow  = new Ext.Window({
//									title: record.data.name,
//									modal: true,
//									resizeable: false,		
//									autoHeight: true,
//									width: 500,
//									layout: "fit",
//									items: recForm
//								});
//								recWindow.show();
//								Ext.MessageBox.hide();
							} else {
								Ext.MessageBox.hide();
        						showErrorMessage("Invalid Update key");
							}
        				},
        				failure: function () {
        					Ext.MessageBox.hide();
        					showInfoMessage("Invalid Update key");
        				},
        				params: {page: "updatekey", action:"validate", key: Ext.get("updateKey").dom.value}
        			});        			
        		}
        	},{
        		text: "Cancel",
        		handler: function () {
        		//	Ext.QuickTips.disable();    
        			newWindow.close();
        		}
        	}
        	
        ]
	});
	
	var newWindow  = new Ext.Window({
		title: "Self Update Key",
		modal: true,
		resizeable: false,		
		autoHeight: true,
		width: 300,
		layout: "fit",
		items: updateForm
	});
	newWindow.show();
}
Ext.get("signIn").dom.onclick = function () {
	var loginForm = new Ext.form.FormPanel({
		labelWidth: 75,
		baseCls: "x-plain",
		bodyStyle: "padding: 5px",
		defaultType: "textfield",
		height: 125,
		plain: true,
		width: "100%",
		bodyBorder: false,
		items: [
			{name: "username", id: "username", fieldLabel: "Username", allowBlank: false, anchor: "100%"},
			{name: "password", inputType: "password", id: "password", fieldLabel: "Password", allowBlank: false, anchor: "100%"}
		],
		buttons: [
        	{
        		text: "Login",
        		handler: function () {
        		
        		}
        	},{
        		text: "Cancel",
        		handler: function () {
        			newWindow.close();
        		}
        	}
        	
        ]
	});
	
	var newWindow  = new Ext.Window({
		title: "Sign In",
		modal: true,
		resizeable: false,		
		autoHeight: true,
		width: 300,
		layout: "fit",
		items: loginForm
		
	});
	newWindow.show();
}

Ext.get("contactUs").dom.onclick = function () {
	 var form = new Ext.form.FormPanel({
        baseCls: "x-plain",
        bodyStyle: "padding: 5px",
        labelWidth: 55,
        url:"index.php",
        defaultType: "textfield",
        items: [{
            fieldLabel: "Name",
            name: "contactName",
            allowBlank:false,
            anchor: "100%"
        },{
            fieldLabel: "Email",
            name: "contactEmail",
            vtype: "email",
            allowBlank: false,
            anchor: "100%"
        }, {
            fieldLabel: "Phone",
            name: "contactPhone",
            allowBlank:true,
            anchor: "100%"  
        }, {
            xtype: "textarea",
            hideLabel: true,
            allowBlank: false,
            name: "msg",
            anchor: "100% -53"
        }],
        buttons: [
        	{
        		text: "Send",
        		handler: function () {
        			form.getForm().submit({
        				waitTitle: "Please wait",
        				waitMsg: "Sending...",
        				success: function () {
        					showInfoMessage("Successfully sent ");
        					newWindow.close();
        				},
        				failure: function () {
        				},
        				params: {page: "common", action: "send"}
        			})
        		}
        	},{
        		text: "Close",
        		handler: function () {
        			newWindow.close();
        		}
        	}
        	
        ]
    });
    
	var newWindow  = new Ext.Window({
		title: "Contact Us",
		modal: true,
		resizeable: false,
		width: 400,
		height: 300,
		layout: "fit",
		items: form
	});
	newWindow.show();
}