function getObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// http://cguc6.hncb3.servertrust.com/v/vspfiles/templates/102/nav.html";

function loadjs(filename, filetype){
  var fileref=document.createElement('script');
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("charset","UTF-8");
  fileref.setAttribute("src", filename);
  document.getElementsByTagName("head")[0].appendChild(fileref);
}


function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function setnav() {
    http.open('get', '/v/vspfiles/templates/102/nav.asp');
    http.onreadystatechange = handleResponse;
    http.send(null);
    removemessages();

	pagename = location.href.substring(location.href.lastIndexOf('/')+1);

        var liveassist = new Array(
        "ka10nostal",
        "ka10prosdd",
        "ka10pros",
        "ka10procon",
        "ka10sahcomp",
      	"ka10sahpro",
      	"ka10proc",
        "ka09pros",
        "ka09proc",
      	"ka09tasm",
      	"ka10tasm",
      	"ka10agat",
      	"ka09se27",
      	"ka09sel8",
      	"ka09auro",
      	"ka09enti",
      	"ka09conn",
      	"e-bikes",
      	"commuting-bikes");
      	
      for(i=0; i<liveassist.length; i++){
        if (pagename.toLowerCase().indexOf(liveassist[i]) > -1) {
      		setTimeout('loadjs("https://server.iad.liveperson.net/hc/2648647/?cmd=mTagRepstate&site=2648647&buttonID=12&divID=lpButDivID-1280154976&bt=1&c=1", "js")', 1000);

      		setTimeout("getObj('lpButDivID-1280154976').style.visibility= 'visible';", 2000);


      	}
      }
}

function removemessages() {
	if ( (location.pathname == "/ProductDetails.asp") && (getQueryVariable("Message") != null) ) { document.location = 'http://store.kalkhoffusa.com/ProductDetails.asp?ProductCode='+getQueryVariable("ProductCode"); }	
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            getObj('mainnav').innerHTML = update[0];
        }
    }
    
    // We're assuming that kalkhoff_utilities has already been loaded.
    // nudge the left nav menu over 1 pixel
	if(BrowserDetect.browser == "Opera") {
		document.getElementById("searchbox").getElementsByTagName("img")[0].style.marginLeft = "-1px"
	}
}

function getProductCode() {
	if (location.pathname.indexOf('_p/') > 0) {
		document.write ( "<a href=\"http://www.kalkhoffusa.com/product_compare.php?a=" + location.pathname.substring(location.pathname.indexOf('_p/')+3,location.pathname.indexOf('.htm')) + "\"><IMG border=0 alt=\"Compare Bikes\" src=\"/v/vspfiles/assets/images/compare-bikes.gif\"></A>" );	
	}
         else if (location.pathname.indexOf('-p/') > 0) {
		document.write ( "<a href=\"http://www.kalkhoffusa.com/product_compare.php?a=" + location.pathname.substring(location.pathname.indexOf('-p/')+3,location.pathname.indexOf('.htm')) + "\"><IMG border=0 alt=\"Compare Bikes\" src=\"/v/vspfiles/assets/images/compare-bikes.gif\"></A>" );	
	}
	else {
		document.write ( "<a href=\"http://www.kalkhoffusa.com/product_compare.php?a=" + location.href.substring(window.location.href.indexOf('Code=')+5) + "\"><IMG border=0 alt=\"Compare Bikes\" src=\"/v/vspfiles/assets/images/compare-bikes.gif\"></A>" );	
	}
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
}