function launchSMSPricing() {
	var w = window.open( "html/smsprices.htm", "win_sms", "width=400,height=300,toolbar=no,resizable=no,scrollbars=no,status=no");
}

function launch_demo() { 
	window.open( "action-demo-start.do", "win_demo", "width=800,height=400,left=0,top=0,screenX=0,screenY=0,toolbar=no,resizable=no,scrollbars=yes,status=no");
}

function launch_loading_popup( _msg ) { 
	var w = window.open( "html/popups.jsp?msg=" + _msg, "popups", "width=200,height=260,left=0,top=0,screenX=0,screenY=0,toolbar=no,resizable=no,scrollbars=no,status=no");
	w.focus();
	return;
}

function launch_questionmark_popup( _msg ) { 
	var w = window.open( "html/popups.jsp?msg=" + _msg, "popups", "width=200,height=260,left=0,top=0,screenX=0,screenY=0,toolbar=no,resizable=no,scrollbars=no,status=no");
	w.focus();
}

function launch_help_popup( f ) { 
	var w = window.open( f, "win_help_popup", "width=280,height=440,left=0,top=0,screenX=0,screenY=0,toolbar=no,resizable=no,scrollbars=no,status=no");
	w.focus();
}

function launch_comm_fail_popup( e ) { 
	var w = window.open( "", "win_comm_fail_popup", "width=280,height=440,left=0,top=0,screenX=0,screenY=0,toolbar=no,resizable=no,scrollbars=no,status=no");
	w.document.open();
	w.document.writeln( '<html>\n<head>\n\t<title>Site Caddy</title>\n\t<link rel=stylesheet type="text/css" href="lib/common.css">\n</head><body><table class="text"><tr><td>' );
	w.document.writeln( '<p><b>Failure Message</b></p>' );
	w.document.writeln( '<p>The following error message may or may not be helpful.  If there is a recurring problem sending to an individual member, first confirm that their mobile/cellular number and country code is correct in the directory.  If still a problem, copy the follwoing error message and send to Site Caddy support at support@sitecaddy.com.</b></p>' );
	w.document.writeln( '<p><div class="errorReport">' + e + '</div></p>' );
	w.document.writeln( '</table></td></tr></body></html>' );
	w.document.close();
	w.focus();
}

function getRandomEndorsement() {

	var beechpark = [ "We are very happy with the Site Caddy service and the support has been excellent.", "Beech Park Golf Club" ];
	var edmondstown = [ "Site Caddy allows us to provide a great service to our members, who frequently use the club web site to check on the latest results and news.  It's a cost effective way to drive traffic to our site.", "Edmondstown Golf Club" ];
	var mags = [ "The Site Caddy system is very easy to use, and allows my staff to keep our web site up to date without the need for outside assistance.  I would recommend the product to any golf club.", "St. Margaret's Golf Club" ];
	var sigma = [ "Site Caddy has proved a great success, allowing us to provide our society members with all the benefits of a full serviced club at a fraction of the cost.  Using Site Caddy has helped develop a sense of interest and community within the society.", "Sigma Wireless Golf Society" ];
	var hollystown = [ "With Site Caddy, we can easily send SMS text and email messages to our members and guests. Our members are delighted to receive club news and last minute course changes in a timely fashion. The club saves money and staff time, and has increased turnout for events.", "Hollystown Golf Club" ];
	var carp1 = [ "Site Caddy is great!  We are finding it very useful, members can view their handicap details, check out the various scheduled outings and look at our rules, results, news and photos.", "Carpenter Golf Society" ];
	var carp2 = [ "The SMS feature is very useful and came into its own recently when we had a change of venue on the morning of a golf outing.  Within a few minutes, I had logged on to Site Caddy and sent an SMS message re an alternative venue to all members... everyone was impressed.", "Carpenter Golf Society" ];
	var e = [ beechpark, edmondstown, mags, sigma, hollystown, carp1, carp2 ];

	var r = ( Math.round( Math.random() * 10 ) ) % 7;
	return e[ r ];
}

function trimLeadingZeros( n ) {

	while ( true ) {

		if ( ( n.length > 1 ) && ( n.indexOf( "0" ) == 0 ) ) n = n.substr( 1 );
		else break;
	}
	return n;
}

function validateInt( n ) {

	if ( ( n == null ) || ( n == undefined ) || ( n.length < 1 ) ) return false;
	n = trimLeadingZeros( n );
	return ( "" + parseInt(n) ) == n;
}

function isValidDate() {
	
	if( validateInt(this.year) == false ) return false;
	if( validateInt(this.month) == false ) return false;
	if( validateInt(this.date) == false ) return false;
	
	if ( ( this.year > 0 ) && ( this.year < 3000 ) ) {;}
	else { return false; }
	if ( ( this.month >= 0 ) && ( this.month <= 12 ) ) {;}
	else { return false; }
	if ( ( this.date >= 0 ) && ( this.date <= 31 ) ) {;}
	else { return false; }
	
	return true;
}

function dateToString() {

	return this.year + "/" + this.month + "/" + this.date;
}

function compareDate( _date ) {

	if ( ( this.year*1 == _date.year*1 ) && ( this.month*1 == _date.month*1 ) && ( this.date*1 == _date.date*1 ) ) return 0;
	
	if ( this.year*1 < _date.year*1 ) return -1;
	if ( this.year*1 > _date.year*1 ) return 1;
	
	if ( this.month*1 < _date.month*1 ) return -1;
	if ( this.month*1 > _date.month*1 ) return 1;
	
	if ( this.date*1 < _date.date*1 ) return -1;
	if ( this.date*1 > _date.date*1 ) return 1;
	
	return 0;
}

function getDxsDateNow() {

	var now = new Date();
	var dxsDate = new DxsDate( now.getFullYear(), now.getMonth() + 1, now.getDate() );
	return dxsDate;
}

function DxsDate( y, m, d ) {

	y += ""; m += ""; d += "";
	this.year = y;
	this.month = trimLeadingZeros( m );
	this.date = trimLeadingZeros( d );
	
	this.compareDate = compareDate;
	this.isValidDate = isValidDate;
	this.getDxsDateNow = getDxsDateNow;
	this.toString = dateToString;
}

function isValidTime() {
	
	if( validateInt(this.hour) == false ) return false;
	if( validateInt(this.minute) == false ) return false;
	
	if ( ( this.hour >= 0 ) && ( this.hour < 24 ) ) {;}
	else { return false; }
	if ( ( this.minute >= 0 ) && ( this.minute < 60 ) ) {;}
	else { return false; }

	return true;
}

function timeToString() {

	return this.hour + ":" + this.minute;
}

function compareTime( _time ) {

	if ( ( this.hour*1 == _time.hour*1 ) && ( this.minute*1 == _time.minute*1 ) ) return 0;
	
	if ( this.hour*1 < _time.hour*1 ) return -1;
	if ( this.hour*1 > _time.hour*1 ) return 1;
	
	if ( this.minute*1 < _time.minute*1 ) return -1;
	if ( this.minute*1 > _time.minute*1 ) return 1;
	
	return 0;
}

function DxsTime( hour, minute ) {

	if ( ( hour == null ) || ( hour == undefined ) ) this.hour = -1;
	if ( ( minute == null ) || ( minute == undefined ) ) this.minute = -1;

	this.hour = trimLeadingZeros( hour );
	this.minute = trimLeadingZeros( minute );
	
	if ( validateInt( hour ) ) this.hour = hour*1;
	if ( validateInt( minute ) ) this.minute = minute*1;
	
	this.compareTime = compareTime;
	this.isValidTime = isValidTime;
	this.toString = timeToString;
}

function isValidUsername( userName, min, max ) {

	if ( userName.length < min ) return false;
	if ( userName.length > max ) return false;
	var match = userName.search( /\W/ );	// search for any non word character
	if ( match != -1 ) return false;
	
	return true;
}

function isAlphaNumeric( userName ) {

	var match = userName.search( /\W/ );	// search for any non word character
	if ( match != -1 ) return false;	
	return true;
}

function isValidPassword( password, min, max ) {

	if ( password.length < min ) return false;
	if ( password.length > max ) return false;
	var match = password.search( /\W/ );	// search for any non word character
	if ( match != -1 ) return false;
	
	return true;
}

function guessUsernameCommon( f ) {
}

function guessUsernameBackup( f ) {

	var _firstName = f.firstName.value;
	var _lastName = f.lastName.value;
	
	if ( _lastName == null ) _lastName == "";
	if ( _firstName == null ) _firstName == "";
	
	var _guess = _lastName.toLowerCase() + _firstName.toLowerCase().substring(0,1);
	f.userName.value = _guess;
}

function isLowerCase( _input ) {

	if ( _input.toLowerCase() == _input ) return true;
	else return false;
}

function isNumber( _input ) {
	
	var result = true;
	var l = _input.length;
	var i = 0;

	for ( i=0; i<l; i++ ) {
		var c = _input.substr(i,1);
		if ( isNaN( parseInt( c ) ) ) { result = false; }
	}

	return result;
}

function stripNonNumbers( _input ) {
	
	var result = "";
	var l = _input.length;
	var i = 0;

	for ( i=0; i<l; i++ ) {
		var c = _input.substr(i,1);
		if ( !isNaN( parseInt( c ) ) ) { result += c; }
	}

	return result;
}

function valid_phone( _currentValue ) {

	_currentValue = stripNonNumbers( _currentValue );
	if ( (_currentValue.length < 8) || (_currentValue.length > 32) ) { return false; }
	else { return true; }
}

function valid_phone( _currentValue, _min, _max ) {

	_currentValue = stripNonNumbers( _currentValue );
	if ( ( _currentValue.length < _min ) || ( _currentValue.length > _max ) ) { return false; }
	else { return true; }
}

function valid_email( _currentValue, min, max ) {

	var _emailError = isEmail( _currentValue );
	if ( _emailError.length > 0 ) { return false; }
	else { return true; }
}

function isEmail( _input, min, max ) {
	
	var err = "";
	var blankSpace = " ";
	var foundAt = false;
	var foundDot = false;

	var l = _input.length;
	var i = 0;

	if ( ( _input.length < (min*1) ) || ( _input.length > (max*1) ) ) {
		err = "Email address must use between " + min + " and " + max + " characters.";
		return err;
	}

	for ( i=0; i<l; i++ ) {
		var c = _input.substr(i,1);

		if ( c == blankSpace ) { 
			err = "Email address cannot contain spaces."	
			result = false;
		}
		if ( c == "@" ) { foundAt = true; }
		if ( c == "." ) { foundDot = true; }
	}

	if ( foundAt == false ) { err = "Email address must contain an \'@\' symbol to be valid.";  }
	if ( foundDot == false ) { err = "Email address must contain a \'.\' symbol to be valid.";  }

	return err;
}


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_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_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_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];
		}
}
