/* JavaScript Utils */

// onMouseOver Window Status 
function ks(t) {
	window.status=t;
	return true;
}

// open new win func
function openWin( path, width, height ) {
		korawin=window.open(path,'_kor','scrollbars=no,resizable=no,resize=no,width='+width+',height='+height+',screenX=20,screenY=50');
		korawin.focus();
}
function openWinSc( path, width, height ) {
		korawins=window.open(path,'_kors','scrollbars=yes,resizable=no,resize=no,width='+width+',height='+height+',screenX=20,screenY=50');
		korawins.focus();
}

function openWinDef( path, name, width, height,scroll ) {
		var scrollBar = "scrollbars=no";
		if (scroll == 1) {
			scrollBar = "scrollbars";
		}
		eval(name +"=window.open(path,'"+name+"','"+scrollBar+",resizable=no,resize=no,width='+width+',height='+height+',screenX='+getCenterW(width)+',screenY='+getCenterH(height)+',top='+getCenterH(height)+',left='+getCenterW(width))");
		eval(name+".focus()");
}

function getCenterW(width) {
	return parseInt( eval( (screen.width-parseInt(width))/2 ) );
}
function getCenterH(height) {
	return parseInt( eval( (screen.height-parseInt(height))/2 ) );
}

// javasript dynamic menus control
function setMenu ( menuid )	{
	//alert(parent.frames[0].name + ", " + parent.frames[2].name );
	if ( parent.navigation.menuItem != menuid )	{
		//alert(parent.frames[2].menuStatus );
		intid = setInterval( "checkMenu(" + menuid + ");", 500 );
	}
}
function checkMenu ( menuid ) {
	if ( parent.navigation.menuStatus )	{
		parent.navigation.buildMenu( menuid );
		clearInterval(intid);
	}
}

// onMouseOver image swap funtions
function preload(imgSrc) {
	if (document.images) {
		eval(imgSrc+' = new Image()');
		var imsrc = imdir+"/"+imgSrc+"."+imtype;
		eval(imgSrc+'.src = "'+imsrc+'"');
	}
} 
  
function rollIt(imgName,imgObj,imiObj) {
	if (document.images) {
		if (imgObj == "over") {
			imgObj=imname+imgName+"_over";
			if ( imiObj == "im" ) { 
				imiObj=imname+imgName+"_im"; 
			} 
		} else {
			if ( imgName != ses_id ) { 
				imiObj="spm";
			}
			else { imiObj=imname+imgName+"_im"; }
			imgObj=imname+imgName;
		}	
		cislo=imgName;
		imgName="im"+cislo;
		document.images[imgName].src = eval(imgObj+".src");
		imiName="imi"+cislo;
		if ( document.images[imiName] ) {
			document.images[imiName].src = eval(imiObj+".src");
		}
	}
}
   

function doPreload(imfr,imto) {
	preload ("spm");
	for (i=imfr; i<=imto; i++) {
		if (i < 10) {
	  		i="0"+i;
	  	}
	preload(imname+i); preload(imname+i+"_over"); preload(imname+i+"_im"); 
   	}
}

function section(id) {
	if (document.images) {
		eval(imname+id+' = new Image()');
		var imsrc = imdir+"/"+imname+id+"_over."+imtype;
		eval(imname+id+'.src = "'+imsrc+'"');
  		  { document.images['im'+id].src = eval(imname+id+".src");}
		ses_id = id;
	}
	rollIt(id);
} 

/**
	BackButton Code
*/
		// Sets cookie values. Expiration date is optional
		//
		function setCookie(name, value, expire) {
		   document.cookie = name + "=" + escape(value)  + "; path=/vyrobky" + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
		}
		
		// Reads cookie values. 
		//
		function getCookie(Name) {
			   var search = Name + "="
			   if (document.cookie.length > 0) { // if there are any cookies
			      offset = document.cookie.indexOf(search) 
			      if (offset != -1) { // if cookie exists 
			         offset += search.length 
			         // set index of beginning of value
			         end = document.cookie.indexOf(";", offset) 
			         // set index of end of cookie value
			         if (end == -1) 
					 end = document.cookie.length
			         return unescape(document.cookie.substring(offset, end))
		      } 
		   }
		}
		
		// Enables Back button -  set text and URL
		//
		function enableBackButton(txt) {
		    setCookie("KoradoBackName", txt, null);
			setCookie("KoradoBackURL", document.location, null);
		}
		
		// Resets Back URL to current page
		//
		function setBackUrlHere() {
			setCookie("KoradoBackURL", document.location, null);
		}
		
		// Disables Back button 
		//
		function disableBackButton(txt) {
		    setCookie("KoradoBackName", "", null);
			setCookie("KoradoBackURL", "", null);
		}
		
		// Check 4 Back Button and show it
		//
		function checkBackButton() {
			var txt = getCookie("KoradoBackName");
			var backUrl = getCookie("KoradoBackURL");
			if (txt && backUrl) {
				document.write('<br><table width="515" border="0" cellspacing="0" cellpadding="0"><tr><td width="13" valign="top""><img src="/img/arr_bc.gif" alt="&laquo;" border="0" width="8" height="8" vspace="2"></td>');
				document.write('<td width="502" valign="top" class="black"><a href="'+ backUrl + '"  class="bc">Popierają do'+ txt +'<\/a><\/td><\/tr><\/table>');
			}
		}
		
		// Radik - koramont back to selection or menu setter
		//
		function checkMenuFunction(id) {
			var txt = getCookie("KoradoBackName");
			var backUrl = getCookie("KoradoBackURL");
			if (txt && backUrl) {
				document.write('<br><table width="515" border="0" cellspacing="0" cellpadding="0"><tr><td width="13" valign="top""><img src="/img/arr_bc.gif" alt="&laquo;" border="0" width="8" height="8" vspace="2"></td>');
				document.write('<td width="502" valign="top" class="black"><a href="'+ backUrl + '"  class="bc">Popierają do wybóra grzejnika dla '+ txt +'<\/a><\/td><\/tr><\/table>');
			} else {
				if (!parent.navigation) {
					window.opener.location=window.location;
					window.close();
				} else {
					setMenu(id);
				}
			}
		}
		
		// Radik - koramont - write center divs if needed
		//
		function openCenterDiv() {
			var txt = getCookie("KoradoBackName");
			var backUrl = getCookie("KoradoBackURL");
			if (txt && backUrl) {
				document.write('<div align="center">');
			} 
		}
		function closeCenterDiv() {
			var txt = getCookie("KoradoBackName");
			var backUrl = getCookie("KoradoBackURL");
			if (txt && backUrl) {
				document.write('<\/div>');
			} 
		}
		
/**
	Quick Navigation Button
*/
		
function fastNavi(id) {
	top.frames.location = "/cgi/f.cgi?s=" + id;
}

/**
	CloseButton Code
*/
		// Tests if opened in new window {not in frameset} and inserts close button
		//
		function insertClose(id) {
			if (!parent.main) {
				document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">');
				document.write('<tr>');
				document.write('	<td  bgcolor="#C9C9C9" width="100%">');
				document.write('	<table width="100%" border="0" cellspacing="1" cellpadding="0" align="center">');
				document.write('	<tr>');
				document.write('		<td width="66" bgcolor="#C9C9C9"><a href="#" onclick="javascript:window.close()"><img src="\/img\/vyrobky\/koramont\/close_okno.gif" width="86" height="20" border="0" align="left" alt="Zamknij Podgląd"><\/a><\/td>');
				document.write('		<td  bgcolor="#C9C9C9">&nbsp;&nbsp;<\/td>');
				document.write('	<\/tr>');
				document.write('	<\/table>');
				document.write('	<\/td>');
				document.write('<\/tr>');
				document.write('<\/table>');
			} else {
				setMenu(id);
			}
		}
		
