/**
 * Vers. 3.3 (22-09-2011)(c) by Bernd Kiessling 
 * All Rights Reserved.
 * Es ist nicht erlaubt, diese Scripts ohne schriftliche Zustimmung des Autorīs zu verwenden, zu kopieren oder weiterzugeben !!
**/
var frm_folder="local/data";
function Frm(p_id,p_lid,p_allcont,p_fid,p_fidcl,p_isfocus,p_nxtbtins,p_clrbtins,p_toemail,p_ref,p_fromail,p_caller){
	var thisobj=this;
	thisobj.cont=document.getElementById(p_id);
	thisobj.pcont=thisobj.cont.parentNode;
	thisobj.allcont=document.getElementById(p_allcont);
	thisobj.nwe=document.getElementById(p_lid);
	thisobj.tbody=thisobj.cont.childNodes[0];
	thisobj.ids=new Array();
	thisobj.frml;
	thisobj.tmpl=new Array();
	thisobj.strt_id;
	thisobj.alldata;
	thisobj.isrqst=false;
	thisobj.cid=-1;
	thisobj.lstdtidx=0;
	thisobj.init=function(){
		thisobj.strt_id=-1;
		for(var i=0;i<thisobj.tbody.childNodes.length;i++){
			if(thisobj.tbody.childNodes[i].tagName){
				if(thisobj.tbody.childNodes[i].tagName.toLowerCase()=="tr"){
					if(thisobj.tbody.childNodes[i].id!=""){
						thisobj.tmpl.push(thisobj.tbody.childNodes[i]);
						for(var j=0;j<thisobj.tbody.childNodes[i].childNodes.length;j++){
							if(thisobj.tbody.childNodes[i].childNodes[j].tagName){
								if(thisobj.tbody.childNodes[i].childNodes[j].tagName.toLowerCase()=="td"){
									if(thisobj.tbody.childNodes[i].childNodes[j].id!=""){
										thisobj.ids.push(thisobj.tbody.childNodes[i].childNodes[j].id);
									}
								}
							}
						}
						thisobj.strt_id=i;
					}else{						
						if(thisobj.strt_id>-1){
							break;
						}
					}
				}
			}
		}
		thisobj.ids.push("dataindex");
		for(var i=0;i<thisobj.tmpl.length;i++){
			bc_remObjFrm(thisobj.tmpl[i],thisobj.tbody,false);
		}
		thisobj.strt_id=thisobj.strt_id-(thisobj.tmpl.length-1);
		thisobj.parseToSend(null,false);
	};
	thisobj.nwe.onkeyup=function(p_event){
		if(!p_event){
			p_event=window.event;	
		}
		if(p_event.which){
			if(p_event.which==13){
				thisobj.nwEntr();
			}
		}else if(p_event.keyCode){
			if(p_event.keyCode==13){
				thisobj.nwEntr();
			}
		}
	};
	thisobj.nwEntr=function(){
		thisobj.pcont.removeChild(thisobj.cont);
		for(var i=0;i<thisobj.allcont.childNodes.length;i++){
			if(thisobj.allcont.childNodes[i].style){
				thisobj.allcont.childNodes[i].style.display="none";
			}
		}
		document.getElementById(p_fid).style.display="inline";
		if(thisobj.frml==null){
			thisobj.frml=new FRML(p_fid,p_fidcl,p_isfocus,p_nxtbtins,p_clrbtins,thisobj);
		}else{
			thisobj.frml.setFocus();
		}
	};
	thisobj.nxtEntr=function(p_data,p_id){
		var tmpto=0;
		if(bc_isdsgn==true){
			tmpto=-1;
		}
		for(var i=thisobj.tmpl.length-1;i>tmpto;i--){
			var tmptr=document.createElement("tr");
			bc_addDublObj(tmptr,thisobj.tmpl[i]);
			for(var j=0;j<thisobj.tmpl[i].childNodes.length;j++){
				if(thisobj.tmpl[i].childNodes[j].tagName){
					if(thisobj.tmpl[i].childNodes[j].tagName.toLowerCase()=="td"){
						var tmptd=document.createElement("td");
						if(thisobj.tmpl[i].childNodes[j].colSpan){						
							tmptd.colSpan=thisobj.tmpl[i].childNodes[j].colSpan;
						}
						if(thisobj.tmpl[i].childNodes[j].rowSpan){					
							tmptd.rowSpan=thisobj.tmpl[i].childNodes[j].rowSpan;
						}
						bc_addDublObj(tmptd,thisobj.tmpl[i].childNodes[j]);
						if(i==0){
							for(var k=0;k<thisobj.tmpl[i].childNodes[j].childNodes.length;k++){
								if(thisobj.tmpl[i].childNodes[j].childNodes[k].tagName){
									if(thisobj.tmpl[i].childNodes[j].childNodes[k].tagName.toLowerCase()=="a"){
										var tmplk=document.createElement("a");
										tmplk.href=thisobj.tmpl[i].childNodes[j].childNodes[k].href;
										tmplk.id=thisobj.tmpl[i].childNodes[j].childNodes[k].id;
										tmplk.className=thisobj.tmpl[i].childNodes[j].childNodes[k].className;
										if(thisobj.tmpl[i].childNodes[j].childNodes[k].childNodes.length>0){
											addHTxt(thisobj.tmpl[i].childNodes[j].childNodes[k].childNodes[0].nodeValue,true,tmplk);
										}
										bc_addDublObj(tmplk,thisobj.tmpl[i].childNodes[j].childNodes[k]);
										tmptd.appendChild(tmplk);
										tmplk.onmouseup=function(p_event){
											p_event = p_event || window.event;
											var target = p_event.target || p_event.srcElement;
											if(target.id=="dataclr"){
												thisobj.clrEntr(p_id,target.parentNode.parentNode);
											}else if(target.id=="datachg"){
												thisobj.chgEntr(p_id,target.parentNode.parentNode);
											}
										};
									}
								}
							}
						}else{
							if(thisobj.tmpl[i].childNodes[j].id!=""){						
								var tmpv="";
								for(var k=0;k<p_data.length-1;k++){
									if(String(p_data[k][0])==thisobj.tmpl[i].childNodes[j].id){
										tmpv=String(p_data[k][1]);
										break;
									}
								}
								if(tmpv==""){
									addHTxt(" ",true,tmptd);
								}else{
									addHTxt(tmpv,true,tmptd);
								}
							}
						}
					}
				}
				tmptr.appendChild(tmptd);
			}
			if((thisobj.strt_id>0)&&(thisobj.tbody.childNodes.length>thisobj.strt_id)){
				thisobj.tbody.insertBefore(tmptr,thisobj.tbody.childNodes[thisobj.strt_id]);
			}else{
				thisobj.tbody.appendChild(tmptr);
			}
		}
	};
	thisobj.clrEntr=function(p_id,p_frtr){
		for(var i=0;i<thisobj.tbody.childNodes.length;i++){
			if(thisobj.tbody.childNodes[i]==p_frtr){
				for(j=i+thisobj.tmpl.length-1;j>=i;j--){
					bc_remObjFrm(thisobj.tbody.childNodes[j],thisobj.tbody,true);
				}
				break;
			}
		}
		thisobj.alldata=bc_remElmnt(p_id,thisobj.alldata);
		thisobj.parseToSend(null,true);
	};
	thisobj.chgEntr=function(p_id,p_frtr){
		thisobj.cid=p_id;
		thisobj.pcont.removeChild(thisobj.cont);
		for(var i=0;i<thisobj.allcont.childNodes.length;i++){
			if(thisobj.allcont.childNodes[i].style){
				thisobj.allcont.childNodes[i].style.display="none";
			}
		}
		document.getElementById(p_fid).style.display="inline";
		if(thisobj.frml==null){
			thisobj.frml=new FRML(p_fid,p_fidcl,p_isfocus,p_nxtbtins,p_clrbtins,thisobj);
		}else{
			thisobj.frml.setFocus();
		}
		thisobj.frml.setVls(thisobj.alldata[p_id]);
	};
	thisobj.nxtFRML=function(p_form){
		var tmpdata=new Array();
		for(var i=0;i<thisobj.ids.length-1;i++){
			tmpdata.push(new Array(thisobj.ids[i],thisobj.frml.getVls(thisobj.ids[i])));
		}
		if(thisobj.alldata==null){
			thisobj.alldata=new Array();	
		}
		if(thisobj.cid==-1){
			if(thisobj.alldata.length==0){
				tmpdata.push(new Array("dataindex",1));
			}else{
				thisobj.lstdtidx++;
				tmpdata.push(new Array("dataindex",thisobj.lstdtidx));
			}
			thisobj.alldata.push(tmpdata);
			thisobj.nxtEntr(tmpdata,thisobj.alldata.length-1);
		}else{
			tmpdata.push(thisobj.alldata[thisobj.cid][thisobj.alldata[thisobj.cid].length-1]);
			thisobj.alldata[thisobj.cid]=tmpdata;
			thisobj.cid=-1;
		}
		thisobj.pcont.appendChild(thisobj.cont);
		for(var i=0;i<thisobj.allcont.childNodes.length;i++){
			if(thisobj.allcont.childNodes[i].style){
				thisobj.allcont.childNodes[i].style.display="inline";
			}
		}		
		thisobj.frml.reset();
		thisobj.frml.getFrml().style.display="none";
		thisobj.parseToSend(tmpdata,false);
	};
	thisobj.parseToSend=function(p_data,p_del){
		var senddata="toemail="+p_toemail+"&reference="+p_ref+"&fromail="+p_fromail;
		if((p_data!=null)&&(p_del==false)){
			senddata=senddata+"&filetext="+parseToData(p_data);
		}else if(p_del==true){
			senddata=senddata+"&filetext=";
			for(var i=0;i<thisobj.alldata.length;i++){
				senddata=senddata+parseToData(thisobj.alldata[i]);
			}
		}else{
			senddata=senddata+"&filetext=null";
		}
		senddata=senddata+"&url=../../"+frm_folder+"/"+p_id+".dbx";
		senddata=senddata+"&del="+String(p_del);
		sendPHP(senddata,"forum.php",thisobj);
		window.setTimeout(function(){if(thisobj.isrqst==false){sendPHP(senddata,"forum.php",thisobj);}},3000);
	};
	thisobj.phpSended=function(p_rqst){
		if(thisobj.isrqst==false){
			thisobj.isrqst=true;
			if(p_rqst.responseText!="false"){
				thisobj.alldata=reparseAllData(thisobj.ids,p_rqst.responseText);
				if(thisobj.alldata!=null){
					for(var i=thisobj.alldata.length-1;i>=0;i--){
						thisobj.nxtEntr(thisobj.alldata[i],i);
						if(Number(thisobj.alldata[i][thisobj.alldata[i].length-1][1])>thisobj.lstdtidx){
							thisobj.lstdtidx=Number(thisobj.alldata[i][thisobj.alldata[i].length-1][1]);
						}
					}
				}
				if(p_caller!=null){
					p_caller.intCompl(thisobj);	
				}
			}
		}
	};
	thisobj.clrFRML=function(p_form){
		thisobj.frml.reset();
		for(var i=0;i<thisobj.allcont.childNodes.length;i++){
			if(thisobj.allcont.childNodes[i].style){
				thisobj.allcont.childNodes[i].style.display="inline";
			}
		}
		thisobj.frml.getFrml().style.display="none";
		thisobj.pcont.appendChild(thisobj.cont);
	};
	thisobj.init();	
	thisobj.nwe.onmouseup=function(){
		thisobj.nwEntr();
	};
}
