	/* -------------------------------
	   (c) 2010, MH2 Design
	   Project: mh2_templatetools
	   Type: Javascript
	   Date: 12/01/2008
	   Change Log:
	   	Select Boxes
	   ------------------------------- */

	var mh2GEThttp		= '';				// HTTP Get object 
	var mh2GETPHP			= '';				// PHP Path
	var mh2Rdiv				= '';				// Receiving DIV 
	var mh2Rdiv2			= '';				// Secondary Receiving DIV 
	var mh2Rbutton		= '';				// Used if disabling a button
	var mh2Window			= '';
	var mh2MainWindow	= '';

	//============================================================================================================
	// === Setup begin
	// =================================
		// -----------------------------------
		// -- Set the main options
		// -----------------------------------
		function _mh2_setOptions(p_runURL)
		{
			mh2GetPHP 	= p_runURL;
			mh2GEThttp 	= getHTTPObject();
		}

		// -----------------------------------
		// -- Get the HTTP Object
		// -----------------------------------
		function getHTTPObject() {
		  var xmlhttp;
		  
			try 
			{ 
			 var xmlhttp = new XMLHttpRequest(); 
			} 
			catch (error) 
			{ 
			 try 
			 { 
			   var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
			 } 
			 catch (error) 
			 { 
			   return false; 
			 } 
			}  
		  return xmlhttp;
		}

		// -----------------------------------
		// -- Open Child - Dialog
		// -----------------------------------
		function _OpenChild(p_url, p_width, p_height, p_checkflash)
		{
	    var _settings = "center:1;resizable:0;help:0;status:0;edge:sunken;scroll:0;dialogHeight:" + (p_height) + "px;dialogWidth:" + (p_width) + "px;"
	    var _settings2 = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=" + (p_width) + ",height=" + (p_height);
	//    mh2Window = window.showModalDialog( p_url, null, _settings);

			// Do we want to check for flash?
			if ((p_checkflash == null) || (p_checkflash))
				{ var _checkflash = true; }
			else 
				{ var _checkflash = false; }
			
			var _valid = true;
			if (_checkflash) 
			{
				if (!$j.browser.flash)
				{ _valid = false; }
			}

			mh2MainWindow = window;
//			if ( (_checkflash) && ($j.browser.flash))
			if ( _valid )
			{
				if (!mh2Window)
				{
					if (window.showModalDialog) 
					{
	    			mh2Window = window.showModalDialog( p_url, self, _settings);
					} else {
	    			mh2Window = window.open( p_url, self, _settings2);
					}
				}
			} else {
				alert('Flash is not installed, You cannot continue.');
			}
		}
		
		// -----------------------------------
		// -- Open Window - Blind
		// -----------------------------------
		function _OpenWindow(p_url, p_width, p_height)
		{
	    var _settings = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=" + (p_width) + ",height=" + (p_height);

			mh2Window = window.open( p_url, self, _settings);
		}
		
		// -----------------------------------
		// -- Popup Window, with Data
		// -----------------------------------
		function _PopupWindow(p_data, _height, _width)
		{
			mh2String	= Base64.decode(p_data);
			mh2Window = window.open('','name','height='+ + _height +',width='+ _width +'');
			
			var mh2out = mh2Window.document;
			
			mh2out.write(mh2String);
			mh2out.write('<p style="text-align:center;width:100%"><a href="javascript:self.close()">Close Window</a></p>');
			mh2out.close();
		}

	// =================================
	// === Set Setup finish
	//============================================================================================================

	//============================================================================================================
	// === Image Effects begin
	// =================================
	// -----------------------------------
	// -- Image Rotate In
	// -----------------------------------
	function _imgrotate(_times, _div)
	{
		if ($j.webkit)
		{
			var _method = '-webkit-transform: rotate(0deg);';
		}
		if ($j.safari)
		{
			var _method = '-moz-transform: rotate(0deg);';
		}
		if ($j.opera)
		{
			var _method = 'rotation: 0deg;';
		}
		if ($j.msie)
		{
			var _method = 'filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0)';
		}
		if ($j.mozilla)
		{
			var _method = '-moz-transform: rotate(0deg);';
		}
		
	}
  
	// =================================
	// === Image Effects finish
	//============================================================================================================

	//============================================================================================================
	// === Common Functions begin
	// =================================
  	
	// =================================
	// === Common Function finish
	//============================================================================================================

	//============================================================================================================
	// === Show/Hide/Content begin
	// =================================
		// -----------------------------------
		// -- Show Main Menu
		// -----------------------------------
		function _showmainMenu(_menudiv)
		{
			var _rand = 0;
			
			$j('div.' + _menudiv).children('ul').children('li').each(function(index) {
				var _rand = ( Math.floor( Math.random() * 3 ) + 1);
				if ( $j(this).is('.active') )
					{ $j(this).children('span').after('<span class="active"></span>'); }
				else 
					{ $j(this).children('span').after('<span class="thought'+_rand+'"></span>'); }
			});

 			return true;
		}
	
		// -----------------------------------
		// -- Show Emotes
		// -----------------------------------
		function _showrandomEmote()
		{
			var _rand = 0;
			var _show = 0;
			
			$j('div.mm_emote').each(function(index) {
				var _rand = ( Math.floor( Math.random() * 10 ) + 1);
//				var _show = ( Math.floor( Math.random() * 2 )); 
// Always Show
				var _show = 1;	
				if (_show)
					{ $j(this).children('div.mm_panel_content').after('<span class="mm_random_emote' + _rand + '"></span>'); }
			});

 			return true;
		}

		// -----------------------------------
		// -- Show Loading: content to the DIV
		// -----------------------------------
		function showLoadingContent()	
		{
			// MHK -- Add Image
//			document.getElementById(mh2Rdiv).innerHTML = '';
//			document.getElementById('mh2bpo_messagecontainer').innerHTML = '<div class="mh2bpo_messageline" >Loading Content ...</div>';
//			$j('#mh2bpo_messagecontainer').fadeIn("fast").fadeOut("fast");
		}

		// -----------------------------------
		// -- Show/Hide Alert
		// -----------------------------------
		function _showhideAlert(p_div, p_show, p_text, p_parent)
		{
			if (p_parent == null)
			{
				var _jvar = $j;
				document.getElementById(p_div).innerHTML = p_text;
			} else {
				var _opener = window.dialogArguments;
				var _jvar = _opener.$j;
				_opener.document.getElementById(p_div).innerHTML = p_text;
			}
				
			if (p_show == 1)
			{
				_jvar('#' +  p_div)
					.fadeIn("normal")
	    		.animate({opacity: 1.0}, 2000);
	    } else if (p_show == 0) {
				_jvar('#' +  p_div).fadeOut("normal");
			} else if (p_show == 2) {
				_jvar('#' +  p_div).fadeIn("normal").fadeTo(2000, 1).fadeOut("normal");
			} 
		}
		
		// -----------------------------------
		// -- Pass the return content to the DIV
		// -----------------------------------
		function showContent()	// Displaying content in the content <div>
		{
	  	if (mh2GEThttp.readyState == 4)
	  	{
	  		$j(mh2RDiv).html(mh2GEThttp.responseText);
//				document.getElementById(mh2Rdiv).innerHTML = mh2GEThttp.responseText;
//				$j('#mh2bpo_messagecontainer').fadeOut("fast");
				mh2GEThttp.close;
			}
		}
	
	// =================================
	// === Show/Hide/Content finish
	//============================================================================================================

	//============================================================================================================
	// === General Form begin
	// =================================
	// =================================
	// === General Form finish
	//============================================================================================================

	//============================================================================================================
	// === Image/File Functions begin
	// =================================
		// -----------------------------------
		// -- Download File
		// -----------------------------------
		function mh2_downloadfile(p_file, p_path, p_php)
		{
			var _phpfile = Base64.decode(p_php); 
			var _tempurl = '?task=downloadfile&idfm=' + p_file + '&idpa=' + p_path; 
			
  			mh2Window = window.open( _phpfile + _tempurl, 'Download', '');

		}
		
	// =================================
	// === Image/File Functions finish
	//============================================================================================================

	//============================================================================================================
	// === Miscellaneous begin
	// =================================
		// -----------------------------------
		// -- Check Browser for Options
		// -----------------------------------
		function _checkBrowser()
		{
			document.getElementById('hasf').value = $j.browser.flash;
			document.getElementById('hasj').value = $j.browser.java ;
		}

		// -----------------------------------
		// -- Emulate the PHP base64 functions
		// -----------------------------------
		var Base64 = {
	
	    // private property
	    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	
	    // public method for encoding
	    encode : function (input) {
	        var output = "";
	        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
	        var i = 0;
	
	        input = Base64._utf8_encode(input);
	
	        while (i < input.length) {
	
	            chr1 = input.charCodeAt(i++);
	            chr2 = input.charCodeAt(i++);
	            chr3 = input.charCodeAt(i++);
	
	            enc1 = chr1 >> 2;
	            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
	            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
	            enc4 = chr3 & 63;
	
	            if (isNaN(chr2)) {
	                enc3 = enc4 = 64;
	            } else if (isNaN(chr3)) {
	                enc4 = 64;
	            }
	
	            output = output +
	            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
	            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
	
	        }
	
	        return output;
	    },
	
	    // public method for decoding
	    decode : function (input) {
	        var output = "";
	        var chr1, chr2, chr3;
	        var enc1, enc2, enc3, enc4;
	        var i = 0;
	
	        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
	
	        while (i < input.length) {
	
	            enc1 = this._keyStr.indexOf(input.charAt(i++));
	            enc2 = this._keyStr.indexOf(input.charAt(i++));
	            enc3 = this._keyStr.indexOf(input.charAt(i++));
	            enc4 = this._keyStr.indexOf(input.charAt(i++));
	
	            chr1 = (enc1 << 2) | (enc2 >> 4);
	            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
	            chr3 = ((enc3 & 3) << 6) | enc4;
	
	            output = output + String.fromCharCode(chr1);
	
	            if (enc3 != 64) {
	                output = output + String.fromCharCode(chr2);
	            }
	            if (enc4 != 64) {
	                output = output + String.fromCharCode(chr3);
	            }
	
	        }
	
	        output = Base64._utf8_decode(output);
	
	        return output;
	
	    },
	
	    // private method for UTF-8 encoding
	    _utf8_encode : function (string) {
	        string = string.replace(/\r\n/g,"\n");
	        var utftext = "";
	
	        for (var n = 0; n < string.length; n++) {
	
	            var c = string.charCodeAt(n);
	
	            if (c < 128) {
	                utftext += String.fromCharCode(c);
	            }
	            else if((c > 127) && (c < 2048)) {
	                utftext += String.fromCharCode((c >> 6) | 192);
	                utftext += String.fromCharCode((c & 63) | 128);
	            }
	            else {
	                utftext += String.fromCharCode((c >> 12) | 224);
	                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
	                utftext += String.fromCharCode((c & 63) | 128);
	            }
	
	        }
	
	        return utftext;
	    },
	
	    // private method for UTF-8 decoding
	    _utf8_decode : function (utftext) {
	        var string = "";
	        var i = 0;
	        var c = c1 = c2 = 0;
	
	        while ( i < utftext.length ) {
	
	            c = utftext.charCodeAt(i);
	
	            if (c < 128) {
	                string += String.fromCharCode(c);
	                i++;
	            }
	            else if((c > 191) && (c < 224)) {
	                c2 = utftext.charCodeAt(i+1);
	                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
	                i += 2;
	            }
	            else {
	                c2 = utftext.charCodeAt(i+1);
	                c3 = utftext.charCodeAt(i+2);
	                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
	                i += 3;
	            }
	
	        }
	
	        return string;
	    }
	
	}

	// =================================
	// === Miscellaneous finish
	//============================================================================================================

	// -----------------------------------
	// -- Load Functions
	// -----------------------------------
