var hideDocLibProds = 0; // change this to 1 if you want to hide public (but not "sample") document library items from those who are not logged in and "sample" items from those who are
var hideDocLibCats = 0; // change this to 1 if you want to hide public (but not "sample") document library category listings from those who are not logged in and the "sample" category listings from those who are


function getResults(url,func) {
	var req=null;
	if (window.XMLHttpRequest) req=new XMLHttpRequest();
	else if (window.ActiveXObject) req=new ActiveXObject("Microsoft.XMLHTTP");
	if (req!=null) {
		req.open("GET",url+"&iefix="+Math.random(),true);
		req.onreadystatechange=function() {
		if (req.readyState==4&&req.status==200) {
			if (func!=null) {
				var rTXT=req.responseText;
				var rXML=req.responseXML;
				eval(func);
			}
		}
	}
	req.send(null);
	}
}


if(document.changeForm&&document.changeForm.Category) {
	var catList=document.changeForm.Category;
	while(catList.options[1]) catList.removeChild(catList.options[1]);
	getResults("ajax.iml?mdl=2833Dagher/catDropdown.mdl","var div=document.createElement('div');div.innerHTML=rTXT;var h1=div.getElementsByTagName('h1');for(i=0;i<h1.length;i++) { var opt=document.createElement('option');opt.value=h1[i].childNodes[0].data;opt.innerHTML=h1[i].innerHTML;catList.appendChild(opt) }");
}

if(document.getElementById('category_sidebar')) {
	var sibling=document.getElementById('category_sidebar');
	var parent=sibling.parentNode;
	getResults("ajax.iml?mdl=2833Dagher/catSidebar.mdl","var div=document.createElement('div');div.innerHTML=rTXT;parent.insertBefore(div,sibling);");
}

if(document.getElementById('quickCat')) {
	var sibling1=document.getElementById('quickCat');
	var parent1=sibling1.parentNode;
	getResults("ajax.iml?mdl=2833Dagher/catBottom.mdl","var div=document.createElement('div');div.innerHTML=rTXT;parent1.insertBefore(div,sibling1);");
}

if(document.getElementById('product_category_table')) {
	var pTable=document.getElementById('product_category_table');
	var tds=pTable.getElementsByTagName('td');
	for(i=0;i<tds.length;i++) {
		if(tds[i].className=='left-side') {
			var contents=tds[i].innerHTML;
			if(contents.indexOf('Sample')!=-1||contents.indexOf('sample')!=-1) {
				if(PREFS.user_Contact_ID==0||PREFS.user_Contact_ID==""||!hideDocLibCats) pTable.getElementsByTagName('tbody')[0].style.display='block';
				if((window.location.href.indexOf("Category=")!=-1&&window.location.href.indexOf("Sample")!=-1)&&(PREFS.user_Contact_ID>0||!hideDocLibCats)) pTable.getElementsByTagName('tbody')[0].style.display='block';
			} else {
				if(PREFS.user_Contact_ID>0||!hideDocLibCats) pTable.getElementsByTagName('tbody')[0].style.display='block';
			}
		}
	}
}

if(document.getElementById('CONTENT')) {
	if(document.product_order) {
		var tds=document.getElementsByTagName('td');
		var results="";useNode="";
		for(i=0;i<tds.length;i++) {
			if(tds[i].className=="left-side") {
				results=tds[i].getElementsByTagName('nobr')[0].innerHTML;
				useNode=tds[i].getElementsByTagName('nobr')[0];
				break;
			}
		}
		if(results==""||PREFS.user_Contact_ID>0||results.indexOf('Card')!=-1||results.indexOf('sample')!=-1||results.indexOf('Sample')!=-1||1==1) document.getElementById('CONTENT').style.visibility='visible';
		else if(window.location.href.indexOf('Product_KEY=')!=-1) getResults("ajax.iml?mdl=2469wwwpri/catCheck.mdl&Product_KEY="+window.location.href.split('Product_KEY=')[1].split('&')[0],"var div=document.createElement('div');div.innerHTML=rTXT;if(div.getElementsByTagName('h1')[0].innerHTML==1) { if(useNode!='') useNode.innerHTML=div.getElementsByTagName('h2')[0].innerHTML;document.getElementById('CONTENT').style.visibility='visible'; } else document.getElementById('CONTENT').style.visibility='hidden';");
		else document.getElementById('CONTENT').style.display='none';
		if(!hideDocLibProds) { 
			document.getElementById('CONTENT').style.display = 'block';
			document.getElementById('CONTENT').style.visibility = 'visible';
		}
	}
	else document.getElementById('CONTENT').style.visibility='visible';
}
