﻿$(document).ready(function(){
	
	correctPNG();
	//选中所有项目
	$(".SelectAllItem").click(function(){
		$(".chkItme").each(function(){
			if(!$(this).attr('disabled'))$(this).attr("checked",true);
		}); 
	}); 
	//不选中所有项目
	$(".NotSelectAllItem").click(function(){
		$(".chkItme").each(function(){
			$(this).attr("checked",false);
		}); 
	}); 
	$('.menu>li>a').mouseover(function(){
		var pos;
		var id=this.id;
		var submenu=$("#sub"+id);
		//获取子菜单区域资料
		pos=$("#submenu").position();
		var MenuBoxLeft=pos.left;
		var MenuBoxTop=pos.top;
		var MenuBoxWidth=$('#menu').width();
		//取得子菜单的宽度
		var SubMenuWidth=submenu.width();
		//取得当前主菜单项目的宽度
		var MainMenuWidth=$('#'+id).width();
		//取得当前主菜单项目的位置
		pos = $(this).position();
		var MainMenuLeft=pos.left;
		var MainMenuTop=pos.top;
		//隐藏所有子菜单
		$('.submenu').hide();
		//显示当前菜单的子菜单
		submenu.show();
		//计算子菜单的当前位置
		MenuTop=MenuBoxTop+7;
		var SubMenuWidth_Half=SubMenuWidth/2;
		SubMenuWidth_Half=Math.ceil(SubMenuWidth_Half);
		var MenuBoxRightWidth=MenuBoxLeft+MenuBoxWidth-MainMenuLeft-MainMenuWidth/2;
		MenuBoxRightWidth=Math.ceil(MenuBoxRightWidth);
		var MenuBoxLeftWidth=MainMenuLeft-MenuBoxLeft+MainMenuWidth/2;
		MenuBoxLeftWidth=Math.ceil(MenuBoxLeftWidth);
		//alert("SubMenuWidth_Half:"+SubMenuWidth_Half+"，MenuBoxRightWidth:"+MenuBoxRightWidth+"，MenuBoxLeftWidth:"+MenuBoxLeftWidth);

		if(SubMenuWidth>=MenuBoxWidth){
			MenuLeft=MenuBoxLeft;
		}else if(SubMenuWidth_Half<=MenuBoxRightWidth && SubMenuWidth_Half<=MenuBoxLeftWidth){
			MenuLeft=MainMenuLeft+MainMenuWidth/2;
			MenuLeft=MenuLeft-SubMenuWidth/2;
		}else if(SubMenuWidth_Half>=MenuBoxLeftWidth){
			MenuLeft=MenuBoxLeft;
		}else if(SubMenuWidth_Half>=MenuBoxRightWidth){
			MenuLeft=MenuBoxLeft+MenuBoxWidth-SubMenuWidth;
		}else{
			MenuLeft=MenuBoxLeft;
		}
		MenuLeft=Math.ceil(MenuLeft);
		submenu.offset({top:MenuTop,left:MenuLeft});
	});
});

function img_auto_resize(p,w,h){
	var pw,ph;
	var c;
	pw = p.width;
	ph = p.height;
	if(w>0 && pw>w){ph=ph*(w/pw);pw=w;}
	if(h>0 && ph>h){pw=pw*(h/ph);ph=h;}
	p.width=pw;
	p.height=ph;
}

function mhHover(cls){
	event.srcElement.className = cls;
}

function checkNumber(par_val){
	if(par_val==""){
		return false;
	}else{
		for(i=0; i<par_val.length; i++){
			if (par_val.substring(i, i+1)!="."){
				if (par_val.substring(i, i+1)<"0" || par_val.substring(i, i+1)>"9"){
					return false;
				}
			}
		}
		return true;
	}
}

//使用 IE6.0 和 IE5.5 中的 PNG 格式的背景透明
// correctly handle PNG transparency in Win IE 5.5 & 6.0
function correctPNG(){
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version < 7.0) && (document.body.filters)){
		for(var j=0; j<document.images.length; j++){
			var img = document.images[j];
			var imgName = img.src.toUpperCase();
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
				var imgID = (img.id) ? "id='" + img.id + "' " : "";
				var imgClass = (img.className) ? "class='" + img.className + "' " : "";
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
				var imgStyle = "display:inline-block;" + img.style.cssText;
				if (img.align == "left") imgStyle = "float:left;" + imgStyle;
				if (img.align == "right") imgStyle = "float:right;" + imgStyle;
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
				var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
				img.outerHTML = strNewHTML;
				j = j-1;
			}
		}
	}
}

//刷新验证码
function reloadSecurityCode(obj){
	var strlink=$('#'+obj).attr('src');
	strlink+=strlink.indexOf('?')=='-1'?"?":"&";
	strlink+="thistime="+Math.random();
	$('#'+obj).attr("src",strlink);
}

//复制到剪贴板 并且提示
function CopyToClipBoard(content,tip){
	window.clipboardData.setData("Text",content);
	if(tip!='')alert(tip);
}
//注册验证
function Regischeck(){
	if($('#user_name').val()==''){
		alert('请填写用户名');
		$('#user_name').focus();
		return false;
	}
	if($('#user_login_pwd').val()==''){
		alert('请填写密码');
		$('#user_login_pwd').focus();
		return false;
	}
	if($('#user_login_pwd2').val()==''){
		alert('请再次确认密码');
		$('#user_login_pwd2').focus();
		return false;
	}
	if($('#user_login_pwd').val()!=''){
		
		if($('#user_login_pwd').val().length>16 || $('#user_login_pwd').val().length<6  ){
			alert('密码的字符数在6-16范围之间');
			$('#user_login_pwd').focus();
		    return false;
		}
	}
	if($('#user_login_pwd').val()!='' && $('#user_login_pwd2').val()!='' ){
		if($('#user_login_pwd').val() != $('#user_login_pwd2').val()){
			alert('两次输入的密码不一致');
			$('#user_login_pwd2').focus();
			return false;
		}
	}
	return true;
}
//登录客户端验证
function Landischeck(){
	if($('#user_name2').val()==''){
		alert('请填写用户名');
		$('#user_name2').focus();
		return false;
	}
	if($('#user_login_pwd3').val()==''){
		alert('请填写密码');
		$('#user_login_pwd3').focus();
		return false;
	}
}
//找回密码客户端验证
function Forgetischeck(){
	if($('#user_name2').val()==''){
		alert('请填写用户名');
		$('#user_name2').focus();
		return false;
	}
	if($('#user_email').val()==''){
		alert('请填写电子邮箱');
		$('#user_email').focus();
		return false;
	}
	
	return true;

}

$(document).ready(function(){
	$('.submenu_class').hide();
	$('#submenu_1').show();
	$('#menu_1').css("background","url(/images/comment_tab_cur_bg.jpg)");
	$('#menu_1').find("a").css("color","#fff");	
	$('.main_nav').click(function(){						  
		var id=this.id;
		$('.main_nav').css("background","url(/images/comment_tab_bg.jpg)");
		$('.main_nav').find("a").css("color","#992a0c");
		$("#"+id).css("background","url(/images/comment_tab_cur_bg.jpg)");
		$("#"+id).find("a").css("color","#fff");
		var submenu=$("#sub"+id);
		$('.submenu_class').hide();
		submenu.show();
	});
});
