/**
 * <p>Title:       pas.js</p>
 * <p>Description: 扩展js</p>
 * <p>Createtime:  2011-8-3 上午10:42:56</p>
 * @author:        Nycas
 * @version:       1.0     
 */

if(typeof PAS == 'undefined') {
	var PAS = {};
};
/**
 * 保存单击的时间
 */
var clickDate = 0;
PAS.easysk = {
	advertisement:function(){
		PAS.easysk.doForAd();
		$('#act_panel_1').mouseover(function(){PAS.easysk.doForAd();$('#act_panel_1').slideUp(300);});
	},
	doForAd:function(){
		setTimeout(function(){$('#act_panel_2').slideDown(1000);},100);
		setTimeout(function(){
			$('#act_panel_2').slideUp(2500);
			  setTimeout(function(){
				     $('#act_panel_1').slideDown(500);
				},2500);
			},5000);
	},
	submit:false,
	products: {
	    gotoBuy:function(proid){
	      var quantity = $('#quantity').val();
	      if (!quantity || quantity < 1) {
	         quantity = 1;
	      }
	      location.href = './orders.htm?pid=' + proid + '&quantity=' + quantity;
	    },
	    /**
	     * 活动
	     */
	    listenActivity: function(id, dateline){
	    	if (dateline < 1) {
	    		$('#' + id).html('活动结束啦');
	    		window.location.reload(true);
	    		return;
	    	}
	    	//天
	    	var _day = dateline/(24*3600);
	    	//剩下的天数
	    	var day = Math.floor(_day);
            //小时 
	    	var _hour = (_day - day) * 24;
	    	//剩下的小时 
	    	var hour = Math.floor(_hour);
	    	
	    	var _minutes = (_hour - hour) * 60;
	    	//剩下的分钟
	    	var minutes = Math.floor(_minutes);
	    	
	    	var _seconds = (_minutes - minutes) * 60;
	    	//剩下的秒
	    	var seconds = Math.round(_seconds);	    	
	    	var htm = [];
	    	if (day > 0) {
	    		htm.push(this.createTimeStyle(day, '天'));
	    	}
	    	if (hour > 0) {
	    		htm.push(this.createTimeStyle(hour, '时'));
	    	}
	    	if (minutes > 0) {
	    		htm.push(this.createTimeStyle(minutes, '分'));
	    	}
	    	htm.push(this.createTimeStyle(seconds, '秒'));
	    	$('#' + id).html(htm.join(''));
	    },
	    createTimeStyle:function(val, unit){
	    	return "<span>" + val + "</span>" + unit;
	    },
	    feedback:function(gid){
			  if (this.submit) {
			  	  Window.showError('不要操作这么快嘛，请休息一下哦。');
			  	  return;
			  }
		      var feed = $('#feedbackContent');
	          var cont = $.trim(feed.val());
	          if (!cont) {
	        	  Window.showError('请输入要反馈的意见!');
	        	  return ;
	          }
	          if (cont.length > 1000) {
	        	  Window.showError('您要反馈的内容请不要超过1000个字符!');
	        	  return ;
	          }
	          cont = Filter.filteTextArea(cont);
	          this.submit = true;
		      PAS.client.done("./software/feed.htm", {gid:gid, content: cont}, function(rs){
		    		if (rs && rs.success > 0) {
		    			Window.showSuccess('感谢您的反馈!');
		    			feed.val('');
		    		}
		    		else {
		    			Window.showError('保存失败，请稍候再试!');
		    			PAS.easysk.submit = false;
		    		}
		    	});
		},
	    hitHis:[],
		gotoViewProductInfo: function(o, k){
		    var gid = $(o).val();
		    if (gid < 1){return;}
		    var baseUrl = null;
		    if (k) {
		    	baseUrl = '../product.htm';
		    }
		    else {
		    	baseUrl = './product.htm';
		    }
		    location.href = baseUrl + "?gid=" + gid;
	    },
	    /**
	     * 评价
	     */
	    hit:function(gid){
	    	var now = new Date().getTime();
	    	var pass = false;
	    	if (clickDate > 0) {
	    		var his = this.hitHis;
	    		if (his.length > 0) {
	    			for (var i = 0; i < his.length;i++) {
	    				var q = his[i];
	    				if (q == gid) {
	    					pass = true;
	    				}
	    			}
	    		}
	    		if (pass && now - clickDate < 5 * 60 * 1000) {
	    			alert("不要操作这么快嘛，请您休息一下哈。");
	    			return;
	    		}
	    	}
	    	if (!pass) {
	    		this.hitHis.push(gid);//记录评价
	    	}
	    	clickDate = now;
	    	PAS.client.done("./product/hit.htm", {gid:gid}, function(rs){
	    		if (rs && rs.success > 0) {
	    			var o = $('#ev' + gid);
	    			o.html(parseInt(o.html()) + 1);
	    			alert("谢谢您的评价！");
	    		}
	    	});
	    }
	},
	/**
	 * 软件
	 */
	software: {
		hit:function(sid) {
		    PAS.client.done("./software/hit.htm", {sid:sid}, function(rs){});
	    }
	}
    
}
