var timerID;
var hld_model_keyword,hld_subject_keyword,hld_problem_keyword,hld_answer_keyword;
var NN = (!document.all && document.getElementById);

function asus_faq_body_load(){
  //left
  document.getElementById("sel_answer").onchange = sel_answer_change;
  document.getElementById("txt_keyword").onmouseover = txt_keyword_mouseover;
  document.getElementById("txt_keyword").onmouseout = txt_keyword_mouseout;  
  document.getElementById("txt_keyword").hasFocus=false;
  document.getElementById("txt_keyword").onfocus=function(){this.hasFocus=true;};
  document.getElementById("txt_keyword").onblur =function(){this.hasFocus=false;};

  hld_model_keyword = document.getElementById("hld_model_keyword").value;
  hld_subject_keyword = document.getElementById("hld_subject_keyword").value;
  hld_problem_keyword = document.getElementById("hld_problem_keyword").value;
  hld_answer_keyword = document.getElementById("hld_answer_keyword").value;
  document.getElementById("txt_keyword").value = document.getElementById("hld_problem_keyword").value;

  //right
  if (document.getElementById("select1")){
    IE = (document.all && navigator.userAgent.indexOf("Opera") == -1);
    NN = (!document.all && document.getElementById);
    
    if (IE)
      document.getElementById("select1").onchange = select1_change;
      
    //document.getElementById("img_ok").onclick = img_ok_click;
    
    document.getElementById("select2")[0] = new Option(document.getElementById("hld_select2_welcome").value,"0");
  }

  timerID = setInterval("hide_loading()",500);
  
  //detail
//  if(document.getElementById("hld_html").value =="")
//    document.getElementById("hld_html").value = document.getElementById("tablerow1").innerHTML;
   
//  alert(document.getElementById("tablerow1").innerHTML); 
//  document.getElementById("tablerow1").innHTML="";
   
	document.getElementById("tablerow1").style.display = "none";
	document.getElementById("tr_results").style.display = "none";	
	document.getElementById("tr_totalvotes").style.display = "none";
  document.getElementById("btn_submit").onclick = btn_submit_click;
  document.getElementById("rdo_yes").onclick = rdo_yes_onchange;
  document.getElementById("rdo_no").onclick = rdo_no_onchange;
  

}

function img_ok_click() {
  if (document.getElementById("select2")[document.getElementById("select2").selectedIndex].value == "0")
    return;
    
  parent.show_loading();
  parent.document.location = "faq.aspx?model="+ document.getElementById("select2")[document.getElementById("select2").selectedIndex].text + "&SLanguage=" + document.getElementById("langNormal").value;;
  
//  parent.document.getElementById("ifr_user_left").src = "faq_left.aspx?model=" + document.getElementById("select2")[document.getElementById("select2").selectedIndex].text + "&SLanguage=" + document.getElementById("langNormal").value;
//  document.getElementById("ifr_faq_right_second_bottom").src = "faq_right_second_master.aspx?mode=1&model_name=" + document.getElementById("select2")[document.getElementById("select2").selectedIndex].text + "&SLanguage=" + document.getElementById("langNormal").value+"&type_no="+ document.getElementById("hld_select1_id").value;
}

function select1_change() {
  if (document.getElementById("select1").value == "0"){
    document.getElementById("select2").innerHTML = "";
    document.getElementById("select2").add(new Option(document.getElementById("hld_select2_welcome").value,"0"));
    document.getElementById("select2").disabled = true;
    return;
  }
  
  parent.show_loading();
  setTimeout("get_select2()",500);
}

function get_select2() {
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  xmlhttp.open("GET","../common/3combo_databind.aspx?workMode=1&select1_id=" + document.getElementById("hld_select1_id").value + "&select2_id=" + document.getElementById("select1").value + "&SLanguage=" + document.getElementById("langNormal").value,false);
  xmlhttp.send();
  
  xmldoc = new ActiveXObject("Microsoft.XMLDOM");
  xmldoc.loadXML(xmlhttp.responseText);
  
  document.getElementById("select2").innerHTML = "";
  document.getElementById("select2").add(new Option(document.getElementById("hld_select2_welcome").value,"0"));
  
  nodes = xmldoc.selectNodes("/NewDataSet/Table");
  for(i=0; i<nodes.length; i++)
    document.getElementById("select2").add(new Option(nodes[i].childNodes(0).text,nodes[i].childNodes(1).text));
  
  document.getElementById("select2").disabled = false;
  
  parent.hide_loading();
}

function model_click(model_name){
  document.location = "faq.aspx?model="+ model_name + "&SLanguage=" + document.getElementById("langNormal").value;;
}

function detail_click(type_no, kb_guid){
//  var type_no="", model = "";
//  if(document.getElementById("hld_select1_id").value !="")
//    type_no = "&type="+document.getElementById("hld_select1_id").value;
    
//  if(document.getElementById("hld_model").value !="")
//    model = "&model=" + document.getElementById("hld_model").value;


  document.location = "asus-faq.aspx?type="+type_no+"&no=" + kb_guid + "&SLanguage=" + document.getElementById("langNormal").value;
}

function btn_submit_click(){
  sugestion = document.getElementById("txt_sugestion").value;
  var OptionCount = document.getElementById("hld_options").value;
  var CheckedValue = "";
  
  for(i=0; i < OptionCount; i++)
  {
		if(document.getElementById("sug_option_"+i).checked){
			CheckedValue+=document.getElementById("sug_option_"+i).value + "|";
		}
  }
    
  IE = (document.all && navigator.userAgent.indexOf("Opera") == -1)
  
  if (IE) {
    var level = "-1";
    
    if (document.getElementById("rdo_yes").checked)
      level = "0";
      
    if (document.getElementById("rdo_no").checked)
      level = "1";
      
    try {  
      xmldoc = new ActiveXObject("Microsoft.XMLDOM");
    }
    catch(e) {
      return true;
    }
    
    if(level == "1")
    {   
			if (sugestion == "" || CheckedValue == "")
				return false;
		}
		else
		{
			if (sugestion == "")
				return false;
		}
		
		document.getElementById("btn_submit").disabled = true;
	  
    xmldoc.async = false;
    
    strXML = "<?xml version='1.0'?>" + 
                "<root>" +
                  "<kb_id>" + document.getElementById("hld_kb_guid").value + "</kb_id>" + 
                  "<lang_id>" + document.getElementById("langNormal").value + "</lang_id>" + 
                  "<helplevel>" +  level + "</helplevel>" + 
                  "<email>" + "" + "</email>" + 
                  "<context>" + sugestion + "</context>" + 
                  "<fb_options>" + CheckedValue + "</fb_options>" +                   
                "</root>";
                
    xmldoc.loadXML(strXML); 
    
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e) {
      return true;
    }
    xmlhttp.open("POST","faq_right_second_detail_submit.aspx",true);
    xmlhttp.send(xmldoc);
    
    var msg = document.getElementById("hldSubmitOK").value;
    
	  alert(msg);
    if(level=="1")
			parent.parent.location.href = "../techserv/techserv.aspx?SLanguage="+document.getElementById("langNormal").value;
		
    return false;
  }
  else
    return true;
}

function rdo_yes_onchange()
{
  var OptionCount = document.getElementById("hld_options").value;

	if(OptionCount > 0){
		document.getElementById("tablerow1").style.display = "none";
	}
}
function rdo_no_onchange()
{
  var OptionCount = document.getElementById("hld_options").value;
    
	if(OptionCount > 0){
		document.getElementById("tablerow1").style.display = "inline";		
	}
}

function star_clicked(num)
{
  IE = (navigator.appName.toLowerCase() == "microsoft internet explorer");
  var xmlhttp=null;
  var one, two, three, four, five;
  if(IE){
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.open("GET","faq_right_second_detail_rating.aspx?star="+num+"&kb_guid="+document.getElementById("hld_kb_guid").value+"&SLanguage=" + document.getElementById("langNormal").value,false);
    xmlhttp.send();
    
    xmldoc = new ActiveXObject("Microsoft.XMLDOM");
    xmldoc.loadXML(xmlhttp.responseText);
    
    //alert(xmlhttp.responseText);
    nodes = xmldoc.selectNodes("/NewDataSet/Table");
    
    one = nodes[0].childNodes(0).text;
    two = nodes[0].childNodes(1).text;
    three = nodes[0].childNodes(2).text;
    four = nodes[0].childNodes(3).text;
    five = nodes[0].childNodes(4).text;
  } 
    else
  {
    xmlhttp = new XMLHttpRequest();
    xmlhttp.open("GET","faq_right_second_detail_rating.aspx?star="+num+"&kb_guid="+document.getElementById("hld_kb_guid").value+"&SLanguage=" + document.getElementById("langNormal").value,false);
    
    xmlhttp.send(null);
    res = xmlhttp.responseText;  
    parser = new DOMParser();
    xmldoc = parser.parseFromString(res,"text/xml");
    one = xmldoc.getElementsByTagName("one")[0].childNodes[0].nodeValue;  
    two = xmldoc.getElementsByTagName("two")[0].childNodes[0].nodeValue;  
    three = xmldoc.getElementsByTagName("three")[0].childNodes[0].nodeValue;  
    four = xmldoc.getElementsByTagName("four")[0].childNodes[0].nodeValue;  
    five = xmldoc.getElementsByTagName("five")[0].childNodes[0].nodeValue;  
  } 
 
  total = parseInt(one)+parseInt(two)+parseInt(three)+parseInt(four)+parseInt(five);
  
	document.getElementById("td_one").innerHTML="";
	document.getElementById("td_two").innerHTML="";
 	document.getElementById("td_three").innerHTML="";
	document.getElementById("td_four").innerHTML="";
	document.getElementById("td_five").innerHTML="";
 
  var blue = "blue.gif";
  var yellow = "yellow.gif";
  var filename = "";
 	var result="";
 
  if(num == 1) 
		filename = yellow;
	else
	  filename = blue;
  one = Math.round((one/total)*84);//empty.gif°ª¬°84
	for(i=0; i<one; i++)
	{
		result += "<img src=../images/"+filename+" width=20 height=1><br>";
	}
	document.getElementById("td_one").innerHTML = result;

  if(num == 2) 
		filename = yellow;
	else
	  filename = blue;
  two = Math.round((two/total)*84);
	result="";
	for(i=0; i<two; i++)
	{
		result += "<img src=../images/"+filename+" width=20 height=1><br>";
	}
	document.getElementById("td_two").innerHTML = result;

  if(num == 3) 
		filename = yellow;
	else
	  filename = blue;
  three = Math.round((three/total)*84);
	result="";
	for(i=0; i<three; i++)
	{
		result += "<img src=../images/"+filename+" width=20 height=1><br>";
	}
	document.getElementById("td_three").innerHTML = result;

  if(num == 4) 
		filename = yellow;
	else
	  filename = blue;
  four = Math.round((four/total)*84);
	result="";
	for(i=0; i<four; i++)
	{
		result += "<img src=../images/"+filename+" width=20 height=1><br>";
	}
	document.getElementById("td_four").innerHTML = result;
	
  if(num == 5) 
		filename = yellow;
	else
	  filename = blue;
  five = Math.round((five/total)*84);
	result="";
	for(i=0; i<five; i++)
	{
		result += "<img src=../images/"+filename+" width=20 height=1><br>";
	}
	document.getElementById("td_five").innerHTML = result;

  document.getElementById("lbl_totalvotes").innerHTML += total;
	document.getElementById("tr_rating").style.display = "none";
	document.getElementById("tr_results").style.display = "";
	document.getElementById("tr_totalvotes").style.display = "";
	
	//parent.adjust_iframe_bottom_height(document.body.scrollHeight);
	//parent.parent.adjust_iframe_right_height(document.body.scrollHeight + 190);

}

function txt_keyword_KeyDown(e){
  var keyCode;
  
  if (NN)
    keyCode = e.keyCode;
  else
    keyCode = event.keyCode;
  
  if (keyCode == 13)
  {
    img_searach_info_click()
    return false;
  }
}

function img_searach_info_click(){
  keyword = document.getElementById("txt_keyword").value;
  search_type = document.getElementById("sel_answer").value;
  
  if (keyword == "" || keyword == hld_model_keyword || keyword == hld_subject_keyword || keyword == hld_problem_keyword || keyword == hld_answer_keyword)
    return;
  else {
    parent.show_loading();
    parent.document.location = "faq.aspx?keyword=" + escape(keyword) + "&keywordtype=1&column="+search_type+"&search_type=" + search_type + "&SLanguage=" + document.getElementById("langNormal").value;
    //for developing
    //parent.document.getElementById("ifr_user_right").src = "faq_right_second.aspx?keyword=" + escape(keyword) + "&search_type=4&keywordtype=3&pagesize=10&since=5&product=7&SLanguage=" + document.getElementById("langNormal").value;
  }
}

function sel_answer_change() {
  o = document.getElementById("txt_keyword");
  txt_keyword = o.value;
  
  if (txt_keyword == "" || txt_keyword == hld_model_keyword || txt_keyword == hld_subject_keyword || txt_keyword == hld_problem_keyword || txt_keyword == hld_answer_keyword) {
    switch(document.getElementById("sel_answer").value) {
      case "0" :
        o.value = document.getElementById("hld_model_keyword").value;
        break;
        
      case "1" :
        o.value = document.getElementById("hld_subject_keyword").value;
        break;
        
      case "2" :
        o.value = document.getElementById("hld_problem_keyword").value;
        break;
        
      case "3" :
        o.value = document.getElementById("hld_answer_keyword").value;
        break;
    }
  } 
}

function txt_keyword_mouseover() {
  o = document.getElementById("txt_keyword");
  if (o.value == hld_model_keyword || o.value == hld_subject_keyword || o.value == hld_problem_keyword || o.value == hld_answer_keyword)
    o.value = "";
}

function txt_keyword_mouseout(){
  o = document.getElementById("txt_keyword");
  if(o.hasFocus)
    return;
   
  if (o.value == ""){
    switch(document.getElementById("sel_answer").value)
    {
      case "0" :
        o.value = document.getElementById("hld_model_keyword").value;   
        break;
        
      case "1" :
        o.value = document.getElementById("hld_subject_keyword").value;
        break;
        
      case "2" :
        o.value = document.getElementById("hld_problem_keyword").value;
        break;
      
      case "3" :
        o.value = document.getElementById("hld_answer_keyword").value;
        break;
    }
  }
}

function get_model_url() {
  var s = location.href;
  var i = s.indexOf("asus-faq.aspx");
  s = s.substring(0,i);
 
  var type_no ="";
  if(document.getElementById("hld_select1_id").value !="")
    type_no = "&type="+document.getElementById("hld_select1_id").value;
    
  return s + "asus-faq.aspx?no=" + document.getElementById("hld_kb_guid").value + type_no+ "&SLanguage=" + document.getElementById("langNormal").value;
}

function add_shortcut() {
  document.getElementById("copyArea").value = get_model_url();
  r = document.getElementById("copyArea").createTextRange();
  r.select();
  r.execCommand("copy"); 
  parent.window.scrollTo(0,0);
  alert(document.getElementById("hld_shortcut_ok").value);
}

function add_favorite() {
  window.external.AddFavorite(get_model_url(),"ASUS Support--FAQ(" + document.getElementById("msg_problem").innerHTML + ")");
}
