/**
 * 公有js
 * createDate: 2011-02-27
 * */
 var projectName = "/Portal/";

jQuery(function(){
	try {
		$("#functions").treeview();
		
		//提交按钮图片变更
		/*jQuery('.formBtn').hover(function(){
			jQuery(this).css('background','url(../../images/system_rightpic1_bule1.jpg)');
		},function(){
			jQuery(this).css('background','url(../../images/system_rightpic1.jpg)');
		});*/
	} catch(e) {
	
	}
	
	//获取当前时间
	var now = new Date();
	var year = now.getFullYear();
	var month = now.getMonth()+1;
	var day = now.getDate();
	jQuery('#nowDate').html(year+'年'+month+'月'+day+'日');
	
	
	
	 //全选或反选
	jQuery('#checkAll').click(function(){
		if(jQuery(this)[0].checked)
			jQuery('input:checkbox[class=childBox]').attr('checked',true);
		else
			jQuery('input:checkbox[class=childBox]').attr('checked',false);
	});
	
	jQuery('input:checkbox[class=childBox]').each(function(){
		jQuery(this).unbind('click').click(function(){
			var flag = false;
			if(jQuery(this)[0].checked) {
				flag = true;
			} else {
				jQuery('input:checkbox[class=childBox]').each(function(){
					if(jQuery(this)[0].checked) {
						flag=true;
					}
				});
			}
			jQuery('#checkAll')[0].checked=flag;
		});
	});
	
	
	
});

////生成新闻内容
//jQuery.LiUtil = function(opts){
//	jQuery.LiUtil_cascade(opts.dataUrl, opts.target, opts.targetUrl, opts.limit, opts.charLengthLimit, opts.haveTime. opts.model);
//};

//model = "<span></span><a></a>";
//jQuery.LiUtil_cascade = function(dataUrl, target, targetUrl, limit, charLengthLimit, haveTime, model) {
//	jQuery.post(dataUrl,function(data){
//		var newsHtml = "";
//		var json= eval("["+data+"]");
//		json = eval(json[0].newsJson);
//		for(var i=0; i<limit; i++) {
//			var name = json[i].name;
//			if(json[i].name.length>charLengthLimit) {
//				json[i].name = json[i].name.substring(0,charLengthLimit)+"...";
//			}
//			if(model==null) {
//				newsHtml += "<li>";
//				if(haveTime)
//					newsHtml += "<span>"+json[i].addTime+"&nbsp;</span>";
//				newsHtml += "<a title='"+name+"' href='"+targetUrl+json[i].id+"'>"+json[i].name+"</a>";
//				newsHtml += "</li>";
//			} else {
//				
//			}
//		}
//		jQuery(target).html(newsHtml);
//	});
//}

function ajax(url,params,mothod,callback){
	$.ajax({
    	url:projectName + url,
    	type:mothod,
		dataType:'json',
		data: params,
		success:callback,
		error:function(XMLHttpRequest,textStatus,errorThrown){
			alert(XMLHttpRequest.status);
			var msg = '';
			switch(textStatus){
				case 'timeout':
					msg = '服务器连接超时';
				break;
				case 'error':
					msg = '服务器错误';
				break;
				case 'parsererror':
					msg = '服务器分析XML错误';
				break;
				default:
					msg = '发生未知错误';
				break;
			} 
			alert(msg);
		}
    });
}
//分页所用到的js
function page_one(page_one)
{
    if(document.getElementById(page_one).style.display != "block")
    {
        document.getElementById(page_one).style.display = "block";
    }
    else
    {
        document.getElementById(page_one).style.display = "none";
    }
}
//分页所用到的js
function queryPage(url){
	var page_s=jQuery(document.forms[0]).serialize();
	url += ('&data=' + encodeURIComponent(page_s));
    window.location.href=url;
}

//加入收藏
function addCookie() {
	if (document.all)  {
		window.external.addFavorite(document.location.href,'重庆建筑工程职业学院');
	} else if (window.sidebar) {
		window.sidebar.addPanel('重庆建筑工程职业学院', document.location.href, "");
	}
}

//设为主页
function setHomepage() {
	if(document.all) {
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(document.location.href);
	} else if (window.sidebar) {
		if(window.netscape) {
			try { 
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
			} catch (e) { 
				alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" ); 
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage',document.location.href);
		alert('已设置成功')
	}
}

function DrawImage(ImgD,FitWidth,FitHeight){
     var image=new Image();
     image.src=ImgD.src;
     if(image.width>0 && image.height>0){
         if(image.width/image.height>= FitWidth/FitHeight){
             if(image.width>FitWidth){
                 ImgD.width=FitWidth;
                 ImgD.height=(image.height*FitWidth)/image.width;
             }else{
                 ImgD.width=image.width; 
                ImgD.height=image.height;
             }
         } else{
             if(image.height>FitHeight){
              ImgD.height=FitHeight;
              ImgD.width=(image.width*FitHeight)/image.height;
             }else{
               ImgD.width=image.width; 
               ImgD.height=image.height;
            } 
       }
    }
}

/**
 * 获取元素与左边距的方法
 * */
function getAbsLeft(obj){  
	var l = obj.offsetLeft;
//	while(obj.offsetParent != null){  
//		obj = obj.offsetParent;     
//		l += obj.offsetLeft;
//	} 
	return l;  
}

