﻿var msg = "javascript:alert('You are not authorized for this section!<br>You are only authorized to use DirectWire.');";

function chkAccess(DirectWireOnly, KBLink){
	if(DirectWireOnly != ''){
		var objDwnLd = document.getElementById("MenuDownloads"); // $get('MenuDownloads');
		var objTchBy= document.getElementById("MenuTechbay"); // $get('MenuTechbay');
		var objResources = document.getElementById("MenuResources"); // $get('MenuResources');
		var objEdu = document.getElementById("MenuEducation"); // $get('MenuEducation');
		var objForm = document.getElementById("MenuForum"); // $get('MenuEducation');
		var objRewards = document.getElementById("MenuRewards"); // $get('MenuEducation');
		var objLinks = document.getElementById("MenuLinks"); // $get('MenuEducation');
		var htlSmartStart = document.getElementById("htlSmartStart");

		msg = msg.toString().replace("<br>", "\\n");
		if(KBLink != undefined){
			document.getElementById(KBLink).readOnly = true;
			document.getElementById(KBLink).onclick = msg + " return false;";
		}
		objDwnLd.parentNode.href = msg; //alert(objInstall.parentNode.href);
		//objTchBy.parentNode.href = msg;
		objResources.parentNode.href = msg;
		objEdu.parentNode.href = msg;
		objForm.parentNode.href = msg;
		//objRewards.parentNode.href = msg;
		objLinks.parentNode.href = msg;
		if(htlSmartStart != null){
			htlSmartStart.href = msg;
		}

		for(var i = 0, j = document.getElementsByTagName("INPUT").length - 1; j > i; i++){
			if(document.getElementsByTagName("INPUT")[i].id.indexOf("Search") > - 1){
				document.getElementsByTagName("INPUT")[i].disabled = true;
			}
		}
	}
}

function chkAccessBdy(DirectWireOnly){
	if(DirectWireOnly != ''){
		var objInstall = document.getElementById("ViewButton1");
		var objPin = document.getElementById("ViewButton3");
		var objForum = document.getElementById("tblForumSubscribe");

		if(objForum != null){
			if(objForum.rows.length > 2){
				objForum.rows[0].cells[0].style.display = "none";
				objForum.rows[1].cells[0].style.height = 0;
			}else{
				objForum.style.display = "none";
			}
		}

		msg = msg.toString().replace("<br>", "\\n");
		if(objInstall != null){objInstall.parentNode.href = msg;}
		if(objPin != null){objPin.parentNode.href = msg;}
		
	}
}

function chkAccessBy(DirecTech){
	if(DirecTech != ''){
		if(DirecTech == "True"){
			setCookie('Directtech', DirecTech, 1);
		}else{
			setCookie('Directtech', "", -1);
		}
	}
}

function setCookie(c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name) {
var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++){
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name){
			return unescape(y);
		}
	}
}
function checkCookie(){
	var username = getCookie("Directtech");
	if (username != null && username != ""){
//		do nothing!
	} else {
		// notify user and redirect them back to login
		alert("You must be logged into Directechs.com! Please login.");
		location.href = '/Default.aspx';/**/
	}
}
