// JavaScript Document

if(!document.all){
	// check for XPath implementation
	if( document.implementation.hasFeature("XPath", "3.0") )
	{
		// prototying the XMLDocument
		XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
		{
			if( !xNode ) { xNode = this; } 
			var oNSResolver = this.createNSResolver(this.documentElement)
			var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
			var aResult = [];
			for( var i = 0; i < aItems.snapshotLength; i++)
			{
				aResult[i] =  aItems.snapshotItem(i);
			}
			return aResult;
		}
	
		// prototying the Element
		Element.prototype.selectNodes = function(cXPathString)
		{
			if(this.ownerDocument.selectNodes)
			{
				return this.ownerDocument.selectNodes(cXPathString, this);
			}
			else{throw "For XML Elements Only";}
		}
	}
	
	// check for XPath implementation
	if( document.implementation.hasFeature("XPath", "3.0") )
	{
		// prototying the XMLDocument
		XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
		{
			if( !xNode ) { xNode = this; } 
			var xItems = this.selectNodes(cXPathString, xNode);
			if( xItems.length > 0 )
			{
				return xItems[0];
			}
			else
			{
				return null;
			}
		}

		// prototying the Element
		Element.prototype.selectSingleNode = function(cXPathString)
		{    
			if(this.ownerDocument.selectSingleNode)
			{
				return this.ownerDocument.selectSingleNode(cXPathString, this);
			}
			else
			{
				throw "For XML Elements Only";
			}
		}
	}
}

function changeCategory(Category,subCategory,defaultValue) {
	var objSubCategory=document.getElementById(subCategory);
	objSubCategory.options.length=0;
	var objOption;
	objOption=new Option("Loading Sub Catetgory","");
	objOption.style.color="red";
	objSubCategory.options.add(objOption);
	
	new Ajax.Request("/NewPartnerAccess/WebServices/MyOrders.asmx/GetSearchSubCategory", { 
		method:"post",
		parameters:"CategoryCode="+Category.options[Category.selectedIndex].value,
		onSuccess:fillSubCategory,
		onFailure:function(transport){alert("Faild");}
	});

	function fillSubCategory(transport)
	{
		objSubCategory.options.length=0;
		//alert(transport.responseXML.getElementsByTagName("WebSubCategories").length);
		var nodeList=transport.responseXML.documentElement.selectNodes("WebSubCategories");
		for(var i=0;i<nodeList.length;i++)
		{
			if(document.all)
			{
				objOption=new Option(nodeList[i].selectSingleNode("CName").text,nodeList[i].selectSingleNode("CCode").text);
			}
			else
			{
				objOption=new Option(nodeList[i].selectSingleNode("CName").childNodes[0].data,nodeList[i].selectSingleNode("CCode").childNodes[0].data);
			}
			if(objOption.value==defaultValue) objOption.selected=true;
			
			objSubCategory.options.add(objOption);
		}
	}	
}

function ShowProSearch(){
	//var objBox=document.all["prSearchForm"];
	var objBox=document.getElementById("prSearchForm");
	var re=/(\/?)[^\/]+$/ig;
	if(typeof(objBox)!="undefined"){
		if(objBox.style.display=="none"){
			objBox.style.display="block";
			event.srcElement.src=event.srcElement.src.replace(re,"$1arrow_display.gif");
		}else{
			objBox.style.display="none";
			event.srcElement.src=event.srcElement.src.replace(re,"$1arrow_none.gif");
		}
	}
}

function LoadXML(url){
	if(document.all){
		window.xmlDom=new ActiveXObject("Msxml2.DOMDocument");
	}else{
		window.xmlDom=document.implementation.createDocument("text/xml", "", null);
	}
	xmlDom.async = false;
	xmlDom.load(url);
}
function ShowInfo(ContainerName,id){
	var objBranchTips=document.getElementById(ContainerName);
	if(objBranchTips&&xmlDom.documentElement!=null){
		xmlRoot=xmlDom.documentElement;
		objBranch=xmlRoot.selectSingleNode("Branch[@id='"+id+"']");
		if(objBranch!=null){
			var sName=objBranch.attributes[0].value;
			var objDescription=objBranch.selectSingleNode("BranchTips")
			if(objDescription!=null){
				if(document.all){
					sDescription=objDescription.text;
					objBranchTips.childNodes[1].innerHTML=sDescription;
				}else{
					for(var j=0; j<objDescription.childNodes.length; j++) {
						if (objDescription.childNodes[j].nodeName=="#cdata-section") {
							sDescription = objDescription.childNodes[j].data;
						}
					}
					objBranchTips.childNodes[1].innerHTML=sDescription;
				}
			}else{
				sDescription=objBranch.attributes[0].value;
				objBranchTips.childNodes[1].innerHTML=sDescription;
			}
			objBranchTips.style.left=event.x-35;
			objBranchTips.style.top=event.y+3;
			objBranchTips.style.display="block";
		}
	}
}
function HideInfo(ContainerName){
	var objBranchTips=document.getElementById(ContainerName);
	if(objBranchTips&&xmlDom.documentElement!=null){
		objBranchTips.style.display="none";
	}
}
function ShowBranchInfo(ContainerName,id){
	var objBranchDesc=document.getElementById(ContainerName);
	var arrBranchDiv=objBranchDesc.getElementsByTagName("DIV");
	if(xmlDom.documentElement!=null){
		xmlRoot=xmlDom.documentElement;
		objBranch=xmlRoot.selectSingleNode("Branch[@id='"+id+"']");
		if(objBranch!=null){
			var sName=objBranch.attributes[0].value;
			var objDescription=objBranch.selectSingleNode("Description")
			if(document.all){
				sDescription=objDescription.text;
				objBranchDesc.filters[0].Apply();
				arrBranchDiv[0].innerHTML=sName;
				arrBranchDiv[1].innerHTML=sDescription;
				objBranchDesc.filters[0].play();
			}else{
				for(var j=0; j<objDescription.childNodes.length; j++) {
					if (objDescription.childNodes[j].nodeName=="#cdata-section") {
						sDescription = objDescription.childNodes[j].data;
					}
				}
				arrBranchDiv[0].innerHTML=sName;
				arrBranchDiv[1].innerHTML=sDescription;
			}
		}
	}
}