NN = (!document.all && document.getElementById);

function body_load() {
  setInterval("next_flash()",20000);
  document.getElementById("txt_search").onkeydown = txt_search_KeyDown;
  document.getElementById("ibtn_search").onclick = ibtn_search_Click;
  
  lang = document.getElementById("langNormal").value.toLowerCase();
  if(lang == "en-us" || lang == "zh-tw" || lang == "ko-kr" || lang == "de-de" || lang == "fr-fr" || lang == "es-es" || lang == "es-ar")
    document.getElementById("s_feedback").style.display = "inline";
  else
    document.getElementById("s_feedback").style.display = "none";
}

function next_flash() {
  //the following script is for rotating flash banner
	current = parseInt(document.getElementById("hld_current").value);	  
	current = current + 1;
	
  if(current > 3)
    current = 1;
    	
	new_file = document.getElementById("hld_flash"+current.toString()).value;

  if(new_file == "")
  {
    current = 1;
    new_file = document.getElementById("hld_flash"+current.toString()).value;
  }
  
	document.getElementById("hld_current").value = current.toString();

	if(document.getElementById("flash_banner"))
	{
	
	  html_banner = "<object id=\"flash_banner\" codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,12,36 height=210 width=\"100%\" classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 viewastext>" + 
                  "<param NAME=\"_cx\" VALUE=\"19315\">" + 
                  "<param NAME=\"_cy\" VALUE=\"5556\">" + 
                  "<param NAME=\"FlashVars\" VALUE=\"\">" + 
                  "<param NAME=\"Movie\" VALUE=\"" + new_file + "\">" + 
                  "<param NAME=\"Src\" VALUE=\"" + new_file + "\">" + 
                  "<param NAME=\"WMode\" VALUE=\"Opaque\">" + 
                  "<param NAME=\"Play\" VALUE=\"-1\">" + 
                  "<param NAME=\"Loop\" VALUE=\"-1\">" + 
                  "<param NAME=\"Quality\" VALUE=\"High\">" + 
                  "<param NAME=\"SAlign\" VALUE=\"\">" + 
                  "<param NAME=\"Menu\" VALUE=\"-1\">" + 
                  "<param NAME=\"Base\" VALUE=\"\">" + 
                  "<param NAME=\"AllowScriptAccess\" VALUE=\"always\">" + 
                  "<param NAME=\"Scale\" VALUE=\"ShowAll\">" + 
                  "<param NAME=\"DeviceFont\" VALUE=\"0\">" + 
                  "<param NAME=\"EmbedMovie\" VALUE=\"0\">" + 
                  "<param NAME=\"BGColor\" VALUE=\"\">" + 
                  "<param NAME=\"SWRemote\" VALUE=\"\">" + 
                  "<param NAME=\"MovieData\" VALUE=\"\">" + 
                  "<embed src=\"" + new_file + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" wmode=\"opaque\" type=\"application/x-shockwave-flash\" width=\"100%\" height=\"210\">" + 
                  "</embed>" +
                  "</object>";
	  document.getElementById("flash_banner").innerHTML = html_banner;
	}
}

function IM(){
	wx = 777;
	wy = 570;
	x = (screen.width  - wx) / 2;
	y = (screen.height - wy) / 2;
	url = 'http://vip.asus.com/IMPresale/IMLink.html';
	subwin = window.open(url,"newChatWindow","width=777,height=570,status=no, toolbar=no, location=no,menubar=no, left="+x+",top="+y);
}

function IM_TW(){
	wx = 610;
	wy = 460;
	x = (screen.width  - wx) / 2;
	y = (screen.height - wy) / 2;
	url = 'http://vip.asus.com/imv2tw/imlogin.aspx';
	subwin = window.open(url,"newChatWindow","width=610,height=460,status=no, toolbar=no, location=no,menubar=no, left="+x+",top="+y);
}

function txt_search_KeyDown(e) {
  var keyCode;
  
  if (NN)
    keyCode = e.keyCode;
  else
    keyCode = event.keyCode;
  
  if (keyCode == 13) {
    ibtn_search_Click();
    return false;
  }
}

function ibtn_search_Click() {
  keyword = alltrim(document.getElementById("txt_search").value.toLowerCase());
  lang_id = document.getElementById("langNormal").value;
  
  if (keyword == "")
    return;
  
  show_loading();
  location.href = "search/search.aspx?keyword=" + escape(keyword) + "&SLanguage=" + lang_id;
}

function alltrim() {
  return arguments[0].replace(/(^ +)|( +$)/g,'');
}


function body_resize() {
  if (document.body.clientWidth>=778) {
    document.getElementById("rss").style.left = document.body.clientWidth - 424;
    document.getElementById("contact").style.left = document.body.clientWidth - 424;
    document.getElementById("search").style.left = document.body.clientWidth - 424;
    document.getElementById("sitemap").style.left = document.body.clientWidth - 424;
    document.getElementById("home").style.left = document.body.clientWidth - 424;
    document.getElementById("home").style.left = document.body.clientWidth - 424;
    document.getElementById("asus").style.left = document.body.clientWidth - 424;
  }
  else {
    document.getElementById("rss").style.left = 394 + 40;
    document.getElementById("contact").style.left = 394 + 40;
    document.getElementById("search").style.left = 394 + 40;
    document.getElementById("sitemap").style.left = 394 + 40;
    document.getElementById("home").style.left = 394 + 40;
    document.getElementById("home").style.left = 394 + 40;
    document.getElementById("asus").style.left = 394 + 40;
  }
}

function show_loading() { 
  IE = (document.all && navigator.userAgent.indexOf("Opera") == -1)
  
  if (IE)
  {
    document.getElementById("loading").style.display = "inline";
    document.getElementById("loading").offsetHeight;
    document.getElementById("loading").style.pixelTop = (document.body.clientHeight/2)-(document.getElementById("loading").offsetHeight/2)+(document.body.scrollTop); 
    document.getElementById("loading").style.pixelLeft = (document.body.clientWidth/2)-(document.getElementById("loading").offsetWidth/2)+(document.body.scrollLeft); 
  }
} 

function replace(as,as_rex,as_out) {
  var ls_rex;

  ls_rex = new RegExp(as_rex,"g");
  as = as.replace(ls_rex,as_out);
  return as;
}

function switch_lang(lang_id) {
  s = location.href;
  
  if (s.indexOf(document.getElementById("langNormal").value) != -1)
    location.href = replace(s,document.getElementById("langNormal").value,lang_id);
  else if (s.indexOf('default.aspx') == -1 && s.indexOf('?SLanguage') == -1)
    location.href = s + 'default.aspx?SLanguage=' + lang_id;
  else if (s.indexOf('default.aspx') != -1 && s.indexOf('?SLanguage') == -1)
    location.href = s + '?SLanguage=' + lang_id; 
}
