﻿if(!mp_load_img){		  
	var mp_load_img = "images/loadingAnimation.gif";
}
if(!mp_close_img){
	var mp_close_img = "images/default/mp_close.gif";
}
var default_width = 600;
var default_height = 800;


$(document).ready(function(){   
	imgLoader = new Image();// preload image
	imgLoader.src = mp_load_img;
	$('a.mpbox, input.mpbox').click(function(){
		//var title = this.title || this.name || null;
		var url = this.href || this.alt;
		mp_get(url);
		this.blur();
		return false;
	})
});

// 显示登录框
function mp_show(msg, title){
	var clientWidth = document.body.clientWidth;
	var clientHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
	// 添加内容框
	if($('#mp_box').html() == null){
		$("body").prepend("<div id='mp_box'><h1><a href='javascript:mp_hide()'><img src='"+ mp_close_img +"' /></a></h1><div id='mp_box_con'></div></div>");	
	}
	// 添加IE6遮罩层
	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		//$("body","html").css({height: "100%", width: "100%"});
		//$("html").css("overflow","hidden");
		if ($("#mp_hideselect").html() == null) {//iframe to hide select elements in ie6
			$("body").prepend("<iframe id='mp_hideselect'></iframe>");
		}
	}
	// 添加遮罩层
	if($("#mp_overlay").html() == null){
		$("body").prepend("<div id='mp_overlay' onclick='mp_hide();'></div>");
	}
	// 显示弹出层
	$('#mp_box_con').html("<div>"+msg+"</div>");
	// 默认大小
	//alert(clientHeight);
	//alert(scrollTop);
	//alert($('#mp_box').height());
	var width = $('#mp_box').width();
	var height =  $('#mp_box').height();
	if(!width){ width = default_width;}
	if(!height){height = default_height;}
	
	$('#mp_box').css('left',((clientWidth-parseInt(width))/2)+"px");
	$('#mp_box').css('top',((clientHeight-parseInt(height))/2 + scrollTop)+"px");
	$('#mp_box').show();

	
}

// 关闭弹出框
function mp_hide(){
	$('#mp_overlay').remove();
	$('#mp_hideselect').remove();
	$('#mp_box').hide();
}


// ajax_get
function mp_get(url){
	$.ajax({
		url: url,
		cache: false,
		success:function(res){
			mp_show(res);
		}
	}); 
	return false;
}


// ajax_post
function mp_post(formid,funs){
	// 验证一下
	
	var ajaxframeid = 'ajaxframe';
	var ajaxframe = $('#'+ajaxframeid);
	var form = $('#'+formid);
	if(validator(form.get(0))){
		if(ajaxframe.html() == null) {
			$('body').prepend("<iframe name='" + ajaxframeid + "' id='" + ajaxframeid + "' style='display:none;'></iframe>");
		}
		form.prepend("<input type='hidden' name='inajax' value='true' />");
		form.attr('target', ajaxframeid);
		form.submit();
	}
	return false;
}

// mp_valid
function mp_valid(formid){
	var form = $('#'+formid);
	return 	validator(form.get(0));
}


