/*! NV Standard Utilities v2.1 <http://nvinteractive.co.nz>
	Copyright (c) NV Interactive
	
	References:
		swfobject.js
		jquery-1.2.6.js		
		
	Revision History
		2.1 Rewrote forms for jQuery
			Added cookie object
			removed EventUtils (use jQuery instead)
			removed _isIE6 (use jQuery instead)
			removed getElementsBySelector (use jQuery instead)
		
*/

var flashBasePath = "/_resx/js/plugins/";
var flashVersion = 8;
var flashCounter = 0;

/* ============================================================= */
function writeFlash(el, flashFile, w, h, pars, initObj) {

	var embedCode;
	var origHtml;
	el.style.visibility = "visible";	
	
	if(swfobject.getFlashPlayerVersion().major >= flashVersion){

		var replacedContent = el.innerHTML;
		
		var h = h.toString().indexOf("%")>-1 || h.toString() == "auto" ?h:h+"px";
		var w = w.toString().indexOf("%")>-1 || w.toString() == "auto" ?w:w+"px";

		var flashEl = document.createElement("span");
		flashEl.id = "flashobj_" + flashCounter;
		flashEl.style.display = "block";
		el.innerHTML = "";
		
		for(var p in initObj){
			el[p] = initObj[p];
		}
		
		el.appendChild(flashEl);
		
		var rpEl = document.createElement("span");
		rpEl.className = "flash_block_replaced_content";
		rpEl.innerHTML = replacedContent;
		el.appendChild(rpEl);

		flashFile = flashBasePath + flashFile;
		
		if(pars){
			if(pars.flashvars){
				pars.flashvars += "&flashid=" + flashEl.id;
			}else{
				pars.flashvars = "flashid=" + flashEl.id;
			}
		}else{
			pars = {flashvars: "flashid=" + flashEl.id};
		}
		
	  	var att = { data: flashFile, width: w, height: h };
		
		var flashObject = swfobject.createSWF(att, pars, flashEl.id);
		
		var fv = swfobject.getFlashPlayerVersion;
		if( navigator.userAgent.indexOf("MSIE") != -1 && (fv().major < 9 || (fv().major == 9 && fv().release < 100) ) ){
			//Debug.addLine("utilities.js", "writeflash", "fixexternal");
			window[flashEl.id] = flashObject;
		}
		
		
		flashObject.style.display = "block";
		flashObject.className = "flash_block";
		
		flashCounter++;
		
		return flashObject;
	}
	
	return false;
	
}





/* =============================================================================== */
/* { Helper Functions ] */

function getInnerText(e){
  var strText = "";
  var node;
  for(var i=0; i<e.childNodes.length; i++ ) {
	  node = e.childNodes[i];
	  switch(node.nodeType) {
	    case 1: // elements
    		strText += getInnerText(node);
		    break;
	    case 3: // text
		    strText += node.nodeValue;
		    break;
	    default: // comments etc
		    break;
	  }
  }
	
	// Strip leading and trailing spaces.
	var regEx = /[\r\n\t]+|[ ]{2}/g;
	strText = strText.replace(regEx, " ");
	
	var regEx = /[ ]+/g;
	strText = strText.replace(regEx, " ");
	
	return strText;
}


function getInnerHtml(e){
	 var strText = "";
	 var node;
	 for(var i=0; i<e.childNodes.length; i++ )
	 {node = e.childNodes[i];
	  switch(node.nodeType)
	  {
	   case 1: // elements
			var atts = node.attributes;
			var ta = "";
			for (var k = 0; k < atts.length; k++)
			{
				var att = atts[k];
				if(att.specified)
					ta += att.nodeName.toLowerCase() + '="' + att.nodeValue + '" '; 
			}
			if(node.childNodes.length > 0)
				strText += "<" + node.nodeName.toLowerCase() + " " + ta + ">" + getInnerHtml(node) + "</" + node.nodeName.toLowerCase() + ">";
			else
				strText += "<" + node.nodeName.toLowerCase() + " " + ta + " />"
		break;
	   case 3: // text
		strText += node.nodeValue;
		break;
	   default: // comments etc
		break;
	  }
	 }
	 
	//Strip leading and trailing spaces.
	var regEx = /[\r\n\t]+|[ ]{2}/g;
	strText = strText.replace(regEx, " ");
	
	var regEx = /[ ]+/g;
	strText = strText.replace(regEx, " ");

	return strText;
}

var request = function(){
	
	var QueryString = {};

	var _search = window.location.search;
	
	if(_search.indexOf("?") == 0){
		_search = _search.substr(1, _search.length);
		var _searchArray = _search.split("&");
	
		for(var i=0; i<_searchArray.length; i++){
			var pair = _searchArray[i].split("=");
			QueryString[pair[0]] = unescape(pair[1]);
		}
	}

	return {
	/* Public API
	*/
	QueryString: QueryString
	}
}();

/* ============================================================= */
/**
 * A class to parse color values
 * @author Stoyan Stefanov <sstoo@gmail.com>
 * @link   http://www.phpied.com/rgb-color-parser-in-javascript/
 * @license Use it if you like it
 */
function RGBColor(color_string)
{
	
    this.ok = false;
    // strip any leading #
    if (color_string.charAt(0) == '#') { // remove # if any
        color_string = color_string.substr(1,6);
    }

    color_string = color_string.replace(/ /g,'');
    color_string = color_string.toLowerCase();

    // array of color definition objects
    var color_defs = [
        {
            re: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,
            example: ['rgb(123, 234, 45)', 'rgb(255,234,245)'],
            process: function (bits){
                return [
                    parseInt(bits[1]),
                    parseInt(bits[2]),
                    parseInt(bits[3])
                ];
            }
        },
        {
            re: /^(\w{2})(\w{2})(\w{2})$/,
            example: ['#00ff00', '336699'],
            process: function (bits){
                return [
                    parseInt(bits[1], 16),
                    parseInt(bits[2], 16),
                    parseInt(bits[3], 16)
                ];
            }
        },
        {
            re: /^(\w{1})(\w{1})(\w{1})$/,
            example: ['#fb0', 'f0f'],
            process: function (bits){
                return [
                    parseInt(bits[1] + bits[1], 16),
                    parseInt(bits[2] + bits[2], 16),
                    parseInt(bits[3] + bits[3], 16)
                ];
            }
        }
    ];

    // search through the definitions to find a match
    for (var i = 0; i < color_defs.length; i++) {
        var re = color_defs[i].re;
        var processor = color_defs[i].process;
        var bits = re.exec(color_string);
        if (bits) {
            channels = processor(bits);
            this.r = channels[0];
            this.g = channels[1];
            this.b = channels[2];
            this.ok = true;
        }

    }
	
    // validate/cleanup values
    this.r = (this.r < 0 || isNaN(this.r)) ? 0 : ((this.r > 255) ? 255 : this.r);
    this.g = (this.g < 0 || isNaN(this.g)) ? 0 : ((this.g > 255) ? 255 : this.g);
    this.b = (this.b < 0 || isNaN(this.b)) ? 0 : ((this.b > 255) ? 255 : this.b);

    // some getters
    this.toRGB = function () {
        return 'rgb(' + this.r + ', ' + this.g + ', ' + this.b + ')';
    }
	
    this.toHex = function () {
        var r = this.r.toString(16);
        var g = this.g.toString(16);
        var b = this.b.toString(16);
        if (r.length == 1) r = '0' + r;
        if (g.length == 1) g = '0' + g;
        if (b.length == 1) b = '0' + b;
        return '#' + r + g + b;
    }

}

/* ============================================================= */
/* [ Simple javascript debug console ] */
Debug = function(){

	var enabled = false;

	var addLine = function(jsFile, method, message){
		if(!enabled)return;
		var debugEl = document.getElementById("debug");
	
		if(debugEl == null){
			debugEl = document.createElement("div");
			debugEl.id = "debug";
			with(debugEl.style){
				position = "fixed";
				top = 0;
				right = 0;
				width = "500px";
				height = "300px";
				overflow = "scroll";
				background = "#FFFFFF";
				color = "#000000";
				fontSize = "10px";
				border = "1px solid #000000";
				zIndex = "10000";
			}
			document.getElementsByTagName("body")[0].appendChild(debugEl);
		}
		
		debugEl.innerHTML += jsFile + " :: " + method + " > " + message + "<br />";
	}
			
			

	return {
		/* Public API
		*/
		addLine:addLine,
		enabled:enabled
	}

}();


/* [ Cookie Code ] */
nv_cookie = function(){

	var createCookie = function (name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}

	var readCookie = function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

	var eraseCookie = function(name) {
		createCookie(name,"",-1);
	}
	
	return {
	/* Public API
	*/
	createCookie: createCookie,
	readCookie: readCookie,
	eraseCookie: eraseCookie
	}

}();

function NV_openBrWindow(theURL,winName,features) {
var w = window.open(theURL,winName,features);
w.focus();
}