/******************************************************************************/

function Focus(control) {
  control.focus();
  control.select();
}

function IsEmailCorrect(email) {
  return email.match(/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$/)!=null;
}

/******************************************************************************/

function chcls(sender, className) {
  /*
  if (className=="") {
    if (sender.saveClass) className = sender.saveClass;
  } else {
    sender.saveClass = sender.className;
  }
  */
  sender.className = className;
}

function GetRealLink(link) {
  if (!document._realLink) document._realLink = document.createElement("div");
  document._realLink.innerHTML = '<a href="'+link+'"></a>';
  return document._realLink.firstChild.href;
}

function mover(sender) {
  chcls(sender,'over');
  window.status = GetRealLink( sender.getAttribute("_href") );
}
function mout(sender) {
  chcls(sender,'');
  window.status = "";
}
function moverp(sender) {
  chcls(sender.parentNode,'over');
  window.status = GetRealLink( sender.getAttribute("_href") );
}
function moutp(sender) {
  chcls(sender.parentNode,'');
  window.status = "";
}

/******************************************************************************/

function chloc(sender) {
  var href = sender.getAttribute("_href");
  var target = sender.getAttribute("_target");
  
  if (target) {
    if (target.substring(0,11)=="javascript:") {
      target = eval( target.substring(11) );
      target.location.href = href;
    } else
      alert('"target" not supported');
  } else {
    if (href.substring(0,5)=="http:")
      window.open(href);
    else
      location.href = href;
  }
}

function chlocnc(sender) {
  sender.setAttribute("_target", "javascript:parent.frames[1]");
  chloc(sender);
}

/******************************************************************************/

var popupImageHandle = null;
function popupImage(sender,event,src,title,w,h) {
  //if (event && document.all?event.shiftKey:event.ctrlKey) { sender.target='_blank'; sender.href=src; return }
  if (popupImageHandle && !popupImageHandle.closed) popupImageHandle.close();
  var s = 'toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=no,directories=no,status=no,resizable=no,width='+w+',height='+h;
  var img = '<a href="javascript:window.close()" title="Zamknij"><img src="'+src+'" border=0 width='+w+' height='+h+'></a>';
  popupImageHandle = win=window.open('','null',s);
  win.document.open();
  win.document.write('<html><head><title>'+title+'</title></head><body style="margin:0;overflow:hidden" onkeypress="if (event && event.keyCode==27) self.close()">'+img+'</body></html>');
  win.document.close();
  win.focus();
}

var popupHandle = null;
function popupCenterWindow(src,w,h) {
  if (!w) w=760;
  if (!h) h=440;
  if (document.all) {
    // window no border
    var xOffset = window.screenLeft + (document.body.offsetWidth-w)/2;
    var yOffset = window.screenTop + (document.body.offsetHeight-h-80)/2;
  } else {
    // window border, same as parent
    var xOffset = window.screenX + (window.outerWidth-w)/2;
    var yOffset = window.screenY + (window.outerHeight-h-50)/2;
  }
  if (popupHandle && !popupHandle.closed) popupHandle.close();
  var s = 'toolbar=no,menubar=no,personalbar=no,scrollbars=yes,status=yes,directories=no,resizable=no';
	popupHandle = window.open(src, 'null', s+',height='+h+',width='+w+',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset);
}

/******************************************************************************/

function FindParentByTagName(startNode, tagName) {
  tagName = tagName.toUpperCase();
  node = startNode;
  while (node.tagName != tagName)
    node = node.parentNode;
  return node;
}

function FindChildControlByType(node, type) {
  node = node.firstChild;
  while (node) {
    if (node.type && node.type==type) return node;
    if (node.firstChild) result = FindChildControlByType(node, type);
    if (result) return result;
    node = node.nextSibling;
  }
  return null;
}

function GetChildrenByAttr(node, attrName, attrValue, result) {
  node = node.firstChild;
  while (node) {
    if (node.getAttribute && node.getAttribute(attrName) == attrValue) result.push(node);
    if (node.firstChild) GetChildrenByAttr(node, attrName, attrValue, result);
    node = node.nextSibling;
  }
}

function GetChildrenByType(node, type, result) {
  node = node.firstChild;
  while (node) {
    if (node.type && node.type==type) result.push(node);
    if (node.firstChild) GetChildrenByType(node, type, result);
    node = node.nextSibling;
  }
}
