var loginAs=GetCookie('Login_As');
var conID=PREFS.user_Contact_ID;
var a = document.getElementsByTagName('a');
var Product_KEY="";
var category="";


function logAs() {

if (loginAs==conID) {

if (conID==100792) { 
for (i=0;i<a.length;i++) {
if (a[i].getAttribute('href').indexOf('Category=')!=-1&&a[i].getAttribute('href').indexOf('Category=Business')!=-1&&a[i].getAttribute('href').indexOf('Login_As')==-1) a[i].setAttribute('href',a[i].getAttribute('href')+'&Login_As=0');
if (a[i].getAttribute('href').indexOf('mdl=jobcenter/main.mdl')!=-1&&a[i].getAttribute('href').indexOf('Login_As=')==-1) a[i].setAttribute('href',a[i].getAttribute('href')+'&Login_As=0');
}
if (window.location.href.indexOf('docLib/products.mdl')!=-1&&(window.location.href.indexOf('Category=Business')!=-1||category=="Business Cards")&&window.location.href.indexOf('EDIT_Job_ID')==-1) window.location.href=window.location.href+"&Login_As=0";
}

if (conID==189790) {
for (i=0;i<a.length;i++) {
if ((a[i].getAttribute('href').indexOf('Category=')!=-1&&a[i].getAttribute('href').indexOf('Category=Business')==-1&&a[i].getAttribute('href').indexOf('Login_As')==-1)||a[i].getAttribute('href').indexOf('All=yes')!=-1&&a[i].getAttribute('href').indexOf('Login_As')==-1) a[i].setAttribute('href',a[i].getAttribute('href')+'&Login_As=0');
if (a[i].getAttribute('href').indexOf('mdl=jobcenter/main.mdl')!=-1&&a[i].getAttribute('href').indexOf('Login_As=')==-1) a[i].setAttribute('href',a[i].getAttribute('href')+'&Login_As=0');
}
if (window.location.href.indexOf('docLib/products.mdl')!=-1&&window.location.href.indexOf('Category=Business')==-1&&category!=""&&category!="Business Cards") window.location.href=window.location.href+"&Login_As=0";
}
}

else { 

if (conID==100792) { 
for (i=0;i<a.length;i++) {
if (a[i].getAttribute('href').indexOf('Category=')!=-1&&a[i].getAttribute('href').indexOf('Category=Business')!=-1&&a[i].getAttribute('href').indexOf('Login_As')==-1) a[i].setAttribute('href',a[i].getAttribute('href')+'&Login_As=189790');
}
if (window.location.href.indexOf('docLib/products.mdl')!=-1&&(window.location.href.indexOf('Category=Business')!=-1||category=="Business Cards")&&window.location.href.indexOf('EDIT_Job_ID')==-1) window.location.href=window.location.href+"&Login_As=189790";
}

if (conID==189790) {
for (i=0;i<a.length;i++) {
if ((a[i].getAttribute('href').indexOf('Category=')!=-1&&a[i].getAttribute('href').indexOf('Category=Business')==-1&&a[i].getAttribute('href').indexOf('Login_As')==-1)||a[i].getAttribute('href').indexOf('All=yes')!=-1&&a[i].getAttribute('href').indexOf('Login_As')==-1) a[i].setAttribute('href',a[i].getAttribute('href')+'&Login_As=100792');
}
if (window.location.href.indexOf('docLib/products.mdl')!=-1&&window.location.href.indexOf('Category=Business')==-1&&category!=""&&category!="Business Cards") window.location.href=window.location.href+"&Login_As=100792";
}
}
}


function getCategory() {
if (window.location.href.indexOf('Product_KEY=')!=-1&&window.location.href.split('Product_KEY=')[1]) Product_KEY=window.location.href.split('Product_KEY=')[1].split('&')[0];

if (Product_KEY!="") {
var req;
req=null;
if (window.XMLHttpRequest)
  {// code for all new browsers
  req=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE5 and IE6
  req=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (req!=null)
  {
  var url="ajax.iml?mdl=2334ThePri/getCategory.aj";
  var params="Product_KEY="+Product_KEY+"&DEBUG=1";
  req.open("GET",url+"&"+params,true);
  req.onreadystatechange=function() {
    if (req.readyState==4&&req.status==200) {
    if (req.responseXML.getElementsByTagName('category')[0]&&req.responseXML.getElementsByTagName('category')[0].firstChild&&req.responseXML.getElementsByTagName('category')[0].firstChild.data) category=req.responseXML.getElementsByTagName('category')[0].firstChild.data;
    logAs();
}

    }
  req.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}
logAs();
}

getCategory();
