//***********************************************************************************************************************************/
//	util.trekk.com.js
//	 Author: Trekk Cross-Media
//  Website: http://www.trekk.com
//Edit Date: May 01, 2008
//  ******************************************************************************
//	TABLE OF CONTENTS
//  ------------------------------------------------------------------------------
//	BASIC BROWSER BEHAVIOR
//		addLoadEvent(func)
//		popWindow(url,target,width,height)
//	STRING MANIPULATION
//		getQueryStringVariable(variable)
//		EXTENDING STRING MEMBER:
//			.getFileType (str.getFileType();)
//			.trim	(str.trim();)
//			.rtrim	(str.rtrim();)
//			.ltrim	(str.ltrim();)
//***********************************************************************************************************************************/


/* Browser basic behavior */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
function popWindow(url, target, width, height) {
    var x = (screen.width - width)/2;
    var y = (screen.height - height)/2;
    var opts = 'height=' + height + ',width=' + width + ",screenX=" + x + ",left=" + x + ",screenY=" + y + ",top=" + y + ',location=no,scrollbars=yes,menubar=no,resizable=no,status=no,toolbar=no';

    var newWindow = window.open(url, target, opts);
    newWindow.focus();
} 
/* End Basic Browser Behavior */ 

/* String Manipulation */
//sample return: .gif
String.prototype.getFileType = function(){
	var ftype = this.substring(this.lastIndexOf('.'), this.length);
	return ftype;	
}
//pass in desired QS var.
function getQueryStringVariable(variable){ 
    var query = window.location.search.substring(1); 
    var vars = query.split("&"); 
    for (var i=0;i<vars.length;i++) { 
        var pair = vars[i].split("="); 
        if (pair[0] == variable) { 
            return pair[1]; 
        } 
    } 
    //else not found
    return 0; 
} 

//extend string prototype.. implement as follows: alert(mystring.trim());
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
/* End String Manipulation */
