/* Copyright (c) 2006-2008 Nessus Internet Dienstleistungs GmbH
 * All rights reserved.
 *
 * vim: encoding=utf-8:ft=javascript:et:sw=4:ts=8:sts=4:
 */


function show_further_details(productname) {
	new Ajax.Updater('furtherdetails', '/products/details.php?product='+productname, { method: 'get' });
}
/* also needs to work logged out */
function en_fieldattach(id, defaultValue) {
    el = document.getElementById(id);
    el.onfocus = function() { en_fieldclick(id, defaultValue); };
    /*el.onclick = function() { en_fieldclick(id, defaultValue); };*/
    el.onblur = function() { en_fieldblur(id, defaultValue); };
    en_fieldblur(id, defaultValue);
}
function en_fieldclick(id,defaultValue) {
    el = document.getElementById(id);
    if (el.value == defaultValue) {
        el.value = "";
    }
    el.style.color = "#000000";
    return false;
}
function en_fieldblur(id,defaultValue) {
    el = document.getElementById(id);
    if (el.value == "" || el.value == defaultValue) {
        el.style.color = "#666666";
        el.value = defaultValue;
    }
    return true;
}

/* support stuff for /index.php */
var en_focusedelement = null;
function en_idnkbdonfocus(el)
{
    en_focusedelement = el;
    en_fieldclick(el.id,el.defaultValue);
    return true;
}
function en_idnkbdaddchar(char)
{
    var el = en_focusedelement;
    if (el == null) return;
    el.value = el.value + char;
    el.focus();
}
function en_idnkbdshow(elid)
{
    var el = document.getElementById(elid);
    if (el==null) { return; }
    if(el.style.display == 'none')
    {
        el.style.display = '';
        el.style.zIndex = 99;
    }
    else
    {
        el.style.display = 'none';
        el.style.zIndex = -99;
    }
}
function en_idnkbdclose(elid)
{
    var el = document.getElementById(elid);
    if (el==null) { return; }
    el.style.display = 'none';
}


/* IDN Keyboard stuff */
function kbdshow(elemid)
{
    if(document.getElementById(elemid).style.display == 'none')
    {
        document.getElementById(elemid).style.display = '';
    }
    else
    {
        document.getElementById(elemid).style.display = 'none';    
    }
}
function kbdaddchar(xchar)
{
    var el = document.getElementById('domainnamebox');
    el.value = el.value + xchar;
    el.focus();
}


function en_cart_add_renew(elid, domainid, domain) {
    var autorenew = '';
    if ($('autorenew'+domainid)) {
        el = $('autorenew'+domainid);
        if (el.checked) {
            autorenew = '&autorenew='+domainid;
        }
    }
    return en_cart_add('/cart/continuation.php?domain='+domainid+autorenew, elid, cart_str['CART_RENEW']+domain);
}
function en_cart_add_domain(elid, domain) {
    return en_cart_add('/cart/add.php?domain='+escape(domain), elid, domain);
}        

function en_cart_add(url, elid, producttext) {
    var opt = {
        onLoading: function(t) {
            $(elid+'_processing').style.display = '';
            $(elid+'_free').style.display = 'none';
        },
        onSuccess: function(t) {
            $(elid+'_processing').style.display = 'none';
            $(elid+'_free').style.display = '';

            newcount = t.getResponseHeader('x-newproductcount');
            if (newcount != null) {
                el = document.getElementById('cart_link');
                if (newcount == "") {
                    var results = /\((\d+)\)/.exec(el.innerHTML);  // list ["x (1)", "1"]
                    if (results == null) newcount = 1;
                    else newcount = 1 + ((/\((\d+)\)/.exec(el.innerHTML))[1] - 0);
                }
                el.innerHTML = cart_str['CART_NEWCOUNT'] + ' (' + newcount + ')';
            }

            went_ok = t.getResponseHeader('x-cartadd');
            if (went_ok != null) {
                $(elid).innerHTML = cart_str['CART_PUTINTO'];
                //new Effect.Highlight(elid, {endcolor:'#E0F0E0'});
            } else {
                window.location.href = url;
            }
        },
        onFailure: function(t) {
            $(elid+'_processing').style.display = 'none';
            $(elid+'_free').style.display = '';
            window.location.href = url;
        }
    }

    new Ajax.Request(url, opt);
    return false;
}


/* hint ("easyname Info") stuff */
function hintGetPos(src, was)
{
    var val;
    var elem;
    if (was == "Left")
    {
        val = src.offsetWidth;
    }
    if (was == "Top")
    {
        val = src.offsetHeight;
    }
    elem = src; //.offsetParent;
    while (elem != null)
    {
        val += elem["offset"+was];
        elem = elem.offsetParent;
    }
    return val;
}

function hintGetElement() {
    return document.getElementById("hintDiv");
}
function hintShow(show) {
    hintGetElement().style.visibility = show ? "visible" : "hidden";
}

var hintTimeoutId = false;
function hintMe(src, hintId)
{
    var box = hintGetElement();
    var cap = hints_cap[hintId];
    var text = hints_text[hintId];

    if (hintTimeoutId != false) {
        window.clearTimeout(hintTimeoutId);
        hintTimeoutId = false;
    }

    box.innerHTML = "<div class=hintTitle>" + cap + "</div><div class=hintText>" + text + "</div><div class=hintFooter>&nbsp;</div>";
    var v;
    v = hintGetPos(src,"Left") + 2; // 2px space between image and box
		if ((v+300)>window.innerWidth) {
			// 300px fensterbreite
			box.style.left = (v-300) + "px";
		} else {
			box.style.left = v + "px";
		}
    //box.style.left = v + "px";
    v = hintGetPos(src,"Top") - 11;    // img height
    box.style.top = v + "px";
    hintShow(true);
}
function hintZap()
{
    hintTimeoutId = window.setTimeout("hintShow(false)", 300);
}


/* FrontForm support */
function validateInput_RenderResult(id, value, type, required, isError) {
    var fChk = document.getElementById("chk_"+id);
    if (fChk != null) {
        fChk.className = (isError) ? 'errorrow' : '';
    }
    var fRow = document.getElementById("row_"+id);
    if (fRow != null) {
        fRow.className = (isError) ? 'errorrow' : '';
    }
}

function validateInput(field, type, required) {
    var rowid = field.parentNode.parentNode.id;
    rowid = rowid.substring(4,rowid.length);
    var val = field.value.toString();
    validateFieldValue(rowid, val, type, required, validateInput_RenderResult);
    return;
}

function validateFieldValue(fieldname, value, type, required, callback) {

    // need to catch empty fields ASAP
    // IE6 cannot send empty headers and then flashes out js errors :(
    if (!value || value == '') {
        callback(fieldname, value, type, required, required);
        return;
    }

    var xreq = false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
     try {
      xreq = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
      try {
       xreq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
       xreq = false;
      }
     }
    @end @*/
    if (!xreq && typeof XMLHttpRequest!='undefined') {
        try {
            xreq = new XMLHttpRequest();
        } catch (e) {
        }
    }

    if (!xreq) {
        // doesnt make sense to continue from here
        return false;
    }

    // set up our callback
    xreq.onreadystatechange = function () {
        try {
            if (xreq.readyState != 4) {
                // request is not yet complete
                return;
            }

            if (!xreq.responseXML || xreq.responseXML == null) {
                // not really necessary because we are in a try{} block,
                // but makes my life easier when debugging
                return;
            }

            var items = xreq.responseXML.firstChild.childNodes;
            var cfield = "";
            var cstate = "";
            if (items.length == 0) {
                // IE workaround
                items = xreq.responseXML.childNodes.item(1).childNodes;
            }

            for (var i = 0; i < items.length; i++) {
                if (items[i].nodeName == "result") {
                    cstate = items[i].textContent;
                    if (typeof cstate=='undefined') {
                        cstate = items[i].text;    // IE workaround
                    }
                }
                if (items[i].nodeName == "field") {
                    cfield = items[i].textContent;
                    if (typeof cfield=='undefined') {
                        cfield = items[i].text;    // IE workaround
                    }
                }
            }
            callback(fieldname, value, type, required, (cstate == 'ERROR'));

        } catch (e) {
            // silence
//            alert(e);
        }    
    }

    xreq.open("GET", "/util/checkfield.php", true);
    xreq.setRequestHeader("X-EN-CheckField", fieldname);
    xreq.setRequestHeader("X-EN-CheckType", type);
    xreq.setRequestHeader("X-EN-CheckValue", value);
    xreq.send("");
    
    return;
}

/* stuff for contacts/ns edit forms */
function en_contacts_check2(id,field,val)
{
    var v = document.contacts.elements['data['+id+'][' + field + ']'];
    var text = v.options[v.selectedIndex].text;

    if (text == val)
    {
        return true;
    }
    return false;
}

function contact_editSelected(DomainId, dropDownControlId, CookieName) {
    var el = document.getElementById(dropDownControlId);
    Cookie.set(CookieName, el.value, 0.5);
    document.location = '/profiles/handle/edit.php?id=' + el.value + '&flow=' + FlowLink + '&flowdomain=' + DomainId;
    return false;
}
function contact_bindEditLink(DomainId, dropDownControlId, editLinkContainerId) {
    var el = document.getElementById(dropDownControlId);
    var CookieName = 'FormSave' + DomainId + dropDownControlId;
    if (Cookie.get(CookieName) != null) {
        el.value = Cookie.get(CookieName);
    }
    Cookie.erase(CookieName);
    var html_a = '<a href="#" onClick="javascript:contact_editSelected(\'' + DomainId + '\',\'' + dropDownControlId + '\',\'' + CookieName + '\');return false;">';
    var html_a_end = '</a>';
    document.getElementById(editLinkContainerId).innerHTML = html_a + '<img src="/images/iface/edit.png" align=absmiddle">' + html_a_end + ' ' + html_a + cart_str['HANDLE_EDIT'] + html_a_end;
}

// this list is obviously not complete, but should do for now
var phoneCountryPrefixes = new Array();
phoneCountryPrefixes["AT"] = '43';
phoneCountryPrefixes["BE"] = '32';
phoneCountryPrefixes["CA"] = '1';
phoneCountryPrefixes["CH"] = '41';
phoneCountryPrefixes["CY"] = '357';
phoneCountryPrefixes["DE"] = '49';
phoneCountryPrefixes["DK"] = '45';
phoneCountryPrefixes["ES"] = '34';
phoneCountryPrefixes["FI"] = '358';
phoneCountryPrefixes["FR"] = '33';
phoneCountryPrefixes["GR"] = '30';
phoneCountryPrefixes["HU"] = '36';
phoneCountryPrefixes["IT"] = '39';
phoneCountryPrefixes["LI"] = '423';
phoneCountryPrefixes["LU"] = '353';
phoneCountryPrefixes["NL"] = '31';
phoneCountryPrefixes["NO"] = '47';
phoneCountryPrefixes["PL"] = '48';
phoneCountryPrefixes["SE"] = '46';
phoneCountryPrefixes["RU"] = '7';
phoneCountryPrefixes["TR"] = '90';
phoneCountryPrefixes["UK"] = '44';
phoneCountryPrefixes["US"] = '1';

function en_featuredetail(title, url) {
    var opt = {
        onSuccess: function(t) {
            $('featuredetails').innerHTML = t.responseText;
        },
        onFailure: function(t) {
            window.location.href = url;
        }
    }
    new Ajax.Request(url+title, opt);
}

function generate_password(field) {
    var len = 6;
    var pw = '';

    signs = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
    
    for(i = 0; i < len; i++) {
        var sign = Math.ceil(Math.random() * 1000) % 26;
        pw += signs[sign];
    }
    
    document.getElementById(field).value = pw;
}

function tour_forward(langsel, img_index, tour_strings) {
    var field = document.getElementById('tour_img');
    var tour_text = document.getElementById('tour_text');
    
    var new_index = img_index+1;
    if (new_index > 8) {
        new_index = 1;
    }
    
    field.innerHTML = '<img src="/images/tour/tour_' + langsel + '_'+ new_index +'.png" alt="">';
    tour_text.innerHTML = '<div id="tour_left"><img onclick="tour_backward(\'' + langsel + '\', ' + new_index + ', tour_strings)" src="/images/tour_left.png" alt="" style="cursor:pointer"></div><div id="tour_text_value"> ' + tour_strings[new_index] + ' </div><div id="tour_right"><img src="/images/tour_right.png" onclick="tour_forward(\'' + langsel + '\', ' + new_index + ', tour_strings)" alt="" style="vertical-align: middle; cursor:pointer"></div>';
}

function tour_backward(langsel, img_index, tour_strings) {
    var field = document.getElementById('tour_img'); 
    var tour_text = document.getElementById('tour_text');

    var new_index = img_index-1;
    if (new_index < 1) {
        new_index = 8;
    }

    field.innerHTML = '<img src="/images/tour/tour_' + langsel + '_'+ new_index +'.png" alt="">';
    tour_text.innerHTML = '<div id="tour_left"><img onclick="tour_backward(\'' + langsel + '\', ' + new_index + ', tour_strings)" src="/images/tour_left.png" alt="" style="cursor:pointer"></div><div id="tour_text_value"> ' + tour_strings[new_index] + ' </div><div id="tour_right"><img src="/images/tour_right.png" onclick="tour_forward(\'' + langsel + '\', ' + new_index + ', tour_strings)" alt="" style="vertical-align: middle; cursor:pointer"></div>';
}

function showJSConfirmTD(tableid, rowid, delid, text, url, colspan) {
    var table = document.getElementById(tableid);
    var start_row = document.getElementById(rowid);
		document.getElementById(delid).style.display = "none"; 
    
    var new_row = table.insertRow(start_row.rowIndex+1);
    new_row.style.background = "#fffbb6";
		
		var new_cell = new_row.insertCell(0);
		new_cell.colSpan = colspan;
		new_cell.style.verticalAlign = "middle";
		new_cell.style.padding="5px 10px 5px 10px";


		new_cell.innerHTML= '<img src="/images/neweasydesign/warning_16.png" class="inline_image">'+text + '<br><button class="confirm_button" onclick=\'deleteJSRow(this, "'+ tableid+ '", "'+delid+'")\'>nein</button><button class="confirm_button" id="'+rowid+'_yes" onclick="location=\''+url+'\'"\'">ja</button>';
		document.getElementById(rowid+"_yes").focus();

}

function deleteJSRow(rowid, table, delid) {

		var row_to_delete = rowid.parentNode.parentNode.rowIndex;
		document.getElementById(delid).style.display = ""; 
		
		document.getElementById(table).deleteRow(row_to_delete);

}




if (!EASYNAME) var EASYNAME = {};

EASYNAME.Public = function () {
    function auto_resize(obj) {
        obj.rows = obj.value.split('\n').length + 1;
    }
    function auto_resize_eventt(obj, e) {
        if (Event.KEY_RETURN != e.keyCode && Event.KEY_BACKSPACE != e.keyCode) return;
        auto_resize(obj);
    }
    function enable_auto_resize() {
        $A(document.getElementsByClassName('auto-resize')).each(function(obj) {
            obj.setStyle({overflowY: 'hidden'});
            auto_resize(obj);

            Event.observe(obj, 'keyup', function (e) { auto_resize(obj, e); });
        });
    }
    return {
        'window_load': function() {
            enable_auto_resize();
        },
        'set_language': function(lang) {
            new Ajax.Request('/' + lang, {method: 'get', asynchronous: true, onComplete: function() { document.location.href = document.location.href; }})
            return false;
        }
    }
}();

Event.observe(window, 'load', EASYNAME.Public.window_load);




function show (layer){
    if (document.getElementById(layer)) document.getElementById(layer).style.display = "";
}

function hide (layer){
    if (document.getElementById(layer)) document.getElementById(layer).style.display = "none";
}

function show_or_hide(layer) {
		if (document.getElementById(layer)) {
			 if (document.getElementById(layer).style.display == "none") {
			 		show(layer);	
			 } else {
			 		hide(layer);	
			 }
		}
} 

function hide_multiple (id_array){
    for (var i = 0; i < id_array.length; i++) {
        hide(id_array[i]);
    };
}

function show_multiple (id_array){
    for (var i = 0; i < id_array.length; i++) {
        show(id_array[i]);
    };
}

function switch_to(args1, args2) {
    // show
    for (var i = 0; i < args1.length; i++) {
        show(args1[i]);
    };
    // hide
    for (var i = 0; i < args2.length; i++) {
        hide(args2[i]);
    };
}

function switch_around(args1, args2) {
    for (var i = 0; i < args1.length; i++) {
        if (document.getElementById) {
            if (document.getElementById(args1[i]).style.display == "none") {
                show(args1[i]);    
            }
            else if (document.getElementById(args1[i]).style.display == "block" || document.getElementById(args1[i]).style.display == ""){
                hide(args1[i]);
            }
        }
    };
    
    for (var i = 0; i < args2.length; i++) {
        if (document.getElementById) {
            if (document.getElementById(args2[i]).style.display == "none") {
                show(args2[i]);    
            }
            else if (document.getElementById(args2[i]).style.display == "block" || document.getElementById(args2[i]).style.display == ""){
                hide(args2[i]);
            }
        }
    };
}

function switch_around_check(args1, args2, args3) {
    for (var i = 0; i < args1.length; i++) {
        if (document.getElementById) {
            if (document.getElementById(args1[i]).style.display == "none") {
                show(args1[i]);    
            }
            else if (document.getElementById(args1[i]).style.display == "block" || document.getElementById(args1[i]).style.display == ""){
                hide(args1[i]);
            }
        }
    };
    
    for (var i = 0; i < args2.length; i++) {
        if (document.getElementById) {
            if (document.getElementById(args2[i]).style.display == "none") {
                show(args2[i]);    
            }
            else if (document.getElementById(args2[i]).style.display == "block" || document.getElementById(args2[i]).style.display == ""){
                hide(args2[i]);
            }
        }
    };
    
    for (var i = 0; i < args3.length; i++) {
        if (document.getElementById) {
            if (document.getElementById(args3[i]).checked == "true") {
                document.getElementById(args3[i]).checked = "false";
                
                
                
            }
            else if (document.getElementById(args3[i]).checked == "false"){
                document.getElementById(args3[i]).checked = "true";
            }
        }
    };

}
//
function selectAllCheckfields(id_prefix, nr_of_elements, actor) {
	if (document.getElementById(actor).checked == true) {
		var newstatus = true;	
	} else {
		var newstatus = false;	
	}
	
	for (var i = 1; i <= nr_of_elements; i++) {
		document.getElementById(id_prefix + i).checked = newstatus;
	}

}

function pointer_cursor(element) {
	element.style.cursor="pointer";
}

function default_cursor(element) {
	element.style.cursor="default";
}

function highlight_this(element) {
	new Effect.Highlight(element, { startcolor: '#ffffbb', endcolor: '#ffffff', restorecolor: '#ffffff' });
}

function highlight_tld_row(element) {
	pointer_cursor(element);
	new Effect.Highlight(element, { startcolor: '#fbfdfe', endcolor: '#ECF8FE', restorecolor: '#ECF8FE' });
}



/* Author: Lukas Fittl <lf@nessus.at>
 *
 * Released into the public domain.
 *
 * vim: encoding=utf-8:ft=javascript:et:sw=4:ts=8:sts=4:
 *
 * InPlaceEditor hotfix for Bug #10194
 *
 * "InPlaceEditor does not handle escape or enter key"
 * http://dev.rubyonrails.org/ticket/10194
 */

Ajax.InPlaceEditor.prototype.__bug10194_createForm = Ajax.InPlaceEditor.prototype.createForm;
Ajax.InPlaceEditor.prototype.__bug10194_checkForEscapeOrReturn = Ajax.InPlaceEditor.prototype.checkForEscapeOrReturn;

Ajax.InPlaceEditor.prototype = Object.extend(Ajax.InPlaceEditor.prototype, {
    createForm: function() {
        this.__bug10194_createForm();

        listener = this.checkForEscapeOrReturn.bind(this);
        this._controls.editor.observe('keydown', listener);
    },
    checkForEscapeOrReturn: function(e) {
        if (this._controls.editor.rows && Event.KEY_RETURN == e.keyCode) return;

        return this.__bug10194_checkForEscapeOrReturn(e);
    }
});

    
/* SCRIPTACULOUS adds */

/* Author: Lukas Fittl <lf@nessus.at>
 *
 * Released into the public domain.
 *
 * vim: encoding=utf-8:ft=javascript:et:sw=4:ts=8:sts=4:
 *
 * InPlaceEditor extension that auto resizes a textarea when a new line is added.
 *
 * Config Options:
 * - autoResize, Enables the extension and multiline mode, true/false (default false)
 * - autoResizeEmptyRows, Amount of empty rows added after content, integer (default 1)
 */

Ajax.InPlaceEditor.prototype.__autoresize_createEditField = Ajax.InPlaceEditor.prototype.createEditField;

Ajax.InPlaceEditor.prototype = Object.extend(Ajax.InPlaceEditor.prototype, {
    setOptions: function(options){
        this.options = Object.extend(Object.extend(this.options,{
            autoResize: false,
            autoResizeEmptyRows: 1
        }),options||{});
    },
    createEditField: function() {
        if (this.options.autoResize) {
            // Make sure a textarea is created (not an input field)
            this.options.rows = 2;
        }

        this.__autoresize_createEditField();

        if (this.options.autoResize) {
            // We never wanna see a vertical scrollbar
            this._controls.editor.setStyle({overflowY: 'hidden'});

            // Register our event handler
            listener = this['checkForResize'].bind(this);
            this._controls.editor.observe('keyup', listener);

            // Let's resize to the correct number of rows
            this.resize();
        }
    },
    checkForResize: function(e) {
        if (!this.options.autoResize) return;
        if (Event.KEY_RETURN != e.keyCode && Event.KEY_BACKSPACE != e.keyCode) return;

        this.resize();
    },
    resize: function() {
        content = this._controls.editor.value;
        this._controls.editor.rows = content.split('\n').length + this.options.autoResizeEmptyRows;
    }
});


/* Author: Anonymous, Lukas Fittl <lf@nessus.at>
 *
 * Released into the public domain.
 *
 * vim: encoding=utf-8:ft=javascript:et:sw=4:ts=8:sts=4:
 *
 * InPlaceEditor extension that adds a 'click to edit' text when the field is 
 * empty.
 */

Ajax.InPlaceEditor.prototype.__clicktoedit_initialize = Ajax.InPlaceEditor.prototype.initialize;
Ajax.InPlaceEditor.prototype.__clicktoedit_getText = Ajax.InPlaceEditor.prototype.getText;
Ajax.InPlaceEditor.prototype.__clicktoedit_wrapUp = Ajax.InPlaceEditor.prototype.wrapUp;

Ajax.InPlaceEditor.prototype = Object.extend(Ajax.InPlaceEditor.prototype, {
    initialize: function(element, url, options){
        this.__clicktoedit_initialize(element,url,options)
        this.setOptions(options);
        this.checkEmpty();
    },
    setOptions: function(options){
        this.options = Object.extend(Object.extend(this.options,{
            emptyText: '(empty)',
            emptyClassName: 'inplaceeditor-empty'
        }),options||{});
    },
    checkEmpty: function(){
        if (this.element.innerHTML.length != 0) return
        
        node = Builder.node('span', {className:this.options.emptyClassName}, this.options.emptyText);
        this.element.appendChild(node);
    },
    getText: function(){
        $A(this.element.getElementsByClassName(this.options.emptyClassName)).each(function(child){
            this.element.removeChild(child);
        }.bind(this));

        return this.__clicktoedit_getText();
    },
    wrapUp: function(transport){
        this.__clicktoedit_wrapUp(transport);
        this.checkEmpty();
    }
});

/* Author: Lukas Fittl <lf@nessus.at>
 *
 * Released into the public domain.
 *
 * vim: encoding=utf-8:ft=javascript:et:sw=4:ts=8:sts=4:
 *
 * InPlaceEditor extension that converts HTML line breaks to newlines for edit mode.
 */

Ajax.InPlaceEditor.prototype.__newlines_getText = Ajax.InPlaceEditor.prototype.getText;

Ajax.InPlaceEditor.prototype = Object.extend(Ajax.InPlaceEditor.prototype, {
    getText: function() {
        text = this.__newlines_getText();
        text = text.replace(/\n/g, '');
        text = text.replace(/<br\s*\/*>/g, '\n');
        return text;
    }
});

/*
*/

function saveReload(message) {
    var configForm = document.getElementById('configForm');
    var postField = document.getElementById('jscomm');
    postField.value = message;
    configForm.submit();
    return false;
}

function splitDomain(el) {
    return saveReload('action=splitdomain;domain='+el.innerHTML);
}

function addContact(el,tld,contacttype) {
    return saveReload('action=contact_add;tld='+tld+';type='+contacttype);
}

function editSelectedContact(dropDownControlId) {
    var el = document.getElementById(dropDownControlId);
    return saveReload('action=contact_edit;contact='+el.value);
}

function updateStatus(){
    saveReload('action=savestatus');
}


/*
function updateNsSet(id) {
    easydns = false;
    if ($('nseasy_'+id).checked) {
        easydns = true;
    }
    
    document.getElementById('nsBoxes_'+id).style.display = !easydns ? '' : 'none';

    return true;
}

function useNsSet(id,ns1,ns2,ns3,ns4,ns5,ns6) {
    document.contacts.elements['data['+id+'][ns][1]'].value = "" + ns1 +"";
    document.contacts.elements['data['+id+'][ns][2]'].value = "" + ns2 +"";
    document.contacts.elements['data['+id+'][ns][3]'].value = "" + ns3 +"";
    document.contacts.elements['data['+id+'][ns][4]'].value = "" + ns4 +"";
    document.contacts.elements['data['+id+'][ns][5]'].value = "" + ns5 +"";
    document.contacts.elements['data['+id+'][ns][6]'].value = "" + ns6 +"";
}
*/

function updaterow(dropdown,id,tld,contact,type) {
    if(dropdown != "") {
      var contact = dropdown.options[dropdown.selectedIndex].value;
    }
  
    // show loader symbol, when ajax starts
    jQuery(document).ajaxStart(function(){
      jQuery("#load_"+id+"_"+type).show();
    })
    
    // set handle in config
    jQuery.post('/cart/configure.php?action=changedomainconfig&id='+id+'&tld='+tld+'&contact='+contact+'&handle='+type, function() {
       // update handle notes
      jQuery.post('/cart/configure.php?action=updatehandlenotes', function(data) {
        jQuery('#additionaluserinput').html(data);
      }); 
    });
    
    // hide loader symbol, when ajax finished
    jQuery(document).ajaxStop(function(){
      jQuery("#load_"+id+"_"+type).hide();
    })
}

function importHandles(tld,id) {
  var textfield = document.getElementById("autocomplete_" + id);
  var domainname = textfield.value;
  var handle_registrant = document.getElementById("hregistrant"+id);
  var handle_admin = document.getElementById("hadmin"+id);
  var handle_tech = document.getElementById("htech"+id);
  var handle_zone = document.getElementById("hzone"+id);
  
  jQuery.getJSON('/cart/configure.php?action=importhandles&tld='+tld+'&domain='+domainname, function(data) {
    
    if(data.registrant) {  
      for (i=0;i < handle_registrant.length;i++) {
        if(handle_registrant.options[i].value == data.registrant) {
          handle_registrant.options[i].selected = true;
          updaterow("",id,tld,data.registrant,"registrant");
        }
      }
    }
    if(data.admin) {  
      for (i=0;i < handle_admin.length;i++) {
        if(handle_admin.options[i].value == data.admin) {
          handle_admin.options[i].selected = true;
          updaterow("",id,tld,data.admin,"admin");
        }
      }
    }
    if(data.tech) {  
      for (i=0;i < handle_tech.length;i++) {
        if(handle_tech.options[i].value == data.tech) {
          handle_tech.options[i].selected = true;
          updaterow("",id,tld,data.tech,"tech");
        }
      }
    }
    if(data.zone) {  
      for (i=0;i < handle_zone.length;i++) {
        if(handle_zone.options[i].value == data.zone) {
          handle_zone.options[i].selected = true;
          updaterow("",id,tld,data.zone,"zone");
        }
      }
    }
  });
  
}

function setSelectedContactForAllDomains(dropDown) {
  var contact = dropDown.options[dropDown.selectedIndex].value;
  
  if (contact != "") {
    jQuery.post("/cart/configure.php?action=showconfigureform&contactid=" + contact, function(data){
      jQuery('#other_configform').html(data);
    });
  }
}