/*
 * This code compiled from different Internet sources.
 *
 * Software is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.
 */
var oRTE;

//Rich Text Editor written by Kevin Roth: http://www.kevinroth.com
var isRichText = false;
var rteName;
var rng;
var isIE;
var isGecko;
var isSafari;
var isKonqueror;

var imagesPath;
var includesPath;
var cssFile;
var generateXHTML;

var encoding = "iso-8859-1";
var insertParag = false;

function initRTE(imgPath, incPath, css, genXHTML) 
{
	//set browser vars
	var ua = navigator.userAgent.toLowerCase();
	isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1)); 
	isGecko = (ua.indexOf("gecko") != -1);
	isSafari = (ua.indexOf("safari") != -1);
	isKonqueror = (ua.indexOf("konqueror") != -1);
	generateXHTML = genXHTML;
	//check to see if designMode mode is available
	//Safari/Konqueror think they are designMode capable even though they are not
	if (document.getElementById && document.designMode && !isSafari && !isKonqueror) 
	{
		isRichText = true;
	}
	if (isIE) 
	{
		document.onmouseover = raiseButton;
		document.onmouseout  = normalButton;
		document.onmousedown = lowerButton;
		document.onmouseup   = raiseButton;
	}
	//set paths vars
	imagesPath = imgPath;
	includesPath = incPath;
	cssFile = css;
	if (isRichText) document.writeln('<style type="text/css">@import "' + includesPath + 'cyr.css";</style>');
	//for testing standard textarea, uncomment the following line
	//isRichText = false;
}

function writeRichText(rte, html, width, height, buttons, readOnly)
{
	if (isRichText) 
	{
		if (readOnly) buttons = false;
		
		//adjust minimum table widths
		if (isIE) 
		{
			if (buttons && (width < 540)) width = 540;
			var tablewidth = width;
		} else 
		{
			if (buttons && (width < 540)) width = 540;
			var tablewidth = width + 4;
		}
		
		document.writeln('<div class="rteDiv">');
//		if (buttons == true)
		{
			document.writeln('<table class="rteBack" cellpadding="0" cellspacing="0" id="Buttons2_' + rte + '" width="' + tablewidth + '">');
			document.writeln('	<tr>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'blank.gif" width="25" height="24" alt="Clear All" title="Clear All" onClick="rteCommand(\'' + rte + '\', \'clear\', \'\')"></td>');
                  document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'print.gif" width="25" height="24" alt="Print" title="Print" onClick="rteCommand(\'' + rte + '\', \'print\', \'\')"></td>');
			document.writeln('		<td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');			

			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'cut.gif" width="25" height="24" alt="Cut" title="Cut" onClick="rteCommand(\'' + rte + '\', \'cut\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'copy.gif" width="25" height="24" alt="Copy" title="Copy" onClick="rteCommand(\'' + rte + '\', \'copy\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'paste.gif" width="25" height="24" alt="Paste" title="Paste" onClick="rteCommand(\'' + rte + '\', \'paste\')"></td>');
			document.writeln('		<td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'undo.gif" width="25" height="24" alt="Undo" title="Undo" onClick="rteCommand(\'' + rte + '\', \'undo\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'redo.gif" width="25" height="24" alt="Redo" title="Redo" onClick="rteCommand(\'' + rte + '\', \'redo\')"></td>');
			document.writeln('		<td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
			document.writeln('		<td><img id="bold" class="rteImage" src="' + imagesPath + 'bold.gif" width="25" height="24" alt="Bold" title="Bold" onClick="rteCommand(\'' + rte + '\', \'bold\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'italic.gif" width="25" height="24" alt="Italic" title="Italic" onClick="rteCommand(\'' + rte + '\', \'italic\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'underline.gif" width="25" height="24" alt="Underline" title="Underline" onClick="rteCommand(\'' + rte + '\', \'underline\', \'\')"></td>');
			document.writeln('		<td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'left_just.gif" width="25" height="24" alt="Align Left" title="Align Left" onClick="rteCommand(\'' + rte + '\', \'justifyleft\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'centre.gif" width="25" height="24" alt="Center" title="Center" onClick="rteCommand(\'' + rte + '\', \'justifycenter\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'right_just.gif" width="25" height="24" alt="Align Right" title="Align Right" onClick="rteCommand(\'' + rte + '\', \'justifyright\', \'\')"></td>');
//			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'justifyfull.gif" width="25" height="24" alt="Justify Full" title="Justify Full" onclick="rteCommand(\'' + rte + '\', \'justifyfull\', \'\')"></td>');
//			document.writeln('		<td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
//			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'hr.gif" width="25" height="24" alt="Horizontal Rule" title="Horizontal Rule" onClick="rteCommand(\'' + rte + '\', \'inserthorizontalrule\', \'\')"></td>');

			document.writeln('		<td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'numbered_list.gif" width="25" height="24" alt="Ordered List" title="Ordered List" onClick="rteCommand(\'' + rte + '\', \'insertorderedlist\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'list.gif" width="25" height="24" alt="Unordered List" title="Unordered List" onClick="rteCommand(\'' + rte + '\', \'insertunorderedlist\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'outdent.gif" width="25" height="24" alt="Outdent" title="Outdent" onClick="rteCommand(\'' + rte + '\', \'outdent\', \'\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'indent.gif" width="25" height="24" alt="Indent" title="Indent" onClick="rteCommand(\'' + rte + '\', \'indent\', \'\')"></td>');
			document.writeln('		<td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
			document.writeln('		<td><div id="forecolor_' + rte + '"><img class="rteImage" src="' + imagesPath + 'textcolor.gif" width="25" height="24" alt="Text Color" title="Text Color" onClick="dlgColorPalette(\'' + rte + '\', \'forecolor\', \'\')"></div></td>');
			document.writeln('		<td><div id="hilitecolor_' + rte + '"><img class="rteImage" src="' + imagesPath + 'bgcolor.gif" width="25" height="24" alt="Background Color" title="Background Color" onClick="dlgColorPalette(\'' + rte + '\', \'hilitecolor\', \'\')"></div></td>');
			document.writeln('		<td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'hyperlink.gif" width="25" height="24" alt="Insert Link" title="Insert Link" onClick="dlgInsertLink(\'' + rte + '\', \'link\')"></td>');
			document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'image.gif" width="25" height="24" alt="Add Image" title="Add Image" onClick="addImage(\'' + rte + '\')"></td>');
			document.writeln('		<td><div id="table_' + rte + '"><img class="rteImage" src="' + imagesPath + 'insert_table.gif" width="25" height="24" alt="Insert Table" title="Insert Table" onClick="dlgInsertTable(\'' + rte + '\', \'table\', \'\')"></div></td>');
   		      document.writeln('		<td><img class="rteVertSep" src="' + imagesPath + 'blackdot.gif" width="1" height="20" border="0" alt=""></td>');
		      document.writeln('		<td><img class="rteImage" src="' + imagesPath + 'spellcheck.gif" width="25" height="24" alt="Spell Check" title="Spell Check" onClick="spellcheck()"></td>');
			document.writeln('		<td width="100%"></td>');
			document.writeln('	</tr>');
			document.writeln('</table>');
		}
		document.writeln('<iframe id="' + rte + '" name="' + rte + '" width="' + width + 'px" height="' + height + 'px" src="' + includesPath + 'blank.htm"></iframe>');
		document.writeln('<iframe width="154" height="104" id="cp' + rte + '" src="' + includesPath + 'palette.htm" marginwidth="0" marginheight="0" scrolling="no" style="visibility:hidden; position: absolute;"></iframe>');
		document.writeln('<input type="hidden" id="hdn' + rte + '" name="' + rte + '" value="">');
		document.writeln('</div>');
		
		document.getElementById('hdn' + rte).value = html;
		enableDesignMode(rte, html, readOnly);
	} 
	else 
	{
		if (!readOnly) 
		{
			document.writeln('<textarea name="' + rte + '" id="' + rte + '" style="width: ' + width + 'px; height: ' + height + 'px;">' + html + '</textarea>');
		}
		else
		{
			document.writeln('<textarea name="' + rte + '" id="' + rte + '" style="width: ' + width + 'px; height: ' + height + 'px;" readonly>' + html + '</textarea>');
		}
	}
	oRTE = document.getElementById(rte).contentWindow;
	rteName = rte;
}

function enableDesignMode(rte, html, readOnly) 
{
	var frameHtml = "<html id=\"" + rte + "\">\n";
	frameHtml += "<head>\n";
	//to reference your stylesheet, set href property below to your stylesheet path and uncomment
	if (cssFile.length > 0) 
	{
		frameHtml += "<link media=\"all\" type=\"text/css\" href=\"" + cssFile + "\" rel=\"stylesheet\">\n";
	}
	else
	{
		frameHtml += "<style>\n";
		frameHtml += "body {\n";
		frameHtml += "	background: #FFFFFF;\n";
		frameHtml += "	margin: 0px;\n";
		frameHtml += "	padding: 0px;\n";
		frameHtml += "}\n";
		frameHtml += "</style>\n";
	}
	frameHtml += "</head>\n";
	frameHtml += "<body>\n";
	frameHtml += html + "\n";
	frameHtml += "</body>\n";
	frameHtml += "</html>";
	
	if (document.all)
	{
		oRTE = frames[rte].document;
		oRTE.open();
		oRTE.write(frameHtml);
		oRTE.close();
		if (!readOnly)
		{
			oRTE.designMode = "On";
			frames[rte].document.attachEvent("onkeypress", function evt_ie_keypress(event) {ieKeyPress(event, rte);});
			frames[rte].document.attachEvent("onkeydown", function evt_ie_keydown(event) {ieKeyDown(event, rte);});
		}
	} 
	else 
	{
		try 
		{
			if (!readOnly) document.getElementById(rte).contentDocument.designMode = "on";
			try 
			{
				oRTE = document.getElementById(rte).contentWindow.document;
				oRTE.open();
				oRTE.write(frameHtml);
				oRTE.close();
				if (isGecko && !readOnly)
				{
					//attach a keyboard handler for gecko browsers to make keyboard shortcuts work
					oRTE.addEventListener("keypress", geckoKeyPress, true);
				}
			} 
			catch (e) 
			{
				alert("Error preloading content.");
			}
		} catch (e)
		{
			//gecko may take some time to enable design mode.
			//Keep looping until able to set.
			if (isGecko) 
			{
				setTimeout("enableDesignMode('" + rte + "', '" + html + "', " + readOnly + ");", 10);
			} 
			else 
			{
				return false;
			}
		}
	}
}

function rteCommand(rte, command, option)
{
	//function to perform command
	try 
	{
		oRTE.focus();
		if (command == 'clear')
		{
		  if (window.confirm('WARNING: All editor data will be lost!!'))
          {
         	oRTE.document.body.innerHTML = '';
		  }
		}
        else if (command == 'copy')
		{		
          var sel = oRTE.document.selection.createRange();
		  if (sel.text.length > 0)
          {
	  	    oRTE.document.execCommand(command, false, option);
          }
		  else
		  {
		    window.clipboardData.setData('Text', oRTE.document.body.innerText);
		  }
		}
		else
		{
	  	  oRTE.document.execCommand(command, false, option);
		}
		oRTE.focus();
	} catch (e) 
	{
//		alert(e);
//		setTimeout("rteCommand('" + rte + "', '" + command + "', '" + option + "');", 10);
	}
}

function dlgColorPalette(rte, command)
{
	//function to display or hide color palettes
	setRange(rte);
	
	//get dialog position
	var oDialog = document.getElementById('cp' + rte);
	var buttonElement = document.getElementById(command + '_' + rte);
	var iLeftPos = getOffsetLeft(buttonElement);
	var iTopPos = getOffsetTop(buttonElement) + (buttonElement.offsetHeight + 4);
	oDialog.style.left = (iLeftPos) + "px";
	oDialog.style.top = (iTopPos) + "px";
	
	if (oDialog.style.visibility == "hidden") 
	{
		showHideElement(oDialog, 'show');
	} 
	else 
	{
		showHideElement(oDialog, 'hide');
	}
	//save current values
	parent.command = command;
}

function dlgInsertTable(rte, command) 
{
	//function to open/close insert table dialog
	//save current values
	parent.command = command;
	InsertTable = popUpWin(includesPath + 'insert_table.htm', 'InsertTable', 360, 180, '');
}

function dlgInsertLink(rte, command) 
{
	//function to open/close insert table dialog
	//save current values
	parent.command = command;
	InsertLink = popUpWin(includesPath + 'insert_link.htm', 'InsertLink', 360, 180, '');
	
	//get currently highlighted text and set link text value
	setRange(rte);
	var linkText = '';
	if (isIE)
	{
		linkText = stripHTML(rng.htmlText);
	} 
	else 
	{
		linkText = stripHTML(rng.toString());
	}
	setLinkText(linkText);
}

function setLinkText(linkText) 
{
	//set link text value in insert link dialog
	try 
	{
		window.InsertLink.document.linkForm.linkText.value = linkText;
	} catch (e) 
	{
		//may take some time to create dialog window.
		//Keep looping until able to set.
		setTimeout("setLinkText('" + linkText + "');", 10);
	}
}

function popUpWin(url, win, width, height, options) 
{
	var leftPos = (screen.availWidth - width) / 2;
	var topPos = (screen.availHeight - height) / 2;
	options += 'width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos;
	return window.open(url, win, options);
}

function setColor(color)
{
	//function to set color
	var parentCommand = parent.command;	
	if (document.all)
	{
		if (parentCommand == "hilitecolor") parentCommand = "backcolor";
		
		//retrieve selected range
		rng.select();
	}
	rteCommand(oRTE, parentCommand, color);
	showHideElement('cp' + rteName, "hide");
}

function addImage(rte) 
{
	//function to add image
	imagePath = prompt('Enter Image URL:', 'http://');				
	if ((imagePath != null) && (imagePath != ""))
	{
		rteCommand(rte, 'InsertImage', imagePath);
	}
}

// Ernst de Moor: Fix the amount of digging parents up, in case the RTE editor itself is displayed in a div.
// KJR 11/12/2004 Changed to position palette based on parent div, so palette will always appear in proper location regardless of nested divs
function getOffsetTop(elm) 
{
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	var parents_up = 2; //the positioning div is 2 elements up the tree
	
	while(parents_up > 0) 
	{
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
		parents_up--;
	}
	
	return mOffsetTop;
}

// Ernst de Moor: Fix the amount of digging parents up, in case the RTE editor itself is displayed in a div.
// KJR 11/12/2004 Changed to position palette based on parent div, so palette will always appear in proper location regardless of nested divs
function getOffsetLeft(elm) 
{
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	var parents_up = 2;
	
	while(parents_up > 0) 
	{
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
		parents_up--;
	}
	
	return mOffsetLeft;
}

function selectFont(rte, selectname) 
{
	//function to handle font changes
	var idx = document.getElementById(selectname).selectedIndex;
	// First one is always a label
	if (idx != 0) 
	{
		var selected = document.getElementById(selectname).options[idx].value;
		var cmd = selectname.replace('_' + rte, '');
		rteCommand(rte, cmd, selected);
		document.getElementById(selectname).selectedIndex = 0;
	}
}

function insertHTML(html) 
{
	//function to add HTML -- thanks dannyuk1982
	oRTE.focus();
	if (document.all)
	{
		var oRng = oRTE.document.selection.createRange();
		oRng.pasteHTML(html);
		oRng.collapse(false);
		oRng.select();
	}
      else 
      {
		oRTE.document.execCommand('insertHTML', false, html);
	}
}

function showHideElement(element, showHide) 
{
	//function to show or hide elements
	//element variable can be string or object
	if (document.getElementById(element)) 
      {
	  element = document.getElementById(element);
	}
	
	if (showHide == "show")
      {
	  element.style.visibility = "visible";
	}
      else if (showHide == "hide") 
      {
	  element.style.visibility = "hidden";
	}
}

function setRange(rte) 
{
	//function to store range of current selection
	if (document.all)
	{
	  var selection = oRTE.document.selection; 
	  if (selection != null) rng = selection.createRange();
	} 
      else
      {
	  var selection = oRTE.getSelection();
	  rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
	}
	return rng;
}

function stripHTML(oldString) 
{
  //function to strip all html
  var newString = oldString.replace(/(<([^>]+)>)/ig,"");
	
  //replace carriage returns and line feeds
  newString = newString.replace(/\r\n/g," ");
  newString = newString.replace(/\n/g," ");
  newString = newString.replace(/\r/g," ");
  return trim(clean(newString));
}

function geckoKeyPress(evt) 
{
	//function to add bold, italic, and underline shortcut commands to gecko RTEs
	//contributed by Anti Veeranna (thanks Anti!)
	var rte = evt.target.id;
	
	if (evt.ctrlKey) {
		var key = String.fromCharCode(evt.charCode).toLowerCase();
		var cmd = '';
		switch (key) {
			case 'b': cmd = "bold"; break;
			case 'i': cmd = "italic"; break;
			case 'u': cmd = "underline"; break;
		};

		if (cmd) {
			rteCommand(rte, cmd, null);
			
			// stop the event bubble
			evt.preventDefault();
			evt.stopPropagation();
		}
 	}
}

// Time functions
var timeOffset = "0";
function displayTime()
{
	if (hideTime)
	{
      document.getElementById("country").innerText = '';
      document.getElementById("citylist").innerText = '';
      document.getElementById("offsetinfo").innerText = '';
      document.getElementById("time").innerHTML = '';
      document.getElementById("citylist").innerHTML = '';
      document.getElementById("extrastuff").innerHTML = '';
      return;
	}
	setTimeout("displayTime()", 1000);
	var today = new Date();

	var utc = new Date(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate(), today.getUTCHours(), today.getUTCMinutes(), today.getSeconds(), 0);
	utc.setMinutes(utc.getMinutes() + parseInt(timeOffset));
	
	var parts = utc.toString().split(" ");
		
	var dateStr = parts[0] + ", " + parts[1] + " " + parts[2] + ", " + parts[5];
	document.getElementById("time").innerHTML = "<b><span style=\"color:black; font-size:50\">" + parts[3].substring(0, 5) + "</span></b><br><span style=\"font-size:24\">" + dateStr + "</span>";
}

function changeTime(obj)
{
	if (obj.options[obj.selectedIndex].value == "NULL")
	{
		hideTime = true;
    	displayTime();
		return;
	}
	else
	{
		hideTime = false;
    	displayTime();
	}
	var config = obj.options[obj.selectedIndex].value.split("~");
	timeOffset = config[0];
	document.getElementById("country").innerText = obj.options[obj.selectedIndex].text;
	document.getElementById("citylist").innerText = config[1];
	document.getElementById("offsetinfo").innerText = config[2] + " (for Daylight Saving Time add 1 hour)";
	var data = "<table width=\"90%\" style=\"font-size:80%\">";
	if (config[3] != "") {
		data += "<tr><td width=\"40%\"><b>Capital City</b></td><td>" + config[3] + "</td></tr>";
	}
	if (config[4] != "") {
//		data += "<tr><td width=\"40%\"><b>Currency code</b></td><td>" + config[4] + "</td></tr>";
	}
	if (config[5] != "") {
		data += "<tr><td width=\"40%\"><b>Currency Unit</b></td><td>" + config[5] + "</td></tr>";
	}
	if (config[6] != "") {
		data += "<tr><td width=\"40%\"><b>International Dialing Code</b></td><td>+" + config[6] + "</td></tr>";
	}
	data += "</table>";
/*
	var data = "<table width=\"90%\" style=\"font-size:80%\">";
	if (config[4] != "") {
		data += "<tr><td width=\"40%\"><b>Currency code</b></td><td>" + config[4] + "</td><td width=\"30%\"><b>Currency Unit</b></td><td>" + config[5] + "</td></tr>";
	}
	if (config[6] != "") {
		data += "<tr><td width=\"40%\"><b>International Dialing Code</b></td><td>" + config[6] + "</td><td width=\"30%\"><b>Capital City</b></td><td>" + config[3] + "</td></tr>";
	}
*/
	document.getElementById("extrastuff").innerHTML = data;
}

//UTF-8 Support
function buildURL(fld)
{
	if (fld == "") return '';
	var encodedField = "";
	var s = fld;
	if (typeof encodeURIComponent == "function")
	{
		// Use JavaScript built-in function
		// IE 5.5+ and Netscape 6+ and Mozilla
		encodedField = encodeURIComponent(s);
	}
	else 
	{   
		// Need to mimic the JavaScript version
		// Netscape 4 and IE 4 and IE 5.0
		encodedField = encodeURIComponentNew(s);
	}	
	return encodedField;
}

function utf8(wide) 
{
  var c, s;
  var enc = "";
  var i = 0;
  while(i<wide.length) 
  {
    c= wide.charCodeAt(i++);
    // handle UTF-16 surrogates
    if (c>=0xDC00 && c<0xE000) continue;
    if (c>=0xD800 && c<0xDC00) 
	{
      if (i>=wide.length) continue;
      s= wide.charCodeAt(i++);
      if (s<0xDC00 || c>=0xDE00) continue;
      c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
    }
    // output value
    if (c<0x80) enc += String.fromCharCode(c);
    else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
    else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
    else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
  }
  return enc;
}

var hexchars = "0123456789ABCDEF";
function toHex(n) 
{
  return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
function encodeURIComponentNew(s) 
{
  var s = utf8(s);
  var c;
  var enc = "";
  for (var i= 0; i<s.length; i++) 
  {
    if (okURIchars.indexOf(s.charAt(i))==-1) enc += "%"+toHex(s.charCodeAt(i));
    else enc += s.charAt(i);
  }
  return enc;
}

