
var request = null;
try {
  request = new XMLHttpRequest();
} catch (trymicrosoft) {
  try {
    request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
    try {
      request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (failed) {
      request = null;
    }
  }
}

//if (request == null)
//  alert("Error creating request object!");

function replaceText(el, text) {
  if (el != null) {
    clearText(el);
    var newNode = document.createTextNode(text);
    el.appendChild(newNode);
  }
}
function clearText(el) {
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        el.removeChild(childNode);
      }
    }
  }
}
function getText(el) {
  var text = "";
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        if (childNode.nodeValue != null) {
          text = text + childNode.nodeValue;
        }
      }
    }
  }
  return text;
}
	function setdata(element,value){
	        var ie4 = document.all;
                var ns4 = document.layers;
                var ns6 = document.getElementById && !document.all;
                if(ie4){
                        document.getElementById(element).innerHTML = value;
                }else if(ns4){
                        document.layers[element].innerHTML = value;
                }else{
                        document.getElementById(element).innerHTML = value;
                }
	}
	function changePage(chapterID){
	  var url = "/includes/bvtv/data.php";

		if (parseInt(chapterID) > 0) {
	  url = url + "?id=" + chapterID + "&dummy=" + new Date().getTime();
	  request.open("GET", url, true);
	  request.onreadystatechange = updatePage;
	  request.send(null);
		}
	}	

function getandset(xmlDoc,xmltag,divtag){
	var xmldata = xmlDoc.getElementsByTagName(xmltag)[0];
	var fielddata = xmldata.firstChild.nodeValue;
	setdata(divtag,fielddata);
}

function getxml (xmlDoc,xmltag){
	var xmldata = xmlDoc.getElementsByTagName(xmltag)[0];
	var fielddata = xmldata.firstChild.nodeValue;
	return fielddata;
}

function syncRoadBlock(adTag) {
    document.getElementById("SITE_NAV_A").innerHTML = '<iframe src="' + adTag + '" id="ifr_companion" width=300 height=250 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no>' + '</iframe>';
}

function updatePage() {
  if (request.readyState == 4) {
    if (request.status == 200) {
	var xmlDoc = request.responseXML;

	document.title=getxml(xmlDoc,"video-title");

var agt=navigator.userAgent.toLowerCase();
var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
if (is_safari== false){
//	setdata("divadstop","<iframe src=/includes/bvtv/bvtv-ads-top.html  border=0 width=728 height=90 frameborder=0 marginwidth=0 marginheight=0 scrolling=no></iframe>");
//	setdata("divadsleft","<iframe src=/includes/bvtv/bvtv-ads-left.html border=0 width=300 height=850 frameborder=0 marginwidth=0 marginheight=0 scrolling=no></iframe>");
}
	getandset(xmlDoc,"video-breadcrumb","divBreadcrumb");
	getandset(xmlDoc,"video-videotitle","divTitle");
	getandset(xmlDoc,"video-description","divDescription");
	getandset(xmlDoc,"video-projecttitle","divProjectTitle");
	getandset(xmlDoc,"video-showroom","divShowroom");
	//getandset(xmlDoc,"video-showroomred","divShowroomRed");
	getandset(xmlDoc,"video-morevideos","divMoreVideos");
	getandset(xmlDoc,"video-productresources","divProductResource");
	getandset(xmlDoc,"video-moretopic","divMoreTopic");


//	getandset(xmlDoc,"video-ads-top","divadstop");
//	getandset(xmlDoc,"video-ads-left","divadsleft");

    } else {
      var message = request.getResponseHeader("Status");
      if ((message.length == null) || (message.length <= 0)) {
        alert("Error! Request status is " + request.status);
      } else {
        alert(message);
      }
    }
  }
}


