window.loading=[];function startup()
{act._search('hide');act._paging('hide');act._status('','hide');if(window.loading){try{loading.forEach(eval);}catch(e){}}}window.addEvent('domready',startup);var ACT=new Class({Implements:[Options,Events],options:{},initialize:function(options){this.setOptions(options);},_list:function(){var div=$('content_div');var lc=$('limit_count');if(!div)return false;if(lc)Cookie.write('limit_count',lc.value,{path:'/',duration:'30'});if($('list_div'))$('list_div').fade(0.5);this._status('loading...','gray');return rpc._list({'frm':div.toQueryString()},function(json){var div=$('list_div');if(!div)return false;div.set('html',json.html);div.fade(1);});},_new:function(){return rpc._new();},_edit:function(id){return rpc._edit({'id':id});},_delete:function(id){if(confirm(T_('Do you want to delete this record?')))
return rpc._delete({'id':id});return false;},_save:function(f,e){e=new Event(e);var div=$('edit_container');if(!div)return false;var el=new Element('input');el.setProperty('type','hidden');el.setProperty('name','inp[]');el.setProperty('value',div.toQueryString());el.injectInside('edit_form');if(!e.control){act._status('updating record','','gray');act._cancel();}else{f.getElement('input[name=cmd]').value='insert';f.getElement('input[name=id]').value='0';act._status('insert as new record','','gray');}},_update:function(f,id){return rpc._update({'id':id,frm:f.toQueryString()});},_insert:function(f){return rpc._insert({frm:f.toQueryString()});},_search:function(w){if(w=='toggle'||w=='hide'||w=='show'){if($('search_div'))$('search_div').slide(w);return true;}},_paging:function(w){if(w=='toggle'||w=='hide'||w=='show'){if($('paging_div'))$('paging_div').slide(w);return true;}},_goto:function(p,e){e=new Event(e);if(e.control)return true;var lc=$('limit_count');var lo=$('limit_offset');if(!lc||!lo)return false;lo.value=lc.value*(p-1);this._list();return false;},_status:function(txt,mode,cl){var div=$('status');if(!div)return false;var fx1=new Fx.Tween(div,{'link':'chain','duration':'short'});var fx2=new Fx.Tween(div,{'link':'chain','duration':'short'});fx1.start('opacity',0);fx1.addEvent('complete',function(){div.set('html',txt);div.set('class',cl);fx2.start('opacity',1);}.bind(this));if(mode=='fadeout'){div.t=div.fade.delay(3000,div,['out']);}return true;},_cancel:function(){var div;if(cmd.indexOf('edit')!=-1){var url=document.location.href.replace(/\/edit\/\d+.*/,'');document.location.href=url;return;}if(div=$('edit_container')){var fx1=new Fx.Tween(div,{'link':'chain','duration':'short'});fx1.start('opacity',0).chain(function(){$('edit_container').set('html','');});}},_call:function(){}});act=new ACT();function url(opt)
{var h=document.location.pathname.substr(1).split(/\/+/g);var url={'protocol':(opt.protocol?opt.protocol:document.location.protocol),'host':(opt.host?opt.host:document.location.host),'section':(opt.section?opt.section:(h[0]?h[0]:'index')),'module':(opt.module?opt.module:(h[1]?h[1]:'home')),'cmd':(opt.cmd?opt.cmd:(h[2]?h[2]:'')),'id':(opt.id?opt.id:(h[3]?h[3]:'0')),'rest':(opt.rest?opt.rest:(h[4]?'/'+h[4]:'')+(h[5]?'/'+h[5]:'')+(h[6]?'/'+h[6]:'')+(h[7]?'/'+h[7]:'')+(h[8]?'/'+h[8]:'')+(h[9]?'/'+h[9]:''))
};return url.protocol+'//'+url.host+'/'+url.section+'/'+url.module+'/'+url.cmd+'/'+url.id+url.rest+(document.location.search);}function rpc_call(func,arg)
{func=func.substr(1);var div=$('NULL');switch(func){case 'new':case 'edit':div=$('edit_box');if(!div)return false;div.fade('hide');break;case 'insert':case 'update':;break;case 'delete':;break;case 'list':div=$('list_div');if(!div)return false;div.fade(0.5);break;}act._status('requesting '+func,'','gray');var inp='';for(var i in arg){if(typeof(arg[i])=='string'||typeof(arg[i])=='number')
inp+='inp['+encodeURIComponent(i)+']='+encodeURIComponent(arg[i])+'&';}var id=(arg&&arg.id)?arg.id:0;var R=new Request.HTML({url:'/'+section+'/'+module+'/'+func+'/'+id,evalScripts:true,update:div});R.addEvent('success',function(responseText,responseXML){rpc_done(this.reqid,this.func);});R.addEvent('failure',function(){act._status('error in '+func+' call','','red');});R.reqid=Math.round((Math.random()*10000000000));R.func=func;R.send(inp+'_r_='+R.reqid);return true;}function rpc_done(id,func)
{act._status(func+' responded ok','fadeout','green');switch(func){case 'new':case 'edit':var div=$('edit_box');if(!div)return false;div.makeDraggable({handle:'edit_header'});div.setStyle('top',window.getScrollTop()+20+'px');var width=div.getFirst().getSize().x;div.setStyle('width',width+10+'px');div.setStyle('left',(window.getSize().x-width)/2-20+'px');div.fade('in');break;case 'insert':case 'update':;break;case 'delete':var row=$$('#mainlist .n'+Cookie.read('deleted'));console.log(row);if(row&&row[0])
row.dispose();break;case 'list':var div=$('list_div');if(!div)return false;div.fade(1);break;}return true;}var SHORT_KEY=new Class({initialize:function(){document.addEvent('keypress',function(e){var e=new Event(e);txt=[];if(e.alt)txt.push('alt');if(e.control)txt.push('control');if(e.shift)txt.push('shift');if(e.meta)txt.push('meta');txt.push(e.code);txt=txt.join('+');var done=true;switch(txt){case 'control+shift+6':case 'control+114':shortkey._search();break;case 'control+13':case 'control+10':case 'control+shift+10':case 'control+shift+19':case 'control+115':done=shortkey._save();break;case 'control+shift+82':done=shortkey._refresh();break;case 'control+shift+14':case 'control+110':done=shortkey._new();break;case 'control+shift+16':case 'control+112':done=shortkey._print();break;case '27':done=shortkey._cancel();break;default:return true;}if(done)e.stop();return!done;});},_search:function(){},_save:function(){act._update();return false;},_new:function(){act._new();return true;},_print:function(){},_refresh:function(){act._list();return true;},_cancel:function(){act._cancel();return true;}});shortkey=new SHORT_KEY();function T_(txt)
{if($msg&&$msg[txt])
return $msg[txt];return txt;}function readLog()
{var c=Cookie.read('log');if(!c||c==lastCookie)return;lastCookie=c;c=eval(c);act._status.delay(100,this,[decodeURI(c[1]),'fadeout',c[0]=='error'?'red':'green']);Cookie.dispose('log');}var lastCookie;readLog.periodical(5000);function printForm()
{var nw=window.open('','PrintWindow','width=720px,height=500px,scrollbars=yes');nw.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'+'<html>'+'<head>'+'<link type="text/css" rel="stylesheet" href="/assets/style.css" />'+'<title></title>'+'<script language="javascript" type="text/javascript" src="../+script/class.js"></script>'+'<script language="javascript" type="text/javascript">'+'function printWindow(){'+'document.body.innerHTML = window.opener.document.getElementById("Cont").innerHTML;'+'setTimeout("window.print();", 200);'+'}'+'</script>'+'<style type="text/css">'+'.button, .noprint{'+'display:none;'+'}'+'</style>'+'</head>'+'<body dir="rtl" onload="window.printWindow();"></body></html>');nw.document.close();}
function RestoreToggle(obj,id,page)
{$$('.opSlide'+page+'[rel!=1]').each(function(el){if(el==obj)return;var h=el.get('h');el.fx.start({'height':0,onComplete:function(){this.set('rel',1);this.getParent().getPrevious().removeClass('OpenRedArrow');}.bind(el)});});var obj=$(obj).getParent('#pageHolder');if(!obj)return;obj=obj.getElement('.'+id);var h=obj.get('h');if(obj.get('rel')==1){obj.fx.start({'height':h,onComplete:function(){this.set('rel',0);this.getParent().getPrevious().addClass('OpenRedArrow');}.bind(obj)
});obj.fx.start({'margin-top':0
});}else{obj.fx.start({'height':0,onComplete:function(){this.set('rel',1);this.getParent().getPrevious().removeClass('OpenRedArrow');}.bind(obj)
});obj.fx.start({'margin-top':-h
});}}function menuMaker(pos,dir)
{var dx1=165;var dy1=0;var dx2=0;var dy2=0;var menu=$(menu);var mul=(dir=='rtl'?-1:1);$$('ul.dropdown').each(function(el){el.addClass('dropdown_'+pos);el.addClass('dropdown_'+dir);el=el.getElement('li');do{el.addClass('first_li');}while(el=el.getNext('li'));});$$('ul.dropdown > li').each(function(el){el.addEvent('mouseenter',function(){stoper=setTimeout('stoper=0;',20);el.addClass('first_li_hover');$$('ul.dropdown li > ul').each(function(el2){el2.fade('hide');});var par=this;while(!par.hasClass('dropdown')){if(par.tagName.toLowerCase()=='ul'){par.setStyle('visibility','visible');}par=par.getParent('ul');}if(this.getElement('ul')){var ul=this.getElement('ul');if(ul.dropdownT)clearTimeout(ul.dropdownT);if(!ul)return;ul.fade(1);if(pos=='h'){if(this.hasClass('first_li')){var x=(dir=='rtl'?this.getPosition().x-ul.getSize().x+this.getSize().x:this.getPosition().x)+dx1;var y=this.getPosition().y+this.getSize().y+dy1;}else{var x=mul*(ul.getSize().x)+dx2;var y=this.getPosition().y-this.getSize().y+dy2;}}else{if(this.hasClass('first_li')){var x=ul.getSize().x+dx1;var y=this.getPosition().y+dy1;}else{var x=mul*(ul.getSize().x)+dx2;var y=this.offsetTop+dy2;}}ul.setStyle('left',x+'px');ul.setStyle('top',y+'px');}}.bind(el));el.addEvent('mouseleave',function(){el.removeClass('first_li_hover');var ul=this.getElement('ul');if(!ul)return;if(ul.dropdownT)clearTimeout(ul.dropdownT);if(stoper)clearTimeout(stoper);stoper=0;ul.dropdownT=ul.fade.delay(300,ul,[0]);}.bind(el));});}function changePic(cnt1)
{$$('.infront').each(function(el){el.removeClass('infront');el.setStyles({'width':'0','height':'0'});var transEffect=new Fx.Morph(el,{duration:0,transition:Fx.Transitions.Sine.easeOut});transEffect.start({opacity:1});});var pic=$$('.topBanner');var p1=pic[cnt1];var cnt2=(cnt1>=maxBannerCnt-1)?0:cnt1+1;var p2=pic[cnt2];p1.setStyles({'width':'948px','height':'235px','visibility':'visible','opacity':1});var transEffect=new Fx.Morph(p1,{duration:1000,transition:Fx.Transitions.Sine.easeOut});transEffect.start({opacity:0.001});$('topBanner_div').setStyle('background-image','url('+p2.src+')');p1.addClass('infront');setTimeout("changePic("+cnt2+");",8000);}function setHeight(){var sidebarHeight=$('sidebarBox').getSize().y;var contentHeight=$('contentBox').getSize().y;if(sidebarHeight>=contentHeight){$('contentHeight').setStyle('height',sidebarHeight+'px');}else{$('contentHeight').setStyle('height','auto');}}function initCbox()
{var cbox=new CeraBox();cbox.addImages('a[rel^=lightbox]',{animation:'ease',loaderAtItem:true,displayTitle:false,group:false
});}document.addEvent('domready',initCbox);function openPage(id)
{var name="adetail_r_"+id;$$('.sliderArrow').each(function(e3){e3.removeClass('openSlide');});$$('.pageDetail').each(function(el){if(el==$(name)){el.myfx.toggle();if(!el.myfx.open){$('test_'+id).addClass('openSlide');setTimeout(function(){setHeight();},500);}}else{if(el.myfx.open)
el.myfx.slideOut();}});}function hideAttraction()
{$$('.pageDetail').each(function(el){if(!el.myfx)
el.myfx=new Fx.Slide(el,{duration:500});el.myfx.hide();});}function disableSelection(target)
{if(typeof target.onselectstart!="undefined")target.onselectstart=function(){return false};else if(typeof target.style.MozUserSelect!="undefined")target.style.MozUserSelect="none";else	target.onmousedown=function(){return false};target.style.cursor="default";}document.addEvent('domready',function(){disableSelection(document.body);var tenth='';function ninth()
{if(document.all){(tenth);return false;}}function twelfth(e)
{if(document.layers||(document.getElementById&&!document.all)){if(e.which==2||e.which==3){(tenth);return false;}}}if(document.layers){document.captureEvents(Event.MOUSEDOWN);document.onmousedown=twelfth;}else{document.onmouseup=twelfth;document.oncontextmenu=ninth;}document.oncontextmenu=new Function('return false');});function checkSearch()
{var sbox=$$('.gsc-results.gsc-webResult')[0];if(!sbox){return false;}if(sbox.get('text').trim()&&$('contentHeight').get('html')!=sbox.get('html'))
{$$('.gsc-input').getChildren()[0].each(function(el){searchentry=el.value;});clearTimeout(checkSearchTimeOut);$('contentHeight').set('html','<div style="background:#FFF;padding-top:10px"><div class="title"><div class="titleLine"><span class="titleText">نتیجه جستجو: '+searchentry+'</span></div></div>'+sbox.get('html'));sbox.set('html','');}else{checkSearchTimeOut=checkSearch.delay(500);}}window.addEvent('load',function(){(initSearch=function(){$$('.gsc-search-button').addEvent('click',function(){$('contentHeight').set('html','');checkSearch();});}).delay(1000);});

