/**
 * ITZSK JavaScript framework
 * (c) 2010 ITZSK Inc.
 * qiusnay@gmail.com
 */
/* init ITzsk class */
var ITzsk = window.ITzsk || {};

/* config */
ITzsk.config ={
	
	root_www : 'http://www.itzsk.com',
	
	root_static:'http://static.itzsk.com',
	
	root_down :'http://down.itzsk.com'
}
/* cookie */
ITzsk.cookie = {
	get : function (name) {
		var arg  = name + "=";
		var alen = arg.length;
		var clen = document.cookie.length;
		var i = 0;
		while (i < clen) {
			var j = i + alen;
			if (document.cookie.substring(i, j) == arg) {
				var endstr = document.cookie.indexOf(";", j);
				if (endstr == -1) {
					endstr = document.cookie.length;
				}
				return decodeURIComponent(document.cookie.substring(j, endstr));
			}
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) {
				break;
			}
		}
		return null;
	},
	set : function (name, value) {
		var argv   = arguments;
		var argc   = arguments.length;
		var expr   = (argc > 2) ? argv[2] : null;
		var path   = (argc > 3) ? argv[3] : null;
		var domain = (argc > 4) ? argv[4] : null;
		var secure = (argc > 5) ? argv[5] : false;
		document.cookie = name + "=" + encodeURIComponent(value) +
			((expr   == null) ? "" : ("; expires=" + expr.toGMTString())) +
			((path   == null) ? "" : ("; path=" + path)) +
			((domain == null) ? "" : ("; domain=" + domain)) +
			((secure == true) ? "; secure" : "");
	}
}
var getCookie  = ITzsk.cookie.get; // ln -s ITzsk.cookie.get getCookie
var setCookie  = ITzsk.cookie.set; // ln -s ITzsk.cookie.set setCookie
if (1 != getCookie('is_root')) {
	window.onerror = function () {
		return false;
	}
}

var pop=null;
/**
 * 登录小窗口
 */
ITzsk.popuplogin = function() {
	if(pop!=null) pop.close();
	pop = new Popup({contentType:1,isSupportDraging:false,isReloadOnClose:false,width:540,height:300});
	pop.setContents({'title':'IT知识库会员登录','contentUrl':'/signup/signin.html'});
	pop.build().show();
}

ITzsk.logon = function() {
	var userName = $('#username').val();
	if(userName == '' || userName == 'Email或昵称'){
		alert('请填写用户名.')
		$('#username').focus();
		return false;
	}
	var passWord = $('#password').val();
	if(passWord == '' || passWord == '登录密码'){
		alert('请填写密码.')
		$('#password').focus();
		return false;
	}
	var forever = $('#forever').checked ? '1' : '0';
	$.post(ITzsk.config.root_www+"/api/member/login",{userName:userName,passWord:passWord,forever:forever}, function (data, textStatus){
		//返回的 data 可以是 xmlDoc, jsonObj, html, text, 等等.
		var json = eval('(' + data + ')'); 
		if(json['status']){
			alert(json['msg']);
		}else{
			// 更新页面header
			window.location.href = document.URL;
		}
	});
}
/**
 * 获取解决方案信息
 */
ITzsk.getsolutiondate = function(type, obj ){
	$(obj).addClass("d1").siblings().removeClass('d1');
	$(obj).removeClass("d2").siblings().addClass('d2'); 
	if (ITzsk[obj.id]) {
		$("#soldetail").html(ITzsk[obj.id][0]);	
		return false;
	}
	//http://itzsk.qiusnay.book.com/api/apisolution/getsolutioninfo?bigtype=0&smaltype=basic_php
	$("#soldetail").html('<p style="height:200px;padding-top:20px;font-size:18px;text-align:center">正在获取数据，请稍等... </p>');
	$.get(ITzsk.config.root_www+"/api/apisolution/getsolutioninfo",{bigtype:type}, function (data, textStatus){
		//返回的 data 可以是 xmlDoc, jsonObj, html, text, 等等.
		// 在这里this指向的是Ajax请求的选项配置信息，请参考下图
		html = '';
		json = eval(data)
		for( j=0;j < json.length;j++){
			html +='<ul class="ul" style="height:27px;line-height:27px;width:670px;padding:0 5px;">';
			html +='<li style="float:left;width:25px;text-align:right;">'+(j+1)+'.&nbsp;</li>';
			html +='<li style="float:left;height:25px;width:400px;white-space:nowrap;overflow:hidden">';
			html +='<a target="_blank" href="/sold/'+json[j]['id']+'.html">'+json[j]['title']+'</a></li>';
			html +='<li style="float:left;width:97px;overflow:hidden;"><span style="color:#888888">['+json[j]['ctype']+']</span></li>';
			html +='<li style="float:left;width:65px;overflow:hidden;"><span style="color:#888888">'+json[j]['name']+'</span></li>';
			html +='<li style="float:left;list-style:none"><span>'+json[j]['time']+'</span></li></ul>'
		}
		ITzsk[obj.id]=[html];
		$("#soldetail").html(html);
	});
}
/**
 * 获取疑难解答信息
 */
ITzsk.getquesdate = function (type, obj ){
	var arr = Array('all','basic','proj','server','db','combasic','ps','other');
	for( i = 0 ; i< arr.length; i++){
		if(obj.id == arr[i]){
			$('#'+arr[i]).addClass("hover");
		}else{
			$('#'+arr[i]).removeClass("hover");
		}
	}
	if (ITzsk[obj.id]) {
		$("#queorder").html(ITzsk[obj.id][0]);	
		return false;
	}
	$("#queorder").html('<p style="height:200px;padding-top:20px;font-size:18px;text-align:center">正在获取数据，请稍等... </p>');
	$.get(ITzsk.root_www+"/api/question/getqueinfo",{type:type}, function (data, textStatus){
		//返回的 data 可以是 xmlDoc, jsonObj, html, text, 等等.
		// 在这里this指向的是Ajax请求的选项配置信息，请参考下图
		html = '';
		json = eval(data);
		for( j=0;j < json.length;j++){
			html +='<ul class="ul" style="clear:both;height:30px;line-height:30px;padding:0 5px;">';
			html +='<li style="float:left;width:25px;text-align:right;">'+(j+1)+'.&nbsp;</li>';
			html +='<li style="float:left;height:25px;width:45px;"><span class="listbody" style="color:red">';
			html +=json[j]['que_weight']+'</span></li>';
			html +='<li style="float:left;height:25px;width:500px;white-space:nowrap;overflow:hidden"><a target="_blank" href="/qad/'+json[j]['queid']+'.html">'+json[j]['que_title']+'</a></li>';
			html +='<li style="float:left;"><span style="color:#888888">['+json[j]['fenlei']['name']+']</span></li>';
			html +='<li style="float:right;color:#666666"><span>'+json[j]['count']+'回答</span></li></ul>'
		}
		ITzsk[obj.id]=[html];
		$("#queorder").html(html);
	});
}
/**
 * 获取疑难解答信息
 */
ITzsk.fixPNG = function(myImage) {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version >= 5.5) && (version < 7) && (document.body.filters)){
		var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
		var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
		var imgTitle = (myImage.title) ? "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' ";
		var imgStyle = "display:inline-block;" + myImage.style.cssText;
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + myImage.width
			+ "px; height:" + myImage.height
			+ "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
		myImage.outerHTML = strNewHTML;
	}
}
/**
 * 显示时间
 */
ITzsk.setday = function (){
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds();
	var datevalue = now.getFullYear()+"年"+(now.getMonth()+1)+"月"+now.getDate()+"日" +' 星期'+'日一二三四五六'.charAt(now.getDay());
	timeValue = hours;
	timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
	timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
	timeValue += '&nbsp;('+'日一二三四五六'.charAt(now.getDay())+')';
	if(hours>23 || hours<4){
		notice='IT知识库友情提示:夜深了,请注意休息!';
	}else{
		notice='IT知识库页面改版完成,招募网站编辑!';
	}
	$("#notices").html(notice+'&nbsp;&nbsp;|&nbsp;&nbsp;' + timeValue);
}
setInterval("ITzsk.setday()",1000);

ITzsk.resizeDiv = function(b,j){
	var k=b.id;
	var g=false;
	if(!k){
	   k=b.id="_resize_rand_"+new Date().getTime()+"_"+Math.ceil(Math.random()*100000000);
	   g=true;
	}
	ITzsk._resizeDiv_runNum=ITzsk._resizeDiv_runNum||{};
	if(ITzsk._resizeDiv_runNum[k]>0){
		return false;
	}
	ITzsk._resizeDiv_runNum[k]=0;
	var f="hidden";
	if(b.style.display=="none"){
		f="show";
	}
	var h=b.offsetHeight;
	if(h==0){
		b.style.visibility="hidden";
		b.style.display="";
		h=b.offsetHeight;
		b.style.visibility="";
	}
	var c=b.style.overflow;
	b.style.display="";
	b.style.overflow="hidden";
	if(f=="show"){
		b.style.opacity=0;
		b.style.filter="alpha(opacity=0)";
	}
	var d=h;
	var a=function(){
		ITzsk._resizeDiv_runNum[k]++;
		var m=ITzsk._resizeDiv_runNum[k];
		d=d*4/5;
		var l;
		if(f=="show"){
			b.style.opacity=m*20/100;
			b.style.filter="alpha(opacity="+(m*10)+")";
			l=h-d;
		}else{
			b.style.opacity=1-m*20/100;
			b.style.filter="alpha(opacity="+(100-m*10)+")";
			l=d;
		}
		b.style.height=l+"px";
		if(m<=5){
			setTimeout(a,10);
		}else{
			if(f=="hidden"){
				b.style.display="none";
			}
			b.style.height="";
			b.style.opacity="";
			b.style.filter="";
			b.style.overflow=c;
			ITzsk._resizeDiv_runNum[k]=0;
			delete ITzsk._resizeDiv_runNum[k];
			if(j){
				try{
					j();
				}catch(n){}
			}
			if(g){
				b.id="";
			}
		}
	};
	a();
}
///*
///***写法1******/
//var IndexEvent = {};
//IndexEvent.prototype = {
//	initialize: function() {},
//	test1:function(){
//		alert(1111)
//	},
//	test2:function(){
//		alert(2222)
//	},
//}
//var QIndex = new IndexEvent();
//QIndex.test();
///***写法2******/
//var IndexEvent = {};
//IndexEvent.initialize = function(){}
//
//IndexEvent.test1 = function(){
//	alert(1111)
//}
//IndexEvent.test2 = function(){
//	alert(2222)
//}
//IndexEvent.test2();
//*/
