var windowHandle = null;
var windowHandle_closed = false;

function launchwin(winurl,winfeatures) {
    windowHandle = window.open(winurl,'newwindow',winfeatures + ',scrollbars=yes,status=no');
    if (windowHandle_closed) {
        windowHandle_closed = false;
    }
//    return false;
}

function launchwin2(winurl,winfeatures) {
    windowHandle = window.open(winurl,'newwindow',winfeatures + ',scrollbars=yes,status=no');
    if (windowHandle_closed) {
        windowHandle_closed = false;
    }
    return false;
}

function closewin() {
    if (windowHandle != null) {
        if (!windowHandle_closed) {
            windowHandle_closed = true;
            windowHandle.close();
        }
    }
}

function setCab(id,value) {
	document.getElementById(id).href = document.getElementById(id).href.replace(/type\=[0-9]+/,'type=' + value);
}

function setCabSearch(id1,id2,value) {
	document.getElementById(id1).href = document.getElementById(id1).href.replace(/type\=[0-9]+/,'type=' + value);
	document.getElementById(id2).href = document.getElementById(id2).href.replace(/\,[0-9]+$/,',' + value);
}

function setProd(id,value) {
	document.getElementById('l' + id).href = document.getElementById('l'+id).href.replace(/id\=[0-9]+/,'id=' + value);
	var new_art = document.createTextNode(typ[value].art);
	var old_art = document.getElementById('art_' + id);
	old_art.replaceChild(new_art,old_art.firstChild);

	var old_price =  document.getElementById('price_' + id);
	for (var i=0;i<=old_price.childNodes.length;i++) {
		 if (old_price.childNodes[i])
			 old_price.removeChild(old_price.childNodes[i]);
	}	 
	if (old_price.firstChild) old_price.removeChild(old_price.firstChild);
	
	if (parseFloat(typ[value].cena_old) > parseFloat(typ[value].cena)) {
		
		var new_price = document.createElement('span');
		new_price.className = 'strike';
		new_price.setAttribute('className','strike');
		new_price.appendChild(document.createTextNode(typ[value].cena_old));
		old_price.appendChild(new_price);
	}	
	old_price.appendChild(document.createTextNode(' ' + typ[value].cena + ' EUR'));
}

function loadImg(a) {
    
    var link_node = a.parentNode;
    var img = link_node.parentNode;

    var links = link_node.getElementsByTagName('a');
    for (var i=0,l=links.length; i<l; i++) {
        links[i].removeAttribute('id');
    }

    a.setAttribute('id','img_selected');



    var current = img.getElementsByTagName('div')[0]
    current.firstChild.firstChild.src = a.href;
    current.firstChild.href = a.href.replace('l_','xl_').replace('upload/e','upload/xl_e');


    var cl = a.className.split('|');

    current.firstChild.onclick = function() {
        return launchwin2('/pop.php?' + this.href, 'width=' + cl[0] + ',height=' + cl[1]);
    }        

    return false;

}
