function ShowWindow(Title,tbl,tsk,ID,Opac,w,h)
{

    if (typeof w == 'undefined'){w = 680}
    if (typeof h == 'undefined'){h = 480}
    //alert(w + ' ' + h)
	var wsa = window.open('ShowDialog.aspx?Title=' + Title + '&tbl=' + tbl + '&tsk=' + tsk + '&ID=' + ID + '&Opac=' + Opac,'Dettaglio','width=' + w + ',height=' + h + ',status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
	wsa.focus();
	//wsa.print();
	return false;
}

function ShowFile(QryStr, page, w,h){
	var wsc ='';
	if (typeof w == 'undefined'){w = 400}
    if (typeof h == 'undefined'){h = 400}
	//alert(w + ' ' + h)
	var wsv = window.open(page + '.aspx?' + QryStr,'Visualizzatore','width=' + w + ',height=' + h + ',status=yes,toolbar=no,menubar=no,location=yes,resizable=yes,scrollbars=yes');
	wsv.focus();
}

function ShowPopUp(title, tbl, ID, Opac, IW, w, h)
{
    if (typeof w == 'undefined'){w = 600}
    if (typeof h == 'undefined'){h = 480}
    if (typeof Opac == 'undefined'){Opac = 'Default'}
    if (typeof IW == 'undefined'){IW = 'NO'}
    //alert(w + ' ' + h)
	if (IW == 'NO') {
		var wsv = window.open('ShowDialog.aspx?Title=' + title + '&tbl=' + tbl + '&ID=' + ID + '&Opac=' + Opac,'Visualizzatore','width=' + w + ',height=' + h + ',status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
	} else {
		var wsv = window.open('ShowViewer.aspx?Title=VIEWERTITLE&tbl=' + tbl + '&ID=' + ID + '&Opac=' + Opac,'Visualizzatore','width=800,height=600,,status=yes,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes');
	}
	wsv.focus();
}


var dialogw = null;

function CloseDialogs(){
    if (dialogw && !dialogw.closed) {
        dialogw.close();
    }
    dialogw=null;
}
      

function addEvent(obj, evType, fn){
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, false);
		return true;
	} else if (obj.attachEvent){
		obj.attachEvent("on"+evType, fn);
		return true
	} else {
		return false;
	}
}
		
addEvent(window, 'unload',CloseDialogs)


var ctlID = '';

function ShowDialog(title, tbl, tsk, opac, fldCtl, retCtl, noFld, w, h){
    ctlID = retCtl;
    if (typeof w == 'undefined'){w = 640}
    if (typeof h == 'undefined'){h = 480}
    var fld = document.getElementById(fldCtl).value;
	if (fld !=''){
		CloseDialogs()
		var dialogoptions = 'width=' + w + ',height=' + h + ',status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes'
		var wsa = window.open('',title,dialogoptions);
		wsa.location = 'ShowDialog.aspx?Title=' + title + '&TBL=' + tbl + '&Tsk=' + tsk + '&Fld=' + fld + '&Opac=' + opac;
		wsa.focus();
		dialogw = wsa;
	} else {
		alert(noFld);
		document.getElementById(fldCtl).focus()
	}
}

function SetReturnValue(returnValue){
    if (typeof returnValue != 'undefined'){
        document.getElementById(ctlID).value=returnValue;
        document.getElementById(ctlID).focus()
    }
}

function SetSearchReturnValue(RetVal)
{
     if (!top.opener.closed){;
         top.opener.SetReturnValue(RetVal);
     }
     window.close();
}


function fnTrapKD(ctl, e){
	var key =  window.event ? e.keyCode : e.which;
	if (key == 13)
	{ 
		if (window.event) {
			e.returnValue=false;
			e.cancel = true;
		} else {
			correctSubmitHandler
		}
		if (ctl.type == "submit") {
			ctl.click();
		} else {
			__doPostBack(ctl.id.replace('_', '$'),'');
		}
	} 
}


function correctSubmitHandler(e)
{
	if (e && e.preventDefault)
		e.preventDefault();
	return false;
}

