// global flag
var isIE = false;

// global request and XML document objects
var req;

function loadXMLDoc(url) {
     // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
            req.send();
        }
    }
	
}

// handle onreadystatechange event of req object
function processReqChange() {
    // only if req shows "loaded"
	//alert(req.responseText);
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            clearTopicList();
			buildTopicList();
         } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
         }
    }
	try{
	status();
	}catch(e){}
}

// empty Topics select list content
function clearTopicList() {
	try{
     var select = document.getElementById(dropV);
    while (select.length > 0) {
        select.remove(0);
    }
	}catch(e){};

}



// fill Topics select list with items from
// the current XML document
function buildTopicList() {

	try{
   var select = document.getElementById(dropV);
      var items = req.responseXML.getElementsByTagName("item");
    // loop through <item> elements, and add each nested
    // <title> element to Topics select element
    for (var i = 0; i < items.length; i++) {
	(getElementTextNS("", "title", items[i], 0))
        appendToSelect(select, getElementTextNS("", "id", items[i], 0),
            document.createTextNode(getElementTextNS("", "title", items[i], 0)));
     }
	}catch(e){}
     
}

// 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 {
            return result.firstChild.nodeValue;    		
        }
    } else {
        return "n/a";
    }
}

// add item to select element the less
// elegant, but compatible way.

function appendToSelect(select, value, content) {
    var opt;
    opt = document.createElement("option");
	//alert(value)
    opt.value = value;
    opt.appendChild(content);
    select.appendChild(opt);
}

function productDetail(productId,browserAddress)
{
	var url = baseurl+"/"+browserAddress+".htm";
	window.location	=	url;
}

function showAppraisalReport(prodId,orderID)
{
	var url	=	 baseurl+"/admin/productAppraisalReport?prodId="+prodId+"&orderid="+orderID;
	window.open(url,'appraisalreport');
}
function form_submit(val)
{
	document.search_products.page_item.value=val;
	document.search_products.submit()
}
function form_submit1(val)
{
	document.search_products1.page_item.value=val;
	document.search_products1.submit()
}

