document.onmousemove=drag;
var mouseY=0;
var mouseX=0;
var dialogOpen=0;
var processing=0;
function doSubmit(obj){
	xajax_procForm(obj.name, xajax.getFormValues(obj.name+"Form"));
	dialog("<center>Loading</center>", 0, 90);
}
function dialog(content, w, h, y){
	if(w){
		sizeDialogWidth(w);
	}
	if(h){
		sizeDialogHeight(h);
	}
	if(dialogOpen){
		
		updateDialog(content);
	}
	else{
		openDialog(content);
	}
	if(h==0 || !h){
		autoHeightDialog();
	}
	if(y){
		if(y=="scroll"){
			shiftDialogToScroll();
		}
	}
}
function openDialog(content){
	if(dialogOpen){
		closeDialog();
		setTimeout('open(\''+content+'\')', 1300);
	}
	else{			
		$('dialogCase').style.zIndex="10";$('dialogContent').style.zIndex="10";	$('dialogBack').style.zIndex="10";
		$('dialogCase').style.top="100px";
	
		$('dialogContent').innerHTML = content;
		new Effect.Appear('dialogBack', {from:0.0, to:0.6,afterFinish:function(){autoHeightDialog(); $('dialogCase').style.zIndex="10";$('dialogContent').style.zIndex="10";$('dialogBack').style.zIndex="10";}});
		new Effect.Appear('dialogContent', {from:0.0, to:1.0});
		dialogOpen=1;
	}
}
function updateDialog(content){
	$('dialogContent').innerHTML = content;
	shiftSubmitCase();
}
function closeDialog(wait){
	if(dialogOpen){
		if(wait){
			pause(wait);
		}
		dialogOpen=0;
		var oh = $('dialogContent').offsetHeight;
		new Effect.Fade('dialogBack', {from:0.6, to:0.0, afterFinish:function(){$('dialogCase').style.zIndex="2";$('dialogContent').style.zIndex="2";$('dialogBack').style.zIndex="2";}});
		new Effect.Fade('dialogContent', {from:1.0, to:0.0});
			
	}
}
function doPopulateForm(form, formDataLong){
	var formData = formDataLong.split("`");
	var formObj = $(form+'Form');
	for(var f=0; f<formObj.elements.length; f++){
		formObj.elements[f].value=formData[f];
	}
}
function sizeDialogWidth(w){
	$('dialogCase').style.width=w/1.75+"px";
	$('dialogContent').style.width=w-60+"px";
	$('dialogBack').style.width=w+"px";
}
function sizeDialogHeight(h){
	$('dialogContent').style.height=h-60+"px";
	$('dialogBack').style.height=h+"px";
}
function autoHeightDialog(){
	$('dialogContent').style.overflow="auto";
	var oh = $('dialogContent').offsetHeight;
	$('dialogBack').style.height=oh+20+"px";
	shiftSubmitCase();
}
function shiftDialogToScroll(){
	var min=0;
	if(window.scrollY>200){
		min = 100;
	}
		
	$('dialogCase').style.top= window.scrollY - min + "px";
}
function shiftSubmitCase(){
	if($('dialogContent').scrollHeight){
		$('submitCase').style.bottom= 20 - ($('dialogContent').scrollHeight-$('dialogContent').offsetHeight) + "px";
	}
	$('submitCase').style.display="block";
	
}
//Specific Dialogs
//
function loginDialog(must){
	var msg="You must be logged in to do that!";
	var dialogHeight=180;
	if(!must){
		msg="";
		var noAlert="display:none; height:0px;";
	}
	else{
		dialogHeight=220;
	}
	dialog("<div id='dialogHead'>Login</div><div class='warning' id='dialogAlert' style=\"width:522px; margin-top:5px; margin-left:-10px; "+noAlert+" \">"+msg+"</div><form method='post' action='log.php' onsubmit='return false;'   name='loginForm'  id='loginForm'><div><table  style='width:500px; font-family:trebuchet ms; font-size:.8em; margin-top:15px;' valign='top'><tr><td>E-Mail</td><td><input class='longInp' type='text' id='uemail' name='uemail'/></td></tr><tr><td>Password</td><td><input class='longInp' type='password' id='psw' name='psw'/></td></tr></table></div></form><div id='submitCase'><a href='#' class='dialogLink' name='login' onclick='doSubmit(this); return false;'/>Login</a>&nbsp;&nbsp;&nbsp;<a href='#' class='dialogLink' id='closeDialog'  onclick='closeDialog(); return false;'/>Close</a>", 0, dialogHeight); 	
}
function drag(evt){
	evt = (!evt && window.event)?window.event:evt;
	mouseY = evt.clientY+(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	mouseX = evt.clientX+(document.documentElement.scrollLeft ?	document.documentElement.scrollLeft : document.body.scrollLeft);
}
var dateForm="";
function getDateForm(df){
	dateForm=df;
}

function pause(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
} 