YAHOO.namespace("generali.form");

YAHOO.generali.form.addPolicy = {
    counter : 0,

    config : {
        counterField : "LNpolicies",
        container : "policies",    
        buttonId : "addPolicyNr",
        event : "click"
    },
    
    init : function() {       
        YAHOO.util.Dom.setStyle(this.config.buttonId, "visibility", "visible");        
        this.container = YAHOO.util.Dom.get(this.config.container);
        this.counterField = YAHOO.util.Dom.get(this.config.counterField);
        YAHOO.util.Event.addListener(this.config.buttonId, this.config.event, this.handleEvent, this, true);
    },
    
    handleEvent : function(e) {
        this.counter++;
        this.container.innerHTML += '';
        this.counterField.value = this.counter + 1 ;
        this.init();               
    }
}

YAHOO.generali.form.addOffer = {
    counter : 0,

    config : {
        counterField : "LNoffers",
        container : "offers",    
        buttonId : "addOfferNr",
        event : "click"
    },
    
    init : function() {       
        YAHOO.util.Dom.setStyle(this.config.buttonId, "visibility", "visible");        
        this.container = YAHOO.util.Dom.get(this.config.container);
        this.counterField = YAHOO.util.Dom.get(this.config.counterField);
        YAHOO.util.Event.addListener(this.config.buttonId, this.config.event, this.handleEvent, this, true);
    },
    
    handleEvent : function(e) {
        this.counter++;
        this.counterField.value = this.counter + 1;
        this.init();               
    }
}

YAHOO.generali.form.addPerson = {
    config : {
        elementId : "persons",
        buttonId : "addPerson",
        event : "click"
    },
    
    init : function() {
        YAHOO.util.Dom.setStyle(this.config.buttonId, "visibility", "visible");
        this.element = YAHOO.util.Dom.get(this.config.elementId);
        YAHOO.util.Event.addListener(this.config.buttonId, this.config.event, this.handleEvent, this, true);
    },
    
    handleEvent : function (e) {
        this.element.innerHTML += '<tr><td><input type="text" style="width: 100px;" name="" /></td><td><input type="text" style="width: 100px;" name="" /></td><td><input type="text" style="width: 100px;" name="" /></td><td><input type="text" style="width: 50px;" name="" /></td><td></td></tr>';
        this.init();
    }
}

YAHOO.generali.form.showSipoForm = {
    config : {
        elementId : "sipoNr",
        buttonId : "sipo",
        event : "click"
    },
    
    init : function() {
        this.element = YAHOO.util.Dom.get(this.config.elementId);
            YAHOO.util.Dom.setStyle(this.config.elementId, "visibility", "hidden");         
            YAHOO.util.Event.addListener(this.config.buttonId, this.config.event, this.handleEvent, this, true);
    },
    
    handleEvent : function (e) {
        YAHOO.util.Dom.setStyle(this.config.elementId, "visibility", "visible");
    }
}

YAHOO.generali.form.showInkasoForm = {
    config : {
        elementId : "accountNr",
        buttonId : "collectPayment",
        event : "click"
    },
    
    init : function() {
        this.element = YAHOO.util.Dom.get(this.config.elementId);
        YAHOO.util.Dom.setStyle(this.config.elementId, "visibility", "hidden");         
        YAHOO.util.Event.addListener(this.config.buttonId, this.config.event, this.handleEvent, this, true);
    },
    
    handleEvent : function (e) {
        YAHOO.util.Dom.setStyle(this.config.elementId, "visibility", "visible");
    }
}

YAHOO.generali.form.agree = {
    config : {
        handleId : "agree",
        event : "click"
    },
    
    init : function() {
            this.handler = YAHOO.util.Dom.get(this.config.handleId);
            YAHOO.util.Event.addListener(this.config.handleId, this.config.event, this.handleEvent, this, true);                                    
    },          
    
    onBlur : function (e) {
        YAHOO.util.Dom.setStyle(e, "background", "#ffff99");
    },
    
    onFocus : function(e) {
        YAHOO.util.Dom.setStyle(e, "background", "#cfcfcf");
    },
    
    handleEvent : function (e) { 
    frm = window.location.search.substring(1).split("=");
    if(frm[1] == null) {
      document.location="/hlaseni/prehled";} else{
        document.location="/hlaseni/?q="+frm[1]+"&cont=1";
      };
    }
}
YAHOO.util.Event.onContentReady("container",YAHOO.generali.form.agree.init, YAHOO.generali.form.agree, true);
YAHOO.util.Event.onContentReady("container",YAHOO.generali.form.showInkasoForm.init, YAHOO.generali.form.showInkasoForm, true);
YAHOO.util.Event.onContentReady("container",YAHOO.generali.form.showSipoForm.init, YAHOO.generali.form.showSipoForm, true);
YAHOO.util.Event.onContentReady("container",YAHOO.generali.form.addPerson.init, YAHOO.generali.form.addPerson, true);
YAHOO.util.Event.onContentReady("container",YAHOO.generali.form.addOffer.init, YAHOO.generali.form.addOffer, true);
YAHOO.util.Event.onContentReady("container",YAHOO.generali.form.addPolicy.init, YAHOO.generali.form.addPolicy, true);

