
function XmlNodeToArray(xmlNode)
{var ret=new Array();if(xmlNode==null)
{return ret;}
for(var i=0;i<xmlNode.childNodes.length;i++)
{if(xmlNode.childNodes[i].nodeType==1)
{var nodeName=xmlNode.childNodes[i].nodeName;if(xmlNode.childNodes[i].childNodes)
{if(xmlNode.childNodes[i].childNodes.length>0)
{ret[nodeName]=xmlNode.childNodes[i].childNodes[0].nodeValue;}else
{ret[nodeName]="";}}}}
return ret;}
function XmlNodeGetAttrs(xmlNode)
{var ret=new Array();for(var i=0;i<xmlNode.attributes.length;i++)
{if(xmlNode.attributes[i].nodeType==2)
{var nodeName=xmlNode.attributes[i].nodeName;var nodeValue=xmlNode.attributes[i].nodeValue;ret[nodeName]=nodeValue;}}
return ret;}
function WinAppendHtml(win,doc,par,type,content,ns)
{var obj=WinAppendHtml2(win,doc,par,type,content,ns);return obj;}
function WinAppendHtml2(win,doc,par,type,content,ns)
{if(win==null)
{return null;}
if(doc==null||(typeof doc=="undefined"))
{doc=win.document;}
if(typeof par=="string")
{par=doc.getElementById(par);}
if(!par)
{par=doc.body||doc.documentElement;}
var obj;if(type)
{if(ns&&doc.createElementNS)
{obj=doc.createElementNS(ns,type);}else
{obj=doc.createElement(type);}}else
{obj=par;}
if(content&&content.length>0)
{{obj.innerHTML=content;}}
if(par&&obj&&par!=obj)
{obj=par.appendChild(obj);}
return obj;}
function WinFlashTitle(win,maxTime)
{WinFlashTitle_maxTime=maxTime;WinFlashTitleStart(win);}
var WinFlashTitle_maxTime=0;var WinFlashTitle_pastTime=0;var WinFlashTitle_currentTitle="";var WinFlashTitle_window=null;var WinFlashTitle_timerId=0;function WinFlashTitleInterval()
{var title1='!!! Changed !!!';if(document.title==title1)
WinFlashTitle_window.document.title=WinFlashTitle_currentTitle;else
WinFlashTitle_window.document.title=title1;WinFlashTitle_pastTime+=100;if((WinFlashTitle_maxTime>0&&WinFlashTitle_pastTime>WinFlashTitle_maxTime))
{WinFlashTitleStop();}else
{WinFlashTitle_timerId=setTimeout('WinFlashTitleInterval()',100);}}
function WinFlashTitleStart(win)
{WinFlashTitle_window=win;WinFlashTitle_pastTime=0;WinFlashTitle_currentTitle=WinFlashTitle_window.document.title;WinFlashTitle_timerId=setTimeout('WinFlashTitleInterval()',100);}
function WinFlashTitleStop()
{WinFlashTitle_window.document.title=WinFlashTitle_currentTitle;WinFlashTitle_pastTime=0;WinFlashTitle_maxTime=0;clearTimeout(WinFlashTitle_timerId);}
function newXMLHttpRequest(xmlhttpprovider)
{if(typeof xmlhttpprovider=="string"&&xmlhttpprovider)
{if(xmlhttpprovider=="XMLHTTP")
{var obj=new XMLHTTP();return obj;}}
if(isIE)
{return new ActiveXObject("Microsoft.XMLHTTP");}else
{return new XMLHttpRequest;}}
function UrlEncode(url)
{return escape(url).replace(/\+/g,'%2C').replace(/\"/g,'%22').replace(/\'/g,'%27');}
function UrlEncode2(sStr)
{return encodeURIComponent(sStr).replace(/\+/g,"%2B").replace(/\//g,"%2F");}
function UrlAppendVariable(url,name,value)
{var index;var index2;index=url.indexOf("?");if(index<0)
{newurl=url+"?"+name+"="+value;}else
{index=url.indexOf(name+"=");if(index<0)
{newurl=url+"&"+name+"="+value;}
else
{index=url.indexOf("?"+name+"=");if(index<0)
{index=url.indexOf("&"+name+"=");}
if(index>=0)
{url1=url.substring(0,index+name.length+2);url2=url.substring(index+name.length+2);index2=url2.indexOf("&");if(index2>=0)
{url2=url2.substring(index2);}else
{url2="";}
newurl=url1+value+url2;}}}
return newurl;}
var validTldList=".com.edu.net.org.gov.mil.jp.de.au.in.uk.fr.ca.dk.it.cn.kr.int.arpa.nato.biz.name.museum.pro.aero.coop.info.ac.ae.af.ag.ai.al.am.an.ao.aq.ar.as.at.au.aw.az.ba.bb.bd.be.bf.bg.bh.bi.bj.bm.bn.bo.br.bs.bt.bv.bw.by.bz.ca.cc.cd.cf.cg.ch.ci.ck.cl.cm.cn.co.cr.cu.cv.cx.cy.cz.de.dj.dk.dm.do.dz.ec.ee.eg.eh.er.es.et.fi.fj.fk.fm.fo.fr.ga.gd.ge.gf.gg.gh.gi.gl.gm.gn.gp.gq.gr.gs.gt.gu.gw.gy.hk.hm.hn.hr.ht.hu.id.ie.il.im.in.io.iq.ir.is.it.je.jm.jo.jp.ke.kg.kh.ki.km.kn.kp.kr.kw.ky.kz.la.lb.lc.li.lk.lr.ls.lt.lu.lv.ly.ma.mc.md.mg.mh.mk.ml.mm.mn.mo.mp.mq.mr.ms.mt.mu.mv.mw.mx.my.mz.na.nc.ne.nf.ng.ni.nl.no.np.nr.nu.nz.om.pa.pe.pf.pg.ph.pk.pl.pm.pn.pr.ps.pt.pw.py.qa.re.ro.ru.rw.sa.sb.sc.sd.se.sg.sh.si.sj.sk.sl.sm.sn.so.sr.st.sv.sy.sz.tc.td.tf.tg.th.tj.tk.tm.tn.to.tp.tr.tt.tv.tw.tz.ua.ug.uk.um.us.uy.uz.va.vc.ve.vg.vi.vn.vu.wf.ws.ye.yt.yu.za.zm.zw.";function UrlGetHostname(url)
{var host=url;var start=host.indexOf("://");if(start>0)
{host=url.substring(start+3);var end=0;while(end<host.length)
{var ch=host.charAt(end);if(ch==':'||ch=='/')
break;end++;}
host=host.substring(0,end);}
return host;}
function UrlGetPath(url,level)
{var question=url.indexOf('?');if(question>0)
{url=url.substring(0,question);}
var lastslash=url.lastIndexOf("/");newurl=url.substring(0,lastslash+1);if(typeof(level)=="number")
{while(level>0)
{var lastslash=newurl.substring(0,newurl.length-1).lastIndexOf("/");newurl=newurl.substring(0,lastslash+1);level--;}}
return newurl;}
function UrlGetArgItem(location_search,theArgName,defaultValue)
{sArgs=location_search.slice(1).split('&');r=defaultValue;for(var i=0;i<sArgs.length;i++)
{if(sArgs[i].slice(0,sArgs[i].indexOf('='))==theArgName)
{r=sArgs[i].slice(sArgs[i].indexOf('=')+1);break;}}
if(r.length>0)
{r=unescape(r).split(',');r=r[0];return r;}else
return defaultValue;}
function UrlGetFull(location_href,rel_url)
{var newurl=rel_url;var colon_index=rel_url.indexOf("://");var slash_index=rel_url.indexOf("/");if(colon_index>=0)
{newurl=rel_url;}
else
if(slash_index==0)
{var index=location_href.indexOf("//");var index2=location_href.indexOf("/",index+2);newurl=location_href.substring(0,index2)+rel_url;}else
{var lastquestion=location_href.lastIndexOf("?");if(lastquestion>0)
{location_href=location_href.substring(0,lastquestion);}
var lastslash=location_href.lastIndexOf("/");newurl=location_href.substring(0,lastslash+1)+rel_url;}
return newurl;}
function FormGetValues(fobj,valFunc)
{var str="";var valueArr=null;var val="";var cmd="";for(var i=0;i<fobj.elements.length;i++)
{switch(fobj.elements[i].type)
{case"textarea":case"text":if(valFunc)
{cmd=valFunc+"("+'fobj.elements[i].value'+")";val=eval(cmd)}
str+=fobj.elements[i].name+"="+(fobj.elements[i].value)+"&";break;case"select-one":str+=fobj.elements[i].name+"="+fobj.elements[i].options[fobj.elements[i].selectedIndex].value+"&";break;}}
str=str.substr(0,(str.length-1));return str;}
function FormFieldCheckEmpty(field)
{if(field.value.length>0)
{return true;}
else
{alert("Fields have been filled out, please fill in first");return false;}}
function FormFieldCheckFilled(field,defaultval)
{if(field.value.length>0)
{if(field.value==defaultval)
{alert("Fields have been filled out, please fill in first");return false;}
return true;}
else
{alert("Fields have been filled out, please fill in first");return false;}}
function WinSetBackgroundColor(win,newcolor,elemid)
{var oldcolor="";if(win)
{var doc=win.document;if(doc)
{if(typeof(elemid)!="undefined")
{elem=doc.getElementById(elemid);}else
{elem=doc.body;}
if(elem)
{oldcolor=elem.style.backgroundColor;elem.style.backgroundColor=newcolor;}}}
return oldcolor;}
function NMXmlRequest0(url,method,sendcontent,xmlhttpprovider,xmlprocfunc)
{var xmlhttp;var url;var async=true;if(typeof xmlprocfunc=='undefined'||xmlprocfunc==null)
async=false;if(url.indexOf("://")<0)
{url=UrlGetFull(window.location.href,url);}
xmlhttp=newXMLHttpRequest(xmlhttpprovider);try{xmlhttp.open(method,url,async);}catch(err)
{if(xmlhttpprovider==null)
{xmlhttp=newXMLHttpRequest('XMLHTTP');xmlhttp.open(method,url,async);}}
xmlhttp.setRequestHeader("User-Agent","Mozilla/4.0 (compatible; Windows XP 5.1)");xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");xmlhttp.setRequestHeader("Accept","*/*");if(async)
xmlhttp.onreadystatechange=function()
{if(xmlhttp.readyState==4)
{if(xmlhttp.status==200)
{if(xmlhttp.responseXML)
{}
if(xmlprocfunc)
{xmlprocfunc(xmlhttp);return;}
return;}
xmlprocfunc(null);return;}
else
{}};try{xmlhttp.send(sendcontent);}catch(err)
{if(xmlhttpprovider!='XMLHTTP')
{NMXmlRequest0(url,method,sendcontent,xmlprocfunc,'XMLHTTP');}}
return xmlhttp;}
function NMXmlRequest2(url,method,sendcontent,xmlprocfunc,xmlhttpprovider)
{try{if(isFF)
{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserAccess");}}catch(err){}
NMXmlRequest(url,method,sendcontent,xmlprocfunc,xmlhttpprovider);}
function NMXmlRequest(url,method,sendcontent,xmlprocfunc,xmlhttpprovider)
{var xmlhttp;var url;var async=true;if(typeof xmlprocfunc=='undefined'||xmlprocfunc==null)
async=false;if(url.indexOf("://")<0)
{url=UrlGetFull(window.location.href,url);}
xmlhttp=newXMLHttpRequest(xmlhttpprovider);try{xmlhttp.open(method,url,async);}catch(err)
{if(xmlhttpprovider==null)
{xmlhttp=newXMLHttpRequest('XMLHTTP');xmlhttp.open(method,url,async);}}
xmlhttp.setRequestHeader("User-Agent","Mozilla/4.0 (compatible; Windows XP 5.1)");xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");xmlhttp.setRequestHeader("Accept","*/*");if(async)
xmlhttp.onreadystatechange=function()
{if(xmlhttp.readyState==4)
{if(xmlhttp.status==200)
{var xmlObj=xmlhttp.responseXML.documentElement;if(xmlprocfunc!=null)
{xmlprocfunc(xmlObj);return;}
return;}
xmlprocfunc(null);return;}
else
{}};try{xmlhttp.send(sendcontent);}catch(err)
{if(xmlhttpprovider!='XMLHTTP')
{NMXmlRequest(url,method,sendcontent,xmlprocfunc,'XMLHTTP');}}
return xmlhttp;}
function NMXmlReceiver(xmlObj)
{return 0;}
function WinAppendScript(win,src)
{doc=win.document;var elem=doc.createElement("SCRIPT");elem.type="text/javascript";elem.src=src;var head=doc.getElementsByTagName('head')[0];if(head)
elem=head.appendChild(elem);else
elem=doc.body.appendChild(elem);return elem;}
function WinInvokeScript(win,scripts)
{var doc=win.document;var elem=doc.createElement("SCRIPT");elem.type="text/javascript";elem.innerHTML=scripts;elem=doc.body.appendChild(elem);return elem;}
function MenuItemCheck(menuitem,checked)
{if(!menuitem)
return;(isIE)?MenuItemCheckIE(menuitem,checked):MenuItemCheckFF(menuitem,checked);}
function MenuItemCheckIE(menuitem,checked)
{}
function MenuItemCheckFF(menuitem,checked)
{if(menuitem.setAttribute)
{if(checked)
{menuitem.setAttribute("checked","true");}
else
{menuitem.setAttribute("checked","false");}}}
function MenuCheckOneItem(doc,popupid,itemid)
{var menupopup=doc.getElementById(popupid);var menuitems=menupopup.getElementsByTagName("menuitem");for(var i=0;i<menuitems.length;i++)
{var menuitem=menuitems[i];if(menuitem.id==itemid)
{menuitem.setAttribute("checked","true");}
else
{menuitem.setAttribute("checked","false");}}}
function SelectChooseValue(doc,id,value)
{var elem=doc.getElementById(id);if(elem)
{for(var i=0;i<elem.options.length;i++)
{if(elem.options[i].value==value)
{elem.selectedIndex=i;break;}}}}
function InjectScriptFiles(win,srcdir,files)
{var i=0;for(i=0;i<files.length;i++)
{var jsfilename=srcdir+files[i];WinAppendScript(win,jsfilename);}}
function WinGetIFrameDoc(doc,iframeid)
{var oIframe=doc.getElementById(iframeid);var oDoc=(oIframe.contentWindow||oIframe.contentDocument);if(oDoc.document)
oDoc=oDoc.document;return oDoc;}
function WinSetIFrameUrl(win,doc,iframename,url)
{if(doc==null)
doc=win.document;if(isFF)
{var iframeobj=document.getElementById(iframename);if(iframeobj)
{if(iframeobj.loadURI)
iframeobj.loadURI(url);else
iframeobj.src=url;return;}}
var iframe=win.frames[iframename];if(iframe)
{if(isIE)
{if(iframe.navigate)
{try{iframe.navigate(url);}catch(err){}}else
{iframe.doc.location.href=url;}}
else
{var iframeobj=doc.getElementById(iframename);if(iframeobj)
{iframeobj.src=url;}}}}
function XULMenuListChooseValue(doc,id,value)
{var menulist=doc.getElementById(id);var items=menulist.firstChild.childNodes;if(items)
{for(var i=0;i<items.length;i++)
{if(items[i].value==value)
{menulist.selectedIndex=i;break;}}}}
function WinIsPopup(win)
{var ret=false;if(isFF)
ret=!(win.menubar&&win.menubar.visible);else
ret=false;return ret;}
debug("webutil.js loaded");
