function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function popIm(id){
	window.open("Showimage.php?id="+id,"popIm","top=10,left=20,resizable=no,width=200,height=200,status=no,location=no,menubar=no,scrollbars=yes")
}
function popSpecialIm(id,module){
	window.open("Showimage.php?id="+id+"&module="+module,"popIm","top=10,left=20, resizable=no,width=200,height=200,status=no,location=no,menubar=no,scrollbars=yes")
}

function popUserRegForm(addValues){
	window.open("Register.php?"+addValues,"popUp","top=10,left=20,resizable=no,width=700,height=500,status=no,location=no,menubar=no,scrollbars=yes")
}

function checkInt(field, minInt, maxInt){
	var value=parseInt(field.value);
	field.value=value
	if((value<minInt) || (!value))
		field.value=minInt;
	else if(value>maxInt)
		field.value=maxInt;
}

function popCompare(){
	window.open("comparing.php?","popUp","top=10,left=20,resizable=yes,width=800,height=600,status=no,location=no,menubar=no,scrollbars=yes")
}

function popWin(url,he,wi){
	if(he<=0)he = '300';
	if(wi<=0)wi = '300';
	
	var kyssa=window.open(url,'','scrollbars=yes,width='+wi+',height='+he+',resizable=yes,top=10,left=10');	
}

var activeDMenuItem=0;
var activeMode=0;
function initLayers(maxID){
	for(i=1;i<=maxID;i++){
		var el=document.getElementById("pDmenu"+i);
		var el2=document.getElementById("Dbutton"+i);
		var el3=document.getElementById("Dmenu"+i);
		if(el && el2 && el3){
			var top= getTop(el2)+el2.offsetHeight;
			var left= getLeft(el2);
			var height=el3.offsetHeight;
			el.style.top=top;
			el.style.left=left;
			el.style.visibility='visible';
			el.style.height=1;
		}
	}
	refreshDMenu();
}

function showDLayer(id){
	activeMode=1;
	var el=document.getElementById("pDmenu"+id);
	var el2=document.getElementById("Dmenu"+id);
	
	if(activeDMenuItem && activeDMenuItem!=id)
		hideDLayer(activeDMenuItem);

	if(el && el2){
		var height=el2.offsetHeight;

		scroll(el,el.offsetHeight,height);
		activeDMenuItem=id
	}
}

function hideDLayer(id){ 
	if (document.readyState != 'complete') {
		setTimeout(function() { hideDLayer(id) }, 25);
		return;
	}

	var el=document.getElementById("pDmenu"+id);
	var el2=document.getElementById("Dmenu"+id);
	
	if(el && el2){
		var height=el2.offsetHeight;

		unscroll(el, height, 1);
		activeDMenuItem=0
	}
}

function refreshDMenu(lastMode){
	if(activeMode==0 && activeMode==lastMode &&  activeDMenuItem){
		hideDLayer(activeDMenuItem);	
	}	
	setTimeout('refreshDMenu("'+(activeMode?0:1)+'")',400); 	
}

function scroll(el,curHeight,height){
	var newHeight=curHeight+parseInt((height-curHeight)*0.2)+1
	if(newHeight>height)
		newHeight=height;

	el.style.height=newHeight;
	
	if(newHeight<height)
		setTimeout(function() { scroll(el,newHeight,height) }, 30);

	return;	
}

function unscroll(el,curHeight,height){
	if(activeDMenuItem==1)
		return ;
	var newHeight=parseInt((curHeight-height)/1.2)
	if(newHeight<height)
		newHeight=height;

	el.style.height=newHeight;
	
	if(newHeight>height)
		setTimeout(function() { unscroll(el,newHeight,height) }, 30);

	return;	
}

function getTop(item){
	var myTarget = item;  
	var top=0;
	while(myTarget!= document.body) {
		top += myTarget.offsetTop;     
		myTarget = myTarget.offsetParent;   
	} 
	return top;
}

function getLeft(item){
	var myTarget = item;  
	var left=0;
	while(myTarget!= document.body) {
		left += myTarget.offsetLeft;     
		myTarget = myTarget.offsetParent;   
	} 
	return left;
}
