/* COMMON JAVASCRIPT FUNCTIONS
 * =========================
 * Copyright © 2005 Foxford Services Ltd
 * =========================
 */

// Browser compatibility
var ie = false;

if (document.all)
{
	ie = true;

	document.getElementById = function(id)
	{
		return document.all[id];
	}
}

function bookmark(theURL){
// Browsers:   IE 4.0 and later (degrades gracefully in others)
//Author:     etLux
// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header
// message to show in non-IE browsers
var txt = "Bookmark Us!"

// url you wish to have bookmarked
var url = theURL;

// caption to appear with bookmark
var who = "CodeLifter.com Software and Scripts"

// do not edit below this line
// ===========================

var ver = navigator.appName
var num = parseInt(navigator.appVersion)
if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
   document.write('<A HREF="javascript:window.external.AddFavorite(url,who);" ');
   document.write('onMouseOver=" window.status=')
   document.write("txt; return true ")
   document.write('"onMouseOut=" window.status=')
   document.write("' '; return true ")
   document.write('">'+ txt + '</a>')
}else{
   txt += "  (Ctrl+D)"
   document.write(txt)
} 
}

// Opens a new window and returns its handle
function dialog(src, name, width, height)
{
	newDialog = window.open(src, name, 'toolbar=no, scrollbars=yes, directories=no, status=no, menubar=no, width='+ width + ',height=' + height + ', resizable=yes');

	if (newDialog == null)
		alert('An error occured while trying to show a dialog. \nPlease make sure any popup blockers are disabled for this site.');
	else
		newDialog.focus();
}

var good;

function checkEmailAddress(field) {
// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header


// Note: The next expression must be all on one line...
//       allow no spaces, linefeeds, or carriage returns!
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

if (goodEmail){
   good = true
} else {
   alert('Please enter a valid e-mail address.')
   field.focus()
   field.select()
   good = false
   }
}

function openPictureWindow_Fever(imageName,imageWidth,imageHeight,alt,posLeft,posTop) {
	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
	newWindow.document.write('<img src='+imageName+' width='+imageWidth+' height='+imageHeight+' alt='+alt+'>'); 
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}
// Example:
// var b = new BrowserInfo();
// alert(b.version); 
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function flashEnabled()
{
   return true;
}

function ismaxlength(obj)
{
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}

function arrayReplace(a1, a2)
{
	a1.length = 0;

	for (i=0; i<a2.length; i++)
		a1[a1.length] = a2[i];
}

function roundNumber(num, dp)
{
	var rlength = dp; // The number of decimal places to round to

	if (num > 8191 && num < 10485)
	{
		rnum = rnum-5000;
		var newnumber = Math.round(num*Math.pow(10,rlength))/Math.pow(10,rlength);
		newnumber = newnumber+5000;
	}
	else
		var newnumber = Math.round(num*Math.pow(10,rlength))/Math.pow(10,rlength);

	return newnumber;
}

