 var IndexCenterHandler = new Class({
    initialize:function(args) {
        this.LookCityOverride = null;
        this.args = args;
        
        this.submitProfileEvent = this.SubmitProfile.bind(this);
        this.updatePreviewEvent = this.UpdatePreviewLink.bind(this);
        this.previewAlertEvent = this.PreviewAlert.bind(this);
        
        if (this.args.CountryCode == "XX") {
            /* Spanish test at flipping the look buttons around */
            var button = this.args.LookSubmit;
            this.args.LookSubmit = this.args.LookPreviewLink;
            this.args.LookPreviewLink = button;
        }
        
        
        this.args.LookSubmit.addEvent('click',this.submitProfileEvent);
        this.args.HaveSubmit.addEvent('click',this.submitProfileEvent);
        this.args.LookPanelHandler.addEvent('dropdownchanged',this.updatePreviewEvent,'L');
        this.args.HavePanelHandler.addEvent('dropdownchanged',this.updatePreviewEvent,'H');
		if (this.args.LookPreviewLink.get('href') == this.args.SitePath /*|| this.args.LookPreviewLink.get('href') == this.args.SitePath + "/"*/) {
			this.args.LookPreviewLink.addEvent('click', this.previewAlertEvent);
		}
		if (this.args.HavePreviewLink.get('href') == this.args.SitePath /*|| this.args.LookPreviewLink.get('href') == this.args.SitePath + "/"*/) {
			this.args.HavePreviewLink.addEvent('click', this.previewAlertEvent);
		}
		this.args.LanguageSelector.addEvent("change",this.SetLanguage.bind(this));
    },
    
	GetLanguage: function() {
		return this.args.LanguageSelector.options[this.args.LanguageSelector.selectedIndex].value;
	},
	
	SetLanguage: function() {
	    var locId = "";
	    if (this.args.LookPanelHandler.GetSelectedId() != 0) {
	        locId = this.args.LookPanelHandler.GetSelectedId();
	    } else if (this.args.HavePanelHandler.GetSelectedId() != 0) {
	        locID = this.args.HavePanelHandler.GetSelectedId();
	    }
	    window.location.href=this.args.SitePath+"/default.aspx?lc="+this.GetLanguage()+"&mc="+locId;
	},
	
    SubmitProfile: function(e) {
        e.stop();
       if (this.args.loggedin) {
			alert(captable[951]);
		}
		else {
			if (e.target == this.args.LookSubmit) {
				var location = this.args.LookPanelHandler.GetSelectedId();
				if (this.LookCityOverride != null) location = this.LookCityOverride;
				if (location == 0) {
					ErmJS.Controls.alert(captable[431]);
				}
				else {
					window.location = this.args.SitePath + '/content/look/profilelooking.aspx?id=1&opt=L&mc=' + location + '&sellang=' + this.GetLanguage();
				}
			}
			else 
				if (e.target == this.args.HaveSubmit) {
					var location = this.args.HavePanelHandler.GetSelectedId();
					if (location == 0) {
						ErmJS.Controls.alert(captable[431]);
					}
					else {
						window.location = this.args.SitePath + '/content/have/profilehave.aspx?id=1&opt=H&mc=' + location + '&sellang=' + this.GetLanguage();
					}
				}
		}
    },
	
	UpdatePreviewLink: function(handler,opt) {
		var target;
	    if (opt == 'H') target = this.args.HavePreviewLink;
        if (opt == 'L') target = this.args.LookPreviewLink;
		if (handler.GetSelectedId() != 0) {
            target.set('href',this.args.SitePath + '/content/common/preview_seo.aspx?opt=' + opt + '&mc='+handler.GetSelectedId()+'&sellang='+this.GetLanguage());
			target.removeEvent("click",this.previewAlertEvent);
        } else if (target.get('href') != this.args.SitePath) {
			target.set('href',this.args.SitePath);
			target.addEvent("click",this.previewAlertEvent);
		}
	},
	
	PreviewAlert: function(e) {
		e.stop();
        ErmJS.Controls.alert(captable[431]);
	}
 });
