var xmlDoc;
var winStack;
winStack = new Array("0");
var MAX_z = 100;
var isDragging = false;

// classes
function xColonne(larg, titr, style) {
	this.largeur = larg;
	this.titre = titr;
	this.style = style;
	this.afficher = afficherCol;
}

function afficherCol() {
	$str = '<th width="'+this.largeur+'" nowrap ';
	if(this.style!='')	$str += 'class="'+this.style+'" ';
	$str += '>'+this.titre+'</th>\n';
	return $str;
}

function xWindow(ID_html, g, h, larg, haut, titr, url, z_index, oBD_ID) {
	//this.id 			= ID;
	this.id_html 		= ID_html;
	this.gauche			= g;
	this.haut			= h;
	this.largeur 		= larg;
	this.hauteur		= haut;
	this.titre 			= titr;
	this.style			= 'titlebar';
	this.styleC			= 'td_bord';
	this.z_index		= z_index;
	this.nColonnes		= 0;
	this.icon			= "../images/doc_default.gif"// 20*25
	this.tColonnes		= new Array();
	this.tColonnes[1]	= new xColonne('10','',this.style+'_G');
	this.tColonnes[2]	= new xColonne('100%','<img src='+this.ico+' width="20" height="25" align="left" />&nbsp;'+titr,this.style);
	this.tColonnes[3]	= new xColonne('21','<div id="CloseBox" onclick="fermer(\''+this.id+'\');"></div>',this.style);
	this.tColonnes[4] 	= new xColonne('10','',this.style+'_D');
	this.afficher		= afficher;
	this.fermer			= fermer;
	if(oBD_ID) {
		this.oBD_ID = oBD_ID;
	}
	else {
		r  = '/xWindow/objet.php?a=creer&ID_html='+this.id_html;
		r += '&url='+url+'&type=div&class='+this.style+'&g='+this.gauche;
		r += '&h='+this.haut+'&L='+this.largeur+'&H='+this.hauteur+'&z='+this.z_index+'&t='+this.titre;
		doAjax(r, oBD_ID_set);
	}
}

function afficher(url) {
	var HTML ='<div class="aWindow" id="'+ this.id_html +'" title="'+this.oBD_ID+'"';
	HTML += 'style="height: '+this.hauteur+'px; width: '+this.largeur +'px; left: '+this.gauche+'px; top: '+this.haut+'px; z-index: '+this.z_index+';" onmousedown="downAction(this,event);" onmousemove="moveAction(this, event);"">\n';
	HTML += '<table width="100%"  height=100% border="0" cellpadding="0" cellspacing="0">\n';
	// 	BARRE DE TITRE   //
	HTML += '<tr class="'+this.style+'" >\n';
	HTML += '<th class="'+this.style+'_G" width="10" nowrap ></th>\n';
	HTML += '<th class="'+this.style+'" width="100%" nowrap ><img src="'+this.icon+'" width="20" height="25" align="left" />&nbsp;'+this.titre+'</th>\n';
	HTML += '<th class="'+this.style+'" width="21" nowrap ><div id="CloseBox" onclick="fermer(\''+this.id_html+'\');"></div></th>\n';
	HTML += '<th class="'+this.style+'_D" width="10" nowrap ></th>\n';
	HTML += '</tr>\n';

	// cadre IFRAME
	HTML += '<tr  height=100%>\n';
	HTML += '	<td class="'+this.styleC+'_G" width="10"></td>';
	HTML += '	<td colspan="2"  class="td_iframe"><iframe src="'+url+'" name="ifLignes" width="100%" height="100%" scrolling="auto" frameborder="0" allowtransparency="true" ></iframe></td>';
	HTML += '	<td class="'+this.styleC+'_D" width="10"></td>';
	HTML += '</tr>\n';

	// bas fenetre
	HTML += '<tr class="'+this.style+'">\n';
	HTML += '	<td class="'+this.style+'_Gbas"></td>\n';
	HTML += '	<td class="'+this.style+'" ></td>\n';
	HTML += '	<td class="'+this.style+'" ><div id="'+this.style+'_Handle"></div></td>\n';
	HTML += '	<td class="'+this.style+'_Dbas"></td>\n';
	HTML += '</tr>\n';
	HTML += '</table>\n';
	HTML += '</div>\n';
	if(top.desktop)
	top.desktop.document.body.innerHTML += HTML;
	else document.body.innerHTML += HTML;
	//parent.getElementById(id);
}

function fermer(id){
	div = document.getElementById(id);
	//alert(div.title);
	doAjax('/xWindow/objet.php?a=trash&oBD_ID='+div.title, '');
	div.innerHTML ='';
	div.style.display = 'none';
	div.id='dead';

}

function oBD_ID_set(){/*					rappel httpRequest creation objet*/
	eval(this.req.responseText);
}

function cWin(window_name, url, icon){
	nWin 	= ++winStack[0];
	z 		= ++MAX_z;
	winStack[nWin] = new xWindow(window_name, 150+(30*nWin),50+(30*nWin), 600,300, window_name, url, z, 0);
	if(icon) top.desktop.winStack[nWin].icon = icon;
	winStack[nWin].z_index = z;
	winStack[nWin].afficher(url);
}