var nameservers_dispatch = function(){
    //setup environment for hosting
}

//add a new host entry
function nameservers_ChangeUseDefaults()
{
    $('.fieldblock').each(function (index, domEle) {
         if (domEle.id != "fieldblock_ns_usedefaults") {
            if (Ext.get('ns_usedefaults').getValue() == 0) {
                domEle.style.display = "";
                //remove validation
            } else {
                domEle.style.display = "none";
                //readd validation
            }
         }
    });

}
         
function nameservers_addnameserver()
{
    nth = $('.fieldblock').length - 1;
    if (nth > 1) {
        idarray = $('.fieldblock:nth-child('+nth+')').attr("id").split("_"); 
        controlid = parseInt(idarray[2]) + 1;
    } else {
        controlid = 1;
    }
    var serverName  = 'Name Server '+controlid;
    newdiv = $('<div id="fieldblock_ns_'+controlid+'" class="fieldblock"><dt><label>'+serverName+'</label></dt><dd class="ddelement" style="width:270px;"><div  style="float:left;" id="textfield_'+controlid+'"></div><div style="float:left;padding-left:5px;" id="deleterowbtn_'+controlid+'"></div></dd></div>')
    $('.fieldblock:nth-child('+nth+')').after(newdiv);
    
    //add new record field
    new Ext.form.TextField({
        id:               "ns_"+controlid,
        name:             "ns_"+controlid,
        width:            172,
        disabled:         false,
        border:           false,
        value:            '',
        allowBlank:       false,
        validationEvent: false,
        blankText:        lang("This field is required"),
        renderTo:         'textfield_' + controlid
    });
    
    new Ext.Button({
         id: "CT_"+controlid+"_delete",
         name: "CT_"+controlid+"_delete",
         renderTo : 'deleterowbtn_' + controlid,
         width: 20,
         cls: 'x-box-text-small',
         text: 'X',
         handler: function() {
             nameservers_deleteaddress(this);
         }
     });
    
}

//delete the selected host entry
function nameservers_deleteaddress(row)
{
    id = row.id.split("_");
    $('#fieldblock_ns_'+id[1]).remove();
}