﻿$shop={
    showUrl:function(url){
        var shopframe=document.createElement('iframe');        
        shopframe.style.width='600px';
        shopframe.style.height='490px';
        shopframe.setAttribute('frameborder', '0');
        
        shopframe.setAttribute('src', url);
        var holder=document.createElement('div');
        holder.appendChild(shopframe);        
        
        DialogBox.show('glooqShop',holder.innerHTML,'glooqShop',false,{width:'620px',height:'500px'},$shop.on_close);
    },//

    show:function(pid,ccy,lcid){
        var shopframe=document.createElement('iframe');        
        shopframe.style.width='600px';
        shopframe.style.height='565px';
        shopframe.setAttribute('frameborder', '0');
        
		if(typeof(ccy)=='undefined'){
			ccy='usd';
		}
		if(typeof(lcid)=='undefined'){
			lcid='en_US';
		}
		
        shopframe.setAttribute('src', '/gonline/shop/teller.aspx?pid={0}&ccy={1}&lcid={2}'.format(pid,ccy,lcid));
        
        
        var holder=document.createElement('div');
        holder.appendChild(shopframe);        
        
        DialogBox.show('glooqShop',holder.innerHTML,'glooqShop',false,{width:'620px',height:'605px',top:'32'},$shop.on_close);
    },//
	 payDirect:function(){
		if(product=='' || amount==''){
            $get('id_dp_messages').className='text_normal';
            $get('id_dp_messages').html('');
            return;
        }
        var product= encodeURIComponent($get('id_dp_product').value);
        var ccy = encodeURIComponent($get('id_dp_ccy').value);
        var amount = encodeURIComponent($get('id_dp_ammount').value);        
        
        if(product=='' || amount==''){
            $get('id_dp_messages').className='text_error';
            $get('id_dp_messages').html("Product/price can't left blank. ");
            return;
        }
        
        if(isNaN(parseFloat( amount))){
            $get('id_dp_messages').className='text_error';
            $get('id_dp_messages').html("Not a valid price");
            return;
        }
        
        
        var shopframe=document.createElement('iframe');        
        shopframe.style.width='848px';
        shopframe.style.height='580px';
        shopframe.setAttribute('frameborder', '0');
        
        shopframe.setAttribute('src', '/gonline/shop/teller.aspx?mode=paydirect&product={0}&ccy={1}&amount={2}'.format(product,ccy,amount));
        var holder=document.createElement('div');
        holder.appendChild(shopframe);        
        
        DialogBox.show('glooqShop',holder.innerHTML,'success',false,{width:'860px',height:'620px',top:'32'},$shop.on_close);
    },//
	
	on_close:function(dialog){
        DialogBox.clearContent();
    },//method 
	
	rebill:function(pid,ccy,lcid){
        var shopframe=document.createElement('iframe');        
        shopframe.style.width='600px';
        shopframe.style.height='535px';
        shopframe.setAttribute('frameborder', '0');
        if(typeof(pid)=='undefined'){
			pid='0';
		}
		if(typeof(lcid)=='undefined'){
			lcid='en_US';
		}
		if(typeof(ccy)=='undefined'){
			ccy='USD';
		}
        shopframe.setAttribute('src', '/gonline/shop/rebilling.ashx?action=rebilling&pid={0}&lcid={1}&ccy={2}'.format(pid,lcid,ccy));
        var holder=document.createElement('div');
        holder.appendChild(shopframe);        
        
        DialogBox.show('glooqShop',holder.innerHTML,'glooqShop',false,{width:'620px',height:'565px'},$shop.on_close);
    },//method 
	//Cancel rebilling
	rebill_cancel_request:function(callback){
        debug.trace('>> shop->cancel:load');
        $shop.on_rebill_cancel_requestCallback=callback;
        request('/gonline/shop/rebilling.ashx?action=cancel',false,$shop.on_rebill_cancel_request);
    },//method    
	
    on_rebill_cancel_request:function(xmlhttp){
        debug.trace('>> $shop.on_rebill_cancel_request');
        if(xmlhttp.responseText.search(/jsrespose/i)>=0){
            debug.trace('>> shop.on_rebill_cancel_request:evaluate response');
            eval(xmlhttp.responseText);
        }
        if(typeof(jsrespose)!='undefined'){
            $shop.on_rebill_cancel_requestCallback(jsrespose);
        }else{            
            $shop.on_rebill_cancel_requestCallback(jsHelper.createFail('Cancelation Fail'));
        }
    }//method
	//handle the dialog closing
    
}//object
$dom.loadJsCss('/_core/css/dialog_box.css','css');
$dom.loadJsCss('/_core/scripts/dialog_box.js','js');
