function trim(s) {
	var res = s.replace(/^\s*(.*)/, "$1");
	res = res.replace(/(.*?)\s*$/, "$1");
	return res;
}

function isNumber(n) {
	var validChars = "0123456789.";
	var c;
	var res = true;
 
	if (n == '') {
		res = false;
	} 
 
	for (i = 0; i < n.length && res; i++) { 
		c = n.charAt(i); 
		if (validChars.indexOf(c) == -1) {
			res = false;
		}
	}
	return res;
}

function validateEmailField(emailElem) {
	var email = emailElem.value;
	var atIndex = email.indexOf("@");
	var afterAt = email.substring((atIndex + 1), email.length);
	// find a dot in the portion of the string after the ampersand only
	var dotIndex = afterAt.indexOf(".");
	// determine dot position in entire string (not just after amp portion)
	dotIndex = dotIndex + atIndex + 1;
	// afterAt will be portion of string from ampersand to dot
	afterAt = email.substring((atIndex + 1), dotIndex);
	// afterDot will be portion of string from dot to end of string
	var afterDot = email.substring((dotIndex + 1), email.length);
	var beforeAmp = email.substring(0,(atIndex));
	var email_regex = /^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/ 
	// index of -1 means "not found"
	if ((email.indexOf("@") != "-1") && (email.length > 5) && (afterAt.length > 0) && (beforeAmp.length > 1) && (afterDot.length > 1) && (email_regex.test(email)) ) {
		return true;
	} else {
		return false;
	}
}


//
// Browser Detection
//
var ie  = 0;
var ns4 = 0;
var dom = 1;
var ie4 = 0;
var ie5 = 0;
var ope = 0;
var moz = 0;
var bok = 1;

function init(){
  ie  = (document.all)?true:false;
  ns4 = (document.layers)?true:false;
  dom = (document.getElementById)?true:false;
  ie4 = (document.all && !dom)?true:false;
  ie5 = (dom && navigator.userAgent.indexOf('MSIE 5')>0);
  ope = (dom && navigator.userAgent.indexOf('Opera')>0);
  moz = (dom && navigator.userAgent.indexOf('Gecko')>0);
  bok = ns4 || ie4 || dom;
};


// Get object by ID
function getObj(name) {
  if (ns4) return document[name]
  else if (ie4) return document.all[name]
  else if (dom) return document.getElementById(name);
};

// Make an object visible
function showObj(obj) {
  if (ns4) obj.visibility = "show"
  else obj.style.visibility = "visible";
};

// Hide an object
function hideObj(obj) {
  if (ns4) obj.visibility = "hide"
  else obj.style.visibility = "hidden";
};

// Move an object
function moveObj(obj,x,y) {
  if (ns4) {
    obj.left = x;
    obj.top = y;
  } else {
    obj.style.left = x;
    obj.style.top = y;
  };
};

// Resize an object
function sizeObj(obj,w,h) {
  if (ns4) {
    obj.width = w;
    obj.height = h;
  } else {
    obj.style.width = w;
    obj.style.height = h;
  };
};

// Clip an object
function clipObj(obj,x1,y1,x2,y2) {
  if (ns4) {
    obj.clip.left = x1;
    obj.clip.top = y1;
    obj.clip.right = x2;
    obj.clip.bottom = y2;
  } else {
    obj.style.clip = 'rect('+y1+','+x2+','+y2+','+x1+')';
  };
};

// Write to an object
function writeObj(obj,text) {
  if (ns4) {
    var doc = obj.document;
		doc.open();
    doc.write(text);
    doc.close();
  } else {
    obj.innerHTML = text;
  };
};

function getheightObj(obj){
  if (ns4) {
    return obj.clip.bottom;
  } else {
    return obj.offsetHeight;
  };
};
