
wl.Controls={};wl.Controls.Control=wl.Class(Object,function()
{this.constructor=function()
{this._disabled=false;wl.attachEvent(window,"unload",this.unload.bind(this));}
this.getContainer=function(){return wl.$(this.c_id);}
this.generate=function(c)
{if(typeof(c)=="string")c=wl.$(c.split('$').join('_'));this.c_id=wl.uniqueID(c);c.control=this;this.ongenerate(c);}
this.ongenerate=function(c){}
this.unload=function()
{var c=wl.$(this.c_id);if(c!=null)
{this.onunload();c.control=null;}}
this.onunload=function(){}
this.disable=function(disable)
{if(this._disabled==disable)return;if(!wl.fireEvent(this,"disabling",{disable:disable}).isFalse)
{this._disabled=disable;wl.fireEvent(this,"disable",{disable:disable});this.ondisabled(disable);}}
this.ondisabled=function(disabled){}
this.isDisabled=function(){return this._disabled;}
this.show=function(bShow)
{var c=wl.$(this.c_id);if(c!=null)wl.Utils.setNew(c.style,"display",bShow?"":"none");}});wl.Controls.Button=wl.Class(wl.Controls.Control,function(base)
{this.constructor=function()
{base.constructor.call(this);}
this.ongenerate=function()
{var c=wl.$(this.c_id);if(c.firstChild==null)c.appendChild(wl.$e("b"));if(c.firstChild.firstChild==null)c.firstChild.appendChild(wl.$e("b"));if(c.firstChild.firstChild.firstChild==null)c.firstChild.firstChild.appendChild(wl.$e("b"));c.onclick=this.click.bind(this);if(c.tagName=="BUTTON"&&wl.browser.ie&&wl.browser.v<=7&&c.form)
{var submit=c.form.onsubmit;c.form.onsubmit=function(){if(c.__allowSubmited)c.value=c.innerText;else c.disabled=true;if(typeof(submit)=="function")return submit();}}
preloadButtonImages(c);}
var returnTrue=function(){return true;}
this.setCssClass=function(cssClass)
{var c=wl.$(this.c_id);if(c){wl.Utils.setNew(c,"className","button "+cssClass);preloadButtonImages(c);}}
var bigbtn=false;var preloadButtonImages=function(c)
{var a=[];if(a.length)wl.Utils.preloadImages(null,a);}
this.setLicon=function(icon)
{if(icon)getLiconContainer(wl.$(this.c_id),true).lastChild.className=icon;else{var c=getLiconContainer(wl.$(this.c_id),false);if(c)c.parentNode.removeChild(c);}}
this.setRicon=function(icon)
{if(icon)getRiconContainer(wl.$(this.c_id),true).lastChild.className=icon;else{var c=getLiconContainer(wl.$(this.c_id),false);if(c)c.parentNode.removeChild(c);}}
var getLiconContainer=function(c,bCreate)
{var b=c.firstChild.firstChild.firstChild;var c_icon=b.firstChild;if(bCreate&&(!c_icon||c_icon.tagName!="SPAN"||c_icon.className!="button-licon"||!c_icon.lastChild||c_icon.lastChild.tagName!="IMG"))
{c_icon=wl.$e("SPAN");c_icon.className="button-licon";var icon=wl.$e("IMG");icon.src=wl.pixel;c_icon.appendChild(icon);b.insertBefore(c_icon,b.firstChild);}
return c_icon&&c_icon.tagName=="SPAN"&&c_icon.className=="button-licon"&&c_icon.lastChild&&c_icon.lastChild.tagName=="IMG"?c_icon:null;}
var getRiconContainer=function(c,bCreate)
{var b=c.firstChild.firstChild.firstChild;var c_icon=b.lastChild;if(bCreate&&(!c_icon||c_icon.tagName!="SPAN"||c_icon.className!="button-ricon"||!c_icon.lastChild||c_icon.lastChild.tagName!="IMG"))
{c_icon=wl.$e("SPAN");c_icon.className="button-ricon";var icon=wl.$e("IMG");icon.src=wl.pixel;c_icon.appendChild(icon);b.appendChild(c_icon);}
return c_icon&&c_icon.tagName=="SPAN"&&c_icon.className=="button-ricon"&&c_icon.lastChild&&c_icon.lastChild.tagName=="IMG"?c_icon:null;}
this.setText=function(text,title)
{var c=wl.$(this.c_id);if(c)
{if(typeof(title)=="number")title=wl.S(title);if(typeof(text)=="number")
{var b=c.firstChild.firstChild;if(b.attributes["localeID"]==null)
b.setAttribute("localeID",0);b.attributes["localeID"].nodeValue=text;text=wl.S(text);}
var licon=getLiconContainer(c,false);var ricon=getRiconContainer(c,false);var b=c.firstChild.firstChild.firstChild;b.innerHTML=text;c.title=title||b.textContent||b.innerText||"";if(licon)b.insertBefore(licon,b.firstChild);if(ricon)b.appendChild(ricon);}}
this.click=function(e)
{var cancel=true;if(!this.isDisabled()&&!wl.fireEvent(this,"check").isFalse&&!wl.fireEvent(this,"click").isFalse)cancel=false;try
{var c=wl.$(this.c_id);if(c.href&&c.href.indexOf("#")>=0)cancel=true;c.blur();}catch(ex){}
if(cancel)return false;this.doPostBack();}
this.doPostBack=function(){var c=wl.$(this.c_id);if(c.tagName=="BUTTON"){c.__allowSubmited=true;var pb=this.doPostBack;this.doPostBack=empty;c.click();this.doPostBack=pb;}}
var empty=function(){}
this.ondisabled=function(state)
{var c=wl.$(this.c_id);if(c)wl.Utils.updateCss(c,"disabled",state);}});CALENDAR_MODE={Normal:0,SelectDay:1};CALENDAR_ITEM_TYPE={ThisDay:1,ThisMonth:2,OutMonth:3,OutPeriod:4};wl.Controls.Calendar=wl.Class(wl.Controls.Control,function(base)
{this.constructor=function()
{base.constructor.call(this);this.mode=CALENDAR_MODE.Normal;this.showTime=false;this.timeInterval=1;this.current=new Date();this.from=new Date();this.to=new Date();this.modes={};this.modes[CALENDAR_MODE.Normal]={};this.modes[CALENDAR_MODE.SelectDay]={current:new Date(2001,0,1),from:new Date(2001,0,1),to:new Date(2001,0,31)};this.datePanel=new wl.Controls.Calendar.DatePanel(this);this.dateMatrix=new wl.Controls.Calendar.DateMatrix(this);this.timePanel=new wl.Controls.Calendar.TimePanel(this);}
this.ongenerate=function()
{var c=wl.$(this.c_id);wl.Utils.clean_container(c);wl.Utils.addCss(c,"calendar");wl.Utils.select_action(c,null);if(c.tBodies.length==0)c.appendChild(wl.$e("tbody"));var tbody=c.tBodies[0];wl.Utils.clean_container(tbody);this.datePanel.create(tbody);this.dateMatrix.create(tbody);this.timePanel.create(tbody);this.update();}
this.setCurrent=function(current)
{var old=this.current;this.current=new Date(Math.middle(this.from.valueOf(),current.valueOf(),this.to.valueOf()));if(this.current.getMonth()!=old.getMonth()||this.current.getFullYear()!=old.getFullYear())this.update();this.dateMatrix.selectItem(this.current);if(this.current.valueOf()!=old.valueOf()){wl.$h(this.c_id+"_current",this.current.valueOf(),wl.$(this.c_id));wl.fireEvent(this,"change");}}
this.getCurrent=function(){return this.current.clone();}
this.resetCurrent=function(y,m,d,h,min)
{if(y==null)y=this.current.getFullYear();if(m==null)m=this.current.getMonth();if(d==null)d=this.current.getDate();if(h==null)h=this.current.getHours();if(min==null)min=this.current.getMinutes();this.setCurrent(new Date(y,m,d,h,min));}
this.setPeriod=function(from,to){if(from)this.from=from;if(to)this.to=to;this.update();}
this.isInPeriod=function(date)
{return this.from.valueOf()<=date.valueOf()&&date.valueOf()<=this.to.valueOf();}
this.update=function()
{this.datePanel.update();this.dateMatrix.update();this.timePanel.update();wl.$(this.timePanel.c_id).style.display=(!this.showTime||this.mode==CALENDAR_MODE.SelectDay)?"none":"";}
this.setMode=function(mode)
{if(this.mode!=mode)
{this.modes[this.mode].current=this.current;this.modes[this.mode].from=this.from;this.modes[this.mode].to=this.to;this.current=this.modes[mode].current;this.from=this.modes[mode].from;this.to=this.modes[mode].to;wl.$h(this.c_id+"_current",this.current.valueOf(),wl.$(this.c_id));wl.$(this.datePanel.c_id).style.display=mode==CALENDAR_MODE.SelectDay?"none":"";this.dateMatrix.weekdaysContainer.style.display=mode==CALENDAR_MODE.SelectDay?"none":"";wl.$(this.timePanel.c_id).style.display=(!this.showTime||mode==CALENDAR_MODE.SelectDay)?"none":"";this.mode=mode;this.update();}};(function(){var set_input_value=function(c,value){if(c&&c.value!=value){c.value=value;wl.fireEvent(c,"change");}}
var currentLinkedID=null;this.linkControl=function(c,options)
{if(!options)options={};options.i_id=wl.uniqueID(c);if(!options.c_id)options.c_id=this.c_id;if(!options.format)options.format=CultureInfo.Date.formatPatterns.shortDate;if(options.initValue==null)options.initValue=this.getCurrent();on_change.call(this,options);if(!c.value&&options.initValue)set_input_value(c,options.initValue.toString(options.format));wl.attachEvent(this,"change",on_change.bind(this,options));wl.attachEvent(c,"click",show_calendar.bind(this,options));}
var on_change=function(options,e)
{var c=currentLinkedID&&wl.$(currentLinkedID);if(c==null)
{var cont=wl.$(options.c_id);if(cont)cont.style.display="none";return;}
if(c.tagName=="INPUT")set_input_value(c,this.getCurrent().toString(options.format));else
{c.innerHTML="";c.appendChild(document.createTextNode(this.getCurrent().toString(options.format)));}}
var show_calendar=function(options)
{currentLinkedID=options.i_id;var c=wl.$(options.i_id);if(c.tagName=="INPUT")
{var d=Date.parseExact(c.value,options.format);if(d!=null)this.setCurrent(d);else set_input_value(c,this.getCurrent().toString(options.format));}
wl.popup_show(wl.$(options.c_id),{closeWithClick:true,opacity:0,relativeElement:c});}}).call(this);this.linkDateToCalendar=function(calendar)
{wl.attachEvent(this,"change",(function(){calendar.setPeriod(this.getCurrent(),null);calendar.setCurrent(calendar.getCurrent());}).bind(this));wl.attachEvent(calendar,"change",(function(){this.setPeriod(null,calendar.getCurrent());this.setCurrent(this.getCurrent());}).bind(this));this.setPeriod(null,calendar.getCurrent());calendar.setPeriod(this.getCurrent(),null);}});wl.Controls.Calendar.DatePanel=wl.Class(Object,function()
{this.constructor=function(calendar)
{this.control=calendar;}
this.create=function(container)
{var row=wl.$e("tr");var cell=wl.$e("td");var panel=wl.$e("table");this.c_id=wl.uniqueID(panel);panel.style.tableLayout="fixed";panel.style.width="100%";panel.cellPadding="0px";panel.cellSpacing="0px";var tbody=wl.$e("tbody");var prow=wl.$e("tr");var pcell=wl.$e("td");var table1=wl.$e("table");table1.style.tableLayout="fixed";table1.style.width="100%";table1.cellPadding="0px";table1.cellSpacing="0px";var tbody1=wl.$e("tbody");var row1=wl.$e("tr");var col11=wl.$e("td");col11.className="calendar-prev";col11.onclick=prev_click.bind(this.control);col11.appendChild(wl.$e("div"));var col21=wl.$e("td");col21.style.width="8px";var col31=wl.$e("td");col31.className="calendar-current";var col41=wl.$e("td");col41.style.width="8px";var col51=wl.$e("td");col51.textAlign="top";col51.className="calendar-next";col51.onclick=next_click.bind(this.control);col51.appendChild(wl.$e("div"));row1.appendChild(col11);row1.appendChild(col21);row1.appendChild(col31);row1.appendChild(col41);row1.appendChild(col51);tbody1.appendChild(row1);table1.appendChild(tbody1);pcell.appendChild(table1);prow.appendChild(pcell);tbody.appendChild(prow);prow=wl.$e("tr");pcell=wl.$e("td");var table2=wl.$e("table");table2.style.width="100%";table2.cellPadding="0px";table2.cellSpacing="0px";var tbody2=wl.$e("tbody");var row2=wl.$e("tr");var col12=wl.$e("td");col12.style.width="70%";var col22=wl.$e("td");col22.style.width="8px";var col32=wl.$e("td");col32.style.width="30%";row2.appendChild(col12);row2.appendChild(col22);row2.appendChild(col32);tbody2.appendChild(row2);table2.appendChild(tbody2);pcell.appendChild(table2);prow.appendChild(pcell);tbody.appendChild(prow);panel.appendChild(tbody);cell.appendChild(panel);row.appendChild(cell);container.appendChild(row);var select_month=wl.$e("select");select_month.className="input";select_month.style.width="100%";var select_year=wl.$e("select");select_year.className="input";select_year.style.width="100%";var in_month=wl.$e("span");this.m_id=wl.uniqueID(select_month);this.y_id=wl.uniqueID(select_year);this.n_id=wl.uniqueID(in_month);col31.appendChild(in_month);col12.appendChild(select_month);col32.appendChild(select_year);select_month.onchange=update_month.bind(this.control);select_year.onchange=update_year.bind(this.control);}
var update_month=function(e){this.resetCurrent(null,parseInt(wl.getEvent(e).target.value),null);this.update();}
var update_year=function(e){this.resetCurrent(parseInt(wl.getEvent(e).target.value),null,null);this.update();}
var create_option=function(t,v){var o=wl.$e("option");o.innerHTML=t;o.value=v;return o;}
var prev_click=function(){var date=this.current.clone();date.addMonths(-1);this.resetCurrent(date.getFullYear(),date.getMonth());}
var next_click=function(){var date=this.current.clone();date.addMonths(+1);this.resetCurrent(date.getFullYear(),date.getMonth());}
this.update=function()
{if(this.control.mode==CALENDAR_MODE.SelectDay)return;var select_month=wl.$(this.m_id);var select_year=wl.$(this.y_id);var yfrom=this.control.from.getFullYear();var yto=this.control.to.getFullYear();var i=yfrom;if(select_year.options.length>0)
{while(yfrom>parseInt(select_year.options[0].value))
select_year.removeChild(select_year.options[0]);var first=select_year.options[0];var yto2=Math.min(yto,parseInt(first.value)-1);for(;i<=yto2;++i)
select_year.insertBefore(create_option(i,i),first);while(yto<parseInt(select_year.options[select_year.options.length-1].value))
select_year.removeChild(select_year.options[select_year.options.length-1]);i=parseInt(select_year.options[select_year.options.length-1].value)+1;}
for(;i<=yto;++i)select_year.appendChild(create_option(i,i));var cur=this.control.current.toUserZone();var mfrom=(yfrom==cur.getFullYear())?this.control.from.toUserZone().getMonth():0;var mto=(yto==cur.getFullYear())?this.control.to.toUserZone().getMonth():11;var i=mfrom;if(select_month.options.length>0)
{if(mfrom>parseInt(select_month.options[select_month.options.length-1].value))
wl.Utils.clear_container(select_month);else
{while(mfrom>parseInt(select_month.options[0].value))
select_month.removeChild(select_month.options[0]);var first=select_month.options[0];var mto2=Math.min(mto,parseInt(first.value)-1);for(;i<=mto2;++i)
select_month.insertBefore(create_option(CultureInfo.Date.monthNames[i],i),first);while(mto<parseInt(select_month.options[select_month.options.length-1].value))
select_month.removeChild(select_month.options[select_month.options.length-1]);i=parseInt(select_month.options[select_month.options.length-1].value)+1;}}
for(;i<=mto;++i)select_month.appendChild(create_option(CultureInfo.Date.monthNames[i],i));wl.$(this.n_id).innerHTML=String.format("{0}, {1}",CultureInfo.Date.monthNames[cur.getMonth()],cur.getFullYear());select_month.value=cur.getMonth();select_year.value=cur.getFullYear();}});wl.Controls.Calendar.DateMatrix=wl.Class(Object,function()
{this.constructor=function(calendar)
{this.control=calendar;}
this.create=function(container)
{var row=wl.$e("tr");var cell=wl.$e("td");var table=wl.$e("table");table.cellSpacing="0px";table.cellPadding="0px";var tbody=wl.$e("tbody");table.className="calendar-matrix";var title_row=wl.$e("tr");for(var j=0;j<7;++j)
{var week_day=wl.$e("td");week_day.className="calendar-week-day";week_day.innerHTML=CultureInfo.Date.shortestDayNames[j];title_row.appendChild(week_day);}
this.weekdaysContainer=title_row;tbody.appendChild(title_row);this.matrix=new Array(6);for(var i=0;i<6;++i)
{var week_row=wl.$e("tr");this.matrix[i]=new Array(7);for(var j=0;j<7;++j)
{var day=wl.$e("td");this.matrix[i][j]=new wl.Controls.Calendar.DateMatrix.Item(this.control);this.matrix[i][j].create(day);week_row.appendChild(day);}
tbody.appendChild(week_row);}
for(var i=0;i<7;++i)
this.matrix[0][i].item.style.borderTopWidth="1px";table.appendChild(tbody);cell.appendChild(table);row.appendChild(cell);container.appendChild(row);}
this.update=function()
{var i=0,j=0;var date=this.control.current.toUserZone();date.moveToFirstDayOfMonth(1);var firstWeekDay=date.getDay();if(firstWeekDay!=0)
{date.addMonths(-1);date.set({day:date.getDaysInMonth()-firstWeekDay+1});for(j=0;date.getDate()!=1;++j,date.addDays(1))
{this.matrix[0][j].setValue(date.fromUserZone(),CALENDAR_ITEM_TYPE.OutMonth);}}
for(;j<7;++j,date.addDays(1))
this.matrix[0][j].setValue(date.fromUserZone(),CALENDAR_ITEM_TYPE.ThisMonth);var torow=Math.floor((date.getDaysInMonth()-date.getDate())/7);for(var i=1;i<=torow;++i)
for(j=0;j<7;++j,date.addDays(1))
this.matrix[i][j].setValue(date.fromUserZone(),CALENDAR_ITEM_TYPE.ThisMonth);for(i=torow+1,j=0;date.getDate()!=1&&j<7;++j,date.addDays(1))
this.matrix[i][j].setValue(date.fromUserZone(),CALENDAR_ITEM_TYPE.ThisMonth);for(;i<6;++i,j=0)
for(;j<7;++j,date.addDays(1))
this.matrix[i][j].setValue(date.fromUserZone(),CALENDAR_ITEM_TYPE.OutMonth);this.selectItem(this.control.current);}
this.selectItem=function(date)
{if(this.selectedItem)
this.selectedItem.setStyle();for(var i=0;i<6;++i)
for(var j=0;j<7;++j)
if(wl.Utils.Comparers.date(date,this.matrix[i][j].getValue())==0)
{this.selectedItem=this.matrix[i][j];this.selectedItem.setStyle(CALENDAR_ITEM_TYPE.ThisDay);}}});wl.Controls.Calendar.DateMatrix.Item=wl.Class(Object,function()
{this.constructor=function(calendar)
{this.control=calendar;}
this.create=function(container)
{this.item=container;wl.attachEvent(container,"click",this.click.bind(this));}
this.click=function(){this.control.resetCurrent(this.item.value.getFullYear(),this.item.value.getMonth(),this.item.value.getDate());}
this.setValue=function(date,type)
{this.item.innerHTML=date.toUserZone().getDate();this.item.value=date;this.item.type=this.control.isInPeriod(date)?type:CALENDAR_ITEM_TYPE.OutPeriod;this.setStyle();}
this.getValue=function(){return this.item.value;}
this.setStyle=function(type)
{if(type==null)type=this.item.type;switch(type)
{case CALENDAR_ITEM_TYPE.ThisDay:this.item.className="calendar-day-current";break;case CALENDAR_ITEM_TYPE.ThisMonth:this.item.className="calendar-day";break;case CALENDAR_ITEM_TYPE.OutMonth:this.item.className="calendar-day-outmonth";break;case CALENDAR_ITEM_TYPE.OutPeriod:this.item.className="calendar-day-outperiod";break;}}});wl.Controls.Calendar.TimePanel=wl.Class(Object,function()
{this.constructor=function(calendar)
{this.control=calendar;}
this.create=function(container)
{var row=wl.$e("tr");var cell=wl.$e("td");var panel=wl.$e("table");this.c_id=wl.uniqueID(panel);panel.style.tableLayout="fixed";panel.style.width="100%";panel.cellPadding="0px";panel.cellSpacing="0px";var tbody=wl.$e("tbody");var prow=wl.$e("tr");var pcell=wl.$e("td");var table2=wl.$e("table");table2.style.width="100%";table2.cellPadding="0px";table2.cellSpacing="0px";var tbody2=wl.$e("tbody");var row2=wl.$e("tr");var col12=wl.$e("td");col12.style.width="50%";var col22=wl.$e("td");col22.style.width="8px";col22.innerHTML=":";var col32=wl.$e("td");col32.style.width="50%";row2.appendChild(col12);row2.appendChild(col22);row2.appendChild(col32);tbody2.appendChild(row2);table2.appendChild(tbody2);pcell.appendChild(table2);prow.appendChild(pcell);tbody.appendChild(prow);panel.appendChild(tbody);cell.appendChild(panel);row.appendChild(cell);container.appendChild(row);var select_hour=wl.$e("select");select_hour.className="input";select_hour.style.width="100%";var select_minute=wl.$e("select");select_minute.className="input";select_minute.style.width="100%";this.h_id=wl.uniqueID(select_hour);this.m_id=wl.uniqueID(select_minute);col32.appendChild(select_minute);col12.appendChild(select_hour);for(var i=0;i<24;++i)
select_hour.appendChild(create_option(i.toString(),i));for(var i=0;i<60;i+=this.control.timeInterval)
select_minute.appendChild(create_option(i.toString(),i));select_hour.onchange=update_hours.bind(this.control);select_minute.onchange=update_minutes.bind(this.control);}
var update_minutes=function(e)
{var cur=this.current.toUserZone();cur.set({minute:parseInt(wl.getEvent(e).target.value)});this.setCurrent(cur.fromUserZone());this.update();}
var update_hours=function(e)
{var cur=this.current.toUserZone();cur.set({hour:parseInt(wl.getEvent(e).target.value)});this.setCurrent(cur.fromUserZone());this.update();}
var create_option=function(t,v){var o=wl.$e("option");o.innerHTML=t;o.value=v;return o;}
this.update=function()
{if(this.control.mode==CALENDAR_MODE.SelectDay)return;var cur=this.control.current.toUserZone();wl.Utils.selectNumberValue(wl.$(this.h_id),cur.getHours());wl.Utils.selectNumberValue(wl.$(this.m_id),cur.getMinutes());}});wl.Controls.Pager=wl.Class(wl.Controls.Control,function(base)
{this.constructor=function()
{base.constructor.call(this);this.pagesCount=0;this.pagesPerLine=10;this.currentPage=-1;this.href="#";}
this.ongenerate=function()
{var c=wl.$(this.c_id);for(var i=c.childNodes.length-1;i>=0;--i)
if(c.childNodes[i].nodeType!=1)c.removeChild(c.childNodes[i]);}
this.setCssClass=function(cssClass)
{var c=wl.$(this.c_id);if(c)wl.Utils.setNew(c,"className",cssClass);}
this.linkTo=function(pc)
{this.pagesPerLine=pc.pagesPerLine;this.href=pc.href.indexOf("#")>=0?pc.href:pc.href+'#';wl.attachEvent(pc,"pageselect",(function(e){this.selectPage(e.page,{skipInvoke:true});}).bind(this));wl.attachEvent(pc,"pagecountchange",(function(e){this.setPagesCount(e.pages,{skipInvoke:true});}).bind(this));wl.attachEvent(this,"pageselect",function(e){pc.selectPage(e.page);});this.setPagesCount(pc.pagesCount,{skipInvoke:true});this.selectPage(pc.currentPage,{skipInvoke:true});}
this.setPagesCount=function(pagesCount,p)
{if(this.pagesCount==pagesCount)return;if(!p)p={skipInvoke:false};this.pagesCount=pagesCount;if(!p.skipInvoke)wl.fireEvent(this,"pagecountchange",{pages:pagesCount});if(this.currentPage==-1){this.selectPage(Math.min(0,this.pagesCount-1),p);return;}
if(this.currentPage>=this.pagesCount){this.selectPage(this.pagesCount-1,p);return;}
this.update();}
this.update=function()
{var c=wl.$(this.c_id);resizeChildren.call(this,c,Math.min(this.pagesCount,this.pagesPerLine));if(this.pagesCount==0)return;var handler=pageSelect.bind(this);var pi=0;var shl=Math.floor((this.pagesPerLine-2)/2);var p=Math.max(0,Math.min(this.pagesCount-this.pagesPerLine,this.currentPage-shl));updatePage.call(this,c.childNodes[pi++],0,p++>0?"&lt;&lt;":null,handler);var prev=p-this.pagesPerLine+shl+3;if(prev>0)
updatePage.call(this,c.childNodes[pi++],prev,"&lt;",handler);else
updatePage.call(this,c.childNodes[pi++],p,null,handler);p++;for(;pi<c.childNodes.length-2;++pi,++p)
updatePage.call(this,c.childNodes[pi],p,null,handler);if(p<this.pagesCount-2)
updatePage.call(this,c.childNodes[pi++],p,"&gt;",handler);else
updatePage.call(this,c.childNodes[pi++],p,null,handler);p++;updatePage.call(this,c.childNodes[pi++],this.pagesCount-1,p<this.pagesCount-1?"&gt;&gt;":null,handler);}
this.selectPage=function(pageNumber,p)
{if(this.currentPage==pageNumber||this.isDisabled())return false;if(!p)p={skipInvoke:false};this.currentPage=pageNumber;if(!p.skipInvoke)wl.fireEvent(this,"pageselect",{page:pageNumber});this.update();return true;}
this.selectLastPage=function(p){this.selectPage(Math.max(0,this.pagesCount-1),p);}
var resizeChildren=function(el,size)
{var dist=size-el.childNodes.length;if(dist>0)while(dist-->0)
{var a=wl.$e("a");el.appendChild(a);}
else
if(dist<0)while(dist++<0)el.removeChild(el.lastChild);}
var updatePage=function(a,number,text,handler)
{if(!a)return;a.href=String.format(this.href,number+1);a.onclick=handler;a.pageNumber=number;a.title=number+1;a.innerHTML=text||(number+1).toString();wl.Utils.setNew(a,"className",number==this.currentPage?"page-current":"");}
var pageSelect=function(e)
{e=wl.getEvent(e);var cancel=!this.selectPage(e.target.pageNumber);if(e){try
{if(e.target.href.indexOf("#")>=0)cancel=true;e.target.blur();}catch(ex){}
if(cancel)return false;}}});wl.Controls.TabControlBase=wl.Class(wl.Controls.Control,function(base)
{this.constructor=function()
{base.constructor.call(this);this.items=[];}
this.clear=function(){this.items.clear();}
this.$=function(id)
{for(var i=0;i<this.items.length;++i)
if(this.items[i].id==id)return this.items[i].getContainer();return null;}
this.$$=function(id)
{for(var i=0;i<this.items.length;++i)
if(this.items[i].id==id)return this.items[i];return null;}
this.render=function()
{if(this.tc_id!=null)
{var pool=wl.queryElementsPool();for(var i=0;i<this.items.length;++i)
pool.put(this.items[i].getElement());var tabs=wl.$(this.tabs_id);wl.Utils.clear_container(tabs);for(var i=0;i<this.items.length;++i)
if(!this.items[i].data.hidden)
tabs.appendChild(pool.get(this.items[i].e_id));if(tabs.firstChild)
tabs.style.lineHeight=tabs.clientHeight+Math.max(0,tabs.clientHeight-tabs.firstChild.offsetHeight)+"px";}
if(this._onresize)this._onresize();}
this.selectItem=function(item,p)
{if(!p)p={skipInvoke:false};if(this.isDisabled()||item==null||item.data.hidden||item==this.selectedItem)return false;if(!p.skipInvoke&&wl.fireEvent(this,"selecting",{item:item}).isFalse)return false;var prevItem=this.selectedItem;if(this.selectedItem)
this.selectedItem._activate(false);this.selectedItem=item;item._activate(true);if(!p.skipInvoke)wl.fireEvent(this,"select",{item:item,prevItem:prevItem});this.onselected();return true;}
this.onselected=function(){}
this.getIndex=function(item){for(var i=0;i<this.items.length;++i)if(this.items[i]==item||this.items[i].id==item)return i;return-1;}
this.selectItemByIndex=function(index){return this.selectItem(this.items[index]);}
this.selectFirstItem=function()
{for(var i=0;i<this.items.length;++i)
if(!this.items[i].data.hidden)
return this.selectItem(this.items[i]);}
this.findItem=function(finder,includeHidden)
{for(var i=0;i<this.items.length;++i)
if(!includeHidden||!this.items[i].data.hidden)
if(finder(this.items[i]))return this.items[i];return null;}
this.unselect=function()
{if(this.selectedItem)
{this.selectedItem._activate(false);this.selectedItem=null;}}
this.ondisabled=function(state)
{for(var i=0;i<this.items.length;++i)
this.items[i].getElement().disabled=state;}
this.resize_engine=function()
{if(this.tc_id&&this._onresize)
wl.resizeManager.attachEvent(wl.$(this.c_id),{check:"width"},this._onresize.bind(this));}});wl.Controls.TabControl=wl.Class(wl.Controls.TabControlBase,function(base)
{this.constructor=function()
{base.constructor.call(this);}
this.ongenerate=function()
{if(this.tc_id!=null)
{var tcrow=wl.$(this.tc_id).rows[0];this.tabs_id=wl.uniqueID(tcrow.cells[0].firstChild);this.ul_id=tcrow.cells[3].firstChild?wl.uniqueID(tcrow.cells[3]):null;setupArrows.call(this);}}
this.createTabItem=function(id,data,c_id){return new wl.Controls.TabControl.Item(this.c_id,id,data,c_id);}
var calcContainerWidth=function(c)
{var w=0,ct=null;for(var i=0;i<c.childNodes.length;++i)
{var n=c.childNodes[i];if(n.nodeType==1&&n.style.display!="none")
w+=n.offsetWidth+parseInt(window.getComputedStyle(n,null).marginLeft).NaN0()+parseInt(window.getComputedStyle(n,null).marginRight).NaN0();if(n.nodeType==3)
{if(!ct){ct=wl.$e("span",c);ct.style.whiteSpace="nowrap";}
ct.innerHTML="";ct.appendChild(n.cloneNode(true));w+=ct.offsetWidth+3;}}
if(ct)c.removeChild(ct);return w;}
var setupArrows=function()
{var r=wl.$(this.tc_id).rows[0];var lArrow=r.cells[1];var rArrow=r.cells[2];lArrow.firstChild.onmousedown=startItemsScroll.bind(this,-10);rArrow.firstChild.onmousedown=startItemsScroll.bind(this,10);this.la_id=wl.uniqueID(lArrow);this.ra_id=wl.uniqueID(rArrow);}
this._onresize=function()
{if(this.tc_id!=null)
{var tabsWidth=calcContainerWidth(wl.$(this.tabs_id));var userLayoutWidth=this.ul_id?calcContainerWidth(wl.$(this.ul_id)):0;var width=wl.$(this.c_id).offsetWidth-2;var display=tabsWidth+userLayoutWidth>=width?"":"none";wl.Utils.setNew(wl.$(this.la_id).style,"display",display);wl.Utils.setNew(wl.$(this.ra_id).style,"display",display);if(this.ul_id)wl.$(this.ul_id).style.width=Math.middle(100,width-wl.$(this.la_id).firstChild.offsetWidth-wl.$(this.ra_id).firstChild.offsetWidth-100,userLayoutWidth)+"px";}}
var startItemsScroll=function(dx,e)
{var arrow_id=wl.uniqueID(wl.getEvent(e).target);var cookie=window.setInterval((function(){wl.$(this).scrollLeft+=dx;dx*=1.1;}).bind(this.tabs_id),50);var stopItemsScroll=function()
{wl.$(arrow_id).style.backgroundPositionX="left";window.clearInterval(cookie);wl.detachEvent(document,"mouseup",stopItemsScroll);};wl.$(arrow_id).style.backgroundPositionX="right";wl.attachEvent(document,"mouseup",stopItemsScroll);}});wl.Controls.TabControl.Item=wl.Class(Object,function()
{this.constructor=function(tabcontrol_id,id,data,c_id)
{this.tc_id=tabcontrol_id;this.id=id;this.data=data;this.c_id=c_id;this.generate();}
this.getContainer=function(){return wl.$(this.c_id);}
this.getElement=function(){return wl.$(this.e_id);}
this.generate=function()
{var element=wl.$e("a");element.href="#";element.className="tab-item";this.e_id=wl.uniqueID(element);var n=wl.$e("b",element);this.n_id=wl.uniqueID(n);if(this.data.title)element.title=this.data.title;if(this.data.name||this.data.icon)
{var t=wl.$e("b",n);if(this.data.icon)
{var ico=wl.$e("img",t);ico.src=wl.pixel;ico.className=this.data.icon;}
if(this.data.name)wl.$t(this.data.name,t);}
element.onclick=this.select.bind(this);wl.queryElementsPool().put(element);}
this.select=function(p){wl.$$(this.tc_id).selectItem(this,p);return false;}
this.getID=function(){return this.id;}
this.setName=function(name){this.data.name=name;var t=wl.$(this.n_id).firstChild;t.innerHTML="";t.appendChild(document.createTextNode(name));}
this.getName=function(){return this.data.name;}
this._activate=function(state)
{wl.$(this.e_id).className=state?"tab-item tab-item-active":"tab-item";var c=wl.$(this.c_id);if(c){var width=Math.middle(200,c.offsetWidth,2000);wl.Utils.setNew(c.style,"visibility",state?"visible":"hidden");wl.Utils.setNew(c.style,"left",state?"":-(width+100)+"px");wl.Utils.setNew(c.style,"width",state?"":width+"px");wl.Utils.setNew(c.style,"overflow",state?"":"hidden");wl.Utils.setNew(c.style,"position",state?"static":"absolute");}}
this.hide=function(bHide,bUpdate)
{this.data.hidden=bHide;if(bUpdate)wl.$$(this.tc_id).render();}});
