﻿var ajaxManager;
var selects;
jQuery(function(){
	ajaxManager = jQuery.manageAjax.create('cacheQueue', { 
    queue: true,  
    cacheResponse: false 
	}); 
});

function getModalDiv(src)
{
	ajaxManager.abort();
	ajaxManager.add({ 
	  success: function(html) { 
		getModalDivSuccess(html);
	  }, 
	  url: src
	});
	return false;
}

function getModalDivSuccess(html)
{
	 selects=jQuery('select:visible');
	  jQuery(selects).css("display","none");
	    var modal_div=document.createElement("div");
		modal_div.id="edu_modal_div";
		modal_div.style.height=Utility.getWindowHeight()+Utility.getScrollY()+"px";
		modal_div.style.width=Utility.getPageWidth()+"px";
		modal_div.style.position="absolute";
		modal_div.style.top="0px";
		modal_div.style.left="0px";
		modal_div.style.filter="alpha(opacity=50)";
		modal_div.style.opacity="0.5";
		modal_div.style.backgroundColor="#666";
		modal_div.style.zIndex="100000";
		document.body.appendChild(modal_div);
		var modal_div_content=document.createElement("div");
		modal_div_content.id="edu_modal_div_content";
		//modal_div_content.innerHTML=html;
		
		modal_div_content.style.position="absolute";
		modal_div_content.style.zIndex="100001";
		document.body.appendChild(modal_div_content);
		jQuery('#edu_modal_div_content').html(html);
		setModalSite();
		jQuery(window).scroll(setModalSite);
		jQuery(window).resize(setModalSite);
}
function removeModalDiv()
{
	jQuery('#edu_modal_div').remove();
	jQuery('#edu_modal_div_content').remove();
	jQuery(selects).css("display","");
	jQuery(window).unbind("scroll",setModalSite);
	jQuery(window).unbind("resize",setModalSite);
}
function setModalSite()
{
	jQuery('#edu_modal_div').css("height",Utility.getWindowHeight()+Utility.getScrollY()+"px");
	jQuery('#edu_modal_div').css("width",Utility.getPageWidth()+"px");
	//alert(Utility.getWindowHeight()+":"+Utility.getScrollY()+":"+Utility.getWindowWidth()+":"+Utility.getScrollX());
	jQuery('#edu_modal_div_content').css("top",(Utility.getWindowHeight()-jQuery('#edu_modal_div_content').height())/2+Utility.getScrollY());
	jQuery('#edu_modal_div_content').css("left",(Utility.getWindowWidth()-jQuery('#edu_modal_div_content').width())/2+Utility.getScrollX());
}
/***********************************************************************************
* 功能：得到页面实际尺寸
、滚动尺寸、偏移坐标
* 作者：Jack - http://www.kingyar.com
***********************************************************************************/
var Utility = new Object();

//功能: 得到窗口实际宽度
Utility.getWindowWidth = function()
{
	var windowWidth;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
	}	
    
    return windowWidth;
}

//功能: 得到窗口实际高度
Utility.getWindowHeight = function()
{
	var windowHeight;

	if (self.innerHeight) {	// all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}	
	
	return windowHeight;
}

//功能：得到页面滚动宽度(窗口宽度+滚动条宽度)
Utility.getScrollWidth = function()
{
	var xScroll;
	
	if (window.innerHeight && window.scrollMaxYX) {	
		xScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
	}

    return xScroll;
}

//功能: 得到页面滚动高度(页面实际高度 + 滚动条高度)
Utility.getScrollHeight = function()
{
	var yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
	}
	
    return yScroll;
}

//功能: 得到页面总高度
Utility.getPageWidth = function()
{
    var xScroll = Utility.getScrollWidth();
    var windowWidth = Utility.getWindowWidth();
    return (xScroll > windowWidth) ? xScroll : windowWidth;
}

//功能: 得到页面总宽度
Utility.getPageHeight = function()
{
    var yScroll = Utility.getScrollHeight();
    var windowHeight = Utility.getWindowHeight();
    return (yScroll > windowHeight) ? yScroll : windowHeight;
}

//得到页面水平滚动偏移
Utility.getScrollX = function()
{
	var xScroll;

	if (self.pageXOffset) {
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollLeft){	 // Explorer 6 Strict
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		xScroll = document.body.scrollLeft;	
	}
	
	return xScroll;
}

//功能: 得到页面垂直滚动偏移坐标
Utility.getScrollY = function()
{

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	    // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	return yScroll;
}

function remindMessage(message, flag)
{
	var data = jQuery('#remind_message').html();
	data = data.replace('{message}', message);
	return getModalDivSuccess(data);
}

function delResult(data)
{
	if (data>0)
	{
		return remindMessage('恭喜您，删除成功!');
	} else
	{
		return remindMessage('很遗憾，删除失败!');
	}
}

function insertResult(data)
{
	if (data>0)
	{
		return remindMessage('恭喜您，添加成功!');
	} else
	{
		return remindMessage('很遗憾，添加失败!');
	}
}

function updateResult(data)
{
	if (data>0)
	{
		return remindMessage('恭喜您，更新成功!');
	} else
	{
		return remindMessage('很遗憾，更新失败!');
	}
}