<!-- $Revision: 8 $ $Workfile: td_dynamic_cnt.js $ -->

/*
Methods to make server side requests from client-side JavaScript 
*/

    
	//submits the request for the given URL
	function sendAjaxRequest(url, submitMethod, handlerMethod) {     
		try {
			http.open(submitMethod, url, true);
			http.onreadystatechange = handlerMethod;
			http.send(null);
		} catch(e) {}
	}    
    
		function getHTTPObject() {
		var xmlhttp;
		if(window.XMLHttpRequest) {
			try {
					xmlhttp = new XMLHttpRequest();
			} catch (e) {}
		} else if (window.ActiveXObject) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}

		return xmlhttp;
	}
	
   //AJAX call for Bazaar Voice Rating
    function getBVRating(poid) {
		try {
			var bvratingUrl = "bvrating.jsp?poid="+poid;
			var xmldoc = getBVRatingAJAXResponse(bvratingUrl, "GET");
			
			var rating = xmldoc.getElementsByTagName('rating');
			var imagePath = xmldoc.getElementsByTagName('imagepath');
			var imageId = poid+"_ratingImg";
			var ratingId = poid+"_ratingVal"
			if (document.getElementById(imageId) != null) {
				// Firefox doesn't parse the content properly inside CDATA section.It prints 'CDATA' also along with the content
				// IE works proper. So if 'CDATA' text is present, remove that before setting
				var image = imagePath.item(0).firstChild.data;
				if(image.indexOf("CDATA")!=-1) {
					image = image.substring(7,image.indexOf("]]"));
				}
				document.getElementById(imageId).innerHTML = image;
			}
			if (document.getElementById(ratingId) != null) {
				document.getElementById(ratingId).innerHTML = rating[0].firstChild.nodeValue + " out of 5";
			}		
		} catch(ex) {
		}
    }
    //Get the XMLDOC - Its the response for the AJAX request
    function getBVRatingAJAXResponse(bvratingUrl, reqMethod) {
		try {
			var xmldoc = getLoadedXMLDoc(bvratingUrl, reqMethod);
			return xmldoc;
		} catch(objException) {

		}
    }	
	
	
	function getXmlDoc() {
		var xmldoc;
		if(window.ActiveXObject) {
			//IEXPLORE
			xmldoc = new ActiveXObject("Microsoft.XMLDOM");
	
		} else if(document.implementation && document.implementation.createDocument) {
			//MOZILLA
			xmldoc = document.implementation.createDocument("", "", null);
	
			//add the loadXML() method to the Document class
			Document.prototype.loadXML = function(strXML) {
	
				//create a DOMParser
				var objDOMParser = new DOMParser();
	
				//create new document from string
				var objDoc = objDOMParser.parseFromString(strXML, "text/xml");
	
				//make sure to remove all nodes from the document
				while (this.hasChildNodes())
					this.removeChild(this.lastChild);
	
				//add the nodes from the new document
				for (var i=0; i < objDoc.childNodes.length; i++) {
	
					//import the node
					var objImportedNode = this.importNode(objDoc.childNodes[i], true);
	
					//append the child to the current document
					this.appendChild(objImportedNode);
	
				} //End: for
			} //End: function
	
			//^^function to add xml attribute to the document
			function _Node_getXML() {
	
				//create a new XMLSerializer
				var objXMLSerializer = new XMLSerializer;
	
				//get the XML string
				var strXML = objXMLSerializer.serializeToString(this);
	
				//return the XML string
				return strXML;
			}
			Node.prototype.__defineGetter__("xml", _Node_getXML);
		}
	    return xmldoc;
	}
	
	function enableUniversalRead() {
		try {		
			netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");		
		} catch (e) {		
			//alert("Permission UniversalBrowserRead denied.");		
		} 	
	}
	

	function getLoadedXMLDoc(url, requestMethod) {
		var req = getHTTPObject();
		if(!req) {
			return;
		}
		
		//submit the request
		req.open(requestMethod, url, false);
		req.send(null);
		

		//IE 6 or IE 7 (which supports the XMLHttpRequest object)
		try {
			if(window.ActiveXObject || typeof req.responseXML.firstChild != "undefined"){			
				var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
				xmldoc.loadXML(req.responseText);
				return xmldoc;
			}
		} catch(e) {
			// can be firefox
		}

		// Because Firefox doesn't work with responseXML, create a div
		// and put responseText in the innerHTML. This does not work with IE 7.
		var doc = document.createElement("div");
		doc.innerHTML = req.responseText;
		return doc;
	}
	
	
var http = getHTTPObject(); // We create the HTTP Object	