var lastTabAnchor	= null;
var lastLeftMenu	= null;
var lastLeftSubMenu	= null;
var lastSubMenuTable= null;

function j_onload()
{
}

function j_clickTab(anchor)
{
	try
	{
		if (anchor != null && anchor != lastTabAnchor)
		{
			if (lastTabAnchor != null)
				lastTabAnchor.parentNode.className	= "TABNOTSELECTED";
			if (lastLeftMenu != null)
				lastLeftMenu.parentNode.className	= "MENUNOTSELECTED";
			anchor.parentNode.className	= "TABSELECTED";
			
			lastLeftMenu	= null;
			lastTabAnchor	= anchor;
		}

		document.getElementById('tdTitle').innerText	= anchor.innerText;

	} catch (e) {}
	
	hideRightMenu();
		
	return true;
}

function  j_clickHeaderMenu()
{
    hideRightMenu();
}

function j_changeRightMenu(select)
{
   var index = select.value.lastIndexOf(':');
   
   if (index > 0) 
   {
        var url = select.value.substring(0, index);
        var target = select.value.substring(index + 1);
        if (!target || target.length == 0 || target == "contentIframe")
        {
            document.getElementById("contentIframe").src = url;
        } 
        else 
        {
           var arguments = "toolbar=no, menubar=no, titlebar=no, status=no";
            if (url.indexOf("ispopup") >= 0)
                arguments += ", width= 500, height=300, left=" + ((screen.availWidth - 500) / 2) + ", top=" + ((screen.availHeight - 300) / 2);
            window.open(url, target, arguments);
        }
        
        select.selectedIndex = 0;
        select.blur();
   }
}

function j_clickSubMenu(anchor)
{
	if (anchor != null && anchor != lastLeftSubMenu)
	{
		if (lastTabAnchor != null)
			lastTabAnchor.parentNode.className	= "TABNOTSELECTED";
		if (lastLeftSubMenu != null)
			lastLeftSubMenu.parentNode.className	= "SUBMENUNOTSELECTED";
		anchor.parentNode.className	= "SUBMENUSELECTED";
		
		lastTabAnchor	= null;
		lastLeftSubMenu	= anchor;
	}

	document.getElementById('tdTitle').innerText	= anchor.innerText;

	return true;
}

function j_clickMenu(anchor)
{
	var subMenuTable;

	if (anchor != null && anchor != lastLeftMenu)
	{
		if (lastTabAnchor != null)
			lastTabAnchor.parentNode.className	= "TABNOTSELECTED";
		if (lastLeftMenu != null)
			lastLeftMenu.parentNode.className	= "MENUNOTSELECTED";
		anchor.parentNode.className	= "MENUSELECTED";
		
		lastTabAnchor	= null;
		lastLeftMenu	= anchor;
	}

	document.getElementById('tdTitle').innerText	= anchor.innerText;

	if (lastSubMenuTable)
		lastSubMenuTable.style.display = "none";
	if (anchor.subMenuTable)
	{
		subMenuTable	= document.getElementById(anchor.subMenuTable);
		
		lastSubMenuTable = subMenuTable;
		lastSubMenuTable.style.display = "block";
	}
	
	hideRightMenu();

	return true;
}

function j_clickRightMenu(anchor)
{

	var subMenuTable;

	if (anchor != null && anchor != lastLeftMenu)
	{
		if (lastTabAnchor != null)
			lastTabAnchor.parentNode.className	= "TABNOTSELECTED";
		if (lastLeftMenu != null)
			lastLeftMenu.parentNode.className	= "MENUNOTSELECTED";

		anchor.parentNode.className	= "MENUSELECTED";
		
		lastTabAnchor	= null;
		lastLeftMenu	= anchor;
	}

	document.getElementById('tdTitle').innerText	= anchor.innerText;

	if (lastSubMenuTable)
		lastSubMenuTable.style.display = "none";

	var subMenuTableId =  anchor.getAttribute("subMenuTable")


	if (subMenuTableId)
	{
		subMenuTable	= document.getElementById(subMenuTableId);
		
		lastSubMenuTable = subMenuTable;
		lastSubMenuTable.style.display = "block";
		
		showRightMenu();
	}

	return true;
}

function hideRightMenu()
{
		var contentCell = document.getElementById("tdContent");
		var rightMenuCell = document.getElementById("tdRightMenu");

        if (contentCell && rightMenuCell)
        {
    		contentCell.colSpan = 2;
	    	rightMenuCell.style.display = "none";
	    }
}

function showRightMenu()
{
		var contentCell = document.getElementById("tdContent");
		var rightMenuCell = document.getElementById("tdRightMenu");

        if (contentCell && rightMenuCell)
        {
    		contentCell.colSpan = 1;
	    	rightMenuCell.style.display = "block";
	    }
}

function j_itemSearch()
{
	var searchText = document.getElementById('sbItemSearchText').value;
	
	if (searchText != null && searchText.length > 0)
		document.location.href = "../e-Catalogus/ITHO/Zoek/" + searchText + ".aspx";
}

function j_docSearch(textBoxId, categoryCode)
{
    if (!textBoxId)
        textBoxId = 'searchText';
	var searchText = document.getElementById(textBoxId).value;
	
	
	if (searchText != null && searchText.length > 0)
	{
	    var url = "../Zoek in document/" + searchText + ".aspx";
	    if (categoryCode && categoryCode.length > 0)
	        url += "?CategoryCode=" + categoryCode;
		contentIframe.location.href = url;
	}
}

function j_startSearch()
{
	var searchCategoryList = document.getElementById('searchCategoryList');
	
	switch (searchCategoryList.selectedIndex)
	{
		case 0:	// Downloadcentrum
			document.getElementById(idDownloadAnchor).click();
			break;
		case 1: // Veelgestelde vragen
			document.getElementById(idFAQAnchor).click();
			break;
		case 2: // Assortiment
			document.getElementById(idAssortimentAnchor).click();
			break;
		case 3: // Algemene pagina's
			j_docSearch();
			break;
	}
}

function j_changeSearchCategory(searchCategoryList)
{
	var tr1 = document.getElementById('trSearchTextLabel');
	var tr2 = document.getElementById('trSearchText');
	var display;
	
	switch (searchCategoryList.selectedIndex)
	{
		case 0:	// Downloadcentrum
		case 1: // Veelgestelde vragen
		case 2: // Assortiment
			display = 'none';	
			break;
		case 3: // Algemene pagina's
			display = 'block';	
			break;
	}
	
	tr1.style.display = display;
	tr2.style.display = display;
}

function j_onkeyDownZipCode(e, dealerLocator, zipCode)
{
	if (e == null) e = window.event;
	
	if ((e) && e.keyCode == 13)
	{
		e.cancelBubble = true;
		e.returnValue = false;

		if ((dealerLocator) && (zipCode))
		{
			if (zipCode.length >= 4)
				document.location.href = j_baseAspx()  + "?Page=CRMDealerXsltForm&DealerLocator=" + dealerLocator + "&ZipCode=" + zipCode;
			else
				alert('Vul uw 4 cijferige postcode in.');
		}
	}
}
function j_showDealerLocator(e, dealerLocator, idZipCode)
{
	var tbZipCode;
	var zipCode;
	
	if (e == null) e = window.event;
	
	if (e)
	{
		e.cancelBubble = true;
		e.returnValue = false;
	}
	tbZipCode	= document.getElementById(idZipCode);
	
	if ((dealerLocator) && (tbZipCode) && (tbZipCode.value))
	{
		zipCode	= tbZipCode.value;
		if (zipCode.length < 4)
			alert('Vul uw 4 cijferige postcode in.');
		else
		if (dealerLocator.length > 0)
			document.location.href = j_baseAspx()  + "?Page=CRMDealerXsltForm&DealerLocator=" + dealerLocator + "&ZipCode=" + zipCode;
	}
}

function frameResize(e)
{
    try {
        var oTD = document.getElementById('tdMain');
        //var	oTdLeftMenu		= document.getElementById('tdLeftMenu');

        if (!oTD)
            oTD = document.getElementById('tdLeftMenu');
        var iHeight;
        var wnd;
        var offset;

        if (e == null) e = event;

        if (e == null || e.srcElement == null || e.srcElement.contentWindow == null)
            wnd = document.getElementById('contentIframe').contentWindow;
        else
            wnd = e.srcElement.contentWindow;

        offset = 0;
        var offsetElem = oTD;
        do 
        {
            offset += offsetElem.offsetTop;
            offsetElem = offsetElem.offsetParent;
        }
        while (offsetElem)
        
        
        //oTdLeftMenu.style.height = '300px';
        oTD.style.height = '300px';
        iHeight = wnd.document.body.scrollHeight + 20;

        if (iHeight < oTD.scrollHeight)
            iHeight = oTD.scrollHeight;

        if (iHeight < document.body.clientHeight - offset)
            iHeight = document.body.clientHeight - offset;

        oTD.style.height = iHeight + 'px';
    } 
    catch (exception) {
    }
}

function showImage(url)
{
      url = url.replace("..", "");
      var wnd = window.open('image.axd?image=' + url + '&amp;width=400&amp;height=400&amp;mode=N', 'zoom', 'height=432, width=440');
      wnd.focus();
}

function showDetails(e, anchorId)
{
      if (!e) e = window.event;

      var trigger;

      if (e.target) trigger = e.target;
      else if (e.srcElement) trigger = e.srcElement;

      if (trigger.tagName != 'A' && trigger.tagName != 'IMG')
          document.getElementById(anchorId).click();
}


function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_findObj(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;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
