home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2004 March
/
PCWorld_2004-03_cd.bin
/
Komunikace
/
myIE
/
M2Combo.exe
/
$_14327_
/
config.js
< prev
next >
Wrap
Text File
|
2003-10-21
|
5KB
|
163 lines
// JavaScript Document
var cities;
var tempunit;
var visbunit;
var presunit;
var windunit;
var ssn = "xml.weather.com";
var xmlDoc = null;
function setCookie(name,value) {
var today = new Date();
var expires = new Date();
expires.setTime(today.getTime() + 1000*60*60*24*365);
document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString();
}
function getCookie(Name) {
var search = Name + "=";
if(document.cookie.length > 0) {
offset = document.cookie.indexOf(search);
if(offset != -1) {
offset += search.length;
end = document.cookie.indexOf(";", offset);
if(end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(offset, end));
}
else return('');
}
else return('');
}
var curlocid = getCookie("WT_loc_id")
var curcityname = getCookie("WT_loc_text")
var tempunit = getCookie("WT_T_unit");
var windunit = getCookie("WT_Wind_unit");
var presunit = getCookie("WT_P_unit");
var visbunit = getCookie("WT_Visb_unit");
var lan = getCookie("WT_Lan");
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
if(lan == "1") xmlDoc.load("language/lan_cn.xml"); else xmlDoc.load("language/lan_en.xml");
function retrieveHTML(sURL) {
var htmlContent;
var objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
objXMLHTTP.open("GET", sURL, false);
objXMLHTTP.send();
htmlContent = objXMLHTTP.responseBody;
var objRS = new ActiveXObject("ADODB.Recordset");
objRS.Fields.Append("txt", 200, 40000, 128);
objRS.Open();
objRS.AddNew();
objRS.Fields.item("txt").AppendChunk(htmlContent);
var htmlContent = objRS.Fields.item("txt").value;
objRS.Close();
objRS = null;
objXMLHTTP = null;
return htmlContent;
}
function translateonly(WTwords) {
objwords = xmlDoc.getElementsByTagName(WTwords);
if(objwords.length > 0) {
rewords = objwords.item(0).text;
} else {
rewords = WTwords;
}
return rewords;
}
function xmlParse(xmlText) {
var nodes = new Array()
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async = "false"
xmlDoc.loadXML(xmlText)
for(i=0; i<xmlDoc.documentElement.childNodes.length; i++){
nodes[i] = new Array()
nodes[i][0] = xmlDoc.documentElement.childNodes.item(i).text
nodes[i][1] = xmlDoc.documentElement.childNodes.item(i).getAttribute("id")
nodes[i][2] = xmlDoc.documentElement.childNodes.item(i).getAttribute("type")
}
return nodes
}
function clearRows(oTable) {
var rowsnum = oTable.rows.length
for(i=0; i<rowsnum; i++) {
oTable.deleteRow()
}
}
function addRow(oTable,rowHTML) {
var oRow=oTable.insertRow()
var aRows=oTable.rows
var aCells=oRow.cells
var oCell=aRows(oRow.rowIndex).insertCell(aCells.length)
oCell.innerHTML=rowHTML
}
function findlocid() {
var name = cityname.value
var urlstr = "http://" + ssn + "/search/search?where=" + name
var xmlInfo = retrieveHTML(urlstr)
cities = xmlParse(xmlInfo)
if(cities.length == 0) {
clearRows(resultcontent)
addRow(resultcontent,translateonly("WT_Noresult"));
} else {
clearRows(resultcontent)
addRow(resultcontent,"<B>"+translateonly("WT_Find1")+cities.length+translateonly("WT_Find2")+"</B>")
for(i=0; i<cities.length; i++) {
rowHTML="<label><input class=radio type=radio name=listcities value="+cities[i][1]+"> "+cities[i][0]+"</label>"
addRow(resultcontent,rowHTML)
}
addRow(resultcontent,"<input class=button type=button value="+translateonly("WT_Confirm")+" onClick=confirmcity()>")
}
}
function setPara() {
tempunit = 0;
visbunit = 0;
presunit = 0;
windunit = 0;
if(configtemp[0].checked) tempunit = 1;
if(configvisb[0].checked) visbunit = 1;
if(configpres[0].checked) presunit = 1;
if(configwind[0].checked) windunit = 1;
setCookie("WT_T_unit", tempunit);
setCookie("WT_Wind_unit", windunit);
setCookie("WT_P_unit", presunit);
setCookie("WT_Visb_unit", visbunit);
setCookie("WT_Lan", configlan.selectedIndex);
location.replace("weather.htm")
}
function confirmcity() {
if(cities.length == 1) {
setCookie("WT_loc_id", cities[0][1])
setCookie("WT_loc_type", cities[0][2])
setCookie("WT_loc_text", cities[0][0])
} else {
for(i=0; i<cities.length; i++) {
if(listcities[i].checked) {
setCookie("WT_loc_id", cities[i][1])
setCookie("WT_loc_type", cities[i][2])
setCookie("WT_loc_text", cities[i][0])
}
}
}
location.replace("config.htm")
}
function comment() {
if(curlocid == '') {
strHTML = translateonly("WT_Search_Error");
document.write(strHTML);
} else {
strHTML = translateonly("WT_Search_Normal");
document.write(strHTML);
}
}