﻿// JScript 文件
function createJS(jsSrc){	
    var js = document.createElement('script');    
    js.setAttribute('src',jsSrc)
    try {
        document.getElementsByTagName('head')[0].appendChild(js);
    } catch (exp) {}
    js = null;
}
function createCSS(cssSrc){
	var css=document.createElement('link');
	css.setAttribute('rel','Stylesheet');
	css.setAttribute('type','text/css')
	css.setAttribute('href',cssSrc);
	try {
        document.getElementsByTagName('head')[0].appendChild(css);
    } catch (exp) {}
    css = null;
}

function init(t)
{
    var templateDir= t	//template    
    createCSS('/store/template/'+templateDir+'/shopcss.css');
    createJS('/store/template/store.js')    
}
function Search()
{
    var ob=document.getElementById("keyword");
    var wd=ob.value; 
    if(wd!="")
    {
        location.href="Product.aspx?Corpid="+id+"&Keyword=" + escape(wd);  
    }
    else
    {
        alert("请输入产品关键字.");
    }
    
}

function AddFavorite()
{
    if(document.sidebar)
    {
        window.sidebar.addPanel(document.title,location.href,"");
    }
    else if(document.all)
    {    
        window.external.AddFavorite(location.href,document.title);
    }
}
//文件中传入id参数

var domainUrl= 'http://www.lidodo.com';	//'http://www.lidodo.com';	//测试，上传请改变为域名地址
var actionUrl='/store/action.aspx?corpid='+id+'';
init(t);


//登陆窗口
LoginWin =Ext.extend(function(){	
	LoginWin.superclass.constructor.call(this,{	
		title:'login'				
		,width:350
		,height:140
		,collapsible:true
		,closable:false
		,resizable:false
		,buttonAlign:'center'
		,createFormPanel:function(){
			return new Ext.FormPanel({
				defaultType:'textfield'
				,bodyStyle:'padding:6px 0 0 0;'
				,labelAlign:'right'
				,frame:true
				,defaults:{allowBlank:false,width:180}
				,items:[{id:'username',name:'username',fieldLabel:'用户名',blankText:'this is not null'},{name:'password',fieldLabel:'密 码',inputType:'password',blankText:'password is not be empty.'}]
			});
		}
		,login:function(){
			if(!this.cfp.form.isValid())return ;
			alert(document.getElementById('username').value)
		}
		,initComponent:function(){
			this.keys={
				key:Ext.EventObject.ENTER
				,fn:this.login
				,scope:this
			};			
			LoginWin.superclass.initComponent.call(this);
			this.cfp=this.createFormPanel();
			this.add(this.cfp);
			this.addButton('Login',this.login,this);
			this.addButton('Reset',function(){this.cfp.form.reset();},this);
			
		}
})},Ext.Window);
function memberLogin(){
	var login = new LoginWin();
	login.show();
}
//模版设置
function clickSet(e){
	var store = new Ext.data.JsonStore({
		url:actionUrl + '&cmd=gettemplate'
		,root:'template'
		,fields:['name','id']
		,autoDestroy:true
	
	});
	var comb = new Ext.form.ComboBox({
		mode:'remote'
		,typeAhead:true
		,triggerAction:'all'
		,store:store
		,valueField:'id'
		,displayField:'name'		
		,id:'comb'
		,hiddenName:'combValue'
		,fieldLabel:'模版选择'		
		,labelStyle:'text-align:right'
		,name:'comb'
		,emptyText:'请选择'
		,allowBlank:false
		,blankText:'please choose one'
		,editable:false
	})
	
	var comForm = new Ext.FormPanel({
		items:comb
		,border:false
		,width:'99%'
		,buttons:[{
			id:'submit'
			,text:'保存修改'
			,handler:function(){
				if(comForm.form.isValid()){
					comForm.form.submit({
						url:actionUrl + '&cmd=savetemplate'
						,waitMsg:'正在保存数据......'	
						,waitTitle:'请等候......'
						,failure:function(form,action){
							Ext.MessageBox.alert('提示','网络错误.');
						}
						,success:function(form,action){	
							Ext.MessageBox.alert('提示',action.result.success); 
							top.location.href=location.href;
						}
						
					})
				}
			}
		}]
	})
	
	var tabs = new Ext.TabPanel({
        region: 'center',
        margins:'3 3 3 0', 
        activeTab: 0,
        defaults:{autoScroll:true},
        items:[{
            title: '模版选择：',
            items:[comForm]
        }]
    });
    

    // Panel for the west
    var nav = new Ext.Panel({
        title: '选择设置模块:',
        region: 'west',
        split: true,
        width: 200,
        collapsible: true,
        margins:'3 0 3 3',
        cmargins:'3 3 3 3'
    });
	var obj=document.getElementById(e).getBoundingClientRect();
	var winSet= new Ext.Window({
		title:'多多商铺设置：'
		,closable:true
		,width:300
		,height:150
		,x:obj.left-150
		,y:obj.top+30
		,layout:'border'
		,plain:true
		,items:[tabs]
	});	
	winSet.show()
}
