// JavaScript Document

function XM_MyEncode(s)
{
  if (this.encodeURIComponent)
    return encodeURIComponent(s);
  return escape(s);
}

function GetMainFrame()
{
  if (parent)
    if (parent.hzMainFrame)
      return parent.hzMainFrame;
  return parent;
}

function ChangeMainFrame(newURL)
{
  var f = GetMainFrame();
  if (f && f.location) {
    f.location = newURL;
  }
}

function MyDecode(s)
{
  var d = "";
  for (var i = 0; i < s.length; i++) {
    d += String(s.charCodeAt(i));
  }
  return d;
}

function Trim(s) 
{
  // Remove leading spaces
  while (s.length && (s.substring(0, 1) == ' ')) {
    s = s.substring(1, s.length);
  }
  // Remove trailing spaces
  while (s.length && (s.substring(s.length-1, s.length) == ' ')) {
    s = s.substring(0, s.length-1);
  }
  return s;
}

	function UpdateHanzi()
	{
	  // Get value
	  var txt = document.getElementById("unichar");
	  if (txt) {
		  var theChar = Trim(txt.value);
		  
		  var firstCharacter = theChar.charCodeAt(0).toString(16);
		  
		 if ( parseInt(firstCharacter,16) <= 130)
		  {
			ChangeMainFrame("decide.cfm?textValue=" + XM_MyEncode(theChar));
		  }
		  
			  else{
				  //ChangeMainFrame("getHanzi.cfm?variableValue=" + firstCharacter);
				if (theChar.length == 1) {
					ChangeMainFrame("hanzi.cfm?hexValue=" + theChar.charCodeAt(0).toString(16));
				} else if (theChar.length > 1) {
					s = "";
					for (var i = 0; i < theChar.length; i++) {
						s += String(theChar.charCodeAt(i).toString(16) + "-");
					}
					ChangeMainFrame("compound.php?uniz=" + s);
					window.location = ("compound.cfm?from=1&searchType=4&charactersVar=" + s);
				}
			  }
			
	
	  }
	}
	var xm_UpdateHanzi = new Function("return UpdateHanzi()");




function xm_enter(evt, fn)
{
  var charCode;
  var evt = (evt) ? evt : ((window.event) ? event : null);
  if (!evt) return;
  if (evt.charCode) charCode = evt.charCode;
  else if (evt.keyCode) charCode = evt.keyCode;
  else return;
  if (charCode == 13) {
    // Call function fn
    fn();
  }
}


		
			function openPopupWindow2(word){
	
	   self.name = "Parent_Window";
		
	   winRef = window.open('http://www.instantspeakchinese.com/ca/features/item/item.cfm?word=' + word, "mywindowPronounce", "height=150,width=350,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no");
	   
	   winRef.focus();

        }
		
		function playMp3(str) {
flashvar = thisMovie('test');
flashvar.SetVariable("_root.mp3src",str);
flashvar.SetVariable("playit", 1);
}



function thisMovie(movieName) {
return (navigator.appName.indexOf('Microsoft')!=-1) ? document.getElementById(movieName) : document.getElementById(movieName).getElementsByTagName("embed")[0];
}





	   function populateDropDownMenu(list, selectedOption){
		for (i = 0; i < list.length; i++) {
			if (list.options[i].value == selectedOption)
				list.options[i].selected = true;
		}	
	}





function openAnimationWindow2(word){
	
	   self.name = "Parent_Window";
		
	   winRef = window.open('http://www.instantspeakchinese.com/dictionary/item/itemCharacterAnimation.cfm?word=' + word, "mywindowPronounce2", "height=360,width=350,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no");
	   
	   winRef.focus();

        }