// Removes main window if in frame
if(window != window.top) window.top.location = window.location;

function SearchInputFocus(c) {
	var searchinput = document.getElementById('q');
	if (c=='f') {
		searchinput.style.background = "#ffffff";
	} else if (c=='b') {
		if (searchinput.value == '') {
			searchinput.style.background = "#ffffff url(http:\x2F\x2Fwww.google.com\x2Fcoop\x2Fintl\x2Fen\x2Fimages\x2Fgoogle_custom_search_watermark.gif) left no-repeat";
		}
	}
}

function checkWhichSearch() {
	var selectmenu=document.getElementById("sel_search");
	var searchinput = document.getElementById('q');
	var chosenoption=selectmenu.options[selectmenu.selectedIndex].value;
	var sURL = '';
	if (chosenoption=="cerita"){
		sURL = "http://www.google.com/cse?cx=012209146878732328652%3Ajo3vogbwpy4&ie=UTF-8&q=" + searchinput.value + "&sel_search=cerita&sa.x=0&sa.y=0"
		window.location = sURL;
	} else if (chosenoption=="blog"){								
		sURL = "http://interaktif.mstar.com.my/BlogSearch.aspx?searchtext=" + searchinput.value + "&searchmode=AnyWord";
		window.location = sURL;
	} else if (chosenoption=="forum"){
		sURL = "http://interaktif.mstar.com.my/Forums.aspx?searchtext=" + searchinput.value;
		window.location = sURL;
	} else {
		return false;
	}							
}	
 
 // Function retrieved from: http://cass- hacks.com/articles/code/js_url_encode_decode/  
 function URLEncode (clearString) {  
   var output = '';  
   var x = 0;  
   clearString = clearString.toString();  
   var regex = /(^[a-zA-Z0-9_.]*)/;  
   while (x < clearString.length) {  
     var match = regex.exec(clearString.substr(x));  
     if (match != null && match.length > 1 && match[1] != '') {  
         output += match[1];  
       x += match[1].length;  
     } else {  
       if (clearString[x] == ' ')  
         output += '+';  
       else {  
         var charCode = clearString.charCodeAt(x);  
         var hexVal = charCode.toString(16);  
         output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();  
       }  
       x++;  
     }  
   }  
   return output;  
 }  
 
 // Retrieved from: http://www.htmlcodetutorial.com/forms/index_famsupp_157.html  
 function SubmitOnEnter(myfield, e)  
 {  
     var keycode;  
     if (window.event)  
         keycode = window.event.keyCode;  
     else if (e)  
         keycode = e.which;  
     else  
         return true;  
     if (keycode == 13)  
     {  
         checkWhichSearch();  
         return false;  
     }  
     else  
         return true;  
 }  
  
  function toggleCommonTopstuff(showName, hideName)
  {
    var showHeader = document.getElementById("con_common_topstuff_"+showName+"_header");
    var showBody = document.getElementById("con_common_topstuff_"+showName+"_body");
    var hideHeader = document.getElementById("con_common_topstuff_"+hideName+"_header");
    var hideBody = document.getElementById("con_common_topstuff_"+hideName+"_body");
    var showClass = "con_common_topstuff_show";
    var hideClass = "con_common_topstuff_hide";
    
    try
    {
      if (showHeader != null && showBody != null && hideHeader != null && hideBody)
      {
        showHeader.className = showClass;
        showBody.className = showClass;
        hideHeader.className = hideClass;
        hideBody.className = hideClass;
      }
    }
    catch (err) { alert(err); }
  }
  
  function toggleUtamaSuaraManusia(showName, hideName)
  {
    var showHeader = document.getElementById("con_utama_suaramanusia_"+showName+"_header");
    var showBody = document.getElementById("con_utama_suaramanusia_"+showName+"_body");
    var hideHeader = document.getElementById("con_utama_suaramanusia_"+hideName+"_header");
    var hideBody = document.getElementById("con_utama_suaramanusia_"+hideName+"_body");
    var showClass = "con_utama_suaramanusia_show";
    var hideClass = "con_utama_suaramanusia_hide";
    
    try
    {
      if (showHeader != null && showBody != null && hideHeader != null && hideBody)
      {
        showHeader.className = showClass;
        showBody.className = showClass;
        hideHeader.className = hideClass;
        hideBody.className = hideClass;
      }
    }
    catch (err) { alert(err); }
  }
  
  
  /*  Dropdowns Pt 2
      Code adapted from http://www.alistapart.com/d/horizdropdowns/horizontal.htm
      ----------------
  */
  startListTopMenu = function()
  {
    if (document.all&&document.getElementById)
    {
      navRoot = document.getElementById("topmenu");
      try
      {
        if (navRoot != null)
        {
          for (i=0; i<navRoot.childNodes.length; i++)
          {
            node = navRoot.childNodes[i];
            if (node.nodeName=="LI")
            {
              node.onmouseover=function() { this.className+=" over"; }
              node.onmouseout=function() { this.className=this.className.replace(" over", ""); }
            }
          }
        }
      } catch (err) {}
    }
  }
  window.onload=startListTopMenu;
  /*  ----------------
  */
