// ActionScript Document
// JavaScript Document

function site_url(str)
{
	if (document.domain == 'localhost')
		return "http://"+document.domain+"/projects/faq/" + str;
	else
		return "http://"+document.domain +"/" + str;
}

function _$(id)
{
	return document.getElementById(id);
}
//获取字符串长度
function strlen(str)
{
	return str.replace(/[^\x00-\xff]/g,"**").length;
}


//设置首页菜单
function setMenu(cate, type, count, obj)
{
	var arr = cate.split("-");
	var child = _$("ques"+arr[0]).childNodes;
	for (var j = 0; j<child.length; j++)
	{
		if (child[j].id == cate)
		{
			child[j].className = 'list_mainq2';
		}
		else
		{
			child[j].className = 'list_mainq1';
		}
	}
	for (var i=0; i<count; i++)
	{
		if (arr[1] == i)
		{
			if (_$('adviser'+arr[0]+'-'+arr[1]))
				_$('adviser'+arr[0]+'-'+arr[1]).style.display = '';
			if (_$('question'+arr[0]+'-'+arr[1]))
				_$('question'+arr[0]+'-'+arr[1]).style.display = '';
			
		}
		else
		{
			if (_$('adviser'+arr[0]+'-'+i))
				_$('adviser'+arr[0]+'-'+i).style.display = 'none';
			if (_$('question'+arr[0]+'-'+i))
				_$('question'+arr[0]+'-'+i).style.display = 'none';
		}
	}
}

//设置首页个人申请贷款和企业申请贷款显示
function setDaikuan(type, hidden)
{
	_$('hover'+type).className = 'shengqing11';
	_$('dai'+type).style.display = 'inline-block';
	_$('hover'+hidden).className = 'shengqing12';
	_$('dai'+hidden).style.display = 'none';
	if (type == 2) {
		_$('hover'+1).style.marginLeft = '0px';
		_$('hover'+1).style.marginRight = '4px';
	} else {
		_$('hover'+1).style.marginLeft = '0px';
		_$('hover'+1).style.marginRight = '0px';
	}
}

function checkQuestion(f)
{
	var te = 1;
	var Eereg  = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	var phone = /^(\d+)(-{0,1})(\d+)$/;
	var code  = _$('authCode').value;
	if($.IsEmpty(f.title.value) || strlen(f.title.value) > 100 || strlen(f.title.value) < 10) 
	{
		alert('问题标题不能为空或少于5个或超过50个中文字');
		return false;
	}
	if($.IsEmpty(f.content.value) || strlen(f.content.value) > 2000) 
	{
		alert('问题内容不能为空或超过1000个字');
		return false;
	}
	
	if (f.email.value && !Eereg.test(f.email.value))
	{
		alert('E-mail格式不正确');
		return false;
	}
	
	if (f.phone.value && !phone.test(f.phone.value))
	{
		alert('请填写合法的电话号码');
		return false;
	}
	var option = 
	{
		type: "POST",
		url: site_url('authimg/verify/'),
		data: "authNum="+code+"&reqId=" + Math.random(),
		success: function(msg)
		{
			te = msg;
			if (msg != 1) {
				alert('验证码错误');
				return false;
			} else {
				f.submit();
			}
		}
	};
	$.ajax(option);
}

var temp = 1;
var ParentCategory = '';
var ChildCategory = '';
//弹出式窗口
var popWindow = {
	scall: function()
	{
		_$("mask_main").style.top = (document.documentElement.scrollTop+(document.documentElement.clientHeight-_$("mask_main").offsetHeight)/2)+"px";
		_$("mask_main").style.left = (document.documentElement.scrollLeft+(document.documentElement.clientWidth-_$("mask_main").offsetWidth)/2)+"px";   
	},
	mask: function(m,y)
	{
		bodyheight = (((document.documentElement.clientHeight>document.documentElement.scrollHeight)?document.documentElement.clientHeight:document.documentElement.scrollHeight)+"px");
		var maskdiv = _$("mask");
		var maskdiv2 = _$("mask_main");
		maskdiv.style.height = bodyheight;
		if (m==1){
			maskdiv.style.display="block";
			maskdiv2.style.display="block";
			this.scall();
		
		}else{
			//当选择分类并点击确定时
			if (y)
			{
				temp = 2;
				var parent = ParentCategory ? ParentCategory : $("#pCategory").html();
				var child = ChildCategory ? ChildCategory : $("#cCategory").html();
				if(y==10){
					var strs = 1
					}else{
					var strs = 0
					}
				var option = 
				{
					type: "POST",
					url: site_url('question/editCategory/'),
					data: "parent="+parent+"&child="+child+"&strs="+strs,
					success: function(msg)
					{
						$("#marching").html(msg);
					}
				};
				$.ajax(option);
			}
			maskdiv.style.display="none";
			maskdiv2.style.display="none";
		}  
	}
};
	

//匹配分类
function matchingCategory(title, content)
{
	if (temp == 1)
	{
		var option = 
		{
			type: "POST",
			url: site_url('question/matchingCategory/'),
			data: "title="+title+"&content="+content,
			success: function(msg)
			{
				$("#marching").html(msg);
			}
		};
		$.ajax(option);
	}
}


function favors(qId)
{
	if(isOnline != 1){
		alert("请登录");
		return false;
	}
	else
	{
		$.ajax({
			type: "POST",
			url : site_url("javascript/addCollection/"),
			data: 'qId=' + qId,
			success: function(data){
				switch(data){
					case '-1':
						alert('收藏失败,请重试!');
						break;
					case '1' :
						alert('收藏成功!');
						break;
					case '2' :
						alert('你已经收藏了该信息!');
						break;
					case '-3':
						alert('不能收藏自己的信息哦!');
						break;
					default:
						alert('参数错误!');
						break;
				}
			}
		});
			
	}
}


//修改分类
$(document).ready(function(){
	$(".userId").click(function(){
		this.href = this.rel;
	});
	//操作大分类
	$("#parent li").click(function(){ 
		var obj = $("#parent li");
		for (var i=0; i<obj.length; i++)
		{
			$(obj[i]).attr("class","");
			$("#editCategory"+$(obj[i]).attr("child")).hide();
		}
		$(this).attr("class", "class_f2");
		var child = $(this).attr("child");
		$("#editCategory"+child).show();
		$("#editCategory"+child+" li").attr("class", "");
		$("#editCategory"+child+" li").eq(0).attr("class", "class_f2");
		ParentCategory = child;
		ChildCategory = $("#editCategory"+child+" li").eq(0).attr("v");
	});
	   
	//操作小分类
	$("#child li").click(function(){ 
		var obj = $("#child li");
		for (var i=0; i<obj.length; i++)
		{
			$(obj[i]).attr("class","");
		}
		$(this).attr("class", "class_f2");
		ChildCategory = $(this).attr("v");
	});
	  
}); 
