﻿var tmr;


jQuery.fn.center = function () {  
   this.css("position","absolute");  
   this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");  
   this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");  
   return this;  
}  
function parentdoc()
{
	var doc=document;
	if(parent.parent.parent.document)
	{
		doc=parent.parent.parent.document;
	}
	else
	{
		if(parent.parent.document)
		{
			doc=parent.parent.document;
		}
		else
		{
			if(parent.document)
			{
				doc=parent.document;
			}
		}
	}
	return doc;
}

function scrollto(id)
{
	var g=parentdoc().getElementById(id);
	var curLeft=0;
	var curTop=0;
	if(g)
	{
		if(g.offsetParent) 
		{
			while(g)
			{
				curLeft += g.offsetLeft;
				curTop += g.offsetTop;
				g = g.offsetParent;
			}
		}
		else
		{
			curTop=g.offsetTop;
		}
		window.scrollTo(0,curTop);
	}
}
function hidediv(div)
{
	var sd=parentdoc().getElementById(div);
	if(sd)
	{
		sd.style.visibility="hidden";
		//sd.style.display="block";
		sd.style.overflow="hidden";
		sd.style.height="1px";
		//sd.style.position="absolute";
	}
}
function showdiv(div)
{
	var sd=parentdoc().getElementById(div);
	if(sd)
	{
		sd.style.visibility="visible";
		//sd.style.display="inline";
		sd.style.overflow="";
		sd.style.height="";
		sd.style.position="";
	}
}
function showWait(caption)
{
	var sd=parentdoc().getElementById("await");
	sd.innerHTML='<div class="r" style="margin-right:5px;margin-top:2px;"><img src="/i/tb/close.gif" alt="Close" title="Close" width="19" height="19" class="cb" onclick="hideWait();"></div><img src="/i/jccswait.gif" alt="' 
		+ caption + '" title="' + caption + '" width="32" height="32"><br /><br />'+ caption;
	$('#await').center();
	showdiv("await");
	
}
function hideWait()
{
	hidediv("await");
}

function MessageBox(caption,msg,width,height,okButton)
{
	if(width==null)
	{
		width=300;
	}
	if(height==null)
	{
		height=300;
	}

	document.getElementById("jqdlg").innerHTML=msg;
	$("#jqdlg").dialog(
		{
			autoOpen: true, height: height, width: width, modal: true, title: caption, closeOnEscape: true
		}
	);

	if(okButton)
	{
		$( "#jqdlg" ).dialog( "option", "buttons", { "Ok": function() { eval(okButton);CloseMessageBox(); } , "Cancel": function() { CloseMessageBox(); }} );	
	}
	
	hideWait();
	
	if(document.getElementsByName("fcs001")[0])
	{
		document.getElementsByName("fcs001")[0].focus();
	}
}

function CloseMessageBox()
{
	$("#jqdlg").dialog( "destroy" );
	try
	{
		$("#imgpreview").remove();
	}
	catch(e){}
}

function getValue(id)
{
	var returnValue="";
	
	var g=parentdoc().getElementById(id);
	if(g)
	{
		var idType=g.type;
		if(idType)
		{
			if(idType=="text" || idType=="hidden" || idType=="password" || idType=="textarea")
			{
				returnValue=g.value;
			}
			if(idType.indexOf("select",0)>-1)
			{
				try
				{
					returnValue=g.options[g.selectedIndex].value;
				}
				catch(exp)
				{
					returnValue="";
				}
			}
			if(idType=="checkbox")
			{
				returnValue=(g.checked)?"1":"0";
			}
			if(idType=="radio")
			{
				returnValue=(g.checked)?"1":"0";
			}
		}
	}
	return returnValue;
}
function setem(elm,dom,to)
{
	parentdoc().getElementById(elm).innerHTML = '<a class="n" href="mailto:' + to + '@' + dom + '">' + to + '@' + dom + '</a>';
}

function setStatus(sts)
{
	window.defaultStatus='Copyright, ' + sts;window.status='Copyright, ' + sts;
}

function FileReport(enc)
{
	wsSecurity.FileReport(enc,FileReportDialog,FileReportDialog,enc);
}
function FileReportDialog(res,enc)
{
	if(res.length==3)
	{
		if(res[0]=="0")
		{
			MessageBox('File Report',res[1],400,res[2],"SubmitReport('" + enc + "');");
		}
		else
		{
			MessageBox('System Error',res[1],400,res[2]);
		}
	}
	else
	{
		MessageBox("Error","Session Error, Please refresh this page and try again.",250,250);
	}
}
function SubmitReport(enc)
{
	if(enc.length<30)
	{
		MessageBox("Error","Submission Error, Please refresh this page and try again.",250,250);
	}
	else
	{
		if(rtext.length<10)
		{
			MessageBox("Error","The 'reason' for your report was not descriptive enough.",250,250);
		}
		else
		{
			wsSecurity.SubmitReport(enc,rtext,SubmitReportResult,SubmitReportResult);
		}
	}
}
function SubmitReportResult(res)
{
	MessageBox('Report',res,400,200);
}