 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);
        
        this.args.LookSubmit.addEvent('click',this.submitProfileEvent);
        this.args.HaveSubmit.addEvent('click',this.submitProfileEvent);
        this.args.LookPanelHandler.addEvent('dropdownchanged',this.updatePreviewEvent,'L');
        this.updatePreviewEvent(this.args.LookPanelHandler,"L");
        this.args.HavePanelHandler.addEvent('dropdownchanged',this.updatePreviewEvent,'H');
        this.updatePreviewEvent(this.args.HavePanelHandler,"H");
		if(this.args.LookPreviewLink != null)
		{
		    if (this.args.LookPreviewLink.get('href') == SitePath /*|| this.args.LookPreviewLink.get('href') == this.args.SitePath + "/"*/) {
			    this.args.LookPreviewLink.addEvent('click', this.previewAlertEvent);
		    }
		}
		if(this.args.HavePreviewLink != null)
		{
		    if (this.args.HavePreviewLink.get('href') == SitePath /*|| this.args.HavePreviewLink.get('href') == this.args.SitePath + "/"*/) {
			    this.args.HavePreviewLink.addEvent('click', this.previewAlertEvent);
		    }
		}
		if (this.args.LanguageSelector != null) {
		    this.args.LanguageSelector.addEvent("change",this.SetLanguage.bind(this));
		    this.args.CountrySelector.addEvent("change",this.SetCountry.bind(this));
		}
    },
    
	GetLanguage: function() {
		return this.args.LanguageSelector.options[this.args.LanguageSelector.selectedIndex].value;
	},
	
	SetLanguage: function() {
	    var locId = "";
	    this.args.CountrySelector.set("disabled",true);
	    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;
	},
	SetCountry: function() {
	    this.args.LanguageSelector.set("disabled",true);
	    var split = this.args.CountrySelector.options[this.args.CountrySelector.selectedIndex].value.split(',');
	    if (Cookie.read("redirect") != null) Cookie.dispose("redirect");
        window.location = 'http://' + split[0] + '/content/common/sessionclear.aspx?cc=' + split[1];
	},
	
    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[434]);
				}
				else {
					window.location = '/content/look/profilelooking.aspx?id=1&opt=L&mc=' + location;
				}
			}
			else 
				if (e.target == this.args.HaveSubmit) {
					var location = this.args.HavePanelHandler.GetSelectedId();
					if (location == 0) {
						ErmJS.Controls.alert(captable[434]);
					}
					else {
						window.location = '/content/have/profilehave.aspx?id=1&opt=H&mc=' + location;
					}
				}
		}
    },
	
	UpdatePreviewLink: function(handler,opt) {
		var target;
		 if(this.args.HavePreviewLink != null)
		{
	        if (opt == 'H') target = this.args.HavePreviewLink;
        }
        if(this.args.LookPreviewLink != null)
		{
            if (opt == 'L') target = this.args.LookPreviewLink;
		}
		if(target != null)
		{
		    
		    if (handler.GetSelectedId() != 0) {
                target.set('href',SitePath + '/content/common/preview_seo.aspx?opt=' + opt + '&mc='+handler.GetSelectedId()+'&seo=' + this.args.seoTarget);
			    target.removeEvent("click",this.previewAlertEvent);
            } else if (target.get('href') != SitePath) {
			    target.set('href',SitePath);
			    target.addEvent("click",this.previewAlertEvent);
		    }
		}
	},
	
	PreviewAlert: function(e) {
		e.stop();
        ErmJS.Controls.alert(captable[434]);
	}
 });
