function DG_Res()
{
	DG_Object.call(this);
}

DG_CF.DG_ResFont=function(){return new DG_ResFont();}
function DG_ResFont()
{
	DG_Res.call(this);
	var myself=this;
	this.DgType="DG_ResFont";
	this.PP=new Array(4);
	this.SetFont=function(o)
	{
		if(!o)return;
		o.SS(24,myself.PP[0]);
		o.SS(26,myself.PP[1]);
		o.SS(25,myself.PP[2]);
		o.SS(27,myself.PP[3]);
	}
	this.GetDefault=function(id)
	{
		switch(id)
		{
			case 0: return "Arial";
			case 1: return 12;
			case 2: return false;
			case 3: return false;
		}
	}
	this.PD=function(id)
	{
		switch(id)
		{
			case 0: return {t:"str",n:"FontName",d:"font family name"};
			case 1: return {t:"int",n:"FontSize",d:"font size, in pixels"};
			case 2: return {t:"bool",n:"IsBold",d:"bold font"};
			case 3: return {t:"bool",n:"IsItalic",d:"bold italic"};
		}
	}
	this.InitProps();
}

DG_CF.DG_ResImgList=function(){return new DG_ResImgList();}
function DG_ResImgList()
{
	DG_Res.call(this);
	var myself=this;
	this.DgType="DG_ResImgList";
	this.PP=new Array(4);
	this.GetDefault=function(id)
	{
	}
	this.PD=function(id)
	{
		switch(id)
		{
			case 0: return {t:"str",n:"ImgUrl",d:"url of the image list bitmap"};
			case 1: return {t:"int",n:"ImgNum",d:"number of images in the list"};
			case 2: return {t:"int",n:"Width",d:"width of a single image"};
			case 3: return {t:"int",n:"Height",d:"height of a single image"};
		}
	}
	this.CreateImg=function(po,n,l,t)
	{
		var w=myself.PP[2];
		var h=myself.PP[3];
		var div = DG_CreateDiv(po,{w:w,h:h,l:l,t:t});
		div.SS(19,1);
		var src=myself.PP[0];
		var img=DG_CreateImg(div, {l:0,t:0,src:src});
		img.SS(23,0);
		var dx=-n*w;
		img.SS(12,dx);
		img.SS(23,1);
	}
	this.SetImg=function(o)//object of DG_Img type
	{
		if(!o)return;
		o.DIV.SS(21,{l:0,t:0,r:0,b:0});
		o.PP[0]=myself.PP[0];
	}
	this.InitProps();
}

function DG_Bmp()
{
	DG_Res.call(this);
	var myself=this;
	this.PP=new Array(3);
	
	this.Init=function()
	{
		var img = DG_CreateImg(p,d);
	}
	this.GetDefault=function(id)
	{
		switch(id)
		{
			case 0: return "";
		}
	}	
	this.PD=function(id)
	{
		switch(id)
		{
			case 0: return {t:"url",n:"ImageUrl",d:"url"};
		}
	}
}

DG_CF.DG_Rect=function(){return new DG_Rect();}
function DG_Rect()
{
	DG_Object.call(this);
	var myself=this;
	this.DgType="DG_Rect";
	this.PP=new Array(4);
	this.PPN=["bgColor","border","htmlText","txtColor","ID"];
	this.RenderObj=function(r)
	{
		var m=myself;
		var div=m.DIV;
		var p0=m.PP[0];if(p0)div.SS(0,p0);
		var p1=m.PP[1];if(p1)div.SS(3,p1);
		if(m.PP[2])div.SS(101,m.PP[2]);
		if(m.PP[3])div.SS(4,m.PP[3]);
		if(m.PP[4])div.SS(100,m.PP[4]);
	}
	this.GetDefault=function(id)
	{
		switch(id)
		{
			case 0: return "";
			case 1: return "";
			case 2: return null;
		}
	}
	this.PD=function(id)
	{
		switch(id)
		{
			case 0: return {t:"clr",n:"bgColor",d:"background color"};
			case 1: return {t:"clr",n:"border",d:"border"};
		}
	}
	this.SetText=function(t){myself.DIV.SS(101,t);}
	this.ApplyPP=function()
	{
		var m=myself;
		m.DIV.SS(101,(m.PP[2])?m.PP[2]:"");
    }
}

DG_CF.DG_A=function(){return new DG_A();}
function DG_A()
{
	DG_Object.call(this);
	var myself=this;
	this.DgType="DG_A";
	this.PP=new Array(4);
	this.PPN=["url","title","dom props","onclick"];
	var m_a;
	this.RenderObj=function(r)
	{
		var url=this.PP[0];
		var onclick=this.PP[3];
		if(!url)return;
		m_a=DG_CreateAnchor(this.DIV,{link:url,value:this.PP[1]});
		m_a.JSO=myself;
		m_a.SS(23,1);
		m_a.SS(5,'100%');
		m_a.SS(6,'100%');
		DG_SetDomProps(m_a,this.PP[2]);
		if(onclick)m_a.onclick=onclick;
	}
}

DG_CF.DG_Img=function(){return new DG_Img();}
function DG_Img()
{
	DG_Object.call(this);
	var myself=this;
	this.DgType="DG_Img";
	this.PP=new Array(4);
	this.PPN=["url","onclick","ss","alphaCorrection"];
	var m_img=null;
	this.RenderObj=function(r)
	{
		var url=this.PP[0];
		var onclick=this.PP[1];
		if(!url)return;
		if(myself.PP[3])
			m_img=DG_CreateImg(this.DIV,{pngSrc:url});
		else
			m_img=DG_CreateImg(this.DIV,{src:url});
		DG_SetDomProps(m_img,this.PP[2]);
		if(onclick)m_img.onclick=onclick;
	}
	this.setSrc=function(u)
	{
		if(!m_img){m_img=DG_CreateImg(this.DIV,{src:u});}
		else m_img.src=u;
	}
}
DG_CF.DG_Form=function(){return new DG_Form();}
function DG_Form()
{
	DG_Object.call(this);
	var myself=this;
	this.DgType="DG_Form";
	this.DIV=DG_NewForm();
	var m_fr;
	this.PP=new Array(4);
	this.PPN=["id","action","onsubmit","onvalidate"];
	this.RenderObj=function(r)
	{
		var f=this.DIV;
		f.setAttribute('enctype',"multipart/form-data");
		f.method="POST";
		f.action=this.PP[1];
		f.OnSubmit=this.PP[2];
		f.OnValidate=this.PP[3];
		var btns=this.Area.GetAllKids("DG_ImgBtn");
		for(var i=0;i<btns.length;i++)
		{
			var b=btns[i];
			var t=b.Content.FormType;
			if(t=="submit")b.Content.PP[1]=OnSubmit;
		}
		var combos=this.Area.GetAllKids("DG_InputCombo");
		for(var i=0;i<combos.length;i++)
		{
		    var cb=combos[i];
		    cb.Content.OnFormSubmit=OnSubmit;
        }
	}
	function OnSubmit()
	{
	    myself.DIV.submit();
	}//alert("OnClick");}
}
DG_CF.DG_BtnPanel=function(){return new DG_BtnPanel();}
function DG_BtnPanel()
{
	DG_Object.call(this);
	var myself=this;
	this.DgType="DG_BtnPanel";
	this.PP=new Array(1);
	this.PPN=["isSubMenu"];
	var btns=[];
	this.Select=function(b)
	{
		alert("S");
	}
	this.Select2=function(b)
	{
		for(var i=0;i<btns.length;i++)
		{
			var o=btns[i];
			o.Select(b==o);
		}	
	}
	this.RenderObj=function(r)
	{
		var l=this.DIV.childNodes.length;
		for(var i=0;i<l;i++)
		{
			var o=this.DIV.childNodes[i].JSO;
			btns[i]=o;
			if(o.DgType=="DG_ImgBtn")
				o.OnClickParent=this.Select2;
		}
		if(this.PP[0])
			this.DIV.onmouseleave=function(e){myself.DIV.SS(11,0);}
	}
}

DG_CF.DG_ImgBtn=function(){return new DG_ImgBtn();}
function DG_ImgBtn()
{
	DG_Object.call(this);
	var myself=this;
	this.DgType="DG_ImgBtn";
	this.PP=new Array(9);
	this.PPN=["imgUrl","onclickFnc","href","alphaCorrection","map","indexes","selected","hint","ss"];
	var m_img;
	var m_href;
	var m_map;
	var m_indexes;
	var m_selected=0;
	var m_in=0;
	var m_onclick;
	this.FormType="submit";
	this.OnClickParent=null;
	this.RenderObj=function(r)
	{
		this.DIV.onmouseleave=OnLeave;
		this.DIV.onmouseout=OnLeave;
		this.DIV.onmousemove=function(e){m_in=1;UpdateState();}

		m_selected=(this.PP[6])?this.PP[6]:0;
		m_indexes=this.PP[5];
		ParseMap(this.PP[4]);
		m_href=this.PP[2];
		var src=this.PP[0];
		m_onclick=this.PP[1];
		if(!src)return;
		if(myself.PP[3])
			m_img=DG_CreateImg(this.DIV,{pngSrc:src});
		else
			m_img=DG_CreateImg(this.DIV,{src:src});
		m_img.SS(7,"pointer");
		if(this.PP[7])m_img.SS(10,this.PP[7]);
		DG_SetDomProps(m_img,this.PP[8]);
		m_img.onclick=function(e)
		{
			var pf=myself.OnClickParent;if(pf)pf(myself);
			if(m_onclick)m_onclick(myself);
			if(m_href)document.location=m_href;
			DG_CancelEvent(e);
		}
		myself.Select(m_selected);
	}
	function ParseMap(map)
	{
		if(!map)return null;
		var len=map.length;
		m_map=new Array(len);
		for(var i=0;i<len;i++)
		{
			var m=map[i];
			var o={l:m[0],t:m[1],w:m[2],h:m[3]};
			m_map[i]=o;
		}
	}
	this.Select=function(b){m_selected=b;UpdateState();}
	function OnLeave(e){m_in=0;UpdateState();}
	function UpdateState()
	{
		if(!m_map)return;
		var n=m_in+2*m_selected;
		var index=m_indexes[n];
		if(typeof(index)=="undefined")return;
		var m=m_map[index];
		m_img.SS(12,-m.l);
		m_img.SS(13,-m.t);
		myself.DIV.SS(5,m.w);
		myself.DIV.SS(6,m.h);
	}
}

DG_CF.DG_Span=function(){return new DG_Span();}
function DG_Span()
{
	DG_Object.call(this);
	var myself=this;
	this.DgType="DG_Span";
	this.PP=new Array(3);
	this.PPN=["id","padding","text"];
	var m_span;
	this.PP[1]=0;
	this.PP[2]="";
	this.RenderObj=function(r)
	{
//	return;
		var id=this.PP[0];
		m_span=(id)?DG_Obj(id):DG_CreateSpan(myself.DIV,{txt:this.PP[2]});
		if(!m_span)return;
		m_span.SS(12,0);
		m_span.SS(13,0);
		m_span.SS(19,2);//overflow="auto";
		m_span.SS(18,0);
		m_span.SS(11,1);
		m_span.SS(35,this.PP[1]);
		var padding=this.PP[1];
		this.DIV.SS(12,padding);
		this.DIV.SS(13,padding);
		this.DIV.SS(5,(this.DIV.W-2*padding));
		this.DIV.SS(6,this.DIV.H-2*padding);
		myself.DIV.SS(19,2);//overflow="auto";
		myself.DIV.appendChild(m_span);
	}
	this.GetDefault=function(id)
	{
		switch(id)
		{
			case 0: return null;
			case 1: return 0;
		}
	}	
	this.PD=function(id)
	{
		switch(id)
		{
			case 0: return {t:"clr",n:"bgColor",d:"background color"};
			case 1: return {t:"clr",n:"borderColor",d:"border color"};
		}
	}
}

DG_CF.DG_InputCheckbox=function(){return new DG_InputCheckbox();}
function DG_InputCheckbox()
{
	DG_Object.call(this);
	var myself=this;
}

DG_CF.DG_InputRadio=function(){return new DG_InputRadio();}
function DG_InputRadio()
{
	DG_Object.call(this);
	var myself=this;
	this.DgType="DG_InputRadio";
	this.PP=["",null,false,null,false];
	this.PPN=["formID","value","checked","disabled"];
	var m_btn;
	this.RenderObj=function(r)
	{
		var m=myself;
		m_btn=DG_CreateRadioBtn2(m.DIV,{n:m.PP[0],i:m.PP[0],ch:m.PP[2]});
		m_btn.BtnValue=m.PP[1];
		m_btn.value=m.PP[1];
		m_btn.disabled=m.PP[3];
	}
}

DG_CF.DG_InputText=function(){return new DG_InputText();}
function DG_InputText()
{
	DG_Object.call(this);
	var myself=this;
	this.DgType="DG_InputText";
	this.PP=[null,16,false,false,false,false,null,null];
	this.PPN=["formID","MaxChars","IsPassword","IsReadonly","IsDisabled","IsNoEmpty", "errorLbl","value"];
	//          0          1            2            3           4           5         6         7
	var m_txt;
	var m_isValidateEmail=false;
	var m_isValidateNonempty=false;
	this.ApplyPP=function()
	{
	    m_txt.SS(22,myself.PP[7]);
    }
	this.RenderObj=function(r)
	{
		var m=myself;
		m_txt=DG_CreateTextBox(m.DIV,{v:m.PP[7]},m.PP[2]?"password":"text");
		m_txt.SS(3,"0px");
		m_txt.SS(0,null);
		m_txt.SS(5,"100%");
		m_txt.SS(6,"100%");
		m_txt.maxLength=m.PP[1];
		m_txt.readonly=m.PP[2];
		m_txt.disabled=m.PP[3];
		if(m.PP[0]){m_txt.name=m.PP[0];m_txt.id=m.PP[0];}
		m_txt.onchange=function()
		{
			var v=m_txt.value;
			if(m_isValidateEmail)checkEmail(v);
			if(myself.PP[5])checkNonempty(v);
		}
	}
	function checkNonempty(v)
	{
		if(v.length<=0)
			{ SetError("this field cannot be empty"); m_txt.focus(); }
		else(SetError(""));
	}
	function checkEmail(v)
	{
		if(v.length>0)
		{
			if(v.indexOf(' ')>=0)
				SetError("email addresses cannot have spaces in them");
			else if(v.indexOf('@')<0)
				SetError("a valid email address must have an @ in it");
		}
		else(SetError(""));
	}
	function SetError(t){var e=myself.PP[5];if(e)e.SetText(t);}
}

DG_CF.DG_InputCombo=function(){return new DG_InputCombo();}
function DG_InputCombo()
{
	DG_Object.call(this);
	var myself=this;
	this.DgType="DG_InputCombo";
	this.PP=[null,null,null,null];
	this.PPN=["formID","options","sel","onselect"];
	var m_combo;
	this.FormType="submit";
	this.ApplyPP=function()
	{
		var m=myself;
		var ops=m.PP[1];
		var sel=m.PP[2];
		DG_PopulateSelect(m_combo,ops,sel);
    }
	this.RenderObj=function(r)
	{
		var m=myself;
		m_combo=DG_CreateSelect(m.DIV,{w:100});
		m_combo.SS(3,"1px solid gray");
		m_combo.SS(5,m.DIV.W);
		m_combo.id=m.PP[0];m_combo.name=m.PP[0];
		var ops=m.PP[1];
		var sel=m.PP[2];
		if(ops)DG_PopulateSelect(m_combo,ops,sel);
		m_combo.onchange=function(e)
		{
            DG_CancelEvent(e);
		    var c=m_combo;
		    var i=c.selectedIndex;
            var op=c.options[i];
            if(m.PP[3])
                m.PP[3](op,i,m.OnFormSubmit);
            else
                if(m.OnFormSubmit)m.OnFormSubmit();
        }
	}
}

DG_CF.DG_IFrame=function(){return new DG_IFrame();}
function DG_IFrame()
{
	DG_Object.call(this);
	var myself=this;
	this.DgType="DG_IFrame";
	this.PP=new Array(3);
	var m_fr;
	this.RenderObj=function(r)
	{
		var url=this.PP[0];if(!url)return;
		m_fr=DG_NewIFrame(this.DIV,{s60:url,s5:r.w,s6:r.h,s61:this.PP[1],s62:this.PP[2]});
	}
	this.GetDefault=function(id)
	{
		switch(id)
		{
			case 1: return 0;
			case 2: return 0;
		}
	}
	this.InitProps();
}

DG_CF.DG_ExtDiv=function(){return new DG_ExtDiv();}
function DG_ExtDiv()
{
	DG_Object.call(this);
	var myself=this;
	this.PP=new Array(1);
	this.PPN=["id"];
	var m_extDiv;
	this.PP[0]=null;
	this.RenderObj=function(r)
	{
		var m=myself;
		if(m.PP[0]==null)return;
		var d=DG_Obj(m.PP[0]);
		m.DIV.appendChild(d);
		d.SS(12,0);
		d.SS(13,0);
		d.SS(18,1);
		d.SS(23,1);
	}
}

DG_CF.DG_Widget=function(){return new DG_Widget();}
function DG_Widget()
{
	DG_Object.call(this);
	var myself=this;
	this.PP=new Array(3);
	this.RenderObj=function(r)
	{
		DG_CF.LoadWidget(myself.DIV,myself.PP[0]);
	}
}
