﻿function HotKeywords_Load(){
  document.write("<div id=\"IypHotKeywords\"></div>");
  var strUrl ="/IYP_API/hotKeywordsXML/IypHotKeywords.xml?timestamp=" + new Date().getTime(); ;   
  var xmlhttp=createXMLHTTP();
  xmlhttp.onreadystatechange = function ()
  {
    if (xmlhttp.readyState == 4){
      if (xmlhttp.status == 200){
        var xmlDoc = xmlhttp.responseXML; 
        HotKeywords_Bind(xmlDoc);
      }
    }
  }
  xmlhttp.open("GET",strUrl,true);
  xmlhttp.send(null);
}
function HotKeywords_Bind(resXML) {
    var arrLink = resXML.getElementsByTagName("keywords");
    var iLength =arrLink.length-1;
    var sHtmlTitle = "", sHtml = "";
    var iMax = 79;
    var iLen = 0;
    if(sLang.toLowerCase() == "en"){
        sHtmlTitle = "<b>Hot Keywords : </b>" + sHtml;
        iMax = 84;
    }
    else if(sLang.toLowerCase() == "sc"){
        sHtmlTitle = "<b>热门搜寻 : </b>" + sHtml;    
    }
    else{
        sHtmlTitle = "<b>熱門搜尋 : </b>" + sHtml;   
    }
    
    for(var i = 0; i <= iLength; i++){
        myLink = arrLink[i];
        if(myLink.getAttribute("lang") == sLang.toLowerCase()){
            iLen += myLink.getElementsByTagName("keyword")[0].firstChild.nodeValue.trim().length + 1;
            if(iLen <= iMax){
                if(sHtml != "") sHtml += ", ";
                var sUrl_hot = "";
                if(myLink.getElementsByTagName("url")[0] != undefined){
                    sUrl_hot = myLink.getElementsByTagName("url")[0].firstChild.nodeValue.trim();
                }                
                if(sUrl_hot != ""){
                    if(sUrl_hot.search(/http:\/\//i)==-1)  sUrl_hot="http://"+sUrl_hot;
                    sHtml += " <a class=\"bluelink overunder\" href=\"" + sUrl_hot + "\" onclick=\"webTraffic(43,sLang,this.href);\" target=\"_blank\">" + myLink.getElementsByTagName("keyword")[0].firstChild.nodeValue.trim() + "</a>"
                }
                else{
                    sHtml += " <a class=\"bluelink overunder\" href=\"javascript:hot_search(&quot;" + myLink.getElementsByTagName("keyword")[0].firstChild.nodeValue.trim() + "&quot;,&quot;&quot;,&quot;&quot;)\">" + myLink.getElementsByTagName("keyword")[0].firstChild.nodeValue.trim() + "</a>"
                }
            }
        }
    }
    document.getElementById("IypHotKeywords").innerHTML = sHtmlTitle + sHtml;
}
HotKeywords_Load()


//yp hot search for home.aspx
function HotSearch_Load(){
  var strUrl ="/IYP_API/hotKeywordsXML/IypHotSearchKeywords.xml?timestamp=" + new Date().getTime(); ;   
  var xmlhttp=createXMLHTTP();
  xmlhttp.onreadystatechange = function ()
  {
    if (xmlhttp.readyState == 4){
      if (xmlhttp.status == 200){
        var xmlDoc = xmlhttp.responseXML; 
        HotSearch_Bind(xmlDoc);
      }
    }
  }
  xmlhttp.open("GET",strUrl,true);
  xmlhttp.send(null);
}
function HotSearch_Bind(resXML) {
  var arrLink = resXML.getElementsByTagName("keywords");
  var iLength =arrLink.length-1;
  var sHtml, sHtml_left = "", sHtml_right = "";
  for(var i = 0; i <= iLength; i++){
    myLink = arrLink[i];
    if(myLink.getAttribute("lang") == sLang.toLowerCase()){
      sHtml = " <a class=\"bluelink overunder\" href=\""+ myLink.getElementsByTagName("url")[0].firstChild.nodeValue.trim() + "\" onclick=\"webTraffic(75,sLang,this.href);\"  target=\"_blank\">" + myLink.getElementsByTagName("keyword")[0].firstChild.nodeValue.trim() + "</a>"
      if(i % 2 == 0){
        if(sHtml_left != "")
          sHtml_left += "<br />"
        sHtml_left += sHtml;
      }
      else{
        if(sHtml_right != "")
          sHtml_right += "<br />"
        sHtml_right += sHtml;
      }
    }
  }
  document.getElementById("HotSearch_left").innerHTML = sHtml_left;
  document.getElementById("HotSearch_right").innerHTML = sHtml_right;
}

function SetYPhotsrh(ImgID){
    var yphotsrh_pic = new Array('B18-027_Land', 'C06-019_Land', 'C13_031_Land', 'C15-054_Land', 'C15-059_Land', 'C17-048_Land', 'C18-100_Land', 'E12-066_Land', 'F_Land_Fire-Works_1', 'F_Land_Paintings_1', 'G11-008_Land', 'H06-123_Land', 'I18-012_Land', 'I18-030_Land', 'K03-152_Land', 'K04-024_Land', 'K09-003_Land', 'Xmas1_Land')
    var yphotsrh_index = Math.round(Math.random()*(yphotsrh_pic.length));
    document.images[ImgID].src="/IYP_API/hotKeywordsXML/images/" + yphotsrh_pic[yphotsrh_index-1] + ".jpg"
}
