var brwUnkwnown = 0
var brwNetscape = 1
var brwMSIE = 2

function Browser(){
	var browser_id

	switch(navigator.appName){
	case "Netscape" :
		browser_id = brwNetscape
		break
	case "Microsoft Internet Explorer" :
		browser_id = brwMSIE
		break
	default :
		browser_id = brwUnkwnown
		break
	}
	return browser_id
}

function OpenWin(URL, WindowName, Width, Height){
	var x, y, w, h

	if(Width == undefined)
		Width = 300;
	if(Height == undefined)
		Height = 300;

	if(Width > screen.availWidth * 0.9)
		w = screen.availWidth * 0.9
	else
		w = Width
		
	if(Height > screen.availHeight * 0.9)
		h = screen.availHeight * 0.9
	else
		h = Height

	x = (screen.availWidth - w) / 2
	y = (screen.availHeight - h) / 2

	var xprop, yprop

	if(Browser() == brwNetscape){
		xprop = "screenX"
		yprop = "screenY"
	}
	else {
		xprop = "left"
		yprop = "top"
	}

	return window.open(URL, WindowName, "scrollbars=1,resizable=1,dependent=1,Width=" + String(w) + 
										 ",Height=" + String(h) + "," + 
										 xprop + "=" + String(x) + "," + 
										 yprop + "=" + String(y))
}

function MakeEmail(User, Domain){

	return "<a href='mailto:" + User + "@" + Domain + "'>" + User + "@" + Domain + "</a>"
}

function JumpTo(Page){
	var old_url, new_url

	old_url = window.location.href
	if(old_url.indexOf(":") == -1)
		new_url = old_url.substr(0, old_url.lastIndexOf("/") + 1)  + Page
	else
		new_url = Page

	if(old_url != new_url)
		location.replace(new_url)
}

function TimeToString(Time){
	var days_left = Math.floor(Time / 86400000)
	var hours_left = Math.floor((Time % 86400000) / 3600000)
	var minutes_left = Math.floor((Time % 3600000) / 60000)
	var time_string = ""

	if(days_left){
		time_string += days_left + " day"
		if(days_left > 1)
			time_string += "s"
	}
	if(hours_left){
		if(days_left){
			if(minutes_left)
				time_string += ", "
			else
				time_string += " and "
		}
		time_string += hours_left + " hour"
		if(hours_left > 1)
			time_string += "s"
	}
	if(minutes_left){
		if(days_left || hours_left)
			time_string += " and "
		time_string += minutes_left + " minute"
		if(minutes_left > 1)
			time_string += "s"
	}

	return time_string
}