/* Hide javascript errors from the end user */
function noalert(){
	return true;
}
//window.onerror=noalert;

/* Trim whitespace from right and left */
function trimAll(sString) {
	while (sString.substring(0,1) == ' ') { sString = sString.substring(1, sString.length); }
	while (sString.substring(sString.length-1, sString.length) == ' ') { sString = sString.substring(0,sString.length-1); }
	return sString;
}

/* Popup a new window */
function popWin(url,w,h,attrstring) {
	if (attrstring=='all') {attrstring='toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1,'}
	attr_wh = 'width=' + w + ',height=' + h + ',outerwidth=' + w + ',outerheight=' + h;
	ospw=window.open(url,"",attrstring + attr_wh);
	return false;
}
function popUp(url) {
	ospw=window.open(url,"",'toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1,width=800,height=600,outerwidth=800,outerheight=600');
	return false;
}

/* Calculate page size of viewable page */
function getPageSize() {
	var xWidth = 0, yHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		xWidth = window.innerWidth - 20;
		yHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		xWidth = document.documentElement.clientWidth;
		yHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		xWidth = document.body.clientWidth;
		yHeight = document.body.clientHeight;
	}
	arrayPageSize = new Array(xWidth,yHeight);
//  window.alert( 'Width = ' + myWidth );
//  window.alert( 'Height = ' + myHeight );
	return arrayPageSize;
}

/* Find absolute position of an element */
function findPosition( oElement ) {
	if( typeof( oElement.offsetParent ) != 'undefined' ) {
		for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
			posX += oElement.offsetLeft;
			posY += oElement.offsetTop;
		}
		return [ posX, posY ];
	} else {
		return [ oElement.x, oElement.y ];
	}
}

/* Calculate page size of viewable page */
function getPageSize() {
	var xWidth = 0, yHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		xWidth = window.innerWidth - 20;
		yHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		xWidth = document.documentElement.clientWidth;
		yHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		xWidth = document.body.clientWidth;
		yHeight = document.body.clientHeight;
	}
	arrayPageSize = new Array(xWidth,yHeight);
//  window.alert( 'Width = ' + myWidth );
//  window.alert( 'Height = ' + myHeight );
	return arrayPageSize;
}                                                                                                                             

/* Calculate scrolled amount */
function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

/* Smooth scroll function */
function myscroll(x,y) {
  var curx = getScrollXY()[0];
  var cury = getScrollXY()[1];
  var inc = (y > cury) ? 2 : -2
  for (i=cury; (Math.abs(i-y) >= Math.abs(inc)); i=i+inc) {
    scroll(x,i);
  }
  var cury = getScrollXY()[1];
  var inc = (x > curx) ? 2 : -2
  for (i=curx; (Math.abs(i-x) >= Math.abs(inc)); i=i+inc) {
    scroll(i,cury);
  }
  scroll(x,y);
}

/* form validation - blank string */
function isBlank(s) {
  return (trimAll(s).length==0)
}

/* form validation - valid email */
function invalidEmail(e) {
	var validstr='^[\\w . ! # $ % & * + \\- ~]*@[A-z 0-9 \\-]*\\.[A-z 0-9 . \\-]*[A-z]$';
  return (!e.match(validstr));
}

/* form validation - valid phone */
function invalidPhone(p) {
 	var phonestr = /^\(?(\d{3})\)?[\.\-\/ ]?(\d{3})[\.\-\/ ]?(\d{4})$/;
  return phonestr.exec(p);
}



