/*
@code:zcom js
@author:hqlulu
@mail:hq.lu@zcominc.com
@update:2008-8-5
*/

//jQuery的cookie扩展
jQuery.cookie = function(name, value, options) { 
	if (typeof value != 'undefined') { // name and value given, set cookie 
		options = options || {}; 
		if (value === null) { 
			value = ''; 
			options.expires = -1; 
		} 
		var expires = ''; 
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { 
			var date; 
			if (typeof options.expires == 'number') { 
				date = new Date(); 
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); 
			} else { 
				date = options.expires; 
			} 
			expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE 
		} 
		var path = options.path ? '; path=' + options.path : ''; 
		var domain = options.domain ? '; domain=' + options.domain : ''; 
		var secure = options.secure ? '; secure' : ''; 
		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); 
	} else { // only name given, get cookie 
		var cookieValue = null; 
		if (document.cookie && document.cookie != '') { 
			var cookies = document.cookie.split(';'); 
			for (var i = 0; i < cookies.length; i++) { 
				var cookie = jQuery.trim(cookies[i]); 
				// Does this cookie string begin with the name we want? 
				if (cookie.substring(0, name.length + 1) == (name + '=')) { 
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 
					break; 
				} 
			} 
		} 
		return cookieValue; 
	} 
};


//读取用户信息
passport_usr = $.cookie('zcom_auth') ? $.cookie('zcom_loginuser') : '';


//评论 //////////////
//取得评论数据
function submit_discuss(){
	$.post("/discuss", {
		id: $("#comment_form input[name='id']").attr('value') ,
		idtype : $("#comment_form input[name='idtype']").attr('value') ,
		pagesize : $("#comment_form input[name='pagesize']").attr('value') ,
		comment : $("#comment_form textarea").val()
	}, function(xml) {
		var msg_total = $("msg_total", xml).text();
		var msg = "";
		var i=0;
		if($("#comment_form input[name='idtype']").attr('value') == "magazine"){
			$(xml).find('m').each(function(){
				    msg += "<ul class=\"list_liuyan\">";
				if($(this).attr('userid')>0){
					msg += "<dl class=\"list_12\"><dt><a href=\"http://u.zcom.com/"+$(this).attr('userid')+"\" target=\"_blank\"><img class=\"img_border_01\" src=\"http://uc.zcom.com/avatar.php?uid="+$(this).attr('userid')+"&size=small\" width=\"48\"/></a></dt>" ;
					msg += "<dd>" ;
					msg += " <h2><strong><a href=\"http://u.zcom.com/"+$(this).attr('userid')+"\" target=\"_blank\">"+$(this).attr('username')+"</a></strong> "+ $(this).attr('mytime')+"</h2>" ;
					msg += "<p>"+$(this).text()+"</p>" ;
					msg += "</dd>" ;
					msg += "</dl>" ;
				}else{
					msg += "<dl class=\"list_12\"><dt><a href=\"http://u.zcom.com/\" target=\"_blank\"><img class=\"img_border_01\" src=\"http://uc.zcom.com/images/noavatar_small.gif\" width=\"48\"/></a></dt>" ;
					msg += "<dd>" ;
					msg += "<h2><strong>"+$(this).attr('username')+"[杂志]</strong></span> "+ $(this).attr('mytime')+"</h2>" ;
					msg += "<p>"+$(this).text()+"</p>" ;
					msg += "</dd>" ;
					msg += "</dl>" ;
				}
				if(i<1){
					msg += "<dl class=\"list_12\">" ;
					msg += '<iframe src="/include/google/discuss_iframe.htm" frameborder="0" scrolling="no" width="468px" height="15px"></iframe>' ;
					msg += "</dl>" ;
				}
				i++;
			});
			msg += "</ul>" ;
		}else{
			$(xml).find('m').each(function(){
				msg +="<dl class=\"list_liuyan\">";
				msg += "<dt><a href=\"http://u.zcom.com/"+$(this).attr('userid')+"\" target=\"_blank\"><img src=\"http://uc.zcom.com/avatar.php?uid="+$(this).attr('userid')+"&size=small\" width=\"48\"/></a></dt>" ;
				msg += "<dd>" ;
				msg += "<h3><a href=\"http://u.zcom.com/"+$(this).attr('userid')+"\" target=\"_blank\">"+$(this).attr('username')+"</a>&nbsp;&nbsp;"+ $(this).attr('mytime')+"</h3>";
				msg += "<p>"+$(this).text()+"</p>" ;
				msg += "</dd>" ;
				msg += "</dl>" ;
				if(i<1){
					msg += "<dl class=\"list_12\">" ;
					msg += '<iframe src="/include/google/discuss_iframe.htm" frameborder="0" scrolling="no" width="468px" height="15px"></iframe>' ;
					msg += "</dl>" ;
				}
				i++;
			});
		}
		$("#comment_form textarea").val('');
		$("#comment_display").html(msg);
	});
}	


//文档初始化后改变部分功能
$(document).ready(function() {

	//评论
    //$("#comment_display").html('');
	$("#comment_form").submit( function (e) {
		e.preventDefault();
		submit_discuss();
	});

	//搜索
	$("#zcom_search").submit( function (e) {
		var mystr=$(this).find("input[name=searchword]").attr('value');
		this.method = "post";
		if(this.title){
			this.action = this.title;
		}else{
			this.title = this.action;
		}
		this.action += mystr;
	});
	//搜索
	$("#zcom_search2").submit( function (e) {
		var mystr=$(this).find("input[name=searchword]").attr('value');
		this.method = "post";
		if(this.title){
			this.action = this.title;
		}else{
			this.title = this.action;
		}
		this.action += mystr;
	});

	//看过
	if(passport_usr && $("#page_data").attr('value')){
		/*
		$.post("/stats", {
			s_type : "view",
			id: $("#page_data input[name='id']").attr('value') ,
			idtype : $("#page_data input[name='idtype']").attr('value')
		}, function(xml) {
		});
		*/
	}

	//订阅
	if(passport_usr && $("#page_data").attr('value')){
	}

	//下载
	if(passport_usr && $("#page_data").attr('value')){
	}

	//顶
	if(passport_usr && $("#page_data").attr('value')){
	}
});

/*google自定义广告*/
<!--//--><![CDATA[//><!--
function google_ad_request_done(google_ads) {
	var s = '';
	var i;
	if (google_ads.length == 0) {
	  return;
	}

if (google_ads[0].type == "image") {
	  s += '<a href="' + google_ads[0].url +
			  '" target="_top" title="go to ' + google_ads[0].visible_url +
			  '"><img border="0" src="' + google_ads[0].image_url +
			  '"width="' + google_ads[0].image_width +
			  '"height="' + google_ads[0].image_height + '"></a>';

	} else if (google_ads[0].type == "flash") {
	  s += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
			  ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' +
			  ' width="' + google_ad.image_width +
			  '" height="' + google_ad.image_height + '">' +
			  '<param name="movie" value="' + google_ad.image_url + '">' +
			  '<param name="quality" value="high">' +
			  '<param name="AllowScriptAccess" value="never">' +
			  '<embed src="' + google_ad.image_url +
			  '" width="' + google_ad.image_width +
			  '" height="' + google_ad.image_height + 
			  '" type="application/x-shockwave-flash"' + 
			  ' allowScriptaccess="never" ' + 
			  ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
	}
else if (google_ads[0].type="text") {
		s += '<div class="MTitle_01"><h2 class="title"><a href="https://adwords.google.com/select/Login?hl=zh_CN" target="_blank"  style="text-decoration:none;font-size:14px;color:000000;font-weight:bold">Google提供的广告</a></h2></div>';
	   if (google_ads.length == 1) {
			s +='<div class="b_cont"><div class="b_box" ' + 'onclick="window.open('+"'"+ google_ads[0].url + "'"+')" ' + 'onmouseout="window.status='+"''"+';return true;" ' + 'onmouseover="window.status='+"'"+
		google_ads[0].visible_url + "'" +';return true;">' + 
		'<p class="line_1"><a href="#" style="text-decoration:underline:none;">' + 
		google_ads[0].line1 + '</a></p>' + 
		google_ads[0].line2 + '<p class="line_2">' + google_ads[0].line3 + '</p>'+'<p class="line_3">' + 
		google_ads[0].visible_url + '</p></div></div>'       
	} 
else if (google_ads.length > 1) {
			 s += '<div class="b_cont">';
			for(i=0; i < google_ads.length; ++i) {
				s += '<div class="b_box" ' + 
		'onmouseout="window.status='+"''"+';return true;" ' + 
		'onmouseover="window.status='+"'"+
		google_ads[i].visible_url + "'" +';return true;">' + 
		'<a href="#" onclick="window.open('+"'"+ google_ads[i].url + "'"+')" class="line_1">' +google_ads[i].line1 + '</a><br><a href="#" onclick="window.open('+"'"+ google_ads[i].url + "'"+')" class="line_2">' + google_ads[i].line2 + "&nbsp;" + google_ads[i].line3 + '</a><br>' +'<a href="#" onclick="window.open('+"'"+ google_ads[i].url + "'"+')" class="line_3">' + google_ads[i].visible_url + '</a></div>';
		
			}
		}
	}
	s += '</div>';
	document.getElementById("google_ad_display").innerHTML=s;
	return;
  }
  
jQuery(function(){
jQuery(".s1").parent().mouseover(function(){
jQuery(this).children(".menu").css("display","block");
});
jQuery(".s1").parent().mouseout(function(){
jQuery(this).children(".menu").css("display","none");
});
})

//内容页
function zoom(){try{var s=document.getElementById("article_area").style.fontSize;var size=parseInt(s)+1;document.getElementById("article_area").style.fontSize=size+"px";}catch(e){}}
function zoom_(){try{var s=document.getElementById("article_area").style.fontSize;var size=parseInt(s)-1;document.getElementById("article_area").style.fontSize=size+"px";}catch(e){}}

function clearin(obj){
	if(obj.value=="请输入杂志名称"){
		obj.value="";
	}
}

function copyToClipBoard(){ 
	var clipBoardContent=""; 
	clipBoardContent+=document.title; 
	clipBoardContent+=""; 
	clipBoardContent+=location.href; 
	clipboardData.setData("Text",clipBoardContent); 
	alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友"); 
} 

  

