$( function() {
	$("#footer-rules-link").click( function( e ) {
		e.preventDefault();
		var x = Math.floor( ( screen.width - 600 ) / 2 );
		var y = Math.floor( ( screen.height - 400 ) / 2 );
		window.open( this.href, "choarules", "width=600,height=400,resizable=yes,location=no,status=no,toolbar=no,screenX=" + x + ",screenY=" + y + ",left=" + x + ",top=" + y +",scrollbars=yes" );
	} );
} );

var isValidDate = function( dt ) {
	
	var rv = false;
	var dateRegEx = new RegExp( "^(19|20)[0-9]{2}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$" );
	
	if ( dateRegEx.test( dt ) ) { 
		
		// the format checks out; now see if the date is actually valid
		// JavaScript "helpfully" converts invalid dates to its nearest
		// guess. We'll use this dumb behavior to our advantage...
		
		var year = dt.substr( 0, 4 );
		var month = dt.substr( 5, 2 ) - 1;
		var day = dt.substr( 8, 2 );
		
		var testDate = new Date( year, month, day );
		
		rv = day == testDate.getDate() && month == testDate.getMonth() && year == testDate.getFullYear();

	}
	
	return rv;
	
};
	
String.prototype.getFileExtension = function() {
	return this.substr( this.lastIndexOf( "." ) + 1 ).toLowerCase();
};

String.prototype.isVideoExtension = function() {
	return $.inArray( this.toString(), [ "avi", "flv", "mov", "mpeg", "mpg", "wmv" ] ) !== - 1;
};

String.prototype.isTextExtension = function() {
	return $.inArray( this.toString(), [ "doc", "pdf", "rtf", "txt" ] ) !== - 1;
};

String.prototype.isImageExtension = function() {
	return $.inArray( this.toString(), [ "bmp", "gif", "jpeg", "jpg", "png" ] ) !== - 1;
};

String.prototype.isEmail = function() {
	var re = RegExp( '^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$', 'i' );
	return re.test( this );
};

String.prototype.isZip = function() {
	var re = new RegExp( '^[0-9]{5}(-[0-9]{4})?$' );
	return re.test( this );
};

String.prototype.trim = function( trimType, charList ) {

	if ( typeof trimType === "undefined" ) {
		trimType = "both";
	}

	if ( typeof charList === "undefined" ) {
		charList = " \t\n\r\v\0";
	}
	
	var startPos = 0;
	var endPos = this.length - 1;
	
	if ( trimType === "left" || trimType === "both" ) {
		for ( startPos = 0; startPos < this.length; startPos++ ) {
			if ( charList.indexOf( this.charAt(startPos) ) === -1 ) {
				break;
			}
		}
	}
	
	if ( trimType === "right" || trimType === "both" ) {
	
		for ( endPos = this.length - 1; endPos >= 0; endPos-- ) {
			if ( charList.indexOf( this.charAt(endPos) ) === -1 ) {
				break;
			}
		}
	
	}
	
	return this.substring( startPos, endPos + 1 );

};

String.prototype.wordCount = function() {
	var y = this.toString();
	var r = 0;
	var a = y.replace( /\s/g, " " );
	a = a.split( " " );
	for ( var z = 0; z < a.length; z++ ) {
		if ( a[z].length > 0 ) {
			r++;
		}
	}
	return r;
};
