var LOAD_IMAGE = "<img src='images/ajax_loading.gif' style='margin-left:20px;'/>";
var SAVING_IMAGE = "<img src='images/ajax_saving.gif'/>";
var START_DATE = "_START_DATE"; //全局开始日期
var END_DATE = "_END_DATE";//全局结束日期
var SYSTEM_TIP = null;
var SYSTEM_TIP_INTERVAL = 5000;
var JUMP_ANALYSIS_ASSETS = "JUMP_ANALYSIS_ASSETS";
var PORTLET_COOKIE = "PORTLET_COOKIE";

$(document).ready(function() {
	/* toolTip */
	$('body *').tooltip({
		delay: 0,
		showURL: false
		});
	$("input[@type='text'], input[@type='password']").addClass("InputDefault");
	$("input[@type='text'], input[@type='password'], textarea").focus(function(){$(this).removeClass("InputDefault"),$(this).addClass("InputFocus");$(this).parent("p").find(".Explain").addClass("ExplainOn");}).blur(function(){$(this).removeClass("InputFocus"),$(this).addClass("InputDefault"),$(this).parent("p").find(".Explain").removeClass("ExplainOn");});
        $("a").bind("focus",function(){
            if(this.blur){ //如果支持 this.blur
                this.blur();
             }
        });

		$(".topMenuAction").click( function() {
			if ($("#openCloseIdentifier").is(":hidden")) {
				$("#slider").animate({ 
					marginTop: "-141px"
					}, 500 );
				$("#topMenuImage").html('<img src="images/open.png" alt="快捷添加" />');
				$("#openCloseIdentifier").show();
			} else {
				$("#slider").animate({ 
					marginTop: "0px"
					}, 500 );
				$("#topMenuImage").html('<img src="images/close.png" alt="关闭" />');
				$("#openCloseIdentifier").hide();
			}
		});  

});

function callId(){
	var random = Math.floor(Math.random() * 10001);
  	var id = (random + "_" + new Date().getTime()).toString();
  	return id;
}
/*系统提示相关方法*/
function adjustTipPosition(){
	var scrollTop = document.body.scrollTop;
	if(scrollTop>0){
		$("#idActionTip").css("top",scrollTop+"px");
	}else{
		$("#idActionTip").css("top","37px");
	}
}
function successTip(msg){
	$("#idActionTip").attr("className","success_tip").html(msg);
	SYSTEM_TIP = setInterval(clearTip,SYSTEM_TIP_INTERVAL);
	adjustTipPosition();
}

function failureTip(msg){
	$("#idActionTip").attr("className","failure_tip").html(msg);
	SYSTEM_TIP = setInterval(clearTip,SYSTEM_TIP_INTERVAL);
	adjustTipPosition();
}

function savingTip(msg){
	$("#idActionTip").attr("className","success_tip").html(msg);
}

function clearTip(msg){
	$("#idActionTip").attr("className","").html("");
	clearInterval(SYSTEM_TIP);
	adjustTipPosition();
}

function fetchOffset(obj) {
	var left_offset = obj.offsetLeft;
	var top_offset = obj.offsetTop;
	while((obj = obj.offsetParent) != null) {
		left_offset += obj.offsetLeft;
		top_offset += obj.offsetTop;
	}
	return { 'left' : left_offset, 'top' : top_offset };
}
/*监听浏览器srcoll行为
if($.browser.msie){
	window.attachEvent('onscroll',adjustTipPosition);
}else if($.browser.mozilla){
	window.addEventListener('scroll',adjustTipPosition,false);
}*/

/**
 * 初始化最大化和最小化按钮
 */
function initMinMaxIcon() {
	$('a.toggle').click(function(){
			$(this).parent('div').parent('div').next('div').toggle();
			var str = $(this).children('img').attr('src')
			str = str.substring(str.lastIndexOf('/'));
			// 展开与收起操作
			if (str == '/max.gif'){
				$(this).children('img').attr('src', 'images/min.gif');
				removePortletCookie($(this).attr('id'));
			} else {
				$(this).children('img').attr('src', 'images/max.gif');
				addPortletCookie($(this).attr('id'));
			}
			return false;
		}
	);
	
	$(".title img").hover(function(){
	  $(this).addClass("mouseover");
	},function(){
	  $(this).removeClass("mouseover");
	}).css("cursor","pointer");
	
	// 将cookie中已隐藏的portal执行隐藏操作
	var strPortlet = $.cookie(PORTLET_COOKIE);
	if (strPortlet != null && strPortlet != '' && strPortlet != undefined) {
		var portletArray = strPortlet.split(',');
		for (var i = 0; i < portletArray.length; i++) {
			if (portletArray[i] != "" && document.getElementById(portletArray[i]) != null) {
				// 自动展开与隐藏操作
				$('#' + portletArray[i]).parent('div').parent('div').next('div').toggle();
				var str = $('#' + portletArray[i]).children('img').attr('src')
				str = str.substring(str.lastIndexOf('/'));
				// 展开与收起操作
				if (str == '/max.gif'){
					$('#' + portletArray[i]).children('img').attr('src', 'images/min.gif');
				} else {
					$('#' + portletArray[i]).children('img').attr('src', 'images/max.gif');
				}
			}
		}
	}
}


//设置项目编号
function setProjectSN(){
	$("#idActionTip").attr("className","success_tip").html(msg);
}
//收放菜单
function show_menu(obj,id)
{
	$('#'+obj+id).slideToggle("slow",menu_icon(obj,id)); 
}
function menu_icon(obj,id)
{
	var src = $('#'+obj+'icon_'+id).attr("src");
	if ($('#'+obj+id).css('display') == 'none')
	{
		var re = /expand\.gif/g;
		src = src.replace(re, 'collapse.gif');
		$('#'+obj+'icon_'+id).attr("src", src);
		$('#'+obj+'icon_'+id).attr("alt", 'Collapse');
	}
	else
	{
		var re = /collapse\.gif/g;
		src = src.replace(re, 'expand.gif');
		$('#'+obj+'icon_'+id).attr("src", src);
		$('#'+obj+'icon_'+id).attr("alt", 'Expand');
	}
}