
/*
author:628557@qq.com
获得指定元素的值或选中状态
支持input:radio--返回选中的值 checkbox--返回选中状态 text等返回value
入口:逗号隔开的id列表 如user,pass
返回:&user=test&pass=test
*/
function makedatafromId(v) {
	var tempArr = v.split(",");
	var out_str = "";
	var i;
	for (i = 0; i < tempArr.length; i++) {
	  switch ($("#" + tempArr[i]).attr("type")) {
		case "radio": //raido
			out_str += "&" + $("#" + tempArr[i]).attr("name") + "=" + $("input[name=" + $("#" + tempArr[i]).attr("name") + "][checked]").val();
			break;
		case "checkbox":
			if ($("#" + tempArr[i]).is(':checked') == true) {
				out_str += "&" + tempArr[i] + "=on";
			}
			break;
		default:
			out_str += "&" + tempArr[i] + "=" + encodeURIComponent($("#" + tempArr[i]).val());
		}

	}
	return out_str;
}

//生成下拉列表日期
// 年id,月id,日id,开始年,结束年,日期写入id,2009-6-1格式的默认日期
// 日id。默认值可以为空
function loaddate(oyear, omonth, oday, startyear, endyear, destid, defaultdate, is_show) {
	var i;
	var dayvalue = "";

	$("#" + oyear)[0].options.add(new Option('---', 0));
	for (i = startyear; i <= endyear; i++) {
		$("#" + oyear)[0].options.add(new Option(i, i));
	}
	
	$("#" + omonth)[0].options.add(new Option('---', 0));
	for (i = 1; i < 13; i++) {
		$("#" + omonth)[0].options.add(new Option(i, i));
	}

	if (oday != "") {
		$("#" + oday)[0].options.add(new Option('---', 0));
		for (i = 1; i < 32; i++) {
			$("#" + oday)[0].options.add(new Option(i, i));
		}
	}

	if(is_show!==false)
	if (defaultdate != "") {
		$("#" + oyear).val(defaultdate.split("-")[0].replace(/^0/, ""));
		$("#" + omonth).val(defaultdate.split("-")[1].replace(/^0/, ""));
		$("#"+destid).val(defaultdate.split("-")[0].replace(/^0/,"")+'-'+defaultdate.split("-")[1].replace(/^0/,""));
		if (oday != "") {
			$("#" + oday).val(defaultdate.split("-")[2].replace(/^0/, ""));
			$("#"+destid).val(defaultdate.split("-")[0].replace(/^0/,"")+'-'+defaultdate.split("-")[1].replace(/^0/,"")+'-'+defaultdate.split("-")[2].replace(/^0/,""));
		}
	}

	if (oday != "") {
		$("#" + oday).change(
				function() {
					$("#" + destid).val(
							$("#" + oyear).val() + '-' + $("#" + omonth).val()
									+ '-' + $("#" + oday).val());
				});
	}

	//修改年
	$("#" + oyear).change(
			function() {
				if (oday != "") {
					dayvalue = '-' + $("#" + oday).val();
				}
				$("#" + destid).val(
						$("#" + oyear).val() + '-' + $("#" + omonth).val()
								+ dayvalue);
			});
	// 修改月
	$("#" + omonth).change(
			function() {
				if (oday != "") {
					dayvalue = '-' + $("#" + oday).val();
				}
				$("#" + destid).val(
						$("#" + oyear).val() + '-' + $("#" + omonth).val()
								+ dayvalue);
			});

}

function pickedFunc() {
	$dp.$('birthday_y').value = $dp.cal.getP('y').replace(/^0/, "");
	$dp.$('birthday_m').value = $dp.cal.getP('M').replace(/^0/, "");
	$dp.$('birthday_d').value = $dp.cal.getP('d').replace(/^0/, "");
}

//通用发送数据
// 显示对话框
function sendinfo(url) {
	$.weeboxs.open('正在加载...', {
		title : '提示'
	});
	$.ajax( {
		type : "post",
		dataType : "json",
		url : url,
		success : function(msg) {
			$("#dialog-content").html(msg.out_msg);
			if(msg.url) redirect(msg.url,2);
		}
	});
return false;
}

//弹出菜单
/*
showmenu(thisobjid,menuobjid,state,position)
thisobjid =控件本身id
menuobjid =弹出菜单层的id
state 有两个值可选，show即显示菜单 hidden即隐藏菜单
position 有四个值可选，top菜单显示于顶部 bottom菜单显示于底部 left菜单显示于左侧&amp;nbsp; right菜单显示于右侧
 */
function showmenu(obj1, obj2, state, location) {
	var btn = document.getElementById(obj1);
	var obj = document.getElementById(obj2);

	var h = btn.offsetHeight;
	var w = btn.offsetWidth;
	var x = btn.offsetLeft;
	var y = btn.offsetTop;

	obj.onmouseover = function() {
		showmenu(obj1, obj2, 'show', location);
	}
	obj.onmouseout = function() {
		showmenu(obj1, obj2, 'hide', location);
	}

	while (btn = btn.offsetParent) {
		y += btn.offsetTop;
		x += btn.offsetLeft;
	}

	var hh = obj.offsetHeight;
	var ww = obj.offsetWidth;
	var xx = obj.offsetLeft;// style.left;
	var yy = obj.offsetTop;// style.top;
	var obj2state = state.toLowerCase();
	var obj2location = location.toLowerCase();

	var showx, showy;

	if (obj2location == "left" || obj2location == "l" || obj2location == "top"
			|| obj2location == "t" || obj2location == "u"
			|| obj2location == "b" || obj2location == "r"
			|| obj2location == "up" || obj2location == "right"
			|| obj2location == "bottom") {
		if (obj2location == "left" || obj2location == "l") {
			showx = x - ww;
			showy = y;
		}
		if (obj2location == "top" || obj2location == "t" || obj2location == "u") {
			showx = x;
			showy = y - hh;
		}
		if (obj2location == "right" || obj2location == "r") {
			showx = x + w;
			showy = y;
		}
		if (obj2location == "bottom" || obj2location == "b") {
			showx = x;
			showy = y + h;
		}
	} else {
		showx = xx;
		showy = yy;
	}
	obj.style.left = showx + "px";
	obj.style.top = showy + "px";
	if (state == "hide") {
		hiddenmenu(obj2);
	} else {
		obj.style.visibility = "visible";
	}
}
function hiddenmenu(psObjId) {
	document.getElementById(psObjId).style.visibility = "hidden";
}

//延迟转向
//url：地址
//延迟：秒数
function redirect(url,timeout)
{
	window.setTimeout(function(){top.location.href=url;},timeout*1000);
}

function trySetDefaultText(obj,txt){
	if(obj.value==""){
		obj.value = txt;
		obj.style.color = '#cccccc';
	}
	else obj.style.color = '#000000';
}
function tryClearDefaultText(obj,txt){
	if(obj.value==txt){
		obj.value = '';
		obj.style.color = '#000000';
	}
}

/**
 * by：hansson
 * 
 * 按下class="han_show_click" 则 class="han_show_box" 滑下
 * class="han_show_tip" 为信息展示时的提示信息
 * 注：class="han_show_box" 初始为 style="display：none;"
 */
$(document).ready(function() {
	$(".han_show_click").click(function(){
		$(".han_show_box").slideToggle("slow", function(){});
		if($(".han_show_tip")){
			var tmp = $(".han_show_tip").val();
			$(".han_show_tip").val( $(this).val() );
			$(this).val(tmp);
		}
	});
});

/**
 * by：hansson
 * 
 * 弹出举报框
 */
function show_report_box(type){
	var titls = {1:"举报不良信息", 2:"给人才网提建议"};
	if(!type || type>titls.length || type<1 ) type=1;
	var box_title = titls[type];
	
	$.weeboxs.open('正在加载...', {
		title : box_title,
		showButton : true,
		showCancel : true,
		showOk:false,
		cancelBtnName:'关闭窗口'
	});
	var data = '<form action="/module/report.php" method="post" id="appReport" onsubmit="javascript:post_report(this);return false;">';
		data +='<input name="type" id="type" type="hidden" value="' + type + '"/>';
		data +='<ul style="text-align:left;padding-left:30px;">';
		if(type==1)
		data +='<li style="padding-top:10px"><span>举报URL：</span><br/><input name="from_url" id="from_url" type="text" size="45" disabled="disabled" value="'+window.location.href+'"/></li>';
		data +='<li style="padding-top:10px"><span>具体内容：</span><br/><textarea name="description" id="description" cols="35" rows="4"/></li>';
		data +='<li style="padding-top:10px"><span>联系邮箱：</span><br/><input type="text" name="reporter_email" id="reporter_email" size="45"/></li>';
		data +='<li style="padding-top:10px"><span>其他联系方式：</span><br/><textarea name="reporter_contact" id="reporter_contact" cols="35" rows="3">手机：\nQ Q：\nMSN：</textarea></li>';
		data +='<li style="padding-top:10px"><input type="submit" value=" 提 交 "></li>';
		data +='</ul>';
		data +='</form>';
//$.get("/module/report.php", function(data){
	$("#dialog-content").html(data);
//});
	return false;
}

function post_report(f){
	function trim(str) {
		if(!str) return "";
		return str.replace(/(^\s*)|(\s*$)/g, "");
	}
	var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
	
	var desc = trim(f.description.value);
	var email = trim(f.reporter_email.value);
	
	if(!desc){ alert("具体内容必须填写"); return false;}
	if(desc.length<10){ alert("具体内容不能少于10个字"); return false;}
	else if(desc.length>800){ alert("具体内容不能多于800个字"); return false;}
	if(email&&!reg.test(email)) { alert("邮件格式错误"); return false;}
		
	$("#dialog-content").html("<div style='margin:10px auto;'>正在提交信息...</div>");
	var str = "";
	if(f.type) str += "&type=" + encodeURIComponent(f.type.value);
	str += "&description=" + encodeURIComponent(f.description.value);
	str += "&reporter_email=" + encodeURIComponent(f.reporter_email.value);
	str += "&reporter_contact=" + encodeURIComponent(f.reporter_contact.value);
	$.ajax( {
		type : "post",
		dataType : "json",
		url : "/module/report.php",
		data : "action=report_post" + str,
		success : function(msg) {
			$("#dialog-content").html(msg.out_msg);
		}
	});
}

/**
 * 用法：checkLogin(JS);如果没登陆，会弹出登陆框，登陆完后执行参数JS，如果有登陆，直接执行参数JS
 * 例：checkLogin('top.location.href=<quote>/module/company/joblist.php<quote>;');
 * <quote>代替单引号
 */
function checkLogin(js) {
	js = js.replace(/<quote>/g, "'");
	$.ajax({
		type: "post",
		dataType: "json",
		url: "/checkLogin.php",
		data: "js="+js,
		success: function(msg){
			if(msg.is_suc==1)
			{
				eval(js);
			}
			else
			{
			   $.weeboxs.open('正在加载...', {
					title : '请先登陆',
					showButton : true,
					showCancel : true,
					showOk:false,
					cancelBtnName:'关闭窗口'
				});
				$("#dialog-content").html(msg.out_msg);
			}
		}
		});

		return false;
}

function showLogin(js) {
	$.ajax({
		type: "post",
		dataType: "json",
		url: "/module/login.php",
		data: "action=login"+makedatafromId("username,password,code,rememberpass"),
		success: function(msg){
			if(msg.is_suc==1)
			{
				eval(js);
			}
			else
			{
				alert(msg.out_msg);
				$("#code").val('');
				$("#codeimg").attr("src","/module/validateImg.php?t="+Math.random());
			}
		}
		});
	
		return false;
}

function addFav(sURL, sTitle) 
{ 
    try 
    { 
        window.external.addFavorite(sURL, sTitle); 
    } 
    catch (e) 
    { 
        try 
        { 
            window.sidebar.addPanel(sTitle, sURL, ""); 
        } 
        catch (e) 
        { 
            alert("加入收藏到浏览器失败，请使用Ctrl+D进行添加"); 
        } 
    } 
}