var myTWin;
var last_open_div;
last_open_div = null;

function OpenMyWin(link,width,height)
{
  winName = 'certifikat';
  var retValue=true;
  if (myTWin!=null && !myTWin.closed)
  {
  	 myTWin.location.href=link.href;
    myTWin.focus();
  }
  else
  {
    myTWin=window.open(link.href,winName,'width='+width+',height='+height);
    if (myTWin==null || typeof(myTWin)=="undefined")
      retValue=false;
    else
    {
      try {

		myTWin.focus();
		/*if (myTWin != window) */link.target=winName;
		//else retValue=false;
		}
		
		catch ( e ) {
		
			retValue=false;
			
		} 
		
    }
  }
  return retValue;
}

function clanok(id){
var div;
//znicit posledne otvorene
if(last_open_div != null && last_open_div!=id) {
  document.getElementById('reference_div_'+last_open_div).parentNode.removeChild(document.getElementById('reference_div_'+last_open_div));
  last_open_div = null;
}

//znicit sam seba
if((div=document.getElementById('reference_div_'+id))!=null) {  
    document.getElementById('reference_div_'+id).parentNode.removeChild(document.getElementById('reference_div_'+id));
    last_open_div = null;
    return false;       
}
//ziskat zo servera a vytvorit
var odpoved;
var lg, el;
lg = getURLParam('lg');
odpoved=getHttpContent('get_article.php?lg='+lg+'&art='+id);
el = document.getElementsByName(id);
el = el[0];
newdiv=document.createElement('div');
newdiv.setAttribute('id','reference_div_'+id);
newdiv.innerHTML = odpoved;
el.parentNode.parentNode.appendChild(newdiv);
last_open_div = id;
}

function getHTTPObject(){
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
		try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
		}
	@else
	xmlhttp = false;
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
		xmlhttp = new XMLHttpRequest();
		} catch (e) {
		xmlhttp = false;
		}
	}
	return xmlhttp;
}

function getHttpContent(url)
{
	var http=getHTTPObject();
	http.open("GET", url, false);
	http.send(null);
	var results = http.responseText;
	return results;
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}

function insertAfter(parent, node, referenceNode) {
  parent.insertBefore(node, referenceNode.nextSibling);
}

