(function(){
	window.description = '';
	window.keywords = '';
	window.title = '';
	function init_args(){
		if(window.pic_type == null){
			window.pic_type  = '0';
		}
		
		if(window.ad_format == null){
			window.ad_format = 50;
		}
		if(window.ad_num == null){
			window.ad_num = 5; 
		}
		if(window.dd_ad_client == null){
			window.ad_client = '';
		}
		if(window.open_target == null){
			window.open_target = '_self';
		}
		
		window.title = window.document.title;
		var meta = document.getElementsByTagName('meta');
		for(var i=0;i<meta.length;i++){
            if(typeof meta[i].getAttribute('name') == 'string') {
                if(meta[i].getAttribute('name').toLowerCase()=="keywords"){
                    window.keywords += meta[i].getAttribute('content');
                }else if(meta[i].getAttribute('name').toLowerCase()=="description"){
                    window.description += meta[i].getAttribute('content');
                }
            }
		}
        if(window.description == ''){
            window.description = window.keywords;
        }
	}
	
	function add_str(name,value){
		window.dd_ad_url += "&"+name+"="+value;
	}
	
	function show_ads(){
		var each =0;
		if(window.pic_type=="0"){
			each = 200;
		}else{
			each = 220;
		}
		var height = each*window.ad_num;
		var iframe = '<iframe width="180" height="'+height+'" style="border:none;"  frameborder="0" src="'+window.dd_ad_url+'"><\/iframe>';
		document.write(iframe);
	}

	function creat_ads(){
		window.dd_ad_url = "http://union.dangdang.com/ads/unionads/?";
		window.dd_ad_url += "pic_type=" + window.pic_type;
		add_str('ad_client',window.dd_ad_client);
		add_str('ad_num',window.ad_num);
		add_str('open_target',window.open_target);
        vkeyWords=/^[^`~!@#"$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@"$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/;
        var rs = '';
        var descrip = '';
        for(var i=0; i<window.title.length; i++) {
            if(vkeyWords.test(window.title.substr(i,1))) {
                rs = rs + window.title.substr(i,1);
            }
        }
        for(var i=0; i<window.description.length; i++) {
            if(vkeyWords.test(window.description.substr(i,1))) {
                descrip = descrip + window.description.substr(i,1);
            }
        }
        add_str('title',rs);
		add_str('ad_format',window.ad_format);
		add_str('description',descrip);
		show_ads();
	}

	init_args();
	creat_ads();
}
)()

