window.defineWindowMethod = function(name, func) {
    window['__WIN_'+name+'_METHOD'] = func;
}

var DialogWindow = null;

function showDeport(){
    var file_id = document.getElementById('uplPicture').value;
    var DialogFileURL = "/imod/xc_file_deport/?file_id="+file_id;
    var DialogFileWidth = 750;
    var DialogFileHeight = 525;

    if (!DialogWindow || DialogWindow.closed) {
        defineWindowMethod('FileDialog', function() {
            this.onSubmit = function(fileObject){
               var uplPicture = document.getElementById('uplPicture');
               var imgPreview = document.getElementById('imgPreview');
               uplPicture['value'] = fileObject.id;
               imgPreview.innerHTML='';
               var img = document.createElement('img');
               img['src'] = fileObject.href;
               img['id'] = fileObject.id;
               img['alt'] = fileObject.name;
               img['width'] = 100;
               img['height'] = 100;
               imgPreview.appendChild(img);
            }
        });
        DialogWindow = window.open(DialogFileURL, "FileDialog", "width="+DialogFileWidth+",height="+DialogFileHeight+",left="+parseInt((screen.width - DialogFileWidth)/2)+",top="+parseInt((screen.height - DialogFileHeight)/2)+",toolbar=no,location=no,status=yes,menubar=no,resizable=no,scrollbar=no");

    }
}

function clearDeport(){
    var uplPicture = document.getElementById('uplPicture');
    uplPicture.value = 0;
    var imgPreview = document.getElementById('imgPreview');
    imgPreview.innerHTML='';
}

newURL = function(action, ParamNames, ParamValues) {
    var URL = '/' + action;
    var s = '?';
    for (var i = 0; i < ParamNames.length; i++) {
        URL += s + ParamNames[i] + '=' + escape(ParamValues[i]);
        s = '&';
    }
    return URL;
}

function showAnnotation(el){
    var show_element_id = el.getAttribute('id');
    el['title'] = "Спрятать анонс";
    el.onclick = function(){ hideAnnotation(this); return false; };
    document.getElementById('link_'+show_element_id).style.display = "block";
}

function hideAnnotation(el){
    var show_element_id = el.getAttribute('id');
    el['title'] = "Показать анонс";
    el.onclick = function(){ showAnnotation(this); return false; };
    document.getElementById('link_'+show_element_id).style.display = "none";
}

function addWindow(Aelement){
  window.open(Aelement.href,'addwin','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no');
}