function SubmitFormCheck(formObj,need)
{
  ///Проверка на заполнение обязательных полей
  var idx;
  var selId = 0;
  var tname;
  var tempStr;
  var emailObj = '';
  for (idx = 0; idx < formObj.elements.length; idx++)
  {
    tempObj = formObj.elements.item(idx);
    tname = tempObj.name;

    tempStr = 'need.match(/\\|' + tname + '\\|/)';
    tempStr = eval(tempStr);

    if (tempStr != null) 
    {
      if (tempObj.value == '') selId = selId + 1;
    }

    if ((tname == 'email')&&(tempStr !=null))
    {
      emailObj = tempObj;
    }
  }

  if (selId > 0)
  {
    alert('Пожалуйста, заполните все обязательные поля');
    return false;
  }

  if (emailObj != '')
  {
    selId = 0;
        
    var re = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
    tempStr = emailObj.value.match(re);
    if (tempStr == null)
    {
      selId = selId + 1;
    }
    
    if (selId > 0)
    {
      alert('Пожалуйста, введите корректный E-mail');
      return false;
    }
  }

  return true;
}



function GetPageSize()
{
  var SizeDIV = document.getElementById('MainDiv'); //Вычисление полного размера страницы
  var HWidth = document.body.clientWidth;
  if (HWidth < SizeDIV.offsetWidth) {HWidth = SizeDIV.offsetWidth;};
  var HHeight = document.body.clientHeight;
  if (HHeight < SizeDIV.offsetHeight) {HHeight = SizeDIV.offsetHeight};

  var ar = new Array();
  ar[0] = HHeight;
  ar[1] = HWidth;

  return ar;
}

function GetBodyOffset(obj)
{
  var top = 0;
  var left = 0;
  var theObj=obj
  while (obj && (obj != document.body)) 
  {
    top += obj.offsetTop;
    left += obj.offsetLeft;
    obj = obj.offsetParent;
  }

  obj = theObj
  while (obj && (obj != document.body)) 
  {
    top = top - obj.scrollTop;
    obj = obj.parentNode;
  }

  var values = new Array();
  values[0] = top;
  values[1] = left;
  values[2] = obj;
  return values
}


function IsIE()
{
  var is_opera = /opera/i.test(navigator.userAgent);
  
  var is_ie = ( /msie/i.test(navigator.userAgent) && !is_opera );

  return is_ie;
}


function ShowWCH(w,h,t,l,DivId)
{
  if (!IsIE()) {return};
  if (typeof(DivId)=='object')
  {
    if (DivId.id != '') {DivId = DivId.id + 'WCH';}
    else (DivId = '');
  }
  if (!DivId) {DivId = 'wchDiv';};

  WCH = document.getElementById(DivId);
  if (!WCH) {return};

  WCH.style.width = w;
  WCH.style.height = h;
  WCH.style.top = t;
  WCH.style.left = l;

  WCH.style.display = 'inline';
  WCH.firstChild.style.height = h; //Изменение высоты вложенного IFRAME

}

function HideWCH(id)
{
  if (!IsIE()) {return};
  if (!id) {id = 'wchDiv';};

  WCH = document.getElementById(id);
  if (!WCH) {return};
  WCH.style.display = 'none';
}

function Wndw_GetWCH(id,zIndex) 
{
  if (!id) id = 'wchDiv';
  var div = document.getElementById(id);

  //Нет такого DIV - создание
  if (!div)
  {
    div = document.createElement('DIV');
    document.body.appendChild(div);
    div.className = 'wchDiv';
    div.id = id;
    div.innerHTML = '<IFRAME style="width:100%; height:100%;"></IFRAME>';
  }

  if (zIndex) div.style.zIndex = zIndex;
  return div;
}

function Wndw_GetHideDiv(id,zIndex)
{
  if (!id) id = 'WindowHider';
  var div = document.getElementById(id);

  //Нет такого DIV - создание
  if (!div)
  {
    div = document.createElement('DIV');
    document.body.appendChild(div);
    div.className = 'WindowHider';
    div.id = id;
  }

  if (zIndex) div.style.zIndex = zIndex;
  return div;
}


function ShowHider(DivId)
{
  if (typeof(DivId)=='object') 
  {
    var hDivId = 'WindowHider';
    if (DivId.id != '') hDivId = DivId.id + 'Hider';
    var HDIV = document.getElementById(hDivId);

    if (!HDIV) HDIV = Wndw_GetHideDiv(hDivId);
    HDIV.onclick = function() {CloseWindow(DivId.id);};
  }
  else if (DivId == undefined) 
  {
    var HDIV = document.getElementById('WindowHider');
  }
  else 
  {
    var HDIV = document.getElementById(DivId);
  }
   
  var SizeDIV = document.getElementById('MainDiv'); //Вычисление полного размера страницы
  var ar = GetPageSize();
  HDIV.style.height = ar[0];
  HDIV.style.width = ar[1];
  HDIV.style.display = 'inline';
}

function ShowWindow(DivId, InputId, resize, width, param)
{
  if (resize == '') resize = 0;
  if (resize == undefined) resize = 0;
  if (param == undefined) param = new Array;


  //PARAM: Start
  if (param['copyType']== undefined) 
  {
    var copyType = 0;  
  }
  else
  {
    var copyType = param['copyType'];
  }
  
  if (param['top']== undefined) 
  {
    var topPARAM = undefined;
  }
  else
  {
    var topPARAM = param['top'];
  }

  if (param['right']== undefined) 
  {
    var rightPARAM = undefined;
  }
  else
  {
    var rightPARAM = param['right'];
  }
  //PARAM: End  


  if (!resize) CloseWindow('');
  
  if ((resize > 0)&&(typeof(DivId) == 'object')) 
  {
    var DIV = DivId;
  }
  else
  {
    var DIV=document.getElementById('WindowDiv'); 
    if (!DIV)
    {
      DIV = document.createElement('DIV');
      document.body.appendChild(DIV);
      DIV.style.display = 'none';
      DIV.className = 'WindowDiv';
      DIV.id = 'WindowDiv';
    }
  }

  if (!resize) 
  {
    var CDIV=document.getElementById(DivId); 
    if (!CDIV) {return};
  }

  
  if (!resize) 
  {
    if (copyType == 0)
    {
      DIV.innerHTML = CDIV.innerHTML;
    }
    else if (copyType == 1)
    {
      var fChild = CDIV.firstChild;
      if (fChild.nodeName == '#text') fChild = fChild.nextSibling;
      var newBlock = fChild.cloneNode(true);
      DIV.innerHTML = '';
      DIV.appendChild(newBlock);
      Wndw_CopyInputValues(DIV, CDIV);
    }
    else
    {
      return;
    }
  }

  
  if (width) DIV.style.width = width;
  DIV.style.display = 'inline';
  var CWidth = DIV.offsetWidth;
  var CHeight = DIV.offsetHeight;
  
  if (!resize) DIV.style.display = 'none';


  var WHeight = document.body.clientHeight; 
  var WWidth = document.body.clientWidth; 
  

  if (resize < 2)
  {
    var TopPos = (WHeight - CHeight)/2;
    if (WHeight < CHeight) TopPos = 5;
  }
  else
  {
    TopPos = DIV.style.top;
    TopPos = TopPos.match(/\d*/)[0]; 
  }
  
  var LeftPos = (WWidth - CWidth)/2;
  if (WWidth < CWidth) LeftPos = 5;

  if (resize < 2) TopPos = TopPos + document.body.scrollTop;
  
  
  if (topPARAM !=undefined) TopPos = topPARAM;
  if (rightPARAM !=undefined) LeftPos = WWidth - rightPARAM;

  DIV.style.top = TopPos;
  DIV.style.left = LeftPos;
  DIV.style.display = 'inline';
 
  if (typeof(DivId) == 'object')
  {
    DrawMyShadow(TopPos,LeftPos,DivId);
  }
  else
  {
    DrawMyShadow(TopPos,LeftPos);
  }
  
  if ((resize > 0)&&(typeof(DivId) == 'object'))
  {
    ShowHider(DivId);
    ShowWCH(CWidth, CHeight-10, TopPos+5, LeftPos, DivId);
  }
  else
  {
    ShowHider();
    ShowWCH(CWidth, CHeight-10, TopPos+5, LeftPos );
  }

}

function DrawMyShadow( topPos, leftPos, mainId)
{
  var shDivId = 'WindowDivShadow';
  if (typeof(mainId) == 'object') 
  {
    var mainDIV = mainId;
    
    var docObj = mainDIV.ownerDocument;
    
    
    if (mainDIV.id != '') shDivId = mainDIV.id + 'Shadow';
    var DIV=docObj.getElementById(shDivId);
  }
  else if (mainId == undefined)
  {
    var mainDIV=document.getElementById('WindowDiv');
    var DIV=document.getElementById('WindowDivShadow');
  }
  else //mainId= <ид.окна>
  {
    var mainDIV=document.getElementById(mainId);
    var shDivId = mainId + 'SHADOW';
    var DIV=document.getElementById(shDivId);
  }

  if (!DIV)
  {
    DIV = document.createElement('DIV');
    document.body.appendChild(DIV);
    DIV.style.display = 'none';
    DIV.className = 'WindowDivShadow';
    DIV.id = shDivId;
  }

  topPos = +topPos; 
  DIV.style.top = topPos + 5;
  DIV.style.left = leftPos + 5;
  DIV.style.width = mainDIV.offsetWidth;
  DIV.style.height = mainDIV.offsetHeight;
  DIV.style.display = 'inline';
}

function CloseWindow(winId)
{
  if (!winId) 
  {
    winId = 'WindowDiv';
    shId = 'WindowDivShadow';
    hId = 'WindowHider';
  }
  else
  {
    shId = winId + 'Shadow';
    hId = winId + 'Hider';
  }

  
  var DIVL1 = document.getElementById(winId);
  
  if (!DIVL1) return;

  var DIVL1S = document.getElementById(shId);
  
  if (!DIVL1S) return;

  var HDIV = document.getElementById(hId);
  
  if (!HDIV) return;

  DIVL1.style.display = 'none';
  DIVL1.style.width = '';
  DIVL1S.style.display = 'none';
  HDIV.style.display = 'none';
  HideWCH();
}
