/**
 * Author:殘雪易冷 | E-mail: xueruos520@163.com                   
 * Copyright (c) 版权所有 无锡君通软件                                   
 * 2010.9.25
 * blog.csnowy.com
 */
 
/**
 * 筛选事件
 * 添加搜索项
 */
function changeStyle(ob){
	jQuery(ob).toggleClass('on');
	var content = jQuery(ob).text();
	var $changeS = $('#cx_sx > li');
	var lei_op = ob.id;
	$id_arr = lei_op.split('_');
	ob_id = lei_op + '_ok';
	$('#'+$id_arr[0]+'_0').css("background-color",'');
	
	//已选择区元素处理 
	for(i=0; i<$changeS.length; i++){
	  $id_arr_op = $changeS[i].id.split('_');
	  lei_op_same = $id_arr_op[0] + '_' + $id_arr_op[1];
	  
	  //单击已选择事件执行删除操作
	  if(lei_op == lei_op_same){
		 jQuery($changeS[i]).remove();
		 $('#'+$id_arr[0]+'_0').addClass('on');
		 break;   
	  }
	  
	  //同类别元素处理
	  if($id_arr[0] == $id_arr_op[0]){
		 old_id = $id_arr_op[0] + '_' + $id_arr_op[1];
		 jQuery($changeS[i]).remove();
		 $('#'+old_id).removeClass('on');
		 
		 if($id_arr[1] != 0){
		 $('#'+$id_arr[0]+'_0').removeClass('on');
		
		 $('#cx_sx').append('<li id="'+ob_id+'" style="cursor:pointer; margin-left:10px; float:left" onmouseover="_changeStyle(this);"><span class="ui-icon ui-icon-circle-check" style="float:left" ></span><span id="thisspan">'+content+'</span></li>')
		 }
	     //AJAX事件
	  break;
	  }
	}
	//未选择过的事件
	if(i == $changeS.length){
		 if($id_arr[1] != 0){
			 $('#'+$id_arr[0]+'_0').removeClass('on');
	         $('#cx_sx').append('<li id="'+ob_id+'" style="cursor:pointer; margin-left:10px; float:left" onmouseover="_changeStyle(this);"><span class="ui-icon ui-icon-circle-check" style="float:left" ></span><span style="height:20px;" id="thisspan">'+content+'</span></li>');}
	     //AJAX事件
	}
}

/**
 * 筛选事件
 * 删除搜索项
 */
function _changeStyle(ob){
  	jQuery(ob).children(".ui-icon").removeClass('ui-icon-circle-check').addClass('ui-icon-circle-close');
	jQuery(ob).bind('mouseout',function(){
		 jQuery(ob).children(".ui-icon").removeClass('ui-icon-circle-close').addClass('ui-icon-circle-check');
		});
	jQuery(ob).bind('click', function(){
		  jQuery(ob).remove();
		  _re_id = ob.id;
		  $_re_id_arr = _re_id.split('_');
		  _remove_ob = $_re_id_arr[0] + '_' + $_re_id_arr[1];
		  $('#'+_remove_ob).removeClass('on');
		  $('#'+$_re_id_arr[0]+'_0').addClass('on');
		})
	
}

/**
 * 表格事件
 * 
 */
function table(){
$("tr").mouseover(function(){
	$(this).addClass("over");
}).mouseout(function(){
	$(this).removeClass("over");
})
}

//注册表单用户名验证
function check_username(ob){
	username = jQuery(ob).val();
	if(username == ''){
	  $('#err_username').html('用户名不能为空！');
	  $('#user_name').focus();
	  $('#bt_zhuce').attr("disabled", "false");
	}else{
	CX.getInfo('ajax.php','POST',"app",'action=check_username&name='+username,_check_username,1,"loading_ajax_mess");
	}
}

function _check_username(ret){
	if(ret == '0'){
	  $('#err_username').html('用户名已被注册，请重新输入！');
	  $('#user_name').focus();
	  $('#bt_zhuce').attr("disabled", "false");
	}else if(ret == '2'){
	  $('#err_username').html('用户名不符合规则，大于6且小于18个字符！');
	  $('#user_name').focus();
	  $('#bt_zhuce').attr("disabled", "false");
	}else{
	  $('#err_username').html('');
	  $('#bt_zhuce').removeAttr("disabled");
	  return true;
	}
}

function check_pwd(ob){
	pwd = jQuery(ob).val();
	if(pwd == ''){
	  $('#err_pwd').html('请填写密码！');
	  $('#bt_zhuce').attr("disabled", "false");
	}else{
	  $('#err_pwd').html('');
	  $('#bt_zhuce').removeAttr("disabled");
	  return true;
	}
}

function check_pwd2(ob){
	pwd2 = jQuery(ob).val();
	pwd = $('#pwd').val();
	if(pwd2 != pwd){
	  $('#err_pwd2').html('两次输入的密码不相同！');
	  $('#pwd2').focus();
	  $('#bt_zhuce').attr("disabled", "false");
	}else{
	  $('#err_pwd2').html('');
	  $('#bt_zhuce').removeAttr("disabled");
	  return true;
	}
}

function check_email(ob){
	email = jQuery(ob).val();
	if(email == ''){
	  $('#err_email').html('邮箱不能为空！');
	  $('#bt_zhuce').attr("disabled", "false");
	}else{
	CX.getInfo('ajax.php','POST',"app",'action=check_email&email='+email,_check_email,1,"loading_ajax_mess");
	}
}

function _check_email(ret){
	if(ret == '0'){
	  $('#err_email').html('邮箱格式不正确，请重新输入！');
	  $('#bt_zhuce').attr("disabled", "false");
	}else{
	  $('#err_email').html('');
	  $('#bt_zhuce').removeAttr("disabled");
	  return true;
	}
}

function check_answer(ob){
	answer = jQuery(ob).val();
	if(answer == ''){
	  $('#err_answer').html('保密问题答案不能为空！');
	  $('#answer').focus();
	  $('#bt_zhuce').attr("disabled", "false");
	}else{
	  $('#err_answer').html('');
	  $('#bt_zhuce').removeAttr("disabled");
	  return true;
	}
}

function check_postin_all(ob){
 //合成存储字段
 var str = 'postin_zhuti,'+ob.postin_zhuti.value+'#'+'postin_content,'+ob.postin_content.value;
 CX.getInfo('ajax.php','POST',"app",'action=check_postin_save&str='+str,_check_postin_save);
 return true;
}

function _check_postin_save(ret){
 return true;
}

function check_jubao_all(ob){
 //合成存储字段
 var str = 'jubao_content,'+ob.jubao_content.value;
 CX.getInfo('ajax.php','POST',"app",'action=check_jubao_save&str='+str,_check_jubao_save);
 return true;
}

function _check_jubao_save(ret){
 return true;
}


//获取评论
function get_backword(){
	var id = $('#get_backword_id').val();
	CX.getInfo('message.php','POST',"app",'action=get_backword&info_id='+id,_get_backword,1,'backword_ajax_mes');
}

//获取评论_AJAX
function get_backword_aj(ob){
	var id = $('#get_backword_id').val();
	gpage = jQuery(ob).attr("name");
	CX.getInfo('message.php','POST',"app",'action=get_backword&info_id='+id+'&page='+gpage,_get_backword,1,'backword_ajax_mes');
}

function _get_backword(ret){
	var $atr_arr = ret.split('###');
	$('#backwords').html($atr_arr[0]);
	$('#badoo').html($atr_arr[1]);
}

function post_backword(){
	var post_backword_nickname = $('#post_backword_nickname').val();
	var post_backword_content = $('#post_backword_content').val();
	var post_id = $('#get_backword_id').val();
    if(post_backword_nickname == ''){
		messBox_common('请填写昵称!'); 
		return false;}
	if(post_backword_content == ''){
	    messBox_common('请填写评论内容!'); 
		return false;}
	CX.getInfo('message.php','POST',"app",'action=post_backword&post_id='+post_id+'&post_backword_nickname='+post_backword_nickname+'&post_backword_content='+post_backword_content,_post_backword);
}

function _post_backword(ret){
	if(ret == '1'){
	   messBox_common_p('恭喜！发表评论成功!'); 
	   get_backword()	
	}else{
	   messBox_common('抱歉！发表评论失败!'); 	
	}
}

function post_ding(){
	var id = $('#get_backword_id').val();
	CX.getInfo('message.php','POST',"app",'action=ding&info_id='+id,_post_ding);
}

function _post_ding(ret){
	if(ret == '3'){
		messBox_common_p('抱歉,您已近投过票！');
	    return false;
	}else if(ret == '1'){
	    messBox_common_p('恭喜，顶贴成功！');	
	}else{ messBox_common_p('抱歉，顶贴失败！'); }
}

function cai_ding(){
	var id = $('#get_backword_id').val();
	CX.getInfo('message.php','POST',"app",'action=cai&info_id='+id,_post_cai);
}

function _post_cai(ret){
	if(ret == '3'){
		messBox_common_p('抱歉,您已近投过票！');
	    return false;
	}else if(ret == '1'){
	    messBox_common_p('恭喜，踩贴成功！');	
	}else{ messBox_common_p('抱歉，踩贴失败！'); }
}

function send_inmessage(){
    alertpostinDiv();
}

function send_email(){
    alert("aaa");	
}

function show_information_post(){
	CX.getInfo('ajax.php','POST',"app",'action=check_postin_get',_show_information_post);
}

function _show_information_post(ret){
	if(ret == "false"){
	    messBox_common_p('请先登录！');
		return false;	
	}
	showWindow(300,260, 'tranDiv', 'tranDivBack', 'infoDiv', 'popLayer');
}

function showclock(){
	var Digital = new Date()
	var Year = Digital.getYear();
	var Dates = Digital.getDate();
	var hours = Digital.getHours()
	var minutes = Digital.getMinutes()
	var seconds = Digital.getSeconds()
	var isnMonth = new
	Array("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月");
	var isnDay = new
	Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日");
	var dn = "AM"
	if (hours > 12) {
		dn = "PM"
		hours = hours - 12
	}
	if (hours == 0) hours = 12
	if (minutes <= 9) minutes = "0" + minutes
	if (seconds <= 9) seconds = "0" + seconds
	
	if(dn == "AM"){ 
	  hello = "Hi,上午好！";
	}else{
	  hello = "Hi,下午好！";	
	}
	if(Year<1000){
		Year+=1900;
	}
	myclock=hello+"<font size='5'><b>今天是："+Year+"年"+isnMonth[Digital.getMonth()]+Dates+"日"+isnDay[Digital.getDay()]+'&nbsp;&nbsp;时间：'+hours+":"+minutes+":"+seconds+" "+dn+"</b></font>"
	document.getElementById('liveclock').innerHTML=myclock
	setTimeout("showclock()",1000)
}

//图片居中控制
function imgMiddle(w){
    var img = new Image;
	var ob =  $(".thumbimg");
	for(i=0; i<ob.length; i++){
		img.src = jQuery(ob[i]).attr("src");
		imgH = img.height;
		imgW = img.width;
		/* 计算图片剧中距离顶部的距离 */
		to_top = (w - imgH)/2;
		to_left = (w - imgW)/2;
		jQuery(ob[i]).css({"top":+to_top+"px"});
		jQuery(ob[i]).css({"left":+to_left+"px"});
	}
}

//浏览器关闭删除未处理上传图片
function checkUpImages(){
    CX.getInfo('ajax.php','POST',"app",'action=checkUpImages',_checkUpImages);
}
function _checkUpImages(ret){
    return true;
}
