
kWindow = new Object();
kWindow.DEFAULT_NAME = 'newWin' ;
// width=size,height=size,
// resizable=yes|no,scrollbars=yes|no,
// toolbar=yes|no,location=yes|no,
// directories=yes|no,status=yes|no,
// menubar=yes|no,copyhistory=yes|no
kWindow.DEFAULT_ATTRS = 'resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no,copyhistory=no' ;
kWindow.SCREEN_WIDTH = 0 ;
kWindow.SCREEN_HEIGHT = 0 ;
kWindow.DEFAULT_WIDTH = 630 ;
kWindow.DEFAULT_HEIGHT = 400 ;


function kWindow_Open( strUrl , strName , strAttrs )
{
	objWin = new Object();
	objWin[strName] = window.open( strUrl , strName , strAttrs );
	objWin[strName].moveTo(0,0);
	objWin[strName].focus();
	return objWin[strName];
}

function kWindow_OpenNamedSized( strUrl , strName , intWidth , intHeight )
{
	var strAttrs = kWindow.DEFAULT_ATTRS + ',width=' + intWidth + ',height=' + intHeight;
	return kWindow_Open( strUrl , strName , strAttrs )	;
}

function kWindow_OpenSized( strUrl , intWidth , intHeight )
{
	var strAttrs = kWindow.DEFAULT_ATTRS + ',width=' + intWidth + ',height=' + intHeight;
	return kWindow_Open( strUrl , kWindow.DEFAULT_NAME , strAttrs )	;
}

function kWindow_OpenDefault( strUrl )
{
	var strAttrs = kWindow.DEFAULT_ATTRS + ',width=' + kWindow.DEFAULT_WIDTH + ',height=' + kWindow.DEFAULT_HEIGHT;
	return kWindow_Open( strUrl , kWindow.DEFAULT_NAME , strAttrs )	;
}

function kWindow_OpenEditor( strUrl , strFormName , strFieldName , strCode , intID )
{
	kWindow_OpenNamedSized( strUrl + "?form="+escape( strFormName )+"&field="+escape( strFieldName )+"&code="+strCode+"&id="+intID , "winEditor" , 700 , 420 );
}

function kWindow_OpenFromHref( objA )
{
	strUrl = objA.href;
	return kWindow_OpenDefault( strUrl );
}

function kWindow_OpenFromSrc( objA )
{
	objImage = objA.firstChild;
	strSrc = objImage.src;
	intW = objImage.width*4;
	intH = objImage.height*4;
	strExp = /\/100\//g;
	strSrc = strSrc.replace( strExp , "/400/");
	strHtmlBegin = '<html><head><title>Dettaglio Immagine</title></head><body style="margin: 10px; padding:0px; font-family:Verdana;font-size:11px;">';
	strHtmlImage = '<p><img src="' + strSrc + '" width="' + intW + '" height="' + intH + '" >';
	strHtmlEnd = '</body></html>';
	strHtml = strHtmlBegin+strHtmlImage+strHtmlEnd;
	//alert( strHtml );
	objWindow = kWindow_OpenSized( "/empty.htm" , intW+40 , intH+20 );
	objWindow.document.write( strHtml );
}

function kWindow_MoveBy( x , y ){ window.moveBy( x , y ); }

function kWindow_MoveTo( x , y ){ window.moveTo( x , y ); }

function kWindow_ResizeBy( x , y ){	window.resizeBy( x , y ); }

function kWindow_ResizeTo( x , y ){	window.resizeTo( x , y ); }

function kWindow_OpenFitPicture( x , y )
{ 
	var agt=navigator.userAgent.toLowerCase();
	var NS  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
        && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
        && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
	var iWidth = (NS)?window.innerWidth:document.body.clientWidth; 
	var iHeight = (NS)?window.innerHeight:document.body.clientHeight; 
	var iWidth = document.images[0].width + 26; //-iWidth
	if( iHeight > 740) iHeight = 740;
	iHeight = document.images[0].height + 31; // -iHeight+30
	if( iHeight > 400) iHeight = 400;
	window.resizeTo(iWidth, iHeight); 
	window.moveTo( x , y );
	window.focus(); 
}
