function InsertImage(img,w,h) {

	if (document.body.filters) {
		document.write('<span style="width:'+w+'px; height:'+h+'px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+img+', sizingMethod=scale);"></span>');
	} else {
		document.write('<img src="'+img+'" style="width:'+w+'px; height:'+h+'px;">');
	}

}
function InsertImageAsLink(img,w,h) {

	if (document.body.filters) {
		document.write('<span style="border:0px; width:'+w+'px; height:'+h+'px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+img+', sizingMethod=scale);" class="hand"></span>');
	} else {
		document.write('<img src="'+img+'" style="border:0px; width:'+w+'px; height:'+h+'px;">');
	}

}

function searchMenu(id,val) 
{
    switch(id)
    {
    	case 1:
    		if(val.value>0) {
    			document.getElementById('sel2').disabled=true;
    			document.getElementById('sel3').disabled=true;
    		} else {
    			document.getElementById('sel2').disabled=false;
    			document.getElementById('sel3').disabled=false;
    		}
    		break;
    	case 2:
    		if(val.value>0) {
    			document.getElementById('sel1').disabled=true;
    			document.getElementById('sel3').disabled=true;
    		} else {
    			document.getElementById('sel1').disabled=false;
    			document.getElementById('sel3').disabled=false;
    		}
    		break;
    	case 3:
    		if(val.value>0) {
    			document.getElementById('sel1').disabled=true;
    			document.getElementById('sel2').disabled=true;
    		} else {
    			document.getElementById('sel1').disabled=false;
    			document.getElementById('sel2').disabled=false;
    		}
    		break;
    }
}

function showHint(id) {

	obj=document.getElementById('Hint_'+id);
	if(obj.style.visibility=='hidden')
		obj.style.visibility='visible';
	else
		obj.style.visibility='hidden';		
}

function showHint2(id) {
	obj=document.getElementById('Hint_'+id);
	if(obj.style.display=='none')
		obj.style.display='block';
	else
		obj.style.display='none';		
}
function showHint3(id,pos) {

	obj=document.getElementById('Hint_'+id);
	if(obj.style.visibility=='hidden')
		obj.style.visibility='visible';
	else
		obj.style.visibility='hidden';
}

function showDiv3(id) {

	obj=document.getElementById(id);
	if(obj.style.display=='none')
		obj.style.display='';
	else
		obj.style.display='none';		
}

function showDiv(id) {
	document.getElementById(id+'3').style.display='';
	document.getElementById(id+'2').style.display='';
	document.getElementById(id+'1').style.display='none';
	
	document.getElementById(currentDocSlot+'3').style.display='none';
	document.getElementById(currentDocSlot+'2').style.display='none';
	document.getElementById(currentDocSlot+'1').style.display='';
	
	currentDocSlot=id;		
}

function hideDiv(id) {
	obj=document.getElementById(id);
	obj.style.display='none';
}
function showDiv2(id) {
	obj=document.getElementById(id);
	obj.style.display='';
}

function showDialogHint(id) {

	obj=document.getElementById('Hint_'+id);
	if(obj.style.visibility=='hidden')
		obj.style.visibility='visible';
	else
		obj.style.visibility='hidden';		
	
	for(var idx=1;idx<=9;idx++) {
		if('o'+idx!=id) {
			obj=document.getElementById('Hint_o'+idx);
			obj.style.visibility='hidden';
		}
	}	
}

function submitForm(page) {
	document.getElementById('searchPage').value=page;
	document.getElementById('searchForm').submit();
}

function click(id)
{
	var item = document.getElementById(id);
	if(item.checked == true) {
		 item.checked = false;
	} else {
		item.checked = true;	
	}
}

var cX = 0; var cY = 0;
function UpdateCursorPosition(e){ 
	 e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
	cX = cursor.x;
	cY = cursor.y;
}

document.onmousemove = UpdateCursorPosition; 

function AssignPosition(d) {
d.style.left = (cX+10) + "px";
d.style.top = (cY+10) + "px";
}
function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
dd.style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
if(dd.style.display == "none") { dd.style.display = "block"; }
else { dd.style.display = "none"; }
}

function PopupPic(id) { 
    window.open("img,"+id+".html","","width=750,height=400,resizable,scrollbars=no,status=0");
}
function PopupPic2(id) { 
    window.open("imgn,"+id+".html","","width=750,height=400,resizable,scrollbars=no,status=0");
}
function PopupPic3(id) { 
    window.open("imgp,"+id+".html","","width=750,height=400,resizable,scrollbars=no,status=0");
}
function PopupPic4(name) { 
    window.open("imgo,"+name+".html","","width=750,height=400,resizable,scrollbars=no,status=0");
}
function PopupPic5(name,com) { 
   if(com == 1) {
	   window.open("imgi,"+name+".html?no_comm","","width=750,height=400,resizable,scrollbars=no,status=0");
   } else if(com == 2) {
	   window.open("imgi,"+name+".html?no_comm","","width=750,height=400,resizable,scrollbars=yes,status=0");	   
   } else {
	   window.open("imgi,"+name+".html","","width=750,height=400,resizable,scrollbars=no,status=0");
   }
}
function PopupPic6(name) { 
    window.open("imgu,"+name+".html","","width=750,height=400,resizable,scrollbars=no,status=0");
}

function fitPic(no_add, no_com) {
        if (window.innerWidth){
            iWidth = window.innerWidth;
            iHeight = window.innerHeight;
        }else{
            iWidth = document.body.clientWidth;
            iHeight =document.body.clientHeight;
        }
        iWidth = document.images[0].width - iWidth;
        
        if (no_com != 1) {
	        if(no_add==0)
	        	iHeight = (document.images[0].height - iHeight)+120
	        else	
	       	 	iHeight = (document.images[0].height - iHeight)+170;
        } else {
        	iHeight = (document.images[0].height - iHeight);
        }
        window.resizeBy(iWidth, iHeight);
    };
    
number_sel = 0;   
var selPic = Array(10);
function selectPicture(part,img,id)
{
	am = number_sel;
	am_n = am+1;
	foto = '<a href="imgp,'+id+'.html" target="_blank"><img src="img/dg/sm/'+part+'/'+img+'" style="width: 100px;" class="img3"></a>';
	div = document.getElementById('insertFoto'+am);
	
	content = '<input name="selected_picture['+am+']" id="sel_pic'+am+'" type="hidden" value="'+id+'">';
	content = content+'<table border="0" cellspacing="2" cellpadding="2"><tr><td>';
	content = content+foto+'</td><td valign="top"><textarea name="content['+am+']" class="textarea" style="width:400px; height: 79px;" id="cont'+am+'">'+insertContent('cont'+am)+'</textarea></td></tr>';
	
	if (am_n <= 10) {
		content = content+'<tr><td colspan="2"><p class="line"><img src="img/x.gif" width="1" height="1"></p></td></tr><tr><td colspan="2" align="left"><img src="img/kropka.gif"> <span onClick="showDiv4(\'fotos\','+am_n+');" id="show_'+am_n+'" class="hand" style="color: #169CDF;">wybierz/zmień zdjęcie z listy</span></td></tr></table>';
	} else {
		content = content+'</table>';
	}
	div.style.display = '';
	div.innerHTML = content;
	
	document.getElementById('pph_'+id).style.border="2px red solid";	
	document.getElementById('span_'+id).innerHTML=" ";	
	
	if (selPic[am] != undefined) {
		document.getElementById('pph_'+selPic[am]).style.border="1px #DDC034 solid";
		document.getElementById('span_'+selPic[am]).innerHTML="wybierz";
	}
	
	selPic[am] = id;
	
	document.getElementById('save').style.display ='';
}    

function addPictureBorder(id)
{
	document.getElementById('pph_'+id).style.border="2px red solid";	
	document.getElementById('span_'+id).innerHTML=" ";
}

function showDiv4(id,nb) {

	obj=document.getElementById(id);
	if(obj.style.display=='none')
		obj.style.display='';
	else
		obj.style.display='none';	

	
	obj.style.top = (cY+15) + "px";
	number_sel = nb;
}


function insertContent(id)
{
	r = document.getElementById(id);
	if (r != null){	
		return r.value;
	} else {
		return '';
	}
}

