﻿down_wind = null;
down_id = null;
addbut_name = 'ctl00$ContentPlaceHolder1$addbut';
infobut_name = 'ctl00$ContentPlaceHolder1$infobut';
langCode = 'ctl00_hf_Language';
renewFormMessage = '';

function TestWindowClosed ()
{
  if (!down_wind.closed) return;
  clearTimeout(down_id);
  //var but = document.getElementById(but_name);
  //if (but) but.disabled = false;
  var form = document.forms['aspnetForm'];
  form.submit();
}

function TestRenewFormWindowClosed() {
    if (!down_wind.closed) return;
    clearTimeout(down_id);
//    alert(down_wind.returnValue);
    //var but = document.getElementById(but_name);
    //if (but) but.disabled = false;
    var form = document.forms['aspnetForm'];
    form.submit();
}

function SetLanguage(languageCode) 
{
    var hiddenField = document.getElementById(langCode);
    hiddenField.value = languageCode;
}

function DisableButton(but_name)
{
  var but = document.getElementById(but_name);
  if (but) but.disabled = true;
}

function ShowDownloadForm (url)
{
  DisableButton(addbut_name);
  DisableButton(infobut_name);
  down_wind = window.open(url, '_blank', 
    'height=300, width=545, status=yes, location=no, menubar=no, resizable=no, scrollbars=no');
  down_id = setInterval('TestWindowClosed()', 1000);
  return true;
}

function ShowRenewForm(url) {
    down_wind = window.open(url, '_blank', 'status=yes, location=no, menubar=no, resizable=yes, scrollbars=yes');
    down_id = setInterval('TestRenewFormWindowClosed()', 1000);
//    alert(renewFormMessage);
    //var but = document.getElementById(but_name);
    //if (but) but.disabled = false;
//    var form = document.forms['aspnetForm'];
//    form.submit();
}

function HideDownloadForm ()
{
window.close();
}

function ConfirmDelete (confirmDeleteMessage)
{
  return window.confirm(confirmDeleteMessage);
}

function DisableUpload (createUploadMessage)
{
  var res = document.getElementById('result');
  if (!res) return;

  var typeList = document.getElementById('AvalElemTypeList');
  if (typeList && typeList.selectedIndex == -1) return;

  var title = document.getElementById('AvalElemTitle');
  if (title && title.value == '') return;

  var upload = document.getElementById('AvalElemUpload');
  if (upload && upload.value == '') return;

  /*if (upload.value.lastIndexOf(".jpg") == -1 && upload.value.lastIndexOf(".JPG") == -1 && upload.value.lastIndexOf(".pdf") == -1 && upload.value.lastIndexOf(".PDF") == -1)
  return;*/
  
  var but = document.getElementById('uploadbutton');
  if (but) but.disabled = true;
  if (res) res.value = createUploadMessage;

  var but2 = document.getElementById('uploadbutton2');
  but2.click();
}

function DisableRequestInfo (createRequestMessage)
{
  var res = document.getElementById('result');
  if (!res) return;

  var title = document.getElementById('AvalElemTitle');
  if (title && title.value == '') return;

  var notes = document.getElementById('AvalElemNotes');
  if (notes && notes.value == '') return;

  var upload = document.getElementById('AvalElemUpload');
  
  /*if (upload.appendChild != '' && upload.value.lastIndexOf(".jpg") == -1 && upload.value.lastIndexOf(".JPG") == -1 && upload.value.lastIndexOf(".pdf") == -1 && upload.value.lastIndexOf(".PDF") == -1)
      return;*/

  var but = document.getElementById('uploadbutton');
  if (but) but.disabled = true;
  if (res) res.value = createRequestMessage;
}

