// JavaScript Document
function viewDiv(div) 
{
	document.getElementById(div).style.visibility='visible';
}
function hideDiv(div)
{
	document.getElementById(div).style.visibility='hidden';
}
 function myFocus(element) {
   if (element.value == element.defaultValue) {
     element.value = '';
   }
 }
 function myBlur(element) {
   if (element.value == '') {
     element.value = element.defaultValue;
   }
 }

function doNav(theUrl) {
	document.location.href = theUrl;
}
 function showLightBox(title,message) {
	var viewport = document.viewport.getDimensions();
	var page = $(document.body).getDimensions();
	var width, height;
	if(viewport.width < page.width) {
		width = page.width;
	} else {
		width = viewport.width;
	}
	if(viewport.height < page.height) {
		height = page.height;
	} else {
		height = viewport.height;
	}
	doNav('#');
	$(document.body).insert('<div id="popupMessage" class="popupMessage"><div style="float:right;"><a href="#" onclick="return closeLightBox();"><img src="images/icons/close.gif" border="0" alt="Close Window" /></a></div><h1>'+title+'</h1>'+message+'</div>');
	$(document.body).insert('<div id="overlay" class="overlay" style="width:'+width+'px;height:'+(height+60)+'px"></div>');
	new Event.observe(window,'resize',function() {
		adjustOverlay();
	});
}
function showLightBoxWait(message) {
	var viewport = document.viewport.getDimensions();
	var page = $(document.body).getDimensions();
	var width, height;
	if(viewport.width < page.width) {
		width = page.width;
	} else {
		width = viewport.width;
	}
	if(viewport.height < page.height) {
		height = page.height;
	} else {
		height = viewport.height;
	}
	doNav('#');
	$(document.body).insert('<div id="popupMessage" class="popupMessage">'+message+'</div>');
	$(document.body).insert('<div id="overlay" class="overlay" style="width:'+width+'px;height:'+(height+60)+'px"></div>');
	new Event.observe(window,'resize',function() {
		adjustOverlay();
	});
}
function closeLightBox() {
	if(Object.isElement($('popupMessage'))) {
		$('popupMessage').remove();
	}
	if(Object.isElement($('overlay'))) {
		$('overlay').remove();
	}
}
function adjustOverlay() {
	var viewport = document.viewport.getDimensions();
	var page = $(document.body).getDimensions();
	var width, height;
	if(viewport.width < page.width) {
		width = page.width;
	} else {
		width = viewport.width;
	}
	if(viewport.height < page.height) {
		height = page.height;
	} else {
		height = viewport.height;
	}
	$('overlay').setStyle({width:width+'px',height:(height+60)+'px'});
}
function popUp(URL,width,height)
{
    day = new Date();
    id = day.getTime();
	if(width == '' || height == '')
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=500,height=550,left = 240,top = 100');");
	else
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width="+width+",height="+height+",left = 240,top = 100');");
}
function httpRedirect(url)
{
	window.location = url;	
}
function validEmail(email)
{
	AtPos = email.indexOf("@")
	StopPos = email.lastIndexOf(".")
	Message = ""

	if (email == "")
		return false;
	else if (AtPos == -1 || StopPos == -1)
		return false;
	else if (StopPos < AtPos)
		return false;
	else if (StopPos - AtPos == 1)
		return false;
	else
		return true;
}
function delayedPopOut(message)
{
	setTimeout('', 1000);
	Tip(message);
}
/**
* str_replace
*
* This function returns a string or an array with all occurrences of
* [search] in [subject] replaced with the given [replace] value.
* If you don't need fancy replacing rules (like regular expressions), you should always use this function.
*
* @param	string	search
* @param	string	replace
* @param	string	string
*/
function str_replace (search, replace, subject)
{
var result = "";
var  oldi = 0;
for (i = subject.indexOf (search); i > -1; i = subject.indexOf (search, i))
{
result += subject.substring (oldi, i);
result += replace;
i += search.length;
oldi = i;
}
return result + subject.substring (oldi, subject.length);
}
function checkCheckBox(ElementID)
{
	if(document.getElementById(ElementID).checked == true && document.getElementById(ElementID).type == "checkbox")
		document.getElementById(ElementID).checked = false;
	else
		document.getElementById(ElementID).checked = true;
}
