function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;


//vypise properties objectu pro debug
function  printProps(obj, objName) {
  var output = "" ;
  for (var prop in obj) {
    output += objName + "." + prop + " = " + obj[prop] + "<br />\n" ;
  }
  return output ;
}
function popUpProps(obj)
{
	subwin=window.open("","","height=700,width=550,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no");
    	subwin.document.write('<html><head></head>\n');
    	subwin.document.write('<body>'+printProps(obj, "obj")+'</body>\n');
    	subwin.document.write('</html>\n');
	subwin.focus();
}


function agree( text )
{
	var agree=confirm( text );
	if (agree)
		return true ;
	else
		return false ;
}

function objGetElm(ElmID)
{
	if (typeof ElmID != "string") return ElmID;
	else if (Boolean(document.getElementById)) return document.getElementById(ElmID);
	else if (Boolean(document.all)) return eval("document.all."+ElmID);
	else return null;
}


function objGetElmParent(ElmID)
{
	if (typeof ElmID != "string") return ElmID;
	else if (Boolean(window.opener.document.getElementById)) return window.opener.document.getElementById(ElmID);
	else if (Boolean(window.opener.document.all)) return eval("window.opener.document.all."+ElmID);
	else return null;
}

function setInputValue(obj, val){
	objGetElm(obj).value = val;
}


function inputVisible(elmVisible, elmInvisible)
{
	objGetElm(elmVisible).style.display = "";
	objGetElm(elmInvisible).style.display = "none";
}

function makeVisible(elm){
//	alert(elm);
	objGetElm(elm).style.display = "";
}
function makeInvisible(elm)
{
	objGetElm(elm).style.display = "none";
}

function isVisible(elm){
	if(elm == 'undefined' || objGetElm(elm) == null || objGetElm(elm) == 'undefined'){
		//alert(elm);
		return false;
	}
	return !(objGetElm(elm).style.display == "none" );
}
function changeVisibility(elm)
{
   	if ( isVisible(elm) ) {
		makeInvisible(elm);
	}else{
   		makeVisible(elm);
	}
}


function popUpImageKill()
{
   if (typeof(subwin)=='undefined')
    return;
   if (typeof(subwin.closed)=='undefined')
    return;
   if (subwin.closed==true)
    return;
   subwin.close();
}

function popUpImage(targetUrl, title, width, height)
{
	popUpImageKill();

   	swleft  = Math.round((screen.width - width)/2);
   	swtop   = Math.round((screen.height - height)/3);

	subwin=window.open("","","height="+height+",width="+width+", left = "+swleft+", top = "+swtop+", toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no");
    	subwin.document.write('<html><head><title>'+title+'</title><style>body {margin: 0px; padding: 0px; width:'+width+'; height:'+height+'}</style></head>\n');
    	subwin.document.write('<body><img width="'+width+'" height="'+height+'" src="'+targetUrl+'" onclick="window.close();" /></body>\n');
    	subwin.document.write('</html>\n');

	subwin.focus();
}



function popUpEditor(targetUrl, width, height)
{
   	swleft  = Math.round((screen.width - width)/2);
   	swtop   = Math.round((screen.height - height)/3);
	window.open(targetUrl,'',"height="+height+",width="+width+", left = "+swleft+", top = "+swtop+", toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=yes");
}

function popUpBox(targetUrl, width, height)
{
   	swleft  = Math.round((screen.width - width)/2);
   	swtop   = Math.round((screen.height - height)/3);
	window.open(targetUrl,'',"height="+height+",width="+width+", left = "+swleft+", top = "+swtop+", toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=yes");
//	window.open(targetUrl,title,"height="+height+",width="+width+", toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no");
//alert("height="+height+",width="+width+", left = "+swleft+", top = "+swtop+", toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no");
}

function popBuyBox(targetUrl, width, height){
		var c = 10;
	
		if(width > screen.availWidth - c){
			scrol = 'yes';
			wwidth = screen.availWidth - c;
		}else{
			scrol = 'no';
			wwidth = width;
		}
		wheight = height;
	
		if(wheight > (screen.availHeight - c - 20) )
		{
			//scrol = 'yes';
			wheight = screen.availHeight - c - 20;
		}
		scrol = 'yes';
		wleft = parseInt((screen.availWidth-wwidth)/2,10); wleft -= 5;
		wtop = parseInt((screen.availHeight-wheight)/2,10); wtop -= 20;
	
		features='menu=no,resizable=yes,width='+wwidth+',height='+wheight+',scrollbars='+scrol+',screenX='+wleft+',screenY='+wtop+',left='+wleft+',top='+wtop;//+',dependent=yes';
		window.open(targetUrl, '', features);
		//w.focus();

   	//swleft  = Math.round((screen.width - width)/2);
   	//swtop   = Math.round((screen.height - height)/3);
	//window.open(targetUrl,'',"height="+height+",width="+width+", left = "+swleft+", top = "+swtop+", toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=yes");
}

function phorumAnswer(id){
	textarea = objGetElm('form_add_comment_TEXT_CONTENT');
	if(id != "" && textarea){
		textarea.focus();
		textarea.value= textarea.value + "RE: "+id+"\n\n";
	}
}

