﻿String.format = function( text ) {
    //check if there are two arguments in the arguments list
    if ( arguments.length <= 1 ) {
        //if there are not 2 or more arguments there’s nothing to replace
        //just return the original text
        return text;
    }

    //decrement to move to the second argument in the array
    var tokenCount = arguments.length - 2;
    for( var token = 0; token <= tokenCount; token++ ) {
        //iterate through the tokens and replace their placeholders from the original text in order
        text = text.replace( 
			new RegExp( "\\{" + token + "\\}", "gi" ),
			arguments[ token + 1 ] 
		);

    }

    return text;
};

function openPhotoViewer(imageUrl, imageTitle, imageDesc) {
	window.open(
		String.format(
			"PhotoViewer.aspx?ImageUrl={0}&ImageTitle={1}&ImageDesc={2}",
			encodeURI( imageUrl ),
			encodeURI( imageTitle ),
			encodeURI( imageDesc )
		),
		"PhotoViewer",
		"status=0,toolbar=0,location=0,menubar=0,directories=0,resizeable=0,scrollbars=0,height=668,width=900",
		true
	);
}
