window.name="toplevel";

var ProgressWindow = 0;
var useragent = navigator.userAgent;
var version = parseInt(navigator.appVersion);


function GetCookie(name) 
{
	var index = document.cookie.indexOf(name + "=");
    if (index == -1) return null;
    index = document.cookie.indexOf("=", index) + 1;
    var endstr = document.cookie.indexOf(";", index);
    if (endstr == -1) endstr = document.cookie.length;
    return unescape(document.cookie.substring(index, endstr));
}

function IsBlank(str)
{
	var nCheck = str.value;
	var ln_length = nCheck.length;
	var i = 0;
	var all_blank = true;
	if(ln_length < 1) return true;
	while (i < ln_length && all_blank)
	{
		if ((nCheck.charAt(i) != " ")) all_blank = false;
		i++;
	}
	return all_blank;
}

function ValidateFileUpload(Form_Name)
{
	if (navigator.appName.indexOf("WebTV") == -1)
	{
		var bNoFilesSpecified = true;
		for(i = 0 ; i < Form_Name.elements.length; i++) 
		{
			// Webtv (emulator at least) gives input type of null for the file input item
			if (Form_Name.elements[i].type == "file" || Form_Name.elements[i].type == null) 
			{
				if (!IsBlank(Form_Name.elements[i]))
					bNoFilesSpecified = false;
			}
		}
		if (bNoFilesSpecified) {
			alert('You must browse to a file before you can save it.');
			return false;
		}
	}
	return true;
}

function CheckExtension(str)
{
	extension=str.toUpperCase().split(".");
	index=extension.length-1;
	if ((extension[index]=="BMP") ||
		(extension[index]=="GIF") ||
		(extension[index]=="JPG") ||
		(extension[index]=="JPEG") ||
		(extension[index]=="PCX") ||
		(extension[index]=="PNG") ||
		(extension[index]=="TIF") ||
		(extension[index]=="TIFF") ||
		(extension[index]=="WMF"))
		return true;
	else
		alert("Only files with recognized photo file extensions (.BMP, .GIF, .JPG, .JPEG, .PCX, .PNG, .TIF, .TIFF, .WMF) may be entered.");
	return false;
}

function ValidatePhotoUpload(Form_Name)
{
	var allEmpty=true;
	for(i = 0 ; i < Form_Name.elements.length; i++) 
	{
		// Webtv (emulator at least) gives input type of null for the file input item
		if (Form_Name.elements[i].type == "file" || Form_Name.elements[i].type == null) 
		{
			if (!IsBlank(Form_Name.elements[i]))
			{
				allEmpty=false;
				if(!CheckExtension(Form_Name.elements[i].value)) {
					Form_Name.elements[i].focus();
					Form_Name.elements[i].select();
					return false;
				}
			}
		}
	}
	if(allEmpty) {
		alert("No photo files were specified. Please click the \"Browse...\" button to choose a photo to upload.");
		return false;
	}
	return true;
}

function MultiFileUpload(Form_Name, Content_Class, strProgressURL)
{
	// MAC and webtv pictures do NOT have proper extensions, so don't do this check
	if(Content_Class == "PICT" && navigator.appName.indexOf("WebTV") == -1 && navigator.appVersion.indexOf('Mac') == -1) {
		if(!ValidatePhotoUpload(Form_Name))// If it doesn't pass the validation bail before showing the progress window
			return false;
		// We are a go for photo upload... show the progress window while we are waiting
		ShowProgressWindow(strProgressURL);
		return true;
	}
	else {
		// If it doesn't pass the validation bail before showing the progress window
		if(!ValidateFileUpload(Form_Name))
			return false;
		// We are a go for file upload... show the progress window while we are waiting
		ShowProgressWindow(strProgressURL);
		return true;
	}
}

function OpenWhosOnline(BestResultsURL, WhosOnlineURL, szTitle)
{
	if (((navigator.appName == "Microsoft Internet Explorer") && (parseFloat(navigator.appVersion) < 4.0)) ||
		((navigator.appName == "Netscape") && (parseFloat(navigator.appVersion) < 4.6)))
	{
		alert("Your browser does not support Java 1.1 which is required to run TextChat.");
		window.open(BestResultsURL, szTitle);
	}
	else {
		if (navigator.appName == "Microsoft Internet Explorer")
			window.open(WhosOnlineURL, szTitle, "toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,top=0,left=0,width=205,height=465");
		else
			window.open(WhosOnlineURL, szTitle, "toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,top=0,left=0,width=205,height=465");
	}
}

function OpenDailyInfo(DailyInfoURL)
{
	if (navigator.appName.indexOf("WebTV") == -1 && parseInt(window.navigator.appVersion) >= 3) 
	{
		pmsie4=window.open(DailyInfoURL,"pmsie4","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,top=0,left=0,width=445,height=400");
	}
	else if (parseInt(window.navigator.appVersion) == 2) { ; }
	else alert('Sorry, Your Browser Does not Support Pop Up Windows');
}

function TopLocation(_height)
{
	StartY = ((screen.height/2) - 175);
	if (StartY < 0)
		return 0;
	else
		return StartY;
}
	
function LeftLocation(_width) 
{
	StartX = ((screen.width/2) - 300);
	if (StartY < 0)
		return 0;
	else
		return StartY;
}

function OpenCCalPromo(CCalPromoURL)
{
	if (navigator.appName.indexOf("WebTV") == -1 && parseInt(window.navigator.appVersion) >= 3)
	{
		MainHeight = 350; 
		MainWidth = 600;
		ccalpromo=window.open(CCalPromoURL,"ccalpromo","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,top=" + TopLocation(MainHeight) + ",left=" + LeftLocation(MainWidth) + ",width=" + MainWidth + ",height=" + MainHeight);
	}
	else if (parseInt(window.navigator.appVersion) == 2) { ; }
	else alert('Sorry, Your Browser Does not Support Pop Up Windows');
}

function LaunchThisDayinHistory(TDHURL)
{
	if (navigator.appName.indexOf("WebTV") == -1 && parseInt(window.navigator.appVersion) >= 3) 
	{
		tdihmsie4=window.open(TDHURL,"tdihmsie4","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,top=0,left=0,width=440,height=480");
	}
	else if (parseInt(window.navigator.appVersion) == 2) { ; }
	else alert('Sorry, Your Browser Does not Support Pop Up Windows');
}

function HomePageWindow()
{
	window.open('/','hertfordonline','resizable=1,scrollbars=1,width=470,height=550');
}
	
function tour()
{
	window.open("/html/tour/page01.htm","tour","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,top=0,left=0,width=450,height=375");
}

function ShowHelp(url){
	JSHelpURL="/index.html";
	if(url!='NULL'){
		JSHelpURL="/"+url;
	}
	if(navigator.appName.indexOf("WebTV") == -1 && parseInt(window.navigator.appVersion)>=3||window.navigator.appVersion.indexOf("MSIE 3.")>=0){
		msie4=window.open(JSHelpURL,"msie4","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0,top=0,left=0,width=400,height=265");
		msie4.focus();
	}
	else{
		window.location=JSHelpURL;
	}
}

var ProgressWindow = 0;

function ShowProgressWindow(strProgressURL)
{
	if (navigator.appName.indexOf("WebTV") == -1)
	{
		var WinHeight=370;
		var WinWidth=500;
		var WinPosX = Math.round((screen.width - WinWidth) / 2);
		var WinPosY = Math.round((screen.height - WinHeight) / 3);
		var WinProperties = "height="+WinHeight+",width="+WinWidth+",toolbar=no,status=no,left="+WinPosX+",top="+WinPosY+",screenX="+WinPosX+",screenY="+WinPosY;
		ProgressWindow = window.open(strProgressURL, "UploadinProgress", WinProperties);
		if (ProgressWindow.opener == null)
			ProgressWindow.opener = self;
		ProgressWindow.focus();
	}
}

function UploadFinished()
{
     if (ProgressWindow && !ProgressWindow.closed)
		ProgressWindow.close();
}

