/// <reference path="dependencyHandler.js" />
/// <reference path="helpers.js" />
/// <reference path="../../../test.html" />
/// <reference path="formDataHandler.js" />

//function TestCallback(e)
//{
//    console.log("TestCallback: %o", e);
//}

//function TestRuleCallback(result)
//{
//    console.log("TestCallback: %o", result);  
//    return result;
//}
//var dh = new FormDependencyHandler('order_form', rules);
//var rules = [
//    new FormDependencyRule('transferdesc_row', 'requestmode==1'[, TestRuleCallback])
//];
//dh.RegisterChangeCallback('TestCallback', TestCallback);

var Globals = {
    IsDomain: true,
    ItemsData: [],
    ItemsDataDef: [],
    FullPrice: 0,
    PayedDomainPrice: 0,
    RONSign: String.fromCharCode(187)
    };

var FormHandlerInstanceManager = {
    _instance: null,
    Get: function(e, form, elementsToWatch, cookieNameTransform){
        //alert('FormHandlerInstanceManager >> Get: instance='+this._instance +'; e=' + e)
        if(this._instance == null)
            this._instance = new FormHandler(form, elementsToWatch, cookieNameTransform);
        if(typeof e != 'undefined' && typeof e.persisted != 'undefined' && e.persisted == true)
            this._instance.PersistInit();
        return this._instance;
    }
};

function FormHandler(form, elementsToWatch, cookieNameTransform)
{

    var tthis = this;
    this._form = (typeof form == 'string' ? document.forms[ form ] : form);
    this._veStatus = null;
    
    var rules = [
    new FormDependencyRule('transferdesc_row', 'requestmode==1'/*, TestRuleCallback*/),
    new FormDependencyRule('keepelsewheredesc_row', 'requestmode==2'),
    new FormDependencyRule('alreadypaiddesc_row', 'requestmode==3'),
    new FormDependencyRule('nameserver_row', 'requestmode==2'),
    new FormDependencyRule('ownnameserverdesc_row', 'nameserver_row && nameserver==0'),
    new FormDependencyRule('localnameserverdesc_row', 'nameserver_row && nameserver==1'),
    new FormDependencyRule('priority_row', 'requestmode==0', function(result){
        return tthis._PriorityCallback(result);
    }),
    new FormDependencyRule('priorityyesdesc_row', 'priority==1 && priority_row'),
    new FormDependencyRule('priorityregnum_row', 'priority==1 && priority_row'),
//    new FormDependencyRule('maxdomhostdiscount_row', 'withHosting && hostingDiscountOK && dprice.hostingyearlydiscount>0 && domainyears!=hostingYears/12'),
    new FormDependencyRule('maxdomhostdiscount_row', '(requestmode==0 || requestmode==1) && domainsetting==0'),
    new FormDependencyRule('sosreg_row', 'requestmode==0', function(res){
        return tthis._SosCallback(res);
    }),
    new FormDependencyRule('domainyears_row', 'requestmode!=2 && requestmode!=3', function(res){
        return tthis._DomainYearsCallback(res);
    }),
    new FormDependencyRule('domainsetting', 'requestmode==2', function(res){
        return tthis._DomainSettingCallback(res);
    }),
    new FormDependencyRule('hostingdata_block', 'domainsetting==0'),
    new FormDependencyRule('options_block', 'domainsetting==0'),
    new FormDependencyRule('shareddomain_row', 'domainsetting==1'),
    new FormDependencyRule('shareddomaindesc_row', 'domainsetting==1'),
    new FormDependencyRule('nameservers_row', 'domainsetting==5'),
    new FormDependencyRule('nameserversnote_row', 'domainsetting==5', function(res){
        return tthis._NSCheckCallback(res);
    }),
    new FormDependencyRule('arecord_row', 'domainsetting==6'),
    new FormDependencyRule('mxrecord_row', 'domainsetting==6'),
    new FormDependencyRule('ipnote_row', 'domainsetting==6'),
    new FormDependencyRule('samecontent_row', 'domainsetting==7'),
    new FormDependencyRule('samecontentdesc_row', 'domainsetting==7'),
    new FormDependencyRule('redirect_row', 'domainsetting==8'),
    new FormDependencyRule('redirectdesc_row', 'domainsetting==8'),
    new FormDependencyRule('hostingpack', '1', function(res){
        return tthis._HostingPackDescriptionDisplayerCallback(res);
    }),
    new FormDependencyRule('billpayertax_row', 'billpayertype==1'),
    new FormDependencyRule('billpayeremail_row', 'domainowneraddr==0'),
    new FormDependencyRule('billpayertel_row', 'domainowneraddr==0'),
    new FormDependencyRule('billpayerfax_row', 'domainowneraddr==0'),
    new FormDependencyRule('billpayerbankaccount_row', 'billpayertype==1'),
    new FormDependencyRule('domainownerofficialid_row', 'billpayertype==0 || domainowneraddr==1', function(res){
        return tthis._DomainOwnerOfficialIDCallback(res);
    }),
    new FormDependencyRule('recipientdata_row', 'recipientaddr==1'),
    new FormDependencyRule('domainownerdata_row', 'domainowneraddr==1'),
    new FormDependencyRule('domainownerdata_block', 'Globals.IsDomain'),
    new FormDependencyRule('adminpersondata_block', 'Globals.IsDomain'),
    new FormDependencyRule('adminpersondata_row', 'Globals.IsDomain && adminpersonaddr==1'),
    new FormDependencyRule('contactpersonaddr2_row', 'Globals.IsDomain && adminpersonaddr==0'),
    new FormDependencyRule('mediatorname_row', 'mediatedbuy==1'),
    new FormDependencyRule('orderid_row', 'mediatedbuy==1')
    ];
    
    this._dataHandler = new FormDataHandler(this._form, cookieNameTransform, this._ShowDataError.bind(this));
    this._dataHandler.Init();
    this._dataHandler.RegisterChangeCallback( new CallBackFunction('getItemsData', function(e){ 
        return tthis._GetItemsDataCallback(e);
    }, false) );
    this._dataHandler.RegisterChangeCallback( new CallBackFunction('dataValidityChecker', function(e){ 
        return tthis._DataValidityCheckerCallback(e);
    }, false) );
    this._dataHandler.RegisterChangeCallback( new CallBackFunction('checkPayedDomain', function(e){ 
        return tthis._CheckPayedDomainCallback(e);
    }, true) );
    this._dataHandler.RegisterChangeCallback( new CallBackFunction('checkPayedHosting', function(e){ 
        return tthis._CheckPayedHostingCallback(e);
    }, true) );
    this._dataHandler.Load();
    
    this._depHandler = new FormDependencyHandler(this._form, rules);
    this._depHandler.RegisterChangeCallback(new CallBackFunction('emptyOption', function(e){ 
        tthis._DisableSelectingEmptyOptionCallback(e);
    }, true));
    this._depHandler.RegisterChangeCallback(new CallBackFunction('hostingOptions', function(e){ 
        tthis._HostingPackOptionHandlerCallback(e);
    }));
    this._depHandler.RegisterChangeCallback(new CallBackFunction('hostingPeriod', function(e){ 
        tthis._HostingPackHostingPeriodCallback(e);
    }));
    this._depHandler.RegisterChangeCallback(new CallBackFunction('priceCounter', function(e){ 
        tthis._CalculatePriceSumCallback(e);
    }));
    this._depHandler.RegisterChangeCallback(new CallBackFunction('fixedDYearToHostingYear', function(e){ 
        tthis._HandleFixedDYearToHostingYearCallback(e);
    }));
    this._depHandler.RegisterChangeCallback(new CallBackFunction('isDomainSetter', function(e){ 
        tthis._IsDomainSetterCallback(e);
    }, true));
    this._depHandler.RegisterChangeCallback(new CallBackFunction('trimDomainName', function(e){ 
        tthis._TrimDomainNameCallback(e);
    }, true));
    this._depHandler.RegisterChangeCallback(new CallBackFunction('respondercoupon', function(e){ 
        tthis._CalculatePriceSumCallback(e);
    }, true));
    
    this._depHandler.AddElementsToWatch(['sosreg', 'domaintype', 'domainyears',  'hostingPeriod', 'dynamicmaxi', 'dynamicmini', 'tc', 'contactpersonemail', 'domainname']);
    this._depHandler.AddElementsToWatch(elementsToWatch);
    this._depHandler.Attach();
    
    var nsCheckButton = Helpers.GetElement('nameserverschecking', form);
    if(nsCheckButton != null)
        Event.observe(nsCheckButton, 'click', this._DoNSCheck.bind(this));
}

FormHandler.prototype.PersistInit = function()
{
    this._dataHandler.RestoreItems();
}

//lo egy changed eventet
FormHandler.prototype._FireChanged = function(el)
{
    var ev = el!=null ? {
        target: el,
        type: "changed"
    } : null;
    this._depHandler._ChangeHandler(ev);
}

//hibajelentes a kliensnek
FormHandler.prototype._ShowError = function(msg)
{
    alert(msg);
}

FormHandler.prototype._ShowDataError = function()
{
    this._ShowError(texts['data_not_set_or_incorrect']);
}

//domain evek combo konvertalas, vagyis az indexek ertekre es forditva
FormHandler.prototype._DomainYearsValueConverter = function(num, isIndex)
{
    var transform = [[0,1/12],[1,2/12],[2,3/12],[3,6/12],[4,1],[5,2],[6,3],[7,4],[8,5],[9,0]];
    
    var index = isIndex ? 0 : 1;
    var retIndex = isIndex ? 1 : 0;
    for(var i=0; i<transform.length; i++)
    {
        if(transform[i][index] == num)
            return transform[i][retIndex];
    }
    return -1;
}

FormHandler.prototype._RoundNum = function(num)
{
    return Math.round(num*100)/100;
}

FormHandler.prototype._ConvertToRON = function(price)
{
    var convRatio = parseFloat(cu.configuration.priceConversionRatio);
    return price*convRatio;
}

FormHandler.prototype._GetCMPriceText = function(price)
{
    if(cu.configuration.enablePriceConversion == 0)
        return '';
    var priceInRON = this._ConvertToRON(price);
    return priceInRON>0 ? ' ('+ Globals.RONSign +' '+ this._RoundNum(priceInRON) +' RON) ' : '';
}

FormHandler.prototype._CalcItemPrice = function(item)
{
    var priceFollowing = priceNow = 0;
    
    priceNow = ((item.price*(1+item.percentfirst/100) - item.discountfirst ) + item.onetimeprice - item.onetimediscount) * item.quantity;
    priceFollowing = (item.pricefollowing*(1+item.percentfollowing/100) - item.discountfollowing ) * item.quantity 
    
    return {
        'priceNow': priceNow,
        'priceFollowing': priceFollowing
    };
}

//az osszes ar itt van szamolva: domain, hosting, option, osszes ar
FormHandler.prototype._CalculatePriceSumCallback = function(e, AsyncronAnswer)
{
    AsyncronAnswer = typeof(AsyncronAnswer) != 'undefined' ? AsyncronAnswer : false;
	
    var output = '';
    var domainSettingVal = Helpers.GetInputValue('domainsetting', this._form);
    var withHosting = domainSettingVal == 0;
    var domainyearsIndex = Helpers.GetInputValue('domainyears', this._form);
    var domainyears = this._DomainYearsValueConverter( domainyearsIndex, true);
    var unlimited = domainyearsIndex == 9;
    var defDprice = this._GetCurrentDPrice(false);
    var dprice = this._GetCurrentDPrice(true);
    //var newReg = template.php 38.sor
    var requestmode = Helpers.GetInputValue('requestmode', this._form);
    var priceNow = 0; 
    var priceYearly = 0;
    var hosting = withHosting ? this._GetCurrentHosting() : null;
    var fullPrice = 0;
    var hostingYears = withHosting ? Helpers.GetInputValue('hostingperiod', this._form) : 0; //hosting hany honapra van rendelve
    var hostingDiscountOK = withHosting && hosting && (hosting.domaindiscount<=hostingYears || !hosting.domaindiscount); //hostingnal megvan adva, hogy minimum mennyi idore kell lefoglalni, hogy lehessen kedvezmeny
    //var dprice = hostingDiscountOK ? this._GetCurrentDPrice(true) : defDprice; //ha nemervenyes a kedvezmeny, akkor a defaultot vegye
    Globals.ItemsData = new Array();
    Globals.ItemsDataDef = new Array();
    var domainData = Helpers.CopyObjectData(this._GetCurrentDomain());
    var domainDataDef = Helpers.CopyObjectData(this._GetCurrentDomain());
    
    //a propNum-adik property nevet adja vissza
    var getObjectNthPropertyName = function(obj,propNum){ 
        for(var propName in obj){
            if(propNum==0){
                return propName;
            }else{
                propNum--;
            } return null;
        }
    }
    
    //új vagy transfer) berendelésre kerül, akkor mindig automatikusan jöjjön létre/frissüljön a TetelSorTipusok táblában egy megfelelő _extend is,
    //ami tartalma nem más, mint a bejövő tétel followingja. A bejövő tétel elvártiár-ja és elvártihónap-ja kerül bele az _extend típus
    //ismétlődőár-ba és elvártiár-ba, illetve ismétlődésihónap és elvártihónap-ba is.
    var createDomainExtend = function(item){
        var extend = Helpers.CopyObjectData(item);
        extend.id += '_extend';
        extend.price = item.pricefollowing;
        extend.pricemonth = item.monthfollowing;
        extend.ordername = texts['domain_extend'];
        extend.invoicename = texts['domain_extend_invoicename'];
        return extend;
    }
    //visszadja a legnagyobb kedvezmenyt a viszonteladoi statusz alapjan
    var getVEMaxDiscount = function(veStatus, priceList, yearlypriceList, optionID2Clone){
        var discountProperty = null;
        var maxDiscount = 0;
		veStatus[veStatus['email']] = true;
        for(var dprop in priceList)
        {
            if( dprop == veStatus['email'] )
            {
                maxDiscount = priceList[dprop];
                discountProperty = dprop;
				break;
            }
            if(typeof veStatus[dprop] != 'undefined' && veStatus[dprop] == true && Math.abs(priceList[dprop])>Math.abs(maxDiscount))
            {
                maxDiscount = priceList[dprop];
                discountProperty = dprop;
            }
        }
        var ydiscountProperty = null;
        var ymaxDiscount = 0;
        for(var ydprop in yearlypriceList)
        {
            if( ydprop == veStatus['email'] )
            {
                ymaxDiscount = yearlypriceList[ydprop];
                ydiscountProperty = ydprop;
				break;
            }
            if(typeof veStatus[ydprop] != 'undefined' && veStatus[ydprop] == true && Math.abs(yearlypriceList[ydprop])>Math.abs(ymaxDiscount))
            {
                ymaxDiscount = yearlypriceList[ydprop];
                ydiscountProperty = ydprop;
            }
        }
        if(discountProperty == null) discountProperty = ydiscountProperty; // a reg/átreg az elsodleges, ha nincs, akkor vesszük figyelembe az évit a típus meghatározásához
        if(discountProperty != null)
        {
            var veOptionID = "";
            switch(discountProperty)
            {
                case 'dolcson': veOptionID = 'dolcson'; break;
                case 'dolcson20p': veOptionID = 'dolc20p'; break;
                case 'dviszontelado': veOptionID = 'visz'; break;
                case 'elorefizetett10hu': veOptionID = 'visz'; break;
                case 'elorefizetett': veOptionID = 'elorefiz'; break;
                default: if (discountProperty.indexOf('@')>=0) veOptionID = 'visz'; else throw "unknown VE discountProperty '"+ discountProperty +"'";
            }
            var dOpt = Helpers.GetItemFromObjectListByProp(cu.options, 'id', arguments.length>3 ? optionID2Clone : veOptionID);
            return {
                name: discountProperty,
                value: maxDiscount,
				yearlyvalue: ymaxDiscount,
                option: dOpt
            };
        }
        else
            return null;
    }
    var prefixateItem = function(item, prefix)
    {
        item.id = prefix  + '.' + item.id;
        item.ordername = prefix + item.ordername;
        item.invoicename = prefix + item.invoicename;
        return item;
    }
    //frissiti a viszont eladoi statuszt, ha valtozott
    if ( !AsyncronAnswer ) this._UpdateVEStatus();
    
    var finPrice, finPriceDef;
    var veItem = null;
    var veItemDef = null;
    //domain ar szamolas---------------------------------------------------
    switch(requestmode)
    {
        case '0': //uj igeny
            var sos = Helpers.GetInputValue('sosreg', this._form, true);
            
			// if(typeof dprice.newreg['ev'+domainyears] != 'undefined') { dprice.newreg.price = dprice.newreg['ev'+domainyears]; }
			// if(typeof defDprice.newreg['ev'+domainyears] != 'undefined') { defDprice.newreg.price = defDprice.newreg['ev'+domainyears]; }

            //egyszeri dolgok
            domainData.onetimeprice = dprice.newreg.price + (sos ? dprice.sos : 0);
            domainData.onetimediscount += (withHosting && hostingDiscountOK ? dprice.hostingregdiscount : 0);
            //ismetlodo dolgok
            domainData.price = dprice.yearly.price*domainyears;
            domainData.discountfirst += (dprice.prepaid2yearly>0 && domainyears==2 ? dprice.prepaid2yearly : (dprice.prepaid3yearly>0 && domainyears==3 ? dprice.prepaid3yearly : (dprice.prepaid4yearly>0 && domainyears==4 ? dprice.prepaid4yearly : (dprice.prepaid5yearly>0 && domainyears==5 ? dprice.prepaid5yearly : 0))))*domainyears;
            if(withHosting && hostingDiscountOK && dprice.hostingyearlydiscount>0)
				domainData.discountfirst = dprice.hostingyearlydiscount*( domainyears<hostingYears/12 ? domainyears : hostingYears/12 );
            domainData.pricemonth = domainyears*12;
		
            //elvart dolgok
            domainData.pricefollowing = dprice.yearly.price - (withHosting && hostingDiscountOK ? dprice.hostingyearlydiscount : 0);  //2008-09-15  defDprice.yearly.price

            //jutalekok, nemlehet kissebb mint 0
            finPrice = this._CalcItemPrice(domainData);
            domainData.commissionfirst = Math.max(dprice.commissionfirst!==null ? dprice.commissionfirst-domainData.discountfirst : finPrice.priceNow, 0); 
            domainData.commissionfollowing = Math.max(dprice.commissionfollowing!==null ? dprice.commissionfollowing-domainData.discountfollowing : finPrice.priceFollowing, 0);
            
            Globals.ItemsDataDef.push(createDomainExtend(domainData));
            domainData.ordername = (sos ? texts['domain_newreg_sos'] : texts['domain_newreg']);// + " ("+ domainData.id +")";
            domainData.invoicename = (sos ? texts['domain_newreg_sos_invoicename'] : texts['domain_newreg_invoicename']);// + " ("+ domainData.id +")";
            domainData.id += (sos ? '_sos' : '_new');
            
            //alapertelmezett adatok
            domainDataDef.onetimeprice += defDprice.newreg.price + (sos ? defDprice.sos : 0);
            domainDataDef.price = defDprice.yearly.price*(domainDataDef.pricemonth/12);
            domainDataDef.pricefollowing = dprice.yearly.price; //2008-09-15  defDprice.yearly.price
            
            finPriceDef = this._CalcItemPrice(domainDataDef);
            domainDataDef.commissionfirst = Math.max(defDprice.commissionfirst!==null ? defDprice.commissionfirst-domainDataDef.discountfirst : finPriceDef.priceNow, 0);
            domainDataDef.commissionfollowing = Math.max(defDprice.commissionfollowing!==null ? defDprice.commissionfollowing-domainDataDef.discountfollowing : finPriceDef.priceFollowing, 0);
            
            domainDataDef.ordername = (sos ? texts['domain_newreg_sos'] : texts['domain_newreg']);// + " ("+ domainDataDef.id +")";
            domainDataDef.invoicename = (sos ? texts['domain_newreg_sos_invoicename'] : texts['domain_newreg_invoicename']);// + " ("+ domainDataDef.id +")";
            domainDataDef.id += (sos ? '_sos' : '_new');
            //ha nincs hoszting es uj igeny van
            if(!withHosting && this._veStatus != null)
            {
                var newRegDiscount = getVEMaxDiscount(this._veStatus, dprice.newreg, dprice.yearly);
                if(newRegDiscount != null && newRegDiscount.option != null)
                {
                    var yearlyDiscount = dprice.yearly && dprice.yearly[newRegDiscount.name] ? dprice.yearly[newRegDiscount.name] : 0;
                    veItem = Helpers.CopyObjectData(newRegDiscount.option);
                    veItem = prefixateItem(veItem, dprice.name);
                    veItem.onetimeprice = Math.max(newRegDiscount.value, -1*finPrice.priceNow);
                    veItem.price = yearlyDiscount*domainyears;
                    veItem.pricefollowing = yearlyDiscount;
                    veItem.pricemonth = domainyears*12;

                    veItemDef = Helpers.CopyObjectData(veItem);
                    veItemDef.onetimeprice = newRegDiscount.value;
                    veItemDef.price = yearlyDiscount;
                    veItemDef.pricefollowing = yearlyDiscount;
                    veItemDef.pricemonth = 12;
                    
                    Helpers.Log("_CalculatePriceSumCallback >> Discountproperty found: " + newRegDiscount.name, newRegDiscount.value);
                }
                else
                    Helpers.Log("_CalculatePriceSumCallback >> Discountproperty NOT found");
            }
            break;
        case '1': //reg valtas
            //egyszeri dolgok
            domainData.onetimeprice = dprice.transfer.price;
            domainData.onetimediscount += (withHosting && hostingDiscountOK ? dprice.hostingtransferdiscount : 0);
            //ismetlodo dolgok
            domainData.price = dprice.yearly.price*domainyears;
            domainData.discountfirst += (dprice.prepaid2yearly>0 && domainyears==2 ? dprice.prepaid2yearly : (dprice.prepaid3yearly>0 && domainyears==3 ? dprice.prepaid3yearly : (dprice.prepaid4yearly>0 && domainyears==4 ? dprice.prepaid4yearly : (dprice.prepaid5yearly>0 && domainyears==5 ? dprice.prepaid5yearly : 0))))*domainyears;
            if(withHosting && hostingDiscountOK && dprice.hostingyearlydiscount>0)
				domainData.discountfirst = dprice.hostingyearlydiscount*( domainyears<hostingYears/12 ? domainyears : hostingYears/12 );
            domainData.pricemonth = domainyears*12;
            //elvart dolgok
            domainData.pricefollowing = dprice.yearly.price - (withHosting && hostingDiscountOK ? dprice.hostingyearlydiscount : 0); //2008-09-15  defDprice.yearly.price
            //jutalekok
            finPrice = this._CalcItemPrice(domainData);
            domainData.commissionfirst = Math.max(dprice.commissionfirst!==null ? dprice.commissionfirst-domainData.discountfirst : finPrice.priceNow, 0); 
            domainData.commissionfollowing = Math.max(dprice.commissionfollowing!==null ? dprice.commissionfollowing-domainData.discountfollowing : finPrice.priceFollowing, 0); 
            
            Globals.ItemsDataDef.push(createDomainExtend(domainData));
            domainData.ordername = texts['domain_transf'];// + " ("+ domainData.id +")";
            domainData.invoicename = texts['domain_transf_invoicename'];// + " ("+ domainData.id +")";
            domainData.id += '_transf';
            
            //alapertelmezett adatok
            domainDataDef.onetimeprice += defDprice.transfer.price;
            domainDataDef.price = defDprice.yearly.price*(domainDataDef.pricemonth/12);
            domainDataDef.pricefollowing = dprice.yearly.price; //2008-09-15  defDprice.yearly.price
            
            finPriceDef = this._CalcItemPrice(domainDataDef);
            domainDataDef.commissionfirst = Math.max(defDprice.commissionfirst!==null ? defDprice.commissionfirst-domainDataDef.discountfirst : finPriceDef.priceNow, 0);
            domainDataDef.commissionfollowing = Math.max(defDprice.commissionfollowing!==null ? defDprice.commissionfollowing-domainDataDef.discountfollowing : finPriceDef.priceFollowing, 0);
            
            domainDataDef.ordername = texts['domain_transf'];// + " ("+ domainDataDef.id +")";
            domainDataDef.invoicename = texts['domain_transf_invoicename'];// + " ("+ domainDataDef.id +")";
            domainDataDef.id += '_transf';


            //ha nincs hoszting es uj igeny van
            if(!withHosting && this._veStatus != null)
            {
                var transfDiscount = getVEMaxDiscount(this._veStatus, dprice.transfer, dprice.yearly, 'vetrans');
                if(transfDiscount != null && transfDiscount.option != null)
                {
                    var yearlyDiscountT = dprice.yearly && dprice.yearly[transfDiscount.name] ? dprice.yearly[transfDiscount.name] : 0;
                    veItem = Helpers.CopyObjectData(transfDiscount.option);
                    veItem = prefixateItem(veItem, dprice.name);
                    veItem.onetimeprice = Math.max(transfDiscount.value, -1*finPrice.priceNow);
                    veItem.price = yearlyDiscountT*domainyears;
                    veItem.pricefollowing = yearlyDiscountT;
                    veItem.pricemonth = domainyears*12;

                    veItemDef = Helpers.CopyObjectData(veItem);
                    veItemDef.onetimeprice = transfDiscount.value;
                    veItemDef.price = yearlyDiscountT;
                    veItemDef.pricefollowing = yearlyDiscountT;
                    veItemDef.pricemonth = 12;

                    Helpers.Log("_CalculatePriceSumCallback >> Discountproperty found: " + transfDiscount.name, transfDiscount.value);
                }
                else
                    Helpers.Log("_CalculatePriceSumCallback >> Discountproperty NOT found");
            }
            break;
        case '2': //mashol fenntartva
            domainData.ordername = texts['domain_nsholding'];// + " ("+ domainData.id +")";
            domainData.invoicename = texts['domain_nsholding_invoicename'];// + " ("+ domainData.id +")";
            domainData.id += '_nshold';
            
            //alapertelmezett adatok
            //domainDataDef.onetimeprice = defDprice.transfer.price;
            domainDataDef.ordername = texts['domain_nsholding'];// + " ("+ domainDataDef.id +")";
            domainDataDef.invoicename = texts['domain_nsholding_invoicename'];// + " ("+ domainDataDef.id +")";
            domainDataDef.id += '_nshold';
            break;
        case '3': //mar kifizette
            //egyszeri dolgok
            //domainData.onetimeprice = dprice.newreg.price;
            //domainData.onetimediscount += (withHosting && hostingDiscountOK ? dprice.hostingregdiscount : 0);
            //ismetlodo dolgok
            //domainData.price = dprice.yearly.price - defDprice.yearly.price;
            //domainData.discountfirst += (withHosting && hostingDiscountOK ? dprice.hostingyearlydiscount*hostingYears : 0);
            //domainData.pricemonth = domainyears*12;
            //elvart dolgok
            //domainData.pricefollowing = dprice.yearly.price - defDprice.yearly.price; //2008-09-15  defDprice.yearly.price
            domainData.onetimeprice = 0;
            domainData.onetimediscount = ( domainData.defaultt == 'hu' || domainData.defaultt == 'comnet' ||  domainData.defaultt == 'info' ) ? defDprice.yearly.price : 0 ;
            domainData.price = 0;
            domainData.discountfirst = 0;
            domainData.pricemonth = 12;
            domainData.pricefollowing = 0;

            //jutalekok
            finPrice = this._CalcItemPrice(domainData);
            domainData.commissionfirst = Math.max(dprice.commissionfirst!==null ? dprice.commissionfirst-domainData.discountfirst : finPrice.priceNow, 0); 
            domainData.commissionfollowing = Math.max(dprice.commissionfollowing!==null ? dprice.commissionfollowing-domainData.discountfollowing : finPrice.priceFollowing, 0);
            
            domainData.ordername = texts['domain_payed'];// + " ("+ domainData.id +")";
            domainData.invoicename = texts['domain_payed_invoicename'];// + " ("+ domainData.id +")";
            domainData.id += '_payed';
            
            //alapertelmezett adatok
            //domainDataDef.onetimeprice += defDprice.newreg.price;
            //domainDataDef.price = defDprice.yearly.price*(domainDataDef.pricemonth/12);
            //domainDataDef.pricefollowing = dprice.yearly.price; //2008-09-15  defDprice.yearly.price
            domainDataDef.onetimediscount = ( domainData.defaultt == 'hu' || domainData.defaultt == 'comnet' ||  domainData.defaultt == 'info' ) ? defDprice.yearly.price : 0;
            domainDataDef.onetimeprice = 0;
            domainDataDef.price = 0;
            domainDataDef.pricefollowing = 0;
            
            finPriceDef = this._CalcItemPrice(domainDataDef);
            domainDataDef.commissionfirst = Math.max(defDprice.commissionfirst!==null ? defDprice.commissionfirst-domainDataDef.discountfirst : finPriceDef.priceNow, 0);
            domainDataDef.commissionfollowing = Math.max(dprice.commissionfollowing!==null ? dprice.commissionfollowing-domainDataDef.discountfollowing : finPriceDef.priceFollowing, 0);
            
            domainDataDef.ordername = texts['domain_payed'];// + " ("+ domainDataDef.id +")";
            domainDataDef.invoicename = texts['domain_payed_invoicename'];// + " ("+ domainDataDef.id +")";
            domainDataDef.id += '_payed';
            break;
    }
    
    Globals.ItemsDataDef.push(domainDataDef);
    Globals.ItemsData.push(domainData);                

    finPrice = this._CalcItemPrice(domainData);
    priceNow = finPrice.priceNow;
    priceYearly = finPrice.priceFollowing;

    if(veItem != null && veItemDef != null)
    {
        if ( veItem.monthfollowing == null && veItem.pricefollowing != 0 ) veItem.monthfollowing = 12;
		Globals.ItemsDataDef.push(veItemDef);
        Globals.ItemsData.push(veItem);
        var veFinPrice = this._CalcItemPrice(veItem);
        priceNow += veFinPrice.priceNow;
        priceYearly += veFinPrice.priceFollowing;

		var hutxt = 'hu'; var txt5 = '5'; var txthudolcson = 'hu.dolcson';
		if ( dprice.name == hutxt && veItem.id != txthudolcson && domainSettingVal != txt5 ) { 
        	//viszonteladoi DNS ar, csak .hu domainekre vonatkozik, és csak akkor, ha nem o adja a dns-t
        	var dns = Helpers.GetItemFromObjectListByProp(cu.options, 'id', 'vedns');
        	dns = Helpers.CopyObjectData(dns);
        	dns = prefixateItem(dns, dprice.name);
        	var dnsDef = Helpers.CopyObjectData(dns);
        	Globals.ItemsDataDef.push(dns);
        	Globals.ItemsData.push(dnsDef);
        	veFinPrice = this._CalcItemPrice(dns);
        	priceNow += veFinPrice.priceNow;
        	priceYearly += veFinPrice.priceFollowing;

        	if(this._veStatus.elorefizetettDnsStatus > 0)
        	{
            	var dnsDiscount = Helpers.GetItemFromObjectListByProp(cu.options, 'id', 'vednskedv');
            	dnsDiscount = Helpers.CopyObjectData(dnsDiscount);
            	dnsDiscount = prefixateItem(dnsDiscount, dprice.name);
            	var dnsDiscountDef = Helpers.CopyObjectData(dnsDiscount);
            	Globals.ItemsDataDef.push(dnsDiscount);
            	Globals.ItemsData.push(dnsDiscountDef);
            	veFinPrice = this._CalcItemPrice(dnsDiscount);
            	priceNow += veFinPrice.priceNow;
        		priceYearly += veFinPrice.priceFollowing;
			}
        }
    }
	var txt0 = '0';
    if(this._veStatus != null && (this._veStatus.elorefizetett || this._veStatus.elorefizetettElhasznalt) && domainSettingVal != txt0)
    {
        $('ve_status_row').style.display = '';
        $('ve_status_text').style.display = this._veStatus.elorefizetett ? '' : 'none';
        $('ve_payedout_text').style.display = this._veStatus.elorefizetettElhasznalt ? '' : 'none';
        Helpers.SetText(
            Helpers.GetElement('ve_status_text', this._form),
            Helpers.ReplaceParams(
                Helpers.GetInputText('ve_status_text', this._form),
                [/\$dtype/gi,'$count'],
                [dprice.name, this._veStatus.elorefizetettStatus],
                've_status_text'
                )
            );
        Helpers.SetText(
            Helpers.GetElement('ve_payedout_text', this._form),
            Helpers.ReplaceParams(
                Helpers.GetInputText('ve_payedout_text', this._form),
                /\$dtype/gi,
                dprice.name,
                've_payedout_text'
                )
            );
    }
    else
    {
        if($('ve_status_row'))
            $('ve_status_row').style.display = 'none';
    }



    if(!unlimited)
    {
        output += withHosting                                                           
        ? Helpers.GetInputText('hostingpack', this._form) +' '+ texts['withhosting'] //Miniweb tarhely csomaggal
        : texts['withouthosting'];                                                      //Tarhely rendeles nelkul
        output += ' '+this._RoundNum(priceNow) + ' '+ texts['centralmoneydesc'] + this._GetCMPriceText(priceNow); //9.49 Euro (Â» 22.21 RON)   
        output += priceNow>0 ? '+'+ texts['vatname'] : ''; //+AFA
        
        if(requestmode != 3)//ha nem "Mar kifizette"
        {
            //ha "Domain mashol torteno fenntartasa" akkor a hosting eveket irja ki
            var period = requestmode == 2 ? Helpers.GetInputText('hostingperiod', this._form) : Helpers.GetInputText('domainyears', this._form);
            output += ' ' + period + ' '+ texts['forperiod']; //2 Ă©v idĹ‘tartamra
            output += ', '+ texts['thenyearly'];//majd azt kĂ¶vetĹ‘en Ă©venkĂ©nt   
        }
        else
            output += ', ' + texts['afterperiod']; //majd az eredeti domain rendeles szerinti lejaratot kovetoen 
        
        output += ' '+ this._RoundNum(priceYearly) + ' '+ texts['centralmoneydesc'] + this._GetCMPriceText(priceYearly);//9.49 Euro (>> 22.21 RON)   
        output += priceYearly>0 ? '+'+ texts['vatname'] : '';// +AFA      
    }
    else
    { //ha korlatlan, akkor igy:
        output += withHosting 
        ? Helpers.GetInputText('hostingpack', this._form) +' '+ texts['withhosting'] //Miniweb tarhely csomaggal
        : texts['withouthosting']; //Tarhely rendeles nelkul
        output += ' '+this._RoundNum(priceNow) + ' '+ texts['centralmoneydesc'] + this._GetCMPriceText(priceNow);//9.49 Euro (» 22.21 RON)   
        output += (priceNow>0 ? '+'+ texts['vatname'] : '') + ' ';// +AFA
        output += texts['unlimited'] +' ' +  texts['forperiod'] +' ' ; //korlatlan idotartamra
    }
    fullPrice += priceNow;
    Helpers.SetInputValue('domainpricesum', this._form, output);
    //domain ar szamolas---------------------------------------------------//
    
    //hosting ar szamolas---------------------------------------------------
    output = '';
    if(withHosting)
    {
        var getPrice = function(hostingMonth, monthPrices)
        {
            if(monthPrices[ hostingMonth ])
                return parseFloat(monthPrices[ hostingMonth ].price);
            var prev = 100000;//nagy szam :)
            for(var curr in monthPrices) //ha nincs megadva az a honap, akkor megkeresi a hozza legkozelebb esot (nagyobbat) es abbol kiszamolja
            {
                if(curr > hostingMonth && prev < hostingMonth)
                {
                    break;
                }else
                    prev = curr;
            }
            return monthPrices[ curr ].price*(hostingMonth/curr);
        }
        
        var hostingMonth = Helpers.GetInputValue('hostingperiod', this._form); //hosting hany honapra van rendelve
        var price = getPrice(hostingMonth, hosting.monthPrices);
        var monthFollowing = !hosting.monthfollowing ? (hostingMonth<12 ? hostingMonth: 12) : hosting.monthfollowing;
        var price2 = getPrice(monthFollowing, hosting.monthPrices);
        var hostingData = Helpers.CopyObjectData(hosting);
        hostingData.price = price;
        hostingData.pricefollowing = price2;
        hostingData.pricemonth = hostingMonth;
        hostingData.monthfollowing = monthFollowing;
       
        //commissionfirst es commissionfollowing kiszamolva
        finPrice = this._CalcItemPrice(hostingData);
        hostingData.commissionfirst = hostingData.commissionfirst!==null ? hostingData.commissionfirst : finPrice.priceNow;
        hostingData.commissionfollowing = hostingData.commissionfollowing!==null ? hostingData.commissionfollowing : finPrice.priceFollowing; 
        
        output = hostingMonth + ' '+ texts['formonths'] +' '+ this._RoundNum(finPrice.priceNow) + ' '+ texts['centralmoneydesc'] +this._GetCMPriceText(finPrice.priceFollowing)+ '+'+ texts['vatname'] ;
        fullPrice += finPrice.priceNow;
        
        //alapertelmezett ertek (TetelSorTipus)
        var hostingDataDef = Helpers.CopyObjectData(hosting);
        var hostingMonthDef = getObjectNthPropertyName(hostingDataDef.monthPrices,0);
        var priceDef = getPrice(hostingMonthDef, hostingDataDef.monthPrices);
        hostingDataDef.price = hostingDataDef.pricefollowing = priceDef;
        hostingDataDef.pricemonth =  hostingDataDef.monthfollowing = hostingMonthDef;
        finPriceDef = this._CalcItemPrice(hostingDataDef);
        hostingDataDef.commissionfirst = Math.max(hostingDataDef.commissionfirst!==null ? hostingDataDef.commissionfirst : finPriceDef.priceNow, 0);
        hostingDataDef.commissionfollowing = Math.max(hostingDataDef.commissionfollowing!==null ? hostingDataDef.commissionfollowing : finPriceDef.priceFollowing, 0);
        
        Globals.ItemsData.push(hostingData);
        Globals.ItemsDataDef.push(hostingDataDef);
    }    
    Helpers.SetInputValue('hostingpricesum', this._form, output);
    //hosting ar szamolas---------------------------------------------------//
    
    //option ar szamolas---------------------------------------------------
    output = '';
    if(withHosting)
    {
        var hostingMonth = Helpers.GetInputValue('hostingperiod', this._form); //hosting hany honapra van rendelve
        var optionPriceSum = {
            'onetimePrice': 0,
            'priceNow': 0
        };
        var tthis = this;
        for(var optionName in hosting.options)
        {
            var getOptionPrice = function(option, selectedValue, host, optionData) //visszaadja az option elemenek egyszeri es havi arat
            {
                var basePrice = tthis._GetCombinedOptionValue(option, selectedValue, host, "price");
                var onetimeprice = tthis._GetCombinedOptionValue(option, selectedValue, host, "onetimeprice");
                var quantity = tthis._GetCombinedOptionValue(option, selectedValue, host, "quantity");
                var percentfirst = tthis._GetCombinedOptionValue(option, selectedValue, host, "percentfirst");
                var discountfirst = tthis._GetCombinedOptionValue(option, selectedValue, host, "discountfirst");
                var percentfollowing = tthis._GetCombinedOptionValue(option, selectedValue, host, "percentfollowing");
                var discountfollowing = tthis._GetCombinedOptionValue(option, selectedValue, host, "discountfollowing");
                var onetimediscount = tthis._GetCombinedOptionValue(option, selectedValue, host, "onetimediscount");
                var pricemonth = tthis._GetCombinedOptionValue(option, selectedValue, host, "pricemonth");
                var monthFollowing =  host 
                ? (host.monthfollowing===null ? (hostingMonth<12 ? hostingMonth : 12) : host.monthfollowing)
                : (pricemonth>0 ? pricemonth : 12);
                
                var price = host ? (pricemonth!=0 ? basePrice*(hostingMonth/pricemonth) : 0) : basePrice;
                //var monthFollowing = pricemonth;
                //var price2 = basePrice;
                var price2 = pricemonth!=0 ? basePrice*(monthFollowing/pricemonth) : 0;
                
                var pn = (price*(1+percentfirst/100) - discountfirst ) * quantity;
                var pf = (price2*(1+percentfollowing/100) - discountfollowing ) * quantity;
                var otp = (onetimeprice - onetimediscount)* quantity;
                
                if(optionData != null)
                {
                    //az ujraszamolt arak, amit a szerverre kell kuldeni
                    try{
                        //minden erteket atirunk amit az option kivalasztott eleme felulirna
                        for(var propertyName in option.items[selectedValue])
                        {
                            try{
                                optionData[propertyName] = tthis._GetCombinedOptionValue(option, selectedValue, host, propertyName);
                            }catch(ex)
                            {
                                Helpers.Log('_CalculatePriceSumCallback >> exception: %o', ex);
                            }
                        }
                    }catch(ex)
                    {
                        Helpers.Log('_CalculatePriceSumCallback >> exception2: %o', ex);
                    }
                    optionData.price = price;
                    optionData.pricemonth = hostingMonth;
                    optionData.monthfollowing = monthFollowing;
                    optionData.pricefollowing = price2;
                    //commissionfirst es commissionfollowing kiszamolva
                    var finPrice = tthis._CalcItemPrice(optionData);
                    optionData.commissionfirst = Math.max(optionData.commissionfirst!==null ? optionData.commissionfirst-optionData.discountfirst : finPrice.priceNow, 0);
                    optionData.commissionfollowing = Math.max(optionData.commissionfollowing!==null ? optionData.commissionfollowing-optionData.discountfollowing : finPrice.priceFollowing, 0);
                }
                
                return {
                    'onetimePrice':otp,
                    'priceNow': pn,
                    'priceFollowing': pf,
                    'optionData': optionData
                };
            }
            
            var val = Helpers.GetInputValue(optionName, this._form, true);
            var sel = Helpers.GetElement(optionName, this._form);
            var op = Helpers.GetItemFromObjectListByProp(cu.options, 'id',optionName);
            if(!val)
                continue;
            if(val != '0' || op.firstisdisabled==0)
            {
                op.ordername = Helpers.ReplaceParams(op.ordername, '$orderitem', this._GetCombinedOptionValue(op, val, hosting, "orderitem"), optionName+'_oitem');
                op.invoicename = Helpers.ReplaceParams(op.invoicename, '$invoiceitem', this._GetCombinedOptionValue(op, val, hosting, "invoiceitem"), optionName+'_iitem');
                
                var optionData = Helpers.CopyObjectData(op);
                var opPrice = getOptionPrice(op, val, hosting, optionData);
                optionData = opPrice.optionData;//Helpers.CopyObjectData(optionData, opPrice.optionData);
                
                optionPriceSum.priceNow += opPrice.priceNow;
                optionPriceSum.onetimePrice += opPrice.onetimePrice;
                fullPrice += opPrice.priceNow + opPrice.onetimePrice;
                
                var optionDataDef = Helpers.CopyObjectData(op);
                var valDef = getObjectNthPropertyName(op.items, op.firstisdisabled ? 1 : 0); 
                var opPriceDef = getOptionPrice(op, valDef, null, optionDataDef);
                optionDataDef =opPriceDef.optionData;
                
                Globals.ItemsData.push(optionData);
                Globals.ItemsDataDef.push(optionDataDef);
            }
            var hostingMonthStr = Helpers.GetInputText('hostingperiod', this._form);
            for(var i=0; i<sel.options.length; i++) //az select-ekben at kell szamolni az arakat, majd atirni oket, hogy lassa a juzer
            {
                opPrice = getOptionPrice(op, sel.options[i].value, hosting);
                sel.options[i].text = Helpers.ReplaceParams(sel.options[i].text, ['$ordermonth','$pricenow'], [hostingMonthStr,this._RoundNum(opPrice.priceNow + opPrice.onetimePrice)], optionName+i.toString());
            }
        }
        if(optionPriceSum.onetimePrice>0 || optionPriceSum.priceNow>0)
            output += ""
            + (optionPriceSum.onetimePrice>0 ? this._RoundNum(optionPriceSum.onetimePrice) : '')
            + (optionPriceSum.onetimePrice>0 && optionPriceSum.priceNow>0 ? '+': '')
            + (optionPriceSum.priceNow>0 ? this._RoundNum(optionPriceSum.priceNow) : '')
            + ' ' + texts['centralmoneydesc']
            + this._GetCMPriceText(optionPriceSum.onetimePrice) + this._GetCMPriceText(optionPriceSum.priceNow)
            + '+'+ texts['vatname'] +"\n";
    }
    Helpers.SetInputValue('extrapricesum', this._form, output);
    //option ar szamolas---------------------------------------------------//
    
    //veg ar szamolas---------------------------------------------------
    output = this._RoundNum(fullPrice) + ' ' + texts['centralmoneydesc'] + this._GetCMPriceText(fullPrice) + '+'+ texts['vatname'] + (domainSettingVal == 1 ? ' + ' + texts['shareddomainprice'] : '');
    Helpers.SetInputValue('pricenow', this._form, output);
    Globals.FullPrice = fullPrice;
//veg ar szamolas---------------------------------------------------//
}

//visszaadja a dprice-t, akar figyelembe veve a hosting felulirast is ...
FormHandler.prototype._GetCurrentDPrice = function(IsCombined)
{
    var domain = this._GetCurrentDomain();
    var dprice = null;
    
    if(IsCombined)
    {
        if(Helpers.GetInputValue('domainsetting', this._form) == 0) //ker hostingot is
        {
            var hosting = this._GetCurrentHosting();
            var hostingYears = Helpers.GetInputValue('hostingperiod', this._form); //hosting hany honapra van rendelve
            var hostingDiscountOK = hosting && (hosting.domaindiscount<=hostingYears || !hosting.domaindiscount); //hostingnal megvan adva, hogy minimum mennyi idore kell lefoglalni, hogy lehessen kedvezmeny
            
            if(hostingDiscountOK && hosting.packagedprice && domain.supportedPacks[hosting.packagedprice]) //eloszor megnezni, hogy van e packagedprice kedvezmeny
            {
                dprice = Helpers.GetItemFromObjectListByProp(cu.dprices, 'name', domain.supportedPacks[hosting.packagedprice]);
            }
            else if(hostingDiscountOK && typeof hosting.withhosting == 'string') //ha nincs, akkor megnezni van e withhosting kedvezmeny
            {
                dprice = Helpers.GetItemFromObjectListByProp(cu.dprices, 'name', hosting.withhosting);
            }
        }
        
        if(dprice == null) //ha nincs hosting vagy nincs hosting kedvezmeny, akkor a defaultt
        {
            dprice = Helpers.GetItemFromObjectListByProp(cu.dprices, 'name', domain.defaultt);
        }
    }
    else
    {
        dprice = Helpers.GetItemFromObjectListByProp(cu.dprices, 'name', domain.defaultt);
    }
    
    return dprice;
}

FormHandler.prototype._GetCurrentHosting = function()

{
    var hostingVal = Helpers.GetInputValue('hostingpack', this._form);
    var hosting = Helpers.GetItemFromObjectListByProp(cu.hosts, 'id', hostingVal);
    return hosting;
}

FormHandler.prototype._GetCurrentDomain = function()
{
    var domainVal = Helpers.GetInputValue('domaintype', this._form);
    var domain = Helpers.GetItemFromObjectListByProp(cu.domains, 'name', domainVal);
    return domain;
}

FormHandler.prototype._GetCombinedOptionValue = function(option, selectedValue, host, valueName) //visszaadja az elem arat figyelembe veve a felulirasokat (host es elem)
{
    var baseValue = ((typeof option.items[selectedValue] != 'undefined') && (typeof option.items[selectedValue][valueName] != 'undefined') && option.items[selectedValue][valueName] !== null) //eloszor megnezi, hogy a selectedItemben van e ilyen property
    ? option.items[selectedValue][valueName]           //ha igen, akkor ez a prioritasos
    : (typeof option[valueName]!='undefined' ? option[valueName] : null);  //ha nincs akkor megnezi, van e kozos ilyen property
    
    if(host && host.options && host.options[option.id])    //ezutan jonnek a host-ban felulirt ertekek
    {   //ez az opciok egyes elemeinek ertekeinek felulirasara szolgal:pl. quantity
        if((typeof host.options[option.id][selectedValue]!='undefined') && (typeof host.options[option.id][selectedValue][valueName]!='undefined') && (host.options[option.id][selectedValue][valueName]!==null))
        {
            baseValue = host.options[option.id][selectedValue][valueName];
        } //ez az kozos opciok felulirasara szolgal:pl. price vagy onetimeprice
        else if((typeof host.options[option.id][valueName] !='undefined') && (host.options[option.id][valueName] !== null))
        {
            baseValue = host.options[option.id][valueName]; 
        }
    }
	
	if ( typeof option.items[selectedValue] != 'undefined' && typeof option.items[selectedValue]['coupon'] != 'undefined' ) {
    	var respcoupon = Helpers.GetInputValue('respondercoupon', this._form);
		if ( respcoupon == null ) respcoupon = 0;
		if ( typeof option.items[selectedValue]['coupon']['respondercoupon'][respcoupon][valueName] != 'undefined' )
			baseValue = option.items[selectedValue]['coupon']['respondercoupon'][respcoupon][valueName];
	}
	
    return baseValue;
}

FormHandler.prototype._PriorityCallback = function(result)
{
    var dprice = this._GetCurrentDPrice(false);
    var priority = dprice ? dprice.inputs['priority'] : 0;
    return result && priority;
}

FormHandler.prototype._SosCallback = function(result)
{
    var dprice = this._GetCurrentDPrice(false);
    var sos = dprice ? (dprice.sos > 0) : 0;
    Helpers.SetText('sosprice', dprice.sos);
    
    return result && sos;
}

FormHandler.prototype._DomainYearsCallback = function(result)
{
    //ahol dprice.regyear == 0 ott csak korlatlant (9) lehet valasztani, ellenkezo esetben nincs korlatlan
    var requestmode = Helpers.GetInputValue('requestmode', this._form);
    var sel = Helpers.GetElement('domainyears', this._form);
    var dprice = this._GetCurrentDPrice(true); //ebbe bele van veve a hosting is
    //var defDprice = this._GetCurrentDPrice(false); //ami a domainhoz tartozik
    var allowed = new Array();
    var minYear = requestmode == 1 ? 1 : dprice.regyear;//defDprice.minyear && defDprice.minyear>dprice.regyear ? defDprice.minyear : dprice.regyear ;
    var fromIndex = this._DomainYearsValueConverter(minYear, false);
    var maxIndex = (fromIndex == 9 ? 9 : 8) //ha nem csak korlatlan, akkor nemlehet korlatlan vagyis csak .ro-nal van korlatlan, mashol nincs
    
    for(; fromIndex<=maxIndex; fromIndex++)
        allowed[allowed.length] = fromIndex;
    
    var selVal = Helpers.GetInputValue(sel, this._form);
    var selectValue = selVal == 9 ? cu.configuration.domainYear : null;
    Helpers.DisableSelectOptions(sel, allowed, true, selectValue);
    
    return result;
}

FormHandler.prototype._DomainSettingCallback = function(result)
{
    //ha result true (vagyis: A domain mĂˇshol torteno fenntartasaval), akkor domainsetting erteke csak 0 || 1 lehet
    var sel = Helpers.GetElement('domainsetting', this._form);
    if(result)
    {
        Helpers.DisableSelectOptions(sel, [0, 1], true);
    }
    else
    {
        Helpers.DisableSelectOptions(sel, [], false);
    }
}

//kell e nameserver check
FormHandler.prototype._NSCheckCallback = function(result)
{
    var dprice = this._GetCurrentDPrice(false);
    return result && dprice.nscheck==1;
}

//hosting csomag leirasat jeleniti meg
FormHandler.prototype._HostingPackDescriptionDisplayerCallback = function(result)
{
    var hostingVal = Helpers.GetInputValue('hostingpack', this._form);
    var hosting = Helpers.GetItemFromObjectListByProp(cu.hosts, 'id', hostingVal);
    if(hosting)
    {
        Helpers.SetText('hostingpack_descr', hosting.desc);
    }
    return result;
}

//megjeleniti vagy eltunteti az egyes optionokat a valasztott hosting csomaghoz
FormHandler.prototype._HostingPackOptionHandlerCallback = function(e)
{
    var hostingVal = Helpers.GetInputValue('hostingpack', this._form);
    var hosting = Helpers.GetItemFromObjectListByProp(cu.hosts, 'id', hostingVal);
    var displayOptionsBlock = false;
    var descr, idescr, o;
    var option;
    if(hosting)
    {
        /// optionsok listazasa
        var usedOptions = new Array();
        for(var optionName in hosting.options) 
            usedOptions[usedOptions.length] = optionName;
        //az egyes opciok (portal, +email,...) listazasa (megjelenitese vagy eltuntetese)
        var visible = true; //ezzel van felulirva neha az ertek (pl.: portal)
        for(var optionName2 in cu.options)
        {
            option = cu.options[optionName2];
            visible = true;
            if(option.id == 'portal' && !hosting.dynamic) //portĂˇl csak akkor jĂ¶n fel, ha dinamikus ki van vĂˇlasztva, vagy alapbĂłl dinamikus a csomag
            {
                //var dinValue = typeof hosting.options.dynamicmini != 'undefined' ? 'dynamicmini' : (typeof hosting.options.dynamicmaxi != 'undefined' ? 'dynamicmaxi' : '');
                //TODO: talan meg kene nezni az osszes option[i]['items'][i]['dynamic']
                //visible = hosting.dynamic || (Helpers.GetInputValue(dinValue, this._form) == 1 || Helpers.GetInputValue(dinValue, this._form) == 1);
                visible = false;
                for(var opname in cu.options)
                {
                    if(!Helpers.IsElementVisible(opname, this._form))
                        continue;
                    var fdis = cu.options[opname].firstisdisabled;
                    var val = Helpers.GetInputValue(opname, this._form);
                    if(fdis && val == 0)
                        continue;
                    var dynval = this._GetCombinedOptionValue(cu.options[opname], val, this._GetCurrentHosting(), "dynamic");
                    if(dynval == 1)
                    {
                        visible = true;
                        break;
                   }    
               }
            }
            o = Helpers.GetElement(option.id +'_row', this._form);
            if(o == null)
                continue;
            descr = Helpers.GetElement(optionName2 + '_descr', this._form);
            idescr = Helpers.GetElement(optionName2 + '_idescr_row', this._form);
            if(Helpers.InArray(usedOptions, option.id) && visible)
            {
                o.style.display = '';
                displayOptionsBlock = true;
                if(option.descr != null && option.descr.length>0)//kommentar megjelenitese 
                {
                    //Helpers.SetText(optionName + '_descr', option.descr);
                    descr.style.display = '';
                }else
                    descr.style.display = 'none';
                var selectedValue = Helpers.GetInputValue(optionName2, this._form);
                //selected option kommentar megjelenitese 
                if(option.items[selectedValue] && option.items[selectedValue].descr != null && option.items[selectedValue].descr.length>0)
                {
                    Helpers.SetText(optionName2 + '_idescr', option.items[selectedValue].descr);
                    idescr.style.display = '';
                }else
                    idescr.style.display = 'none';
            }
            else
            {
                descr.style.display = idescr.style.display = o.style.display = 'none';
            }
        }
    }
    var ob = Helpers.GetElement('options_block', this._form);
    if(ob)
        ob.style.display = displayOptionsBlock && Helpers.IsElementVisible('hostingdata_block', this._form) ? '' : 'none';
}

//hosting evek dinamikusan vannak generalva
FormHandler.prototype._HostingPackHostingPeriodCallback = function(e)
{
    var hostingVal = Helpers.GetInputValue('hostingpack', this._form);
    var hosting = Helpers.GetItemFromObjectListByProp(cu.hosts, 'id', hostingVal);
    if(hosting)
    {
        /// hosting evek combo
        var sel = Helpers.GetElement('hostingperiod', this._form);
        var selectedValue = Helpers.GetInputValue('hostingperiod', this._form);
        if(selectedValue == null)
            selectedValue = cu.configuration.hostingMonth;
		if (cu.configuration.hostingMonth > 0) { // miután kiolvastuk az alapértelmezettet, ki kell törölni, hogy késobb ne írja felül
            selectedValue = cu.configuration.hostingMonth;
			cu.configuration.hostingMonth = null;
		}
        while(sel.options.length>0)sel.options[0] = null;
        var lastmp = -1;
        var required = [24, 36]; //ezeknek az elemeknek mindenkeppen szerepelniuk kell a listaban
        var p = 0;
        for(var mp in hosting.monthPrices)
        {
            if(lastmp < required[p] && mp > required[p])
            {
                sel.options[sel.options.length] = new Option(required[p] +' '+ texts['formonths'], required[p], false, selectedValue==required[p]);
                p++;
            }
            else if(mp == required[p])
            {
                p++
            }
            sel.options[sel.options.length] = new Option(mp +' '+ texts['formonths'], mp, false, selectedValue==mp);
            lastmp = mp;
        }
        for(;p<required.length; p++) //amennyiben nemkellett kozbeszurni, akkor a vegere illeszti a required elemeket
            sel.options[sel.options.length] = new Option(required[p] +' '+ texts['formonths'], required[p], false, selectedValue==required[p]);
        
        var selMonth = Helpers.GetInputValue(sel, this._form);
        var descr = hosting.monthPrices[ selMonth ] ? hosting.monthPrices[ selMonth ].name : null;
        Helpers.SetInputValue('hostingperioddescr_row', this._form, descr);
        Helpers.SetText('hostingperiod_descr', descr == null ? "" : descr);
    }
}

//domain tulajdonosnal be kell e kerni a hivatalos azonositot
FormHandler.prototype._DomainOwnerOfficialIDCallback = function(result)
{
    var domain = this._GetCurrentDomain();
    return result && domain.requireGUID;
}

//ha empty options valasztott, akkor disablezza
FormHandler.prototype._DisableSelectingEmptyOptionCallback = function(e)
{
    var target = Helpers.Events.TargetElement(e);
    if(target && target.tagName && target.tagName.toLowerCase() == 'select')
    {
        if(target.options[target.selectedIndex].value == cu.configuration.emptyoption || target.options[target.selectedIndex].text == cu.configuration.emptyoption)
        {
            Helpers.DisableSelectOptions2(target, [target.options[target.selectedIndex].value], false);
        //this._FireChanged(null);
        }
    }
}

//kotve van a domain regisztracio eve a hosting evehez, vagyis ha az egyik valtozik, akkor atallitja a masikat is
//a kotes a dprice.regyearfixedtohosting ertekevel adott
FormHandler.prototype._HandleFixedDYearToHostingYearCallback = function(e)
{
    var withHosting = Helpers.GetInputValue('domainsetting', this._form) == 0;
    if(!withHosting)
        return;
    
    var dprice = this._GetCurrentDPrice(true);
    if(dprice.regyearfixedtohosting)
    {
        
        var domainyearsIndex = Helpers.GetInputValue('domainyears', this._form);
        var domainyears = this._DomainYearsValueConverter( domainyearsIndex, true);
        var hostingyears = Helpers.GetInputValue('hostingperiod', this._form)/12; //hosting hany evre van rendelve
        
        if(domainyears != hostingyears)
        {
            var target = Helpers.Events.TargetElement(e);
            if(target && target.name == 'hostingperiod')
            {
                if(!Helpers.SetInputValue('domainyears', this._form, this._DomainYearsValueConverter( hostingyears, false )))
                {
                    Helpers.SetInputValue('hostingperiod', this._form, domainyears*12);
                }
            }
            else
            {
                if(!Helpers.SetInputValue('hostingperiod', this._form, domainyears*12))
                {
                    Helpers.SetInputValue('domainyears', this._form, this._DomainYearsValueConverter( hostingyears, false ));
                }
            }
            this._FireChanged(null);
        }
    }
}

FormHandler.prototype._IsDomainSetterCallback = function(e) //beallitja a globalis IsDomain erteket
{
    var requestmode = Helpers.GetInputValue('requestmode', this._form);  
    var domainModes = ['0', '1'];
    Globals.IsDomain = Helpers.InArray(domainModes, requestmode);
}

FormHandler.prototype._TrimDomainNameCallback = function(e)
{
    var domainName = Helpers.GetInputValue('domainname', this._form);
    if(!domainName || domainName.length == 0)
        return;
    var parsedDomain = this._ParseDomainName(domainName);
    if(parsedDomain && parsedDomain.name != domainName)
        Helpers.SetInputValue('domainname', this._form, parsedDomain.name);
}

FormHandler.prototype._DoNSCheck = function(e)
{                      
    var form = document.createElement('form');
    form.method = "post";
    form.action = "http://www.domain.hu/domain/regcheck/";
    form.target = "_blank";
    
    var hid1 = document.createElement('input'); 
    hid1.type = 'hidden';
    hid1.name = 'dname';
    hid1.value = Helpers.GetInputValue('domainname', this._form) + Helpers.GetInputValue('domaintype', this._form);//'balazsy.hu'; 
    
    var hid2 = document.createElement('input'); 
    hid2.type = 'hidden';
    hid2.name = 'host';
    hid2.value = Helpers.GetInputValue('ns1', this._form);//'ns1.silihost.hu'; 
    
    form.appendChild(hid1);
    form.appendChild(hid2);
    document.body.appendChild(form);
    form.submit();
    document.body.removeChild(form);
}

FormHandler.prototype._GetItemsDataCallback = function(e)//el kell kuldeni a szerverre a tetelek alapertelmezeseit es aktualis ertekeit is
{
    var withHosting = Helpers.GetInputValue('domainsetting', this._form) == 0;
    if(withHosting) //opcioknal ha a nulladik elem van kivalasztva es ez engedelyezett, akkor le kell cserelni a value-jat
    {
        var hosting = this._GetCurrentHosting();
        
        for(var optionName in hosting.options)
        {
            var selectedValue = Helpers.GetInputValue(optionName, this._form, true);
            if(selectedValue == '0' && cu.options[optionName].firstisdisabled==0) //ha a firstdisabled miatt volt atengedve az elem, akkor at kell allitani a value-jat, mert a resultForm nem fogja megmutatni
            {
                var sel = Helpers.GetElement(optionName, this._form);
                var opObj = sel.options[ sel.selectedIndex ];
                if(opObj.value == '0')
                    opObj.value = '__0';
            }
        }
    }
    
    var tthis = this;
    var prepareItemListToSend = function(itemList)
    {
        //kerekiteni kell az arakat 2 tizedesre
        for(var i=0; i<itemList.length; i++)
        {
            for(var prop in itemList[i])
            {
                if(itemList[i][prop]!='' && !isNaN(itemList[i][prop]))
                {
                    try{
                        itemList[i][prop] = tthis._RoundNum(itemList[i][prop]);
                    }catch(ex)
                    {
                        Helpers.Log('_GetItemsDataCallback >> exception2: %o', ex);
                    }
                }
            }
        }
        //json-olja a listat, hogy kompatibilis legyen a szerverrel
        var valStr = JSON.stringify(itemList);
        valStr = valStr.replace(/"/gi, "'"); 
        return valStr;
    }
    
    //--------------tetelek aktualis ertekei
    itemsStr = prepareItemListToSend(Globals.ItemsData);
    Helpers.SetInputValue('itemsdata', this._form, itemsStr);
    
    //--------------tetelek default ertekei
    itemsDefStr = prepareItemListToSend(Globals.ItemsDataDef);
    Helpers.SetInputValue('itemsdefault', this._form, itemsDefStr);
    
    //--------------teljes ar
    Helpers.SetInputValue('fullprice', this._form, this._RoundNum(Globals.FullPrice));
    
}

FormHandler.prototype._DataValidityCheckerCallback = function(e)
{
    var isOK = true;
    if(Helpers.GetInputValue('contactpersonemail', this._form) != Helpers.GetInputValue('contactpersonemailrep', this._form))
    {
        this._dataHandler.SetError('contactpersonemail_row');
        this._dataHandler.SetError('contactpersonemailrep_row');
        isOK = false;
    }
    
    return !isOK; //breaks if retVal == true
}

//megnezi, hogy a juzer altal megadott "Mar kifizetett domain" letezik e
FormHandler.prototype._CheckPayedDomainCallback = function(e)
{
    var reqmode = Helpers.GetInputValue('requestmode', this._form);
    if(reqmode != 3)
        return false;
    
    var sc = new ServerCommunication('checkdomain', false);
    sc.AddParam('clientEncoding', Helpers.GetInputValue('clientEncoding', this._form));
    sc.AddParam('HonlapID', Helpers.GetInputValue('orderSiteID', this._form));
    sc.AddParam('DomainVeg', Helpers.GetInputValue('domaintype', this._form));
    sc.AddParam('DomainNev', Helpers.GetInputValue('domainname', this._form));

    sc.AddParam('SzamlazasNev', Helpers.GetInputValue('billpayername', this._form));
    sc.AddParam('KapcsolatEmail', Helpers.GetInputValue('contactpersonemail', this._form));
    sc.AddParam('SzemelyiSzam', Helpers.GetInputValue('domainownerofficialid', this._form));
    sc.AddParam('AdoSzam', Helpers.GetInputValue('billpayertax', this._form));
    sc.AddParam('BankszamlaSzam', Helpers.GetInputValue('billpayerbankaccount', this._form));
    sc.AddParam('SzamlazasIrsz', Helpers.GetInputValue('billpayerzip', this._form));
    
    var comres = sc.Send(window.location.href);
    if(comres == null)
    {
        this._ShowError(texts['srv_comm_error']);
        return true;
    }
    
    if(comres.isError || comres.result==sc.RESULT_FAILED)
    {
        var message = '';
        switch(comres.message)
        {
            case 'item_not_found': message=texts['domain_item_not_found']; break;
            case 'order_not_found': message=texts['domain_order_not_found']; break;
            case 'sites_not_equals': message=texts['domain_sites_not_equals']; break;
            case 'order_deleted': message=texts['domain_order_deleted']; break;
            case 'client_not_found': message=texts['client_not_found']; break;
            case 'client_not_equals': message=texts['domain_client_not_equals'].replace("$SzamlazasNev", comres.data.oldClientName); break;
            default:
                message= comres.isError ? texts['error_during_process'] : texts['unknown_error'];
                break;
        }
        this._ShowError(message);
        this._dataHandler.SetError('domainname');
        return true;
    }
    ////    Globals.PayedDomainPrice = res.data['payedPrice'];
    var dom = this._GetCurrentDomain();
    var dItem = Helpers.GetItemFromObjectListByProp(Globals.ItemsData, 'name', dom.name);
    dItem.orderedID = comres.data.orderID;
    //dItem.onetimediscount += comres.data['payedPrice'];
    
    
    //this._ShowError('OK');
    return false;   //breaks if retVal == true
}

FormHandler.prototype._ParseDomainName = function(str)
{
    if(str == null)
        return null;
    var parsedDomain = str.match(/\s*(http:\/\/)?(www\.)?([^\.]+)(\.[a-zA-Z.]+)?(.*)/);
    if(!parsedDomain || parsedDomain.length != 6 || parsedDomain[3].length < 2) //|| parsedDomain[4].length < 3
        return null;
    return {
        name: parsedDomain[3],
        ext: parsedDomain[4]
        };
}

//megnezi, hogy a juzer altal megadott es megosztani kivant "Mar kifizetett hosting" letezik e
FormHandler.prototype._CheckPayedHostingCallback = function(e)
{
    var reqmode = Helpers.GetInputValue('domainsetting', this._form);
    if(reqmode != 1)
        return false;
    
    var domainStr = Helpers.GetInputValue('shareddomain', this._form);
    var parsedDomain = this._ParseDomainName(domainStr);
    if(!parsedDomain || !parsedDomain.ext || parsedDomain.ext.length < 3)
    {
        this._ShowError(texts['domain_name_incorrect']); 
        this._dataHandler.SetError('shareddomain');
        return true;
    }
    
    var sc = new ServerCommunication('checkhosting', false);
    sc.AddParam('clientEncoding', Helpers.GetInputValue('clientEncoding', this._form));
    sc.AddParam('HonlapID', Helpers.GetInputValue('orderSiteID', this._form));
    sc.AddParam('DomainVeg', parsedDomain.ext);
    sc.AddParam('DomainNev', parsedDomain.name);
    
    sc.AddParam('SzamlazasNev', Helpers.GetInputValue('billpayername', this._form));
    sc.AddParam('KapcsolatEmail', Helpers.GetInputValue('contactpersonemail', this._form));
    sc.AddParam('SzemelyiSzam', Helpers.GetInputValue('domainownerofficialid', this._form));
    sc.AddParam('AdoSzam', Helpers.GetInputValue('billpayertax', this._form));
    sc.AddParam('BankszamlaSzam', Helpers.GetInputValue('billpayerbankaccount', this._form));
    sc.AddParam('SzamlazasIrsz', Helpers.GetInputValue('billpayerzip', this._form));
    
    var comres = sc.Send(window.location.href);
    if(comres == null)
    {
        this._ShowError(texts['srv_comm_error']);
        this._dataHandler.SetError('shareddomain');
        return true;
    }
    
    if(comres.isError || comres.result==sc.RESULT_FAILED)
    {
        var message = '';
        switch(comres.message)
        {
            case 'item_not_found': message=texts['host_item_not_found']; break;
            case 'order_not_found': message=texts['host_order_not_found']; break;
            case 'sites_not_equals': message=texts['host_sites_not_equals']; break;
            case 'order_deleted': message=texts['host_order_deleted']; break;
            case 'client_not_found': message=texts['client_not_found']; break;
            case 'client_not_equals': message=texts['host_client_not_equals'].replace("$SzamlazasNev", comres.data.oldClientName); break;
            default:
                message= comres.isError ? texts['error_during_process'] : texts['unknown_error'];
                break;
        }
        this._ShowError(message);
        this._dataHandler.SetError('shareddomain');
        return true;
    }
    
    var hosting = Helpers.GetItemFromObjectListByProp(cu.hosts, 'id', 'shared');
    var hostingData = Helpers.CopyObjectData(hosting);
    var isFree = (comres.data.freeshare - comres.data.sharescount) > 0; 
    var d = comres.data;
    //var price = !isFree ? (d.price*(1-d.sharepricepercent/100) + d.shareprice) : 0; //lehet ingyenes is X megosztas
    var price = !isFree ? (d.shareprice!=0 ? d.shareprice : d.price*(d.sharepricepercent/100)) : 0; //lehet ingyenes is X megosztas
    //var pricefollowing = !isFree ? (d.pricefollowing*(1-d.sharepricepercent/100) + d.shareprice) : 0;
    var pricefollowing = !isFree ? (d.shareprice!=0 ? d.shareprice : d.pricefollowing*(d.sharepricepercent/100)) : 0; //lehet ingyenes is X megosztas
    //var domainyearsIndex = Helpers.GetInputValue('domainyears', this._form);
    //var domainyears = this._DomainYearsValueConverter( domainyearsIndex, true);
    
    hostingData.id = d.itemTypeID + '.' + hostingData.id;//d.domext.substr(1);
    hostingData.ordername = Helpers.ReplaceParams(hostingData.ordername, '$orderItem', d.itemTypeDescr, null);
    hostingData.invoicename = Helpers.ReplaceParams(hostingData.invoicename, '$orderItem', d.itemTypeDescr, null);
    hostingData.info += d.domname + d.domext;
    hostingData.price = price;
    hostingData.pricefollowing = pricefollowing;
    hostingData.pricemonth = 12;
    hostingData.monthfollowing = 12;
    hostingData.orderedID = d.orderID;
    var finPrice = this._CalcItemPrice(hostingData);
    hostingData.commissionfirst = Math.max(hostingData.commissionfirst!==null ? hostingData.commissionfirst-hostingData.discountfirst : finPrice.priceNow, 0);
    hostingData.commissionfollowing = Math.max(hostingData.commissionfollowing!==null ? hostingData.commissionfollowing-hostingData.discountfollowing : finPrice.priceFollowing, 0);
    
    //TODO: ide kell default erteket is csinalni!!!
    var hostingDataDef = Helpers.CopyObjectData(hosting);
    hostingDataDef.id = d.itemTypeID + '.' + hostingDataDef.id;//d.domext.substr(1);
    hostingDataDef.ordername = Helpers.ReplaceParams(hostingDataDef.ordername, '$orderItem', d.itemTypeDescr, null);
    hostingDataDef.invoicename = Helpers.ReplaceParams(hostingDataDef.invoicename, '$orderItem', d.itemTypeDescr, null);
    hostingDataDef.price = price;
    hostingDataDef.pricefollowing = pricefollowing;
    hostingDataDef.pricemonth = 12;
    hostingDataDef.monthfollowing = 12;
    var finPriceDef = this._CalcItemPrice(hostingDataDef);
    hostingDataDef.commissionfirst = Math.max(hostingDataDef.commissionfirst!==null ? hostingDataDef.commissionfirst-hostingData.discountfirst : finPriceDef.priceNow, 0);
    hostingDataDef.commissionfollowing = Math.max(hostingDataDef.commissionfollowing!==null ? hostingDataDef.commissionfollowing-hostingData.discountfollowing : finPriceDef.priceFollowing, 0);
    
    Globals.ItemsData.push(hostingData);
    Globals.ItemsDataDef.push(hostingDataDef);
    
    //    this._ShowError('OK');
    return false;  //breaks if retVal == true
}

FormHandler.prototype._UpdateVEStatus = function()
{
    if(!cu.configuration.VEEnabled)//VE modul kikapcsolva
        return null;
		    
    this.AAcurrentBillPayerEmail = Helpers.GetInputValue('contactpersonemail', this._form, true);
    this.AAdomExt = Helpers.GetInputValue('domaintype', this._form);
    var defDprice = this._GetCurrentDPrice(false);
    var reqmode = Helpers.GetInputValue('requestmode', this._form);

    if(!this.AAcurrentBillPayerEmail || (this._veStatus != null && this._veStatus.email == this.AAcurrentBillPayerEmail && this.AAdomExt == this._veStatus.domExt))
        return this._veStatus;
    var sc = new ServerCommunication('vemod', false);
    
    sc.AddParam('Email', this.AAcurrentBillPayerEmail);
    sc.AddParam('DomainVeg', this.AAdomExt);
    sc.AddParam('DpriceID', defDprice.name);
    sc.AddParam('IgenyTipus', reqmode);
    
    var comres = sc.Send(window.location.href, 1, this);
	return true;
}

FormHandler.prototype._UpdateVEStatusAsyncronAnswer = function(comres, sc)
{
    if(!cu.configuration.VEEnabled)//VE modul kikapcsolva
        return null;
        
    if(comres == null)
    {
        this._ShowError(texts['srv_comm_error']);
        return this._veStatus;
    }
    
    if(comres.isError || comres.result==sc.RESULT_FAILED)
    {
        var message = '';
        switch(comres.message)
        {
            case 'item_not_found': message='host_item_not_found'; break;
            default:
                message= comres.isError ? 'error_during_process' : 'unknown_error'; 
                break;
        }
        this._ShowError(texts[message]);
        
        return this._veStatus;
    }
    
    var d = comres.data;
    if(typeof d.emptyStatus != 'undefined' && d.emptyStatus == true)
    {
		if ( cu.configuration.VEdolcsonStatusEnabled ) 
        	this._veStatus = new VEStatus(this.AAcurrentBillPayerEmail, this.AAdomExt, cu.configuration.VEdolcsonStatusEnabled, false,
            	false, false, false, 0, 0, false);
        else this._veStatus = null;
    }
    else
    {
        this._veStatus = new VEStatus(this.AAcurrentBillPayerEmail, this.AAdomExt, cu.configuration.VEdolcsonStatusEnabled, d.dolcson20p,
            d.dviszontelado, d.elorefizetett, d.elorefizetettElhasznalt, d.elorefizetettStatus, d.elorefizetettDnsStatus, d.eloreFizetett10hu);
    }
    Helpers.Log("_UpdateVEStatus >> success", this._veStatus);
	
	this._CalculatePriceSumCallback(0,true);
	
    return this._veStatus;
}

//FormHandler.prototype._CreateVEItems = function(veStatus, domainData, dprice)
//{
//    var it = null;
//    var itDef = null;
//    return {item: it, itemDef: itDef};
//}
    
function VEStatus(email, dext, dolcson, dolcson20p, dviszontelado, elorefizetett, elorefizetettElhasznalt, elorefizetettStatus, elorefizetettDnsStatus, eloreFizetett10hu)
{
    this.email = email;
    this.domExt = dext;
    this.dolcson = dolcson;
    this.dolcson20p = dolcson20p;
    this.dviszontelado = dviszontelado;
    this.elorefizetett = elorefizetett;
    this.elorefizetettElhasznalt = elorefizetettElhasznalt;
    this.elorefizetettStatus = elorefizetettStatus;
    this.elorefizetettDnsStatus = elorefizetettDnsStatus;
    this.elorefizetett10hu = eloreFizetett10hu;
}

function CopyFromBillPayer()
{
    var myform = document.domhostForm;
	
	if ( Helpers.GetInputValue('billpayertype', myform) == 0 && Helpers.GetInputValue('billpayername', myform) != null ) { 
		Helpers.SetInputValue('contactpersonname', myform, Helpers.GetInputValue('billpayername', myform));
		Helpers.SetInputValue('contactpersonnick', myform, Helpers.GetInputValue('billpayername', myform));
	}
    if ( Helpers.GetInputValue('contactpersonshire', myform) != null && Helpers.GetInputValue('billpayershire', myform) != null ) 
		Helpers.SetInputValue('contactpersonshire', myform, Helpers.GetInputValue('billpayershire', myform));
    if ( Helpers.GetInputValue('contactpersonzip', myform) != null && Helpers.GetInputValue('billpayerzip', myform) != null ) 
		Helpers.SetInputValue('contactpersonzip', myform, Helpers.GetInputValue('billpayerzip', myform));
    if ( Helpers.GetInputValue('contactpersoncountry', myform) != null && Helpers.GetInputValue('billpayerstreet', myform) != null ) 
		Helpers.SetInputValue('contactpersoncountry', myform, Helpers.GetInputValue('billpayerstreet', myform));
    if ( Helpers.GetInputValue('contactpersonstreet', myform) != null && Helpers.GetInputValue('billpayeraddr', myform) != null ) 
		Helpers.SetInputValue('contactpersonstreet', myform, Helpers.GetInputValue('billpayeraddr', myform));
    if ( Helpers.GetInputValue('contactpersonemail', myform) != null && Helpers.GetInputValue('billpayeremail', myform) != null ) 
		Helpers.SetInputValue('contactpersonemail', myform, Helpers.GetInputValue('billpayeremail', myform));
    if ( Helpers.GetInputValue('contactpersonemailrep', myform) != null && Helpers.GetInputValue('billpayeremail', myform) != null ) 
		Helpers.SetInputValue('contactpersonemailrep', myform, Helpers.GetInputValue('billpayeremail', myform));
    if ( Helpers.GetInputValue('contactpersonmobil', myform) != null && Helpers.GetInputValue('billpayertel', myform) != null ) { 
		var tel = Helpers.GetInputValue('billpayertel', myform);
		if ( tel.search('20')>=0 || tel.search('30')>=0 || tel.search('70')>=0 )
			Helpers.SetInputValue('contactpersonmobil', myform, tel);
		else if ( Helpers.GetInputValue('contactpersontel', myform) != null ) Helpers.SetInputValue('contactpersontel', myform, tel);
	}
    if ( Helpers.GetInputValue('contactpersonfax', myform) != null && Helpers.GetInputValue('billpayerfax', myform) != null ) 
		Helpers.SetInputValue('contactpersonfax', myform, Helpers.GetInputValue('billpayerfax', myform));
		
	// kapcsolati email cím módosítás miatt újra kell ellenorizni az adatokat
	var element = Helpers.GetElement('contactpersonemail', myform);
	var evt;
	
	if (document.createEventObject){
        // dispatch for IE
        evt = document.createEventObject();
        element.fireEvent('onchange',evt);
    }
    else{
        // dispatch for firefox + others
        evt = document.createEvent("HTMLEvents");
        evt.initEvent('change', true, true ); // event type,bubbling,cancelable
        element.dispatchEvent(evt);
    }
}