// otreeCMS
// Author FengZhongwei
// E-mail:fenghome123@qq.com

/*** 清除浮动 ***/

$(document).ready(function(){
	$("form :input").blur(function(){
		 $("#formtips").fadeOut("slow");
		 })
	})

/*** 获取服务器时间 ***/

function get_time(types){
	var xmlHttp = false;  
	try {   
	  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");   
	  } 
	  catch (e) {   
	  try {   
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");   
	  } 
	  catch (e2) {   
		xmlHttp = false;   
	  }   
	}   
		
	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {   
		xmlHttp = new XMLHttpRequest();   
	}   
	xmlHttp.open("GET", "null.txt", false); 
	xmlHttp.setRequestHeader("Range", "bytes=-1");   
	xmlHttp.send(null);
	
	severtime=new Date(xmlHttp.getResponseHeader("Date"));
	var year = severtime.getFullYear();
	var month = severtime.getMonth()+1;
	var date = severtime.getDate();
	var hour = severtime.getHours();
	var minute = severtime.getMinutes();
	var second = severtime.getSeconds();
	if(types=="now"){
		return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
		}
	else if(types=="date"){
		return year+"-"+month+"-"+date;
		}
}

/*** 特殊字符过滤 ***/

function checkText(str,type){
	if(!str){
		return "";
		return false;
		}
	var special;
	if(type=="1"){
		special = "代考|外挂|办证|色情|http|ftp|src";
		}
	else{
		special = "#|$|~|!|%|^|&|*|\"|?|>|<|\\|\/|代考|外挂|办证|色情|http|ftp|src";
		}
	var special_str = new Array();
	special_str = special.split("|")
	str=str.replace(/(^\s*)|(\s*$)/g, "");  //去空格
	for(i=0;i<special_str.length;i++){
		if(special_str != ""){
			if(str.indexOf(special_str[i]) !=-1){
				alert("文本框中不能含有非法字符("+special_str[i]+")，请检查输入！");
				return "false";
			}
	 	}
	}
	//转义
	str=str.replace(/\'/g,"&#39;");
	str=str.replace(/\%/g,"&#37;");
	str=str.replace(/\&/g,"%26");
	str=str.replace(/\+/g,"%2B");
	return str;
}

/*** 冒泡提示框 ***/

function alertMsg(id,msg){
	if($("#formtips").hide()){
		$("#formtips").remove();
		var str=id.parent().html();
		id.parent().html('<div id="formtips"><div class="formtips_t">'+msg+'</div><div class="formtips_d"></div></div>'+str);
		$("#formtips").fadeIn("slow");
		}
	return false;
	}

/*** 传递表单信息 ***/

function check_from(type,id){
	var act_user=checkText($(":input[name='act_user']").val());
	var act_telephone=checkText($(":input[name='act_telephone']").val());
	var act_fax=checkText($(":input[name='act_fax']").val());
	var act_email=checkText($(":input[name='act_email']").val());
	var act_title=checkText($(":input[name='act_title']").val());
	var act_address=checkText($(":input[name='act_address']").val(),1);
	var act_content=checkText($(":input[name='act_content']").val(),1);
	var act_from=checkText($(":input[name='act_from']").val());
	var act_time=get_time("now");
	var pro_id="";
	if(id){
		pro_id=id;
		}
	var action=type;
	
	var input="";
	var pack="";
	if(act_user.length<1){
		if(!pack){
			input="act_user";
			pack="pack_54";
			}
		}
	if(act_telephone.length<1){
		if(!pack){
			input="act_telephone";
			pack="pack_55";
			}
		}
	if(act_email.length<1){
		if(!pack){
			input="act_email";
			pack="pack_56"
			}
		}
	if(act_title.length<1){
		if(!pack){
			input="act_title";
			pack="pack_57"
			}
		}
	if(act_content.length<1){
		if(!pack){
			input="act_content";
			pack="pack_58"
			}
		}
	if(act_telephone.length<8){
		if(!pack){
			input="act_telephone";
			pack="pack_59"
			}
		}
	if(act_email.indexOf("@" && ".") <1){
		if(!pack){
			input="act_email";
			pack="pack_60"
			}
		}
		
	//错误信息
	if(pack){
		$.ajax({
		type:"post",
		  url:file_path+"check/check_error.php",
		  data:"pack="+pack,
		  cache:false,
		  success:function (data, status){
			  alertMsg($(":input[name='"+input+"']"),data+"!");
			  }
		})
	return false;
	}
	
	if(act_user=="false" || act_telephone=="false" || act_fax=="false" || act_email=="false" || act_title=="false" || act_address=="false" || act_content=="false" || act_from=="false"){
		return false;
		}
	showLoad();
	$.ajax({
	type:"post",
	  url:file_path+"check/check.php",
	  data:"pro_id="+pro_id+"&"+"act_user="+act_user+"&"+"act_telephone="+act_telephone+"&"+"act_fax="+act_fax+"&"+"act_email="+act_email+"&"+"act_address="+act_address+"&"+"act_title="+act_title+"&"+"act_content="+act_content+"&"+"act_from="+act_from+"&"+"act_time="+act_time+"&"+"action="+action+"",
	  cache:false,
	  success:function (data, status){
		  closeLoad();
		  alert(data);
		  window.location.reload(true);
		  }
	})
}
