var ckmatobj;

function delMat(img,idmat,idr){

			var agree=confirm("Sei sicuro di cancellare il file selezionato?");
			if (agree){
				document.forms['delMat'].elements['Img'].value=img; 
				document.forms['delMat'].elements['recordId'].value=idmat; 
				document.forms['delMat'].elements['idRec'].value=idr; 
				
				document.forms['delMat'].submit();
			}

}

function savematcom(tabmat,tabstr,id){
	var el=document.getElementById('editinfoBox');

 	xmlHttp=GetXmlHttpObject() //See if it works with users browser.
		
	//var url = RootPath+"engine/ajaxphp/matedit.php";

	var url="../www/ajaxindex.php?pag=../engine/ajaxphp/matedit.php";
	
	var params = Array();
	
				
	var tit = el.getElementsByTagName('input').titolo.value;
	tit = encodeURIComponent(tit);
	
	var desc = el.getElementsByTagName('textarea').descrizione.value;
	desc = encodeURIComponent(desc);

	params.push('idtitolo='+ tit);
	params.push('iddescrizione='+ desc);

	params.push('tabmat='+ tabmat);
	params.push('tabstr='+ tabstr);
	params.push('id='+ id);
	params.push('oper=saveinfomat');
	var mypars=params.join("&");
	
	xmlHttp.open("POST", url, true);
	
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", mypars.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(mypars);
	
	parentObj = document.getElementById('editinfoBox').parentNode;
    childObj = document.getElementById('editinfoBox'); 
    parentObj.removeChild(childObj); 
	
}


function imgSelect(tabmat,tabstr,id){

	imageTds=document.getElementsByTagName('div');
	
	for(i=0;i<imageTds.length;i++) {
		if(imageTds[i].id.substring(0,8)=="tdSelect")imageTds[i].style.background ="#ffffff";
	}

	document.getElementById("tdSelect"+id).style.background ="#dadeed";

	if(document.getElementById('editinfoBox')){

   		parentObj = document.getElementById('editinfoBox').parentNode;
        childObj = document.getElementById('editinfoBox'); 
        parentObj.removeChild(childObj); 

	}
	
	
	var infodiv = document.createElement('div');
	infodiv.setAttribute('id','editinfoBox');
	
	var maincont = document.getElementById("tdSelect"+id);
	maincont.appendChild(infodiv);
	
	
	var thumbform="";
	thumbform+="<input type='text' id='titolo' name='titolo' size='27' value='' /><br/>";
	thumbform+="<textarea id='descrizione' name='descrizione' cols='25' rows='2' ></textarea>";
	thumbform+="<div id=\"iarrow\" class='infoarrow'></div>";
	thumbform+="<div onclick=\"closeeditinfobox()\" id='closebt' class='closebt'></div>";
	thumbform+="<div onclick=\"savematcom('"+tabmat+"','"+tabstr+"','"+id+"')\" id=\"savebt\" class='savebt'></div>";
	
	document.getElementById("editinfoBox").innerHTML=thumbform;
	document.getElementById("editinfoBox").className="infobox";

	height = document.getElementById("tdSelect"+id).clientHeight;

	document.getElementById('editinfoBox').style.top=-height+"px";
	document.getElementById('editinfoBox').style.left="0px";
	
	
	
	xmlHttp=GetXmlHttpObject() //See if it works with users browser.
		
	var url = RootPath+"engine/ajaxphp/matedit.php";

	var url="../www/ajaxindex.php?pag=../engine/ajaxphp/matedit.php";
	
	var params = Array();
	
	params.push('tabmat='+ tabmat);
	params.push('tabstr='+ tabstr);
	params.push('id='+ id);
	params.push('oper=openinfomat');
	var mypars=params.join("&");
	
	xmlHttp.open("POST", url, true);
	
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", mypars.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange=function(){
										if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
											 { 
											   	document.getElementById("editinfoBox").innerHTML=xmlHttp.responseText;
											 } 
										};
	xmlHttp.send(mypars);

}

function closeeditinfobox(){

	if(document.getElementById('editinfoBox')){
		var parentObj = document.getElementById('editinfoBox').parentNode;
	    var childObj = document.getElementById('editinfoBox'); 
	    parentObj.removeChild(childObj); 
    }

}







function imgCop(name,tbn,idtab,idmat){

	window.location.href="#"+ Math.ceil(100*Math.random());

    xmlHttp=GetXmlHttpObject() //See if it works with users browser.

	//var url = RootPath+"engine/ajaxphp/matedit.php";

	var url="../www/ajaxindex.php?pag=../engine/ajaxphp/matedit.php";
	
	var params = Array();
	
	ckmatobj = name;
	
	params.push('tbn='+ tbn);
	params.push('idmat='+ idmat);
	params.push('idtab='+ idtab);
	params.push('oper=imgCop');
	var mypars=params.join("&");
	
	xmlHttp.open("POST", url, true);
	
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", mypars.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange=function (){if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ window.location.reload();	}}
	xmlHttp.send(mypars);
}	
function imgDel(name,tbnmat,asstbn,tbstr,idmat){

	var agree=confirm("Sei sicuro di cancellare il contenuto selezionato ?");
			
	if (agree){
					
			window.location.href="#"+ Math.ceil(100*Math.random());
		
		    xmlHttp=GetXmlHttpObject() //See if it works with users browser.
		
			//var url = RootPath+"engine/ajaxphp/matedit.php";

			var url="../www/ajaxindex.php?pag=../engine/ajaxphp/matedit.php";
						
			var params = Array();
			
			ckmatobj = name;
			
			params.push('tbnmat='+ tbnmat);
			params.push('asstbn='+ asstbn);
			params.push('tbstr='+ tbstr);
			params.push('id='+ idmat);
			params.push('oper=imgDel');
			var mypars=params.join("&");
			
			xmlHttp.open("POST", url, true);
		
			//Send the proper header information along with the request
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", mypars.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange=function (){if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ window.location.reload();	}}
			xmlHttp.send(mypars);
	}
}


function videoDel(name,tbnmat,asstbn,tbstr,idmat){
	var agree=confirm("Sei sicuro di cancellare il contenuto selezionato ?");
			
	if (agree){
					
			window.location.href="#"+ Math.ceil(100*Math.random());
		
		    xmlHttp=GetXmlHttpObject() //See if it works with users browser.
		
			//var url = RootPath+"engine/ajaxphp/matedit.php";
			var url="../www/ajaxindex.php?pag=../engine/ajaxphp/matedit.php";
			
			var params = Array();
			
			ckmatobj = name;
			
			params.push('tbnmat='+ tbnmat);
			params.push('asstbn='+ asstbn);
			params.push('tbstr='+ tbstr);
			params.push('id='+ idmat);
			params.push('oper=videoDel');
			var mypars=params.join("&");
			
			xmlHttp.open("POST", url, true);
		
			//Send the proper header information along with the request
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", mypars.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange=function (){if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ window.location.reload();	}}
			xmlHttp.send(mypars);
	}
}


function matDownload(dir,file,name){
	window.location.href="../engine/ajaxphp/download.php?dir=../../www/"+dir+"&file="+file+"&name="+name;
}



function setUpLoad(name,file,fext,fdesc,uplimit,qlimit,session,rootpath){

	///////#########   PROBLEMA MISETRIOSO --- DIFFERENZA LETTURA PERCORSO  ##################
	//////####################################################################################
	/*
	if (navigator.appName.indexOf("Explorer") > -1){
		
	}else{
		file='../'+file;
	}*/
			/*events.add(window, 'load', function(){*/
				this['upload'+name] = new SWFUpload({
					// Backend Settings
					upload_url: file,	// Relative to the SWF file (or you can use 	absolute paths)
					post_params: {"SID" : "" + session + ""},
			
					// File Upload Settings
					file_size_limit : "30536",	// 1,5 MB
					file_types : fext,
					file_types_description : fdesc,
					file_upload_limit : uplimit,
					file_queue_limit : qlimit,
			
					// Event Handler Settings (all my handlers are in the Handler.js file)
					file_dialog_start_handler : fileDialogStart,
					file_queued_handler : fileQueued,
					file_queue_error_handler : fileQueueError,
					file_dialog_complete_handler : fileDialogComplete,
					upload_start_handler : uploadStart,
					upload_progress_handler : uploadProgress,
					upload_error_handler : uploadError,
					upload_success_handler : uploadSuccess,
					upload_complete_handler : uploadComplete,
			
					// Button Settings
					button_image_url : rootpath + "www/share/admin/images/XPButtonUploadText_61x22.png",	// Relative to the SWF file
					button_placeholder_id : "spanButtonPlaceholder"+name,
					button_width: 148,
					button_height: 22,
		
					// Flash Settings
					flash_url : rootpath + "engine/swf/swfupload.swf",
					
					swfupload_element_id : "flashUI"+name,		// Setting from graceful degradation plugin
					degraded_element_id : "degradedUI"+name,	// Setting from graceful degradation plugin
			
					custom_settings : {
						progressTarget : "fsUploadProgress"+name,
						cancelButtonId : "btnCancel"+name
					},
					
					// Debug Settings
					debug: false
				});
	
		
		/*})*/

}

