// JScript File 
// Scripts on pages Account


function getAccountData(){ 
			$accountManager.init();  

			//Page My Banners
            var elm_expr_msg_mb=$get('idExpireMsg');
			if(elm_expr_msg_mb){
				  if($accountManager.profile()['expired']!='true') { 
					 if ($accountManager.profile('isrebilling')=='true') {	
						   elm_expr_msg_mb.html('Monthly recurring subscription ');
						   if ($get('btnExtend')!=null) $get('btnExtend').style.display='none';
						   if ($get('expiere_msg')!=null) $get('expiere_msg').style.marginRight='15px';
						  // if ($get('btnCancelSub')!=null) $get('btnCancelSub').style.display='none';
						   
						 }
						 else {
					      elm_expr_msg_mb.html('Your glooq Outlook license will expire at {0}'.format($accountManager.profile('expire')));
						 }
					}
				    else {
						 elm_expr_msg_mb.html('Free limited version');
					}
				 }

			//Page Account Info
			     var elm_account_type=$get('idAccountType');
				 var elm=$get('idExpire');
				 
				 if(elm){
				  if($accountManager.profile()['expired']!='true') { 
                     if(elm_account_type) { elm_account_type.html('Full version');}
					 if ($accountManager.profile('isrebilling')=='true') {	
						   elm.html('Subscription account  <a href="javascript:$shop.rebill_cancel_request(rebill_cancel_request_calback);" style="margin-left: 5px;" ><img src="/wp-content/uploads/image/buttons/btn_cancel_subsc.gif" alt="" width="69" height="20" align="top" /></a>'.format(glooq_lang));
						   if ($get('btnExtend')!=null) $get('btnExtend').style.display='none';
						   if ($get('expiere_msg')!=null) $get('expiere_msg').style.marginRight='15px';
						  // if ($get('btnCancelSub')!=null) $get('btnCancelSub').style.display='none';
						   
						 }
						 else {
					      elm.html('Your glooq Outlook license will expire at {0} <a href="/shop/buy-now/?lang={0}" style="margin-left: 5px;" ><img src="/wp-content/uploads/image/buttons/btn_extend.gif" alt="" width="68" height="19" align="top" /></a>'.format($accountManager.profile('expire')));
						 }
					}
				    else {
					     if(elm_account_type) {elm_account_type.html('Free limited version <a href="/shop/buy-now/?lang={0}" style="margin-left: 5px;"><img src="/wp-content/uploads/image/buttons/btn_upgrade_to_full.gif" alt="" width="151" height="19" align="top" /></a>'.format(glooq_lang));}
						 elm.html('None');
					}
				 }
				 elm=$get('idEmail');
				 if(elm){
				  elm.html($accountManager.profile()['email']);
				 }
					elm=$get('idSent');
				 if(elm){
				  elm.html($accountManager.statInfo().sent);
				 }
				 elm=$get('idClick');
				 if(elm){
				  elm.html($accountManager.statInfo().click);
			 }
		}
		function rebill_cancel_request_calback(response){
			
			 if(response.isOK()){
				
				if ($get('idAccountType')){
				    $get('idAccountType').html('Free limited version <a href="/shop/buy-now/?lang={0}" style="margin-left: 5px;"><img src="/wp-content/uploads/image/buttons/btn_upgrade_to_full.gif" alt="" width="151" height="19" align="top" /></a>'.format(glooq_lang));
				}
				if ($get('idExpire')){
					$get('idExpire').html('None');	
				}
			  			    
			}
            else{
                       
            }
        
		}

        function LoadLibrary(){
            $mediaProxy.loadDataTable(LoadLibrary_callback);
        }
        function LoadLibrary_callback(datatable){
            $libFactory.create('idlibcontentviewholder',datatable);
        }
        function showBigBanner(elm,id){
			elm.src='/gonline/AdImageHandler.ashx?aduid={0}&mode=0'.format(id);
			elm.style.position='relative';			
			elm.style.zIndex=1000;

		}
		function showThumbBanner(elm,id){
			elm.src='/gonline/AdImageHandler.ashx?aduid={0}&mode=1'.format(id)
			elm.style.position='static';			
			elm.style.zIndex=0;

		}
        $libFactory = {
            pagesize: 4,
            create: function (holder,dataTable){
				
                $get(holder).clear();
                for(var dri in dataTable.rows){
					var boxdiv=createElement('div','class=banner_box');  
					boxdiv.className='banner_box';
					var adid=dataTable.rows[dri][0];            
					var state=dataTable.rows[dri][1];            
                    var sent=dataTable.rows[dri][2]==''?'0':dataTable.rows[dri][2];
                    var click=dataTable.rows[dri][3]==''?'0':dataTable.rows[dri][3];
                    var ctr=dataTable.rows[dri][4]=='n/a'?'0':dataTable.rows[dri][4];

					var cornertop='<div class="LeftTopCorner"></div><div class="RightTopCorner"></div>';
					var cornerbottom='<div class="LeftBottomCorner"></div><div class="RightBottomCorner"></div>';

                    var statview='<div class="statinfo_item banner_sent"><label>Sent:</label><span>{0}</span></div><div class="statinfo_item banner_clicked"><label>Clicked:</label><span>{1}</span></div><div class="statinfo_item banner_ratio"><label>CTR:</label><span>{2}%</span></div>'.format(''+sent,''+click,''+ctr);
					
                    var bannerview='<div class="banner_img"><img  src="/gonline/AdImageHandler.ashx?aduid={0}&mode=1" style="cursor: pointer;" title="Click me" onclick="javascript:window.open(\'/gonline/AdImageHandler.ashx?aduid={0}&mode=0\')" onmouseOver="javascript: showBigBanner(this,\'{0}\');" onmouseOut="javascript: showThumbBanner(this,\'{0}\');"></div>'.format(adid);

                    var delButton='<a class="btn_delete" href="javascript:libManager.deleteAdv(\'{0}\')"></a>'.format(adid);
                    var statButton='<a class="{1}" href="javascript:libManager.toggleAdvState(\'{0}\',\'{2}\')"></a>'.format(adid,(state=='Active')?'btn_stop':'btn_permite',state);	
					
					var boxhtml='{0}<div class="actionbar">{1}{2}</div>{3}'.format(bannerview,delButton,statButton,statview);

					boxdiv.innerHTML='{0}<div class="cont">{2}</div>{1}'.format(cornertop,cornerbottom,boxhtml);					


                    $get(holder).appendChild(boxdiv);
                }//for                
            }//create function
        }//object
    libManager={
        disableAdv:function (id){        
            $mediaProxy.disableAdv(id,libManager.onDisableAdv);        
        },    
        onDisableAdv:function (jsresponse){
            LoadLibrary();
        },
        
        disableAll:function (){
            $mediaProxy.disableAll(libManager.onDisableAll);        
        },    
        onDisableAll:function (jsresponse){
            LoadLibrary();
        },
        enableAdv : function (id){
            debug.trace('>> libManager.enableAdv');
            $mediaProxy.enableAdv(id,libManager.onEnable);
        },   
        onEnable:function (jsresponse){
           LoadLibrary();
            
        },
        enableAll:function (){
            debug.trace('>> libManager.enableAll');
            $mediaProxy.enableAll(libManager.onEnableAll);
        },
        onEnableAll:function (jsresponse){
            LoadLibrary();
        },
        toggleAdvState:function (id,state){       
            if(state=='InActive'){
                libManager.enableAdv(id);
            }else{
                libManager.disableAdv(id);
            }        
        },
        
        deleteAdv:function(id){
            debug.trace('>> libManager.deleteAdv');
			if (!confirm('Are you sure to delete this banner?'))
			{
				return;
			}

            $mediaProxy.deleteAdv(id,libManager.onDeleteAdv);

            
        },
        onDeleteAdv:function(jsresponse){
            LoadLibrary();
        },    
        deleteAll:function(){
            debug.trace('>> libManager.deleteAll');
			if (!confirm('Are you sure to delete all banners? You can\'t undo'))
			{
				return;
			}
            $mediaProxy.deleteAll(libManager.onDeleteAll);
            
        },
        onDeleteAll:function(jsresponse){
            LoadLibrary();
        }
    }//object
UploadManager={
        status:'ready',
        statusString:'Uploading, please wait...',
        caller_id:'',
        on_errorMessage:'Fail to pop the open file dialog. Are you still signed in?',
        upload:function (elm, uploadframe){
			UploadManager.multiUpload();
			return;
        },
        on_uploading:function(){
            var elm=$get(UploadManager.caller_id);
            elm.rel = elm.innerHTML;
            elm.innerHTML = UploadManager.statusString;
            UploadManager.status='uploading';
        },
        on_error:function(){
            alert(UploadManager.on_errorMessage);
            UploadManager.status='ready';
        },
        on_complete:function(status,message){
            var elm=$get(UploadManager.caller_id);
            elm.html(elm.rel);
            if(status=='OK'){                
                LoadLibrary();
            }else{
                alert(message);                
            }//if.else
            UploadManager.status='ready';
        },//method
		multiUpload:function (){
			DialogBox.show('Upload Banner','<iframe src="/gonline/users/multifileupload.aspx" frameborder="0" style="width:420px;height:300px;"></iframe>','prompt',false,{width:'444px',height:'340px',top:'100'},LoadLibrary);
		}
    }//object

	function inviteAll(){
            InviteMediator.invite($get('idName1').value,$get('idEmail1').value)
            InviteMediator.invite($get('idName2').value,$get('idEmail2').value)
            InviteMediator.invite($get('idName3').value,$get('idEmail3').value)
            $get('idName1').value=$get('idEmail1').value='';
            $get('idName2').value=$get('idEmail2').value='';
            $get('idName3').value=$get('idEmail3').value='';
            
                
    }
