    // etot parser texta vzjat s apple.com
    // retrieve text of an XML document element, including
    // elements using namespaces
    function getElementTextNS(prefix, local, parentElem, index)
    {
        var result = "";
        if (prefix && isIE)
        {
            // IE/Windows way of handling namespaces
            result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
        }
        else
        {
            // the namespace versions of this method
            // (getElementsByTagNameNS()) operate
            // differently in Safari and Mozilla, but both
            // return value with just local name, provided
            // there aren\'t conflicts with non-namespace element
            // names
            result = parentElem.getElementsByTagName(local)[index];
        }
        if (result)
        {
            // get text, accounting for possible
            // whitespace (carriage return) text nodes
            if (result.childNodes.length > 1)
            {
                return result.childNodes[1].nodeValue;
            }
            else
            {
                if (result.firstChild)
                {
            		return result.firstChild.nodeValue;
                }
                else
                {
                	return '';
                }

            }
        } else {
            return false;
            return "n/a";
        }
    }


	/**
		перебираем ветку xml и заполняем тем самым форму.
	*/
	function fetchXML2form2(xml, fnum)
	{
		var fields_branch = xml.getElementsByTagName("data");

		var child = fields_branch[0].firstChild;
		while (child)
		{
		    //console.log(child);
		    //debugO(getElementTextNS("", child.tagName, fields_branch[0], 0));
			if (child.nodeName!="#text")
			{
                //debugO(child.tagName);
                //debugO(getElementTextNS("", child.tagName, fields_branch[0], 0));
                //debugO(document.getElementById(child.tagName+fnum))
                var dEl = document.getElementById(child.tagName+fnum);
                if (dEl)
                {
                    dEl.value = getElementTextNS("", child.tagName, fields_branch[0], 0);
                }
			    //console.log(child.nodeName);
			    /*
					var tmp_o = document.getElementById(child.tagName);
					var value = getElementTextNS("", child.tagName, values_branch[0], 0);
					if (tmp_o)
					{
						elementSetValue(tmp_o, value);
					}
				*/
			}

			child = child.nextSibling;
		}
	}

	/**
	   получаем номер дня недели из даты в формате dd.mm.yyyy
	*/
	function determineWeekDay(datestr)
	{
	    var dd = datestr.substr(0, 2);
	    var mm = datestr.substr(3, 2);
	    var yyyy = datestr.substr(6, 4);

	    if (mm.substr(0,1)=='0') mm = mm.substr(1,1);
	    if (dd.substr(0,1)=='0') dd = dd.substr(1,1);

	    //console.log(dd);
	    //console.log(mm);
	    //console.log(yyyy);

	    var date = new Date();
	    //var date = new Date();
	    date.setYear(yyyy);
	    date.setMonth(mm-1);
	    date.setDate(dd);
	    var cdate = new Date();

	    //console.log(date.toGMTString());
	    //console.log(cdate.toGMTString());

	    return date.getDay();
	}

	/**
	   изменение диапазона цен.
    */
    function updPriceDiap(formsuffix)
    {
        indikateChanges(formsuffix);
        var lower_limit = 0;
        for (price_type=1; price_type<=3; price_type++)
        {
            var ofrom = document.getElementById('price_'+price_type+'_diap_from_'+formsuffix);
            var oto = document.getElementById('price_'+price_type+'_diap_to_'+formsuffix);

            //console.log(ofrom.value, oto.value);
            var ofromval = parseInt(ofrom.value);
            ofromval = isNaN(ofromval)?1:ofromval;
            if (ofromval<=lower_limit)
            {
                ofrom.value = lower_limit+1;
                ofromval = lower_limit+1;

            }
            var otoval = parseInt(oto.value);
            otoval = isNaN(otoval)?0:otoval;

            if (otoval<ofromval)
            {
                oto.value = ofromval;
                otoval = ofromval;
            }
            lower_limit = otoval;
        }
    }


function attachOption(box, value, text, selected)
{
	var o = document.createElement("OPTION");
	o.selected = selected;
	o.value = value;
	o.appendChild(document.createTextNode(text));
	box.appendChild(o);
}
