﻿                 
         var rain_oXmlData = xml_CreateDOMFromXMLString("<data/>");         
    
         function rain_GetLocalXmlDoc(controlIndex){
              return rain_oXmlData;
         }
    
         function rain_GetChildControls(controlIndex){
             var oRv; eval("oRv = new rain_JS1_clsControls_"+controlIndex+"();");
             return oRv;
         }
         
         function rain_ddlRangesListChanged(controlIndex,controlClientId){
             eval("rain_ShowMap_"+controlClientId+"();");
             rain_ddlCitiesListChanged(controlIndex);
         }
         
         function rain_ddlCitiesListChanged(controlIndex){
         //debugger;
         //alert("11111");
             var colCtl = rain_GetChildControls(controlIndex);
             var sCityCode = colCtl["ddlCities"].value;
             var sDate = colCtl["ddlDates"].value;
             var oXmlDoc = rain_GetLocalXmlDoc(controlIndex);
             var oXmlNode = oXmlDoc.selectSingleNode("//item[@code='"+sCityCode+"' and @date='"+sDate+"']");
             
             if(oXmlNode!=null){
                 rain_ProcessXmlNode(controlIndex, oXmlNode);
             }else{
                 var oXmlRemote = xml_CreateDOMFromPath(rain_sAjaxUrl+"?rainCity="+escape(sCityCode)+"&rainDate="+escape(sDate)+"&rainLangId="+rain_JS1_LangId);                 
                                                 
                 if(true){
                     oXmlNode = oXmlRemote.selectSingleNode("//item");
                     if(oXmlNode!=null){
                         rain_ProcessXmlNode(controlIndex, oXmlNode);
                         rain_SaveXmlNode(controlIndex, oXmlNode);
                     }else{
                         //alert(oXmlRemote.xml);
                         //alert("invalid remote xml structure");
                     }
                  }else{
                    // alert("invalid remote xml");
                  }                                     
             }
             if(document.getElementById('divBellAbove') != null){
                //document.getElementById('divBellAbove').innerHTML = UserControls_RealTimeViewsRainUC.GetHeightFinalText(oXmlNode.xml).value;
             }          
             if(document.getElementById('divBellAboveFly') != null){
              document.getElementById('divBellAboveFly').innerHTML = UserControls_RealTimeViewsRainUC.GetHeightFinalText(oXmlNode.xml).value;
             }             
         }
      function rain_ddlCitiesListChanged1(controlIndex){
         
             var colCtl = rain_GetChildControls(controlIndex);
             var sCityCode = colCtl["ddlCities"].value;
             var sDate = colCtl["ddlDates"].value;
             var oXmlDoc = rain_GetLocalXmlDoc(controlIndex);
             var oXmlNode = oXmlDoc.selectSingleNode("//item[@code='"+sCityCode+"' and @date='"+sDate+"']");
             
             if(oXmlNode!=null){
                 rain_ProcessXmlNode(controlIndex, oXmlNode);
             }else{
                 var oXmlRemote = xml_CreateDOMFromPath(rain_sAjaxUrl+"?rainCity="+escape(sCityCode)+"&rainDate="+escape(sDate)+"&rainLangId="+rain_JS1_LangId);                 
                                                 
                 if(true){
                     oXmlNode = oXmlRemote.selectSingleNode("//item");
                     if(oXmlNode!=null){
                         rain_ProcessXmlNode(controlIndex, oXmlNode);
                         rain_SaveXmlNode(controlIndex, oXmlNode);
                     }else{
                         //alert(oXmlRemote.xml);
                         //alert("invalid remote xml structure");
                     }
                  }else{
                    // alert("invalid remote xml");
                  }                                     
             }
             if(document.getElementById('divBellAbove') != null){
                document.getElementById('divBellAbove').innerHTML = UserControls_RealTimeViewsRainUC.GetHeightFinalText(oXmlNode.xml).value;
             }          
             if(document.getElementById('divBellAboveFly') != null){
               document.getElementById('divBellAboveFly').innerHTML = UserControls_RealTimeViewsRainUC.GetHeightFinalText(oXmlNode.xml).value;
             }             
         }
         
         function rain_ShowMapPointDiv(controlIndex, staticControlIndex, cityCode){
       
          
             var colCtl = rain_GetChildControls(controlIndex);
             var colCtlStaitic = rain_GetChildControls(staticControlIndex);
             
             colCtl["ddlCities"].value = cityCode;
             rain_ddlCitiesListChanged(controlIndex);
             
             var ddlCities = colCtlStaitic["ddlCities"];
             var sCityName = "";
             for(var i=0; i<ddlCities.options.length; i++){
                 if(ddlCities.options[i].value==cityCode){
                     sCityName = ddlCities.options[i].text;
                 }
             }
             colCtl["rain_CityName"].innerHTML = sCityName;

             var oFly = null; eval("oFly=window.oFly_"+controlIndex+";");
             if(oFly==null){
                 oMap = colCtl["imgMap"];
                 if(rain_JS1_LangId==1){
                    oFly = new clsFlyObj(oMap,colCtl["pnlFly"].id,"left","right","top","top",20,100);
                 }else{
                    oFly = new clsFlyObj(oMap,colCtl["pnlFly"].id,"right","left","top","top",-20,100);
                 }
                 eval("window.oFly_"+controlIndex+"=oFly;");                                 
             }
             oFly.SetPosition(); 
             oFly.Show();
                          
             window.status = cityCode;
         }
         
         function rain_HideMapPointDiv(controlIndex, staticControlIndex, cityCode){
             var oFly = null; eval("oFly=window.oFly_"+controlIndex+";");
             if(oFly!=null){
                oFly.Hide();
             }
             window.status = "";
         }
         
         function rain_SaveXmlNode(controlIndex, xmlNode){
             var oXmlDoc = rain_GetLocalXmlDoc(controlIndex);
             var oXmlNode = oXmlDoc.createElement("item");
             
             rain_SaveXmlNode1(xmlNode,oXmlNode,oXmlDoc);
             oXmlDoc.documentElement.appendChild(oXmlNode);
             //alert(oXmlDoc.xml);             
         }
         
         function rain_SaveXmlNode1(srcXmlNode,destinationXmlNode,destinationXmlDocument){
             for(var i=0; i<srcXmlNode.attributes.length; i++){
                 var oXmlAttr = destinationXmlDocument.createAttribute(srcXmlNode.attributes[i].nodeName);
                 oXmlAttr.nodeValue = srcXmlNode.attributes[i].nodeValue;
                 destinationXmlNode.attributes.setNamedItem(oXmlAttr);                 
             }
             for(var i=0; i<srcXmlNode.childNodes.length; i++){
                 var oXmlNode = destinationXmlDocument.createElement(srcXmlNode.childNodes[i].nodeName);
                 rain_SaveXmlNode1(srcXmlNode.childNodes[i],oXmlNode,destinationXmlDocument);
                 destinationXmlNode.appendChild(oXmlNode);
             }
         }
         
         function rain_ProcessFirstTimeXml(controlIndex, xmlHiddenFieldId){
              var oFld = document.getElementById(xmlHiddenFieldId);                             
              var oXmlDoc = xml_CreateDOMFromXMLString(oFld.value);
              var oXmlNode = oXmlDoc.documentElement;    
                                         
              rain_ProcessXmlNode(controlIndex, oXmlNode);
              rain_SaveXmlNode(controlIndex, oXmlNode);                                               
         }
         
         function rain_ProcessXmlNode(controlIndex, xmlNode){
             var colCtl = rain_GetChildControls(controlIndex);
             
             rain_FixEndDates(controlIndex);
             
             for(var i=0; i<xmlNode.attributes.length; i++){
                 rain_ProcessValue(colCtl,xmlNode.attributes[i].nodeName,xmlNode.attributes[i].nodeValue);
             }
             
             var oTbl = colCtl["rain_LastWeekTable"];
             if(oTbl!=null){
                 //oTbl.style.display = "none";
                 
                 var sHtmlTableHead = "";
                 try{
                 sHtmlTableHead = colCtl["rain_LastWeekTable_HeaderTamplate"].innerHTML;
                 sHtmlTableHead = sHtmlTableHead.replace(/\<[\/]?tbody\>/gi,"");
                 }catch(e){}
                 var sHtml = xmlNode.transformNode(rain_oXslStationTable);
                 sHtml = sHtml.replace(/(\<thead[\/]?\>)|(\<thead\>[.]*\<\/thead\>)/i,sHtmlTableHead);
                 oTbl.innerHTML = sHtml;
             }
             
             var sCode = xmlNode.selectSingleNode("@code");
             if(sCode!=null){
                  var ctlDdl = colCtl["ddlCities"];
                  if(ctlDdl!=null){
                      sCode = sCode.nodeValue;
                      if(ctlDdl.value!=sCode){
                          //alert("fix to" + sCode);
                          ctlDdl.value = sCode;
                      }
                  }
             }                                       
         }
         
         function rain_ProcessValue(colCtl, keyName, value){
             switch(keyName){
                case "date" : 
                case "code" : break;
                case "codeid" :                     
                    var oA = colCtl["rain_StationLink_MoreInfo"];
                    if(oA!=null){                    
                        oA.href = rain_sInfoPath+"?GotoPost="+escape(value);
                    }
                    break;
                case "rain_Preliminary" :
                    var oEl = colCtl[keyName];                    
                    if(oEl!=null){
                        oEl.style.display = (value.toLowerCase()=="true")?"block":"none";
                    }
                    break;
                default : 
                    var oEl = colCtl[keyName];                    
                    if(oEl!=null){
                       var sValue = "";
                       var oElContainer = rain_ProcessValue_FindContainer(oEl);
                       switch(keyName){
                           case "rain_CoordinatesInternational" :
                              sValue = value.replace("o",sDegreeHTML);
                              sValue = sValue.replace("o",sDegreeHTML);
                              break;
                           case "rain_CoordinatesHeight" :
                                if(value!=null && value!="")
                                {
                                    sValue = value.replace("-","");
                                }
                              //sValue = "<span dir=\"ltr\">"+value+"</span>";
                              break;    
                           default :
                              sValue = value;
                       }
                       if(sValue!=""){
                          var sMeasure = oEl.getAttribute("measuretext");
                          if(sMeasure!=null && sMeasure!=""){
                             oEl.innerHTML = sValue+sMeasure;
                          }else{
                             oEl.innerHTML = sValue;
                          }
                          if(oElContainer!=null)oElContainer.style.display="block";
                       }else{
                          oEl.innerHTML = "";
                          if(oElContainer!=null)oElContainer.style.display="none";
                       }
                    }
             }             
         }
         
         function rain_ProcessValue_FindContainer(el){
             var el1 = el;
             
             for(var iCnt=0;iCnt<5;iCnt++){
                if(el1==null)break;
                if(el1.tagName=="DIV" && el1.className=="DivMarginBottom"){
                   return el1;
                }                
                el1 = el1.parentNode;                
             }
             
             return null;             
         }
         
         
         function rain_FixEndDates(controlIndex){
             var colCtl = rain_GetChildControls(controlIndex);
             
             var colElEndDates = document.getElementsByName("ims_rain_enddate");
             var ctlDate = colCtl["ddlDates"];
             var sDate = ctlDate.options[ctlDate.selectedIndex].text;
             for(var i=0; i<colElEndDates.length; i++){
                colElEndDates[i].innerHTML = sDate;
             }         
         }


