//Cache control

function H_ELEM(ELEM) 
{
document.getElementById(ELEM).style.visibility = "hidden"
document.getElementById(ELEM).style.display="none"
}
function V_ELEM(ELEM1) 
{
document.getElementById(ELEM1).style.visibility = "visible"
document.getElementById(ELEM1).style.display="block"
}
function addOptionList(pr, selname, optN){

var newCat = prompt( pr, "");
var newOpt = new Option(newCat, newCat, false, true);
//var catField = document.getElementById(selname); 
var catField = document.forms[0].elements[selname];
if ((newCat != null) && (newCat != "")) {
	catField.options[catField.options.length] = newOpt;
}
if(optN=="2"){ShowValue(document.forms[0], '2')}
}
var xmlDoc
//-------------------------------------
var xmlT= "X";
function loadXMLDocNEW(xmlF)
{

if (window.ActiveXObject) 
	{
push_GetXmlDoc(0);
		xmlDoc = new ActiveXObject(xmlT);
		xmlDoc.async = false;
		xmlDoc.load(xmlF);

             }
else if (window.XMLHttpRequest) 
	{ 
// instantiate and load the xsl document
docRequest = new XMLHttpRequest();
docRequest.overrideMimeType('text/xml');
docRequest.open('GET', xmlF, false);
docRequest.send(null);
xmlDoc = docRequest.responseXML;
	}
}
////////////////////////////////////////
//--------------------------------------------------------------------------
function push_GetXmlDoc(index)
{
var  ArrX= new Array("Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.5.0", "Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "Msxml2.DOMDocument", "microsoft.domdocument"); 
var xmlD=null; 
//if (window.ActiveXObject && index < ArrX.length)
{ 
	try{ 
		if (xmlD= new ActiveXObject(ArrX[index]))
{ 
xmlT= ArrX[index];
 }
	}
	catch(e){
push_GetXmlDoc(index+1); 
	}
}
}
///////////////////////////////////////////////////////////////////////////////////
//-----------Функция генерации списков --------------------
      function FillDropDown(URLX,FormName, NameSelect1){
loadXMLDocNEW(URLX);
        var objDDL = FormName.elements[NameSelect1];
        objDDL.options.length = 0;

if (window.ActiveXObject) 
	{
        var xRows = xmlDoc.getElementsByTagName('bs:item');
	}
else if (window.XMLHttpRequest) 
	{ 
// For old Version
//        var xRows = xmlDoc.getElementsByTagName('item');  
        var xRows = xmlDoc.getElementsByTagName('bs:item');
	}

          var option1 = new Option("- Нет -", "0");
          objDDL.options.add(option1, objDDL.options.length);
        for(i=0;i<xRows.length;i++){
          var theValue = xRows[i].childNodes[0].getAttributeNode("EditId").nodeValue;
          var theText  = xRows[i].childNodes[0].firstChild.nodeValue;
//          var theValue = xRows[i].childNodes[0].firstChild.nodeValue;
          var option = new Option(theText, theValue);
          objDDL.options.add(option, objDDL.options.length);
        }
}
//////////////////////////////////////////////////////////////////////////////////
      function Option1(FormName1)
{

itT1 = FormName1.bs_Country.options[FormName1.bs_Country.selectedIndex].text;
itV1 = FormName1.bs_Country.options[FormName1.bs_Country.selectedIndex].value;
REF1='/B_SER/Bs_Ref.nsf/bs_addrlistWEB?openview&restricttocategory=2~'+escape(itT1)+'&count=600';
FillDropDown(REF1,FormName1,'bs_Region');
        var objDDL1 = FormName1.elements['bs_City'];
        objDDL1.options.length = 0;
        var opt1 = new Option("- Нет -", "0");
        objDDL1.options.add(opt1, objDDL1.options.length);
V_ELEM("bs_All");
H_ELEM("bs_City");
if(itV1==0){H_ELEM("buttRegion"); V_ELEM("buttCity");}else{V_ELEM("buttRegion");V_ELEM("buttCity");}
SaveLocation(FormName1);

//FormName1.bs_Country.options.add(new Option('TEST','0',true,true)); 
}
//////////////////--Add---Old---Options
      function AddOldOpt(FormName1,ic1,ic2,ic3)
{
H_ELEM("bs_All");
FillDropDown('/B_SER/Bs_Ref.nsf/bs_addrlistWEB?openview&restricttocategory=1&count=400',document.forms[0],'bs_Country');
FormName1.bs_Country.options.add(new Option(ic1,'0',true,true)); 

FillDropDown('/B_SER/Bs_Ref.nsf/bs_addrlistWEB?openview&restricttocategory=2~'+escape(ic1)+'&count=400',document.forms[0],'bs_Region');
FormName1.bs_Region.options.add(new Option(ic2,'0',true,true)); 


if(ic3!="- Нет -")
     {
if(ic2!="- Нет -")
{
FillDropDown('/B_SER/Bs_Ref.nsf/bs_addrlistWEB?openview&restricttocategory=3~'+escape(ic1)+'~'+escape(ic2)+"&count=1000",document.forms[0],'bs_City');
}
if(ic2=="- Нет -")
{
FillDropDown('/B_SER/Bs_Ref.nsf/bs_addrlistWEB?openview&restricttocategory=3~'+escape(ic1)+"&count=2000",document.forms[0],'bs_City');}
FormName1.bs_City.options.add(new Option(ic3,'0',true,true)); 
    }
else
{
FillDropDown('/B_SER/Bs_Ref.nsf/bs_addrlistWEB?openview&restricttocategory=3~'+escape(ic1)+"&count=2000",document.forms[0],'bs_City');
FormName1.bs_City.options.add(new Option(ic3,'0',true,true)); 
}
}
//////////////////////////////////////////////////////////////////////////////////
      function Option2(FormName1)
{
itT1 = FormName1.bs_Country.options[FormName1.bs_Country.selectedIndex].text;
itV1 = FormName1.bs_Country.options[FormName1.bs_Country.selectedIndex].value;
itT2 = FormName1.bs_Region.options[FormName1.bs_Region.selectedIndex].text;
itV2 = FormName1.bs_Region.options[FormName1.bs_Region.selectedIndex].value;
REF2="/B_SER/Bs_Ref.nsf/bs_addrlistWEB?openview&restricttocategory=3~"+escape(itT1)+"~"+escape(itT2)+"&count=600";
FillDropDown(REF2,FormName1,'bs_City');
H_ELEM("bs_All");
V_ELEM("bs_City");
if(itV2==0){H_ELEM("buttCity");}else{V_ELEM("buttCity");}
SaveLocation(FormName1);
}
//////////////////////////////////////////////////////////////////////////////////
      function OptionALL(FormName1)
{
H_ELEM("bs_All");
V_ELEM("bs_City");
itT1 = document.forms[0].bs_Country.options[document.forms[0].bs_Country.selectedIndex].text;
itV1 = document.forms[0].bs_Country.options[document.forms[0].bs_Country.selectedIndex].value;
REF1='/B_SER/Bs_Ref.nsf/bs_addrlistWEB?openview&restricttocategory=3~'+escape(itT1)+'&count=5000';
FillDropDown(REF1,document.forms[0],'bs_City'); 
///init function---------------------
}
function initReg()
{
var ST1="Россия";
FillDropDown('/B_SER/Bs_Ref.nsf/bs_addrlistWEB?openview&restricttocategory=1&count=400',document.forms[0],'bs_Country');
FillDropDown('/B_SER/Bs_Ref.nsf/bs_addrlistWEB?openview&restricttocategory=2~'+escape('Россия')+'&count=400',document.forms[0],'bs_Region');
FillDropDown('/B_SER/Bs_Ref.nsf/bs_addrlistWEB?openview&restricttocategory=3~'+escape('Россия')+'~'+escape('Москва')+'&count=400',document.forms[0],'bs_City');
document.forms[0].bs_Country.options[1].selected = true;
document.forms[0].bs_Region.options[43].selected = true;
document.forms[0].bs_City.options[1].selected = true;
document.forms[0].Ns_Location.value='Россия'+'\\'+'Москва'+'\\'+'Москва';
H_ELEM("buttCity");
H_ELEM("buttRegion");
H_ELEM("bs_All");
//document.forms[0].bs_Country.text='test';
}
function SaveLocation(FormName1)
{
ii11 = FormName1.bs_Country.options[FormName1.bs_Country.selectedIndex].text;
ii22 = FormName1.bs_Region.options[FormName1.bs_Region.selectedIndex].text;
ii33 = FormName1.bs_City.options[FormName1.bs_City.selectedIndex].text;
//"- Нет -"
if(ii11=="- Нет -"){ii11="";}
if(ii22=="- Нет -"){ii22="";}
if(ii33=="- Нет -"){ii33="";}

//iiSum=ii11+'\\'+ii22+'\'+ii33;
iiSum=ii11+'\\'+ii22+'\\'+ii33;
//iiSum=ii11;
FormName1.Ns_Location.value=iiSum;
}
///////////////////////////////////////////////////////////////////////////////////
