function $(id){
	return document.getElementById(id);
}

function $style(id){
	return document.getElementById(id).style;
}

function trim(str) {
	return str.replace(/^\s+|\s+$/g,"");
}

function getPageOffset() {	
	var x,y;
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	return { 'x':x, 'y':y };
}


function getWindowSize()
{
	var w = 0, h = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		w = window.innerWidth;
		h = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	
	return {width:w, height:h};
}

function goToURL(url){
	if(typeof confirmRedirect !='undefined'){
		if(!confirm("You will lose the content if you leave this page now.\nContinue?" )){
			return;
		}	
	}
	
	document.goToURL = url;
	var f = document.forms;
	if(f.length > 0){ // auto save
		for(i=0;i<f.length;i++){
			if(f[i]._autoSave && f[i]._autoSave.value=='ON') {
				f[i]._goToURL.value = url; f[i].submit();				
			}else{
				window.location=url;
			}	
		}
	}else{
	
		window.location=url;		
	}
}

function openWin(url,width,height,scrollbar,resizable){
	self.name = "main";
	window.open(url,"msW","toolbar=no,width="+width+",height="+height+",directories=no,status=no,scrollbars="+scrollbar+",resizable="+resizable+",menubar=no");
	window.focus;
}

function reLoadPage() {
	window.location.reload();
}

function URLEncode (clearString) {
	var output = '';
	var x = 0;
	clearString = clearString.toString();
	var regex = /(^[a-zA-Z0-9_.]*)/;
	while (x < clearString.length) {
			var match = regex.exec(clearString.substr(x));
			if (match != null && match.length > 1 && match[1] != '') {
					output += match[1];
					x += match[1].length;
			} else {
			  if (clearString[x] == ' ')
					output += '+';
			  else {
					var charCode = clearString.charCodeAt(x);
					var hexVal = charCode.toString(16);
					output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
			  }
			  x++;
			}
	}
	return output;
}

function URLDecode (encodedString) {
	var output = encodedString;
	var binVal, thisString;
	var myregexp = /(%[^%]{2})/;
	while ((match = myregexp.exec(output)) != null
					 && match.length > 1 && match[1] != '') {
			binVal = parseInt(match[1].substr(1),16);
			thisString = String.fromCharCode(binVal);
			output = output.replace(match[1], thisString);
	}
	return output;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers(){ //v3.0 modified by Eric
  var i,p,v,obj,args=MM_showHideLayers.arguments;  
  for (i=0; i<(args.length-2); i+=3)   	 
	//if ((obj=MM_findObj(args[i]))!=null){ v=args[i+2];		  	
	if ((obj=(document.getElementById)?document.getElementById(args[i]):MM_findObj(args[i]))!=null) { v=args[i+2];		
	    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
	   	obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function getEvent(windowEvent) {
	if(typeof(windowEvent.keycode) != 'undefined') { return windowEvent; }
	if(window.event) { windowEvent = window.event; windowEvent.keycode = windowEvent.keyCode;}
	else { windowEvent.keycode = windowEvent.which;	}
	switch(windowEvent.keycode){
		//case 0:
		case 9: windowEvent.key = '\t'; break;
		case 8:	windowEvent.key = '[\b]'; break;
		case 13: windowEvent.key = '\n'; break;		
		default: windowEvent.key = String.fromCharCode(windowEvent.keycode);
	} return windowEvent;
}

//
// validations
//
function isEnterKey(e) { var e = getEvent(e); return e.keycode==13; }
function isBackspaceKey(e) { var e = getEvent(e); return e.keycode == 8;}
function isTabKey(e) { }
function isAlphaNumeric(e){ var e = getEvent(e); return /([0-9a-zA-Z]|[\b])/.test(e.key);}
function isValidEmail(email) { email = email.toLowerCase(); return /^([a-z0-9_\-]+(\.[_a-z0-9\-]+)*@([_a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel)(,|;)?)+$/.test(email);}
function isNumber(e){ var e = getEvent(e); return /([0-9]|[\b])/.test(e.key);}
function isValidZipCode(zipcode){ var re = /^\d{5}([\-]\d{4})?$/; return (re.test(zipcode));}

//
// page blocker
//
function setPageBlockerHeight() {
	var h = $('wrapper').offsetHeight;
	$style('pageBlocker').height = h + 'px';
}
function showPageBlocker(){
	if(typeof($style('pageBlocker').height == 'undefined'))	
		setPageBlockerHeight();
	$style('pageBlocker').display = 'block';	
}
function hidePageBlocker() {
	$style('pageBlocker').display = 'none';
}
