// JavaScript Document

function sendAjaxForm(id, okcallback, failcallback) {
	$.post($(id).attr('action'),$(id).find('*'),function(data) {
		if(parseInt(data)) {
			if(okcallback)
				okcallback();
		} else {
			if(failcallback)
				failcallback();
		}
	});
	
	return false;
}

function openFrontWindow(url,width,height) {
	drawWindowTags(width,height);
	
	var wF = $("#windowFront");
	var wI = $("#windowFrame");
	
	wI.attr('src',url);
	lockWebsite(function() {
		wF.fadeIn('slow')
		wF.animate({width:width+'px',minHeight:height+'px',marginLeft:'-'+(width/2)+'px',marginTop:'-'+(height/2)+'px'},'slow',function() {
			wI.animate({height:height+'px'},'slow',function () {
				$("#windowClose").fadeIn('slow');
			});
		});
	});
}

function drawWindowTags(width,height) {
	$("body").append('<div id="windowFront" style="display:none; -moz-border-radius:6px;" />');
	$("#windowFront").html('<iframe id="windowFrame" scrolling="no" frameborder="0" /><center><a onclick="closeFrontWindow(); return false;"><img id="windowClose" src="xms_resources/images/close.png" /></a><center>');
	
	$("#windowFront").css({position:'fixed',backgroundColor:'#FFF',top:'50%',left:'50%',zIndex:99,width:'100px',height:'100px',marginTop:'-60px',marginLeft:'-50px',padding:'5px',border:'#BBB 1px solid'});
	$("#windowFrame").css({width:'100%',height:'50px',overflow:'hidden'});
	$("#windowClose").css({marginTop:'5px',display:'none',zIndex:97});
}

function closeFrontWindow() {
	var wF = $("#windowFront");
	
	wF.fadeOut('slow',function() {
		unlockWebsite(function() {
			$("#windowFront").replaceWith('');
		});
	});
}

function drawBlackBox() {
	$("body").append('<div id="windowBlack" style="display:none;" />');
	$("#windowBlack").css({position:'fixed',backgroundColor:'#000',top:'0px',left:'0px',width:'100%',height:'100%',zIndex:98});
}

function delBlackBox() {
	$("#windowBlack").replaceWith('');
}

function lockWebsite(callback) {
	drawBlackBox();
	$("#windowBlack").fadeTo('slow',0.5,callback);
}

function unlockWebsite(callback) {
	$("#windowBlack").fadeOut('slow',function() {
		if(callback)callback();
		delBlackBox();
	});
}
