function sales_show_more()
{
    $('sales_show1').hide();
    $('sales_show2').show();
}

function changeLanguage(language)
{
	location.href="/language/changeLanguage/" + language + "/";
}

function direct_contact_edit(id)
{
	new Ajax.Updater('dcEditBox','/admin_ajax/dc_edit/' + id + '/',{method: 'get',evalScripts:true});
}

function change_country(id)
{
	new Ajax.Updater('sdh_dcontact_location','/directcontact/change_country/' + id + '/',{method: 'get',evalScripts:true});
	new Ajax.Updater('sdh_contact_number','/directcontact/change_number_by_country/' + id + '/',{method: 'get',evalScripts:true});
}

function change_location(id)
{
    location22 = document.getElementById("sdh_country_location").value;
	new Ajax.Updater('sdh_contact_number','/directcontact/change_number_by_location/' + id + '/' + location22 + '/',{method: 'get',evalScripts:true});
}

function change_locations()
{
	new Ajax.Updater('sdh_change_maps','/admin_ajax/change_locations/',{method: 'get',evalScripts:true});
}

function change_poly()
{
    document.getElementById('tab_locations').className = "";
    document.getElementById('tab_polys').className = "selected";

    new Ajax.Updater('sdh_change_maps','/admin_ajax/change_polys/',{method: 'get',evalScripts:true});
}

function showResponse()
{
    WYSIWYG.attach('textarea', full);
	WYSIWYG._generate('textarea', full);
}

function change_page_language(country,id)
{
    document.getElementById('tab_english').className = "";
    document.getElementById('tab_dutch').className = "";
    document.getElementById('tab_german').className = "";
    document.getElementById('tab_french').className = "";

    document.getElementById('tab_'+ country + '').className = "selected";

    //tinyMCE.execCommand('mceRemoveControler',false,'elm1');
    new Ajax.Updater('areaText','/admin_ajax/edit_page_change_country/' + id + '/' + country + '/',{method: 'get',evalScripts:true, onComplete: showResponse});
}

function select_page_language(country)
{
	new Ajax.Updater('areaText','/admin_ajax/new_page_select_country/' + country + '/',{method: 'get',evalScripts:true, onComplete: showResponse});
}

function direct_contact_new()
{
	new Ajax.Updater('dcEditBox','/admin_ajax/dc_new/',{method: 'get',evalScripts:true});
}

function select_page_by_category(category)
{
	new Ajax.Updater('areaText','/admin_ajax/select_page/' + category + '/',{method: 'get',evalScripts:true});
}

function create_sub_page(pageid)
{
	new Ajax.Updater('pageUpdate','/admin_ajax/make_subpage/' + pageid + '/',{method: 'get',evalScripts:true});
}

function change_general(id)
{
	new Ajax.Updater('areaText','/admin_ajax/change_general/' + id + '/',{method: 'get',evalScripts:true});
}

function change_page_category(pageid)
{
	new Ajax.Updater('pageUpdate','/admin_ajax/change_category/' + pageid + '/',{method: 'get',evalScripts:true});
}

function edit_picture(pageid,name)
{
	new Ajax.Updater('sdh_photo_edit','/admin_ajax/edit_picture/' + pageid + '/' + name + '/',{method: 'get',evalScripts:true});
}

function changeSalesLocation(id)
{
	new Ajax.Updater('sdh_sales_com','/admin_ajax/change_sales_location/' + id + '/',{method: 'get',evalScripts:true});
}

function load_sales()
{
	new Ajax.Updater('flashcontent','/extra/sales/',{method: 'get',evalScripts:true});
}

function sdh_sales_location(id)
{
	new Ajax.Updater('sdh_sales_products','/extra/sales_products/' + id + '/',{method: 'get',evalScripts:true});
}

function sdh_remove_location(id)
{
    if(confirm('Weet u zeker dat u deze locatie wilt verwijderen?'))
    {
        location.href = "/admin/remove_sales_location/" + id + "/";
    }
}

function sdh_remove_photo(name, id)
{
    if(confirm('Weet u zeker dat u deze foto wilt verwijderen?'))
    {
        location.href = "/admin/photo_remove/" + name + "/" + id + "/";
    }
}

function sdh_remove_user(name)
{
    if(confirm('Weet u zeker dat u deze gebruiker wilt verwijderen?'))
    {
        location.href = "/admin/remove_user/" + name + "/";
    }
}

function sdh_make_subpage(pageid, catid)
{
    new Ajax.Updater('sdh_make_subpage', '/admin_ajax/show_subpage/'+ pageid +'/' + catid + '/', {method: 'get',evalScripts:true});
}

function add_photo(pageid)
{
    new Ajax.Updater('sdh_photo_edit', '/admin_ajax/show_add_photo/'+ pageid +'/', {method: 'get',evalScripts:true});
}

function sdh_remove_product(id)
{
    if(confirm('Weet u zeker dat u dit product wilt verwijderen?'))
    {
        location.href = "/admin/remove_sales_product/" + id + "/";
    }
}

function sdh_sales_connect()
{
    document.getElementById('tab_connect').className = "";
    document.getElementById('tab_control').className = "selected";

    new Ajax.Updater('sdh_sales_control', '/admin_ajax/sales_connect/', {method: 'get',evalScripts:true});
}

function sdh_remove_connect(locid, proid)
{
    new Ajax.Request('/admin_ajax/sales_remove_connect/' + locid + '/' + proid + '/', {onComplete: show_sales});
}

function show_sales()
{
    location.href = '/admin/sales/';
}

function sdh_remove_page(id)
{
     if(confirm('Weet u zeker dat u deze pagina wilt verwijderen? \n Alle mogelijk onderliggende subpaginas worden dan ook verwijderd.'))
     {
        new Ajax.Request('/admin_ajax/remove_page/' + id + '/',{
  onSuccess: function(transport, json) {
    alert('De pagina is verwijderd.');
  }
});

parent.parent.GB_hide();
     }
}

function delete_poly(id)
{
    if(confirm('Weet u zeker dat u dit gebied wilt verwijderen?'))
    {
        location.href= '/admin/polygon_delete/' + id + '/';
    }
}

loadAdmin = function(caption, url, /* optional */ height, width, callback_fn) {

    var options = {

        caption: "",

        height: height || 600,

        width: width || 800,

        overlay_click_close: true,

        fullscreen: false,

        show_loading: false,

		center_win: true,

        callback_fn: callback_fn

    }

    var win = new GB_Window(options);

    return win.show(url);

}



loadLogin = function(caption, url, /* optional */ height, width, callback_fn) {

    var options = {

        caption: "Login - SDH",

        height: height || 190,

        width: width || 350,

        overlay_click_close: true,

        fullscreen: false,

        show_loading: false,

		center_win: true,

        callback_fn: callback_fn

    }

    var win = new GB_Window(options);

    return win.show(url);

}

    function selectReplacement(obj) {

      obj.className += ' replaced';

      var ul = document.createElement('ul');

      ul.className = 'selectReplacement';

      var opts = obj.options;

      var selectedOpt = (!obj.selectedIndex) ? 0 : obj.selectedIndex;

      for (var i=0; i<opts.length; i++) {

        var li = document.createElement('li');

        var txt = document.createTextNode(opts[i].text);

        li.appendChild(txt);

        li.selIndex = i;

        li.selectID = obj.id;

        li.onclick = function() {

          selectMe(this);

        };

        if (i == selectedOpt) {

          li.className = 'selected';

          li.onclick = function() {

            this.parentNode.className += ' selectOpen';

            this.onclick = function() {

              selectMe(this);

            };

          };

        }

        if (window.attachEvent) {

          li.onmouseover = function() {

            this.className += ' hover';

          };

          li.onmouseout = function() {

            this.className =

              this.className.replace(new RegExp(" hover\\b"), '');

          };

        }

        ul.appendChild(li);

      }

      obj.onfocus = function() {

        ul.className += ' selectFocused';

      };

      obj.onblur = function() {

        ul.className = 'selectReplacement';

      };

      obj.onchange = function() {

        var idx = this.selectedIndex;

        selectMe(ul.childNodes[idx]);

      };

      obj.onkeypress = obj.onchange;

      obj.parentNode.insertBefore(ul,obj);

    }

    function selectMe(obj) {

      var lis = obj.parentNode.getElementsByTagName('li');

      for (var i=0; i<lis.length; i++) {

        if (lis[i] != obj) {

          lis[i].className='';

          lis[i].onclick = function() {

            selectMe(this);

          };

       } else {

          setVal(obj.selectID, obj.selIndex);

          obj.className='selected';

          obj.parentNode.className =

            obj.parentNode.className.replace(new RegExp(" selectOpen\\b"), '');

          obj.onclick = function() {

            obj.parentNode.className += ' selectOpen';

            this.onclick = function() {

              selectMe(this);

            };

          };

        }

      }

    }

    function setVal(objID,val) {

      var obj = document.getElementById(objID);

      obj.selectedIndex = val;

    }

    function setForm() {

      var s = document.getElementsByTagName('select');

     // for (var i=0; i<s.length; i++) {

     //   selectReplacement(s[i]);

     // }

    }

    window.onload = function() {

      (document.all && !window.print) ? null : setForm();

    };

function PopUp(URL) {
window.open(URL, 'popupvenster', 'width=800, height=600, resizable=no, menubar=no, scrollbars=yes, status=no, toolbar=no');
}