function dialog_create(id,dtitle) {
 var dialogWidget = dijit.byId(id);
 
 if( dialogWidget ) {
 if (!dialogWidget.open) dialogWidget.destroyRecursive(true);else return;
 } 
 dialogWidget = new dijit.Dialog({ title:dtitle,width:'950px'
 }, dojo.byId(id));
 dojo.style(dialogWidget.closeButtonNode,"display","none");
 var dialog = dojo.byId(id);
 dialog.parentNode.removeChild(dialog);
 var form = document.forms[0]; form.appendChild(dialog);
 dialogWidget.startup();
}
function LoadNumSpinner(fname,fvalue,delta,mmin,mmax,dec,mwidth,rg,hhelp){
	fvalue=parseFloat(fvalue);
	new dijit.form.NumberSpinner({name:fname, required:rg,style: "width:"+mwidth+"px",
	value:fvalue, scrollOnFocus:false,smallDelta:delta, constraints:{min:mmin,max:mmax,places:dec}}, 
	XSP.getElementById(fname)); 
	if (hhelp!="" & hhelp!=null & hhelp!="null") new dijit.Tooltip({connectId:fname,label:hhelp});
}
function LoadTextBox(fname,fvalue,mwidth,hhelp){
	var TextBoxWidget = dijit.byId(fname);
	if(TextBoxWidget) {TextBoxWidget.destroy(true);}
	new dijit.form.Textarea({name:fname,style: "width:"+mwidth+"px",
	value:fvalue,scrollOnFocus:false},XSP.getElementById(fname)); 
	if (hhelp!="" & hhelp!=null & hhelp!="null") new dijit.Tooltip({connectId:fname,label:hhelp});
	
}

function LoadDateTextBox(fname,fvalue,hhelp){
	new dijit.form.DateTextBox({name:fname,
	value:fvalue},XSP.getElementById(fname)); 
	if (hhelp!="" & hhelp!=null & hhelp!="null") new dijit.Tooltip({connectId:fname,label:hhelp});
}

function LoadCheckBox(fname,dvalue,fvalue,hhelp){

	ch=false;
	if(dvalue!='' | fvalue!=''){ch=true};
	new dijit.form.CheckBox({name:fname,checked:ch,
	value:fvalue},XSP.getElementById(fname)); 
	if (hhelp!="" & hhelp!=null & hhelp!="null") new dijit.Tooltip({connectId:fname,label:hhelp});
}

function LoadSelectBox(fname,fvalues,fvalue,hhelp){
//alert(fname);
	var SelectBoxWidget = dijit.byId(fname);
	if(SelectBoxWidget) {SelectBoxWidget.destroy(true);}
       var vvstore22 = new dojo.data.ItemFileReadStore({
           url: fvalues
        });
//window.location.href=fvalues
	dds2=new dijit.form.ComboBox({name:fname,value:fvalue,store:vvstore22,scrollOnFocus:false,autoComplete:true},XSP.getElementById(fname)); 
	
	if (hhelp!="" & hhelp!=null & hhelp!="null") new dijit.Tooltip({connectId:fname,label:hhelp});
}


function ToSaleAnonymous(sid,nid,ColVoID,AtomID,title,datomid){
try{

	if(document.getElementById("ColVo_"+sid+nid)!=null){
		colvo=parseInt(document.getElementById("ColVo_"+sid+nid).value);
		document.getElementById("ColVo_"+sid+nid).value="1";
	} else colvo=1;
	if(!isNaN(colvo)){
		if(colvo>0){
		document.getElementById(ColVoID).value=colvo
		document.getElementById(AtomID).value=nid
		if(dijit.byId(datomid)!=null){
			if(dojo.isOpera==undefined){
				dijit.byId(datomid).hide(); 
				dijit.byId("danoperson").show()
			}else {
				//dijit.byId(datomid).hide(); 
				//dijit.byId(datomid).destroy(); 
				//setTimeout(function(){dijit.byId("danoperson").show()},5000)
				window.location.reload()
			}
		}else dijit.byId("danoperson").show();
		
	}
	}
}catch (e){
alert(e)
}
}

function ToSale(ToSalePanelID,NIDID,ColVoID,aunid,ColVo,aname)
{


if(dojo.byId(ColVo)!=null){
	cc=parseInt(dojo.byId(ColVo).value);
	dojo.byId(ColVo).value="1";
}else cc=1;
if(!isNaN(cc)){
	if(cc>0){
	dojo.byId(ColVoID).value=cc;
	dojo.byId(NIDID).value=aunid;
	XSP.partialRefreshPost(ToSalePanelID, {
    	onStart: null,
    	onComplete: null,
    	onError: null                         
	});
	alert(aname+" - \u0432 \u043A\u043E\u043B\u0438\u0447\u0435\u0441\u0442\u0432\u0435 - "+cc+" - \u0432 \u043A\u043E\u0440\u0437\u0438\u043D\u0435");
	}
	}
}
function ToDel(dbpatch,aunid,punid)
{
location.href=dbpatch+"/ToDel?OpenAgent&atomid="+aunid
}
function OpenAtomDialog(nid,nidid,COREatomID,title){
try{
	nn=document.getElementById(nidid);
	//if(nn.value==nid){
	//		window.location.reload(true);                        
	//}else{
	nn.value=nid;
	XSP.partialRefreshPost(COREatomID, {
        onStart: null,
        onComplete: null,
        onError: null                         
    });
	underlay = new dijit.DialogUnderlay({'class':'loading'});
   	underlay.show();
  	//}
}catch (e){alert(e)}	
}
function ItogoRefresh(summid2,itogoid,colvo,aunid,vtype){
try{
	if(vtype=='2'){
		var res=prompt('\u041A\u043E\u043B\u0438\u0447\u0435\u0441\u0442\u0432\u043E:',"");
		if (!isNaN(res)){
			tosum=res+"##"+aunid
			document.getElementById(summid2).value=tosum;
			XSP.partialRefreshPost(itogoid);
		}
	}else{
		tosum=dojo.byId(colvo).value+"##"+aunid
		document.getElementById(summid2).value=tosum;
		XSP.partialRefreshPost(itogoid);
	}
	
}catch (e){alert(e)}	
}

function GetCookieValueByName(name)
{
 var beg = document.cookie.indexOf(name+"=");
 if(beg==-1)
  return "";
  
 var end = document.cookie.indexOf(";", beg + name.length);
 if(end==-1)
  end = document.cookie.length;
  
return unescape(document.cookie.substring(beg + name.length + 1, end));
}

function RefreshView(catdoc,CatDocID,ViewRefreshID){
	dojo.byId(CatDocID).value=catdoc;	
	underlay2 = new dijit.DialogUnderlay({'class':'loading'});
   	underlay2.show();
	XSP.partialRefreshPost(ViewRefreshID, {
        onStart: null,
        onComplete: null,
        onError: null                         
    });
}
function SortView(catdoc,CatDocID,sortview,SortViewID,ViewRefreshID){
	dojo.byId(CatDocID).value=catdoc;
	dojo.byId(SortViewID).value=sortview;	
	underlay2 = new dijit.DialogUnderlay({'class':'loading'});
   	underlay2.show();
	XSP.partialRefreshPost(ViewRefreshID, {
        onStart: null,
        onComplete: null,
        onError: null                         
    });
}

