var W=window, D=document, B, F, E, EvSrc, ETo, bLocal, aCookies, bDev, aErrScr=[];
var oPL, oPLVar, oEBImg, oKTImg, qseid, PLStart=new Date();
var Gec, Op, Ns, Saf, IE7Q, Nav, IEVer, FFVer, Quirks, Chrome, IEMob, bFF36Err;

//-----

function PL_Init(){

oPL={ //!!
	Srv:'----------', VertPad:3, bAutoClose:false, AnimTimer:null, Timer:null, bNoGeo:true, //!bDev
	bShown:false,	oReq:null, bOld:false, PLStage:'init', oSB:null, ErrNum:0
	};

if (IEVer<7) setTimeout('PL_BG();', 100);
bLocal=(W.location.host.indexOf(".loc/")!=-1);

if (W.location.search.indexOf('delcook=1')!=-1){
	DelCookie('pl_country'); DelCookie('pl_state');
	}

oPL.AnimFix=+aCookies['animfix']; oPL.S="pri"+"cel"+"ist";
oPL.Host="pri"+"ce-li"+"st.sops"+"erver.com"; 
PL_Reset(); W.focus();
}

//-----
//Util

function getbyid(id){return D.getElementById(id);}

function GetText(o){

while(o){
	if (o.nodeType==3) break;
	o=o.firstChild;
	}
if (!o) return '';
return o.data;
}

function getat(o, at){
var val=o.getAttribute(at); if (Op && val=='') val=null; return val;
}

function setat(o, at, val){
if (Op && val==null) val=''; o.setAttribute(at, val);
} 

function Contains(o, Ch){
while(Ch && Ch!==o && Ch!==D) Ch=Ch.parentNode;
return (Ch===o);
}

function GetPosRoot(){
return (D.getElementsByTagName((D.compatMode=='BackCompat' && !Saf) || Op ? 'BODY' : 'HTML')[0]);
} 

function InitUA(){

IEVer=0; FFVer=0; Nav=W.navigator.userAgent; 
Gec=(Nav.indexOf('Gecko')!=-1); 
Saf=(Nav.indexOf(' AppleWebKit/')!=-1 && Nav.indexOf(' Safari/')!=-1);
Op=(Nav.indexOf('Opera')!=-1); //Ns=(Gec && Nav.indexOf('Netscape')!=-1); 
Chrome=(Saf && Nav.indexOf(' Chrome/')!=-1);
Quirks=(D.compatMode=='BackCompat');
bDev=(W.location.search.match("[?&]test=1"));

if (!Gec && !Op && !Saf){
	if (D.documentMode){
		IEVer=D.documentMode; if (IEVer==5) IEVer=6;
		}
	else{
		if (Nav.match(/ MSIE (\d+)/)) IEVer=RegExp.$1;
		if (IEVer==7 && Quirks) IE7Q=true; //IEVer=6; ?!
		}
	if (Nav.indexOf('IEMobile')!=-1) IEMob=true;
	}
else if (Gec && Nav.match(/Firefox\/(\d+)/)) FFVer=RegExp.$1;

if (D.body) SetBodyCls(); else setTimeout("SetBodyCls();", 100);
if (IEVer) setTimeout("PL_WatchDiscl()", 250);
} 

function SetBodyCls(){
var Cls="";

if (!D.body){
	setTimeout("SetBodyCls()", 500); return;
	}

if (Gec) Cls+=" FF"+(FFVer ? " FF"+FFVer : "");
if (Saf) Cls+=" Saf"+(Chrome ? " Chrome" : "");
if (IEVer) Cls+=" IE"+(" IE"+IEVer);
if (Quirks) Cls+=" Quirks";
//else if (Op) Cls+=" Op";

if (Cls) D.body.className+=Cls;
}

function PL_BG(){
//if (D.execCommand) D.execCommand("BackgroundImageCache", false, true);
try { //Some IE6's say "Invalid argument" I have no idea why
	D.execCommand("BackgroundImageCache", false, true);
	}
catch (oError){}
}

function EventInit(e, bTo){

E=(!Gec ? event : e); EvSrc=E[Gec ? 'target' : 'srcElement'];
if (Ns && EvSrc.nodeType==3) EvSrc=EvSrc.parentNode;
//!!
if (EvSrc.tagName=='DIV') EvSrc=EvSrc.parentNode;
if (bTo) ETo=(!Gec ? E.toElement : E.relatedTarget);
else ETo=null;
}

function SetCookie(Name, Value, Time, Path){
var Res;

Value=Value.toString(); if (Value=="") Time=-1;
if (Time==null) Time=3600*24*30*3;
Res=Name+"="+Value+
	(Time!=0 ? ";expires="+_CookieDate(Time) : "")+
	(Path==null ? "" : ";path="+Path);
D.cookie=Res; aCookies[Name]=Value; return false; //should escape but all values are Ok
}

function DelCookie(Name, Path){
D.cookie=Name+"=;expires=Mon, 26 Jul 1997 05:00:00 GMT;path="+(Path ? Path : "/");
delete aCookies[Name];
} 

function _CookieDate(Time){
var DT=new Date();

if (Time!=null){
	End=new Date(Date.UTC(DT.getUTCFullYear(), DT.getUTCMonth(),
		 DT.getUTCDate(), DT.getUTCHours(), DT.getUTCMinutes(),
		 DT.getUTCSeconds())+Time*1000);
	}
else End=DT;
return End.toGMTString();
}

function ReadCookies(){
var Ck=document.cookie, i, Crumb, Len, Cookies;

if (!Ck) return [];
Ck=Ck.split('; '); Len=Ck.length; Cookies=new Array(Len);

for (i=0; i<Len; i++){
	Crumb=Ck[i].split("="); 
	if (Crumb.length==1) continue;
	Cookies[Crumb[0]]=Crumb[1];
	}
return Cookies;
}

function createXMLHttp(){

if (typeof(XMLHttpRequest)!="undefined") return new XMLHttpRequest();
var aV=["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","Microsoft.XMLHttp"];
for (var i=0; i<aV.length; i++){
	try {var oXmlHttp=new ActiveXObject(aV[i]); return oXmlHttp;}
	catch (e){}
	}
return false;
}

function PL_IsMulBlock(TBody){
return TBody.className.indexOf('MulSup')!=-1;
}

function PL_IsOpenBlock(TBody){
return TBody.className.indexOf('Opened')!=-1;
}


function PL_AnimGetDiv(Row){
if (!Row) return false;
return Row.cells[5].firstChild; //the tallest
}

function PL_AnimGetDivSt(Row){
var aCells, i, aDivsSt;

aCells=Row.cells; aDivsSt=[]; 
for(i=0; i<aCells.length; i++) aDivsSt[i]=aCells[i].firstChild.style;

return aDivsSt;
}

function PL_AnimGetDivH(Row){
var aCells, i, aDivH;

aCells=Row.cells; aDivH=[]; 
for(i=0; i<aCells.length; i++) aDivH[i]=aCells[i].firstChild.scrollHeight;

return aDivH;
}

function PL_GetCellBlock(oTD){return oTD.parentNode.parentNode;}

//-----

function PL_Load(Drugs, Country, State){
var oReq, URL, Host, M, Param, bRmt, L, Path;

oPL.PLStage='load';

if (!Country){
	if (aCookies['pl_country']){
		Country=aCookies['pl_country']; State=aCookies['pl_state'];
		}
	}

L=W.location; Path=L.pathname;
bRmt=(L.href.indexOf("ranslate")!=-1 || L.href.indexOf("/search?q=cache:")!=-1 || L.protocol=='file:');
if (!bRmt){
	Host=L.hostname;
	bRmt=(Host.indexOf("microsofttranslator")!=-1 || Host.indexOf("bingj.com")!=-1 || Host.match("^(\\d+\\.){3}")!=null
		|| Host.indexOf('turbohide.com')!=-1);
	}

oPL.bRmt=bRmt;
if (bRmt) oPL.bOld=true;

if (!oPL.bOld) Host=(!bLocal ? W.location.host : 'www.sopserver.loc');
else Host=(!bLocal ? 'mirror2.pri'+'ce-li'+'st.opse'+'rver.net' : 'mirror2sops'+'erver.loc');

URL="http://"+Host+"/";
if (bLocal) URL+='price-list/'; //oPL.Host

if (!oPL.bOld){
	if (oPL.Scr || (!bLocal && !bRmt)) URL+='commonres/';
	if (oPL.Scr) URL+=oPL.Scr; 
	else URL+=oPL.S+(!bLocal && !bRmt ? "sub" : "");
	
	if (oPL.a) Param=PL_GetVar()+'='+(W.encodeURIComponent ? encodeURIComponent(oPL.a) : escape(oPL.a)); //IE5 exists!
	}
else URL+=oPL.S; 

if (!Param) Param="drugs="+Drugs;

URL+=".php"+"?"+Param+
	(!Country ? "" : "&country="+Country+(Country!=2 ? "" : "&state="+State))+(oPL.bEnc ? '&enc=1' : '');
URL=PL_AddTestIP(URL); oPL.Drugs=Drugs;

//State reselect
if (oPL.bShown){
	oPL.PLDiv.style.cursor='wait'; oPL.bWait=true;
	//D.PLGeo.Go.disabled=true; D.PLGeo.Go.style.cursor='wait';
	var oBtn=getbyid('GoBtn'), oBtnDiv=oBtn.firstChild;
	oBtnDiv.className='GoBtnDis'; oBtn.onclick=null;
	//With WebKit I can't restore it (WebKit cursor bug.rtf)
	if (Saf) oBtnDiv.style.cursor='pointer';
	//oPLVar.GoBtnClk=oBtn.onclick; 
	}

oPL.OldTO=setTimeout('PL_LoadTimeout()', 8000); oPL.URL=URL;

if (!oPL.bOld){
	oReq=createXMLHttp(); oPL.oReq=oReq; oReq.onreadystatechange=PL_OnLoad;
	oReq.open('GET', URL, true); 
	oReq.send(''); 
	//if (oPL.StubHtml) oPL.PLDiv.innerHTML=oPL.StubHtml;
	}
else{
	oPL.URL=URL;
	if (bRmt && !(Gec || Op)) setTimeout("PL_CreateScr();", 100); // && !IE7
	else PL_CreateScr();
	}
oPL.PLStage='sent';
}

function PL_GetVar(){
var v;

if (v=aCookies['var']) return v;
var aV=['color', 'shape', 'radius', 'data', 'nnn', 'length', 'update', 'th'];
v=aV[PL_Rnd(aV.length)]; SetCookie('var', v); return v;
}

function PL_AddTestIP(URL){
if (M=W.location.search.match(/testip=([^&]+)/)) URL+='&testip='+M[1];
return URL;
}

function PL_CreateScr(){

oPL.oScr=D.createElement('SCRIPT');
D.body.insertBefore(oPL.oScr, null);
oPL.oScr.src=oPL.URL+='&scr=1'+(!oPL.bRmt ? '' : '&gt=1');
}

function PL_LoadTimeout(bOk){

if (oPL.bWait) PL_RestoreBtn();
oPL.OldTO=null;
if (!bOk) PL_SendEB("PL load TO; sv: "+aCookies["sv"]);
}

function PL_SendEB(Msg, eid){
// && !W.location.host.match("^(\\d+\\.){3}")
//if (W.location.href.substr(0, 5)=='file:') return;

oImg=D.createElement('IMG'); if (!eid) eid=126;
oImg.src='http://error.sopse'+'rver.com/erro'+'rsbase/handler.php?e='+eid+'&descr='+
	escape(W.location)+KT_Line(oPL.URL)+KT_Line(Msg)+
	KT_Line(W.navigator.userAgent)+KT_Line("Ref:"+D.referrer);
}

function PL_RestoreBtn(){
var oBtn=getbyid('GoBtn'), oBtnDiv=oBtn.firstChild;

/*try{oBtnDiv.className='';} //Errors: 6
catch (oError){
	KT_OE('Not implemented oBtnDiv.className: '+oBtn.nodeName+
		'; HTML!: '+oBtn.innerHTML+'; '+oBtnDiv.nodeName,
		'pricelist.js', 281);
	} */

oPL.PLDiv.style.cursor='auto'; oPL.bWait=false;
//oBtn.onclick=oPLVar.GoBtnClk;
}

function PL_OnLoad(){
var oReq=oPL.oReq;

if (oReq.readyState!=4) return;

if (oReq.status!=200 && oReq.status!=304){
	var m="Wrong status: "+oReq.status; KT_OE(m, W.location.href, 0);
	clearTimeout(oPL.OldTO); return;
	}
//This pseudo timeout saves us from page flash when reselecting the same geo. 
setTimeout('PL_ShowPrices();', 1);
}

function PL_WaitDiv(){
var PLDiv;

if (D.body && !oPL.bKT) PL_KTImg();
if (!(PLDiv=getbyid(oPL.S))){
	setTimeout("PL_WaitDiv()", 125); return;
	}
oPL.PLDiv=PLDiv; PL_Load(PL_Drug);
}

function PL_ShowPrices(){
var PLDiv, oRow, Html;

oPL.PLStage='show';
if (!oPL.bOld) PLDiv=getbyid(oPL.S);
else{
	if (oRow=getbyid('PLRow')) PLDiv=oRow.cells[0];
	else PLDiv=getbyid(oPL.S);
	}

//if (!PLDiv){setTimeout("PL_ShowPrices()", 250); return;}
//oPL.PLDiv=PLDiv;

if (oPL.OldTO){
	clearTimeout(oPL.OldTO); setTimeout("PL_LoadTimeout(true)", 500);
	}

if (!oPL.bOld){
	//if (!oPL.StubHtml) oPL.StubHtml=PLDiv.innerHTML; 
	Html=oPL.oReq.responseText; delete oPL.oReq;
	}
else{
	Html=PLHtml; PLHtml='';
	}

if (Html){
	Html=PL_ProcessPLHtml(Html); PLDiv.innerHTML=Html; oPL.bShown=true; 
	}

//PL_SetHandlers(PLDiv);
oPL.PLStage='done'; PL_Reset(); oPL.PLStage='done-reset'; //clear vars like oCurRow etc

if (bFF36Err){
	KT_OE("PL shown inspite of FF36 error", W.location.href, 0);
	}

if (W.OnPL) OnPL();
if (FFVer) setTimeout("PL_WatchDiscl()", 1500);
}

function PL_ShowLoading(bTbl){
var oImg, oTbl;

oImg=getbyid('LoadImg');
if (!oImg) return;

if (Gec){
	if (!bTbl){
		if (oTbl=getbyid('MainTbl')){
			if (oTbl.style.visibility!='visible'){
				oImg.bShow='1'; return;
				}
			}
		}
	else if (!oImg.bShow) return;
	} 

oImg.style.visibility='visible';
}

function PL_SetHandlers(PLDiv){

if (oPL.bHandle) return;
PL_SetH("onmousedown", PL_OMDown, PLDiv);
PL_SetH((!Gec ? 'onactivate' : (FFVer>=3 ? 'onkeydown' : 'onfocus')), PL_OMDown, PLDiv);
oPL.bHandle=1;
}
function PrL_Links(o){PL_SetHandlers(o);}
function PLstClicks(o){PL_SetHandlers(o);}

function PL_SetH(Ev, F, O){
if (!O) O=D;
if (O.attachEvent) O.attachEvent(Ev, F); else O.addEventListener(Ev.substr(2), F, false);
}

//-----

function PL_OMDown(e){
var p, Tag, HRef, bChg, Host;

EventInit(e); Tag=EvSrc.tagName;
if (Tag!='A' && Tag!='AREA'){
	if (!Tag) return;
	Tag=EvSrc.parentNode.tagName;
	if (Tag!='A' && Tag!='AREA') return;
	EvSrc=EvSrc.parentNode;
	}

if (oPL.LastEvSrc==EvSrc) return;
oPL.LastEvSrc=EvSrc;

HRef=EvSrc.href;
if ((p=HRef.indexOf('#http:'))!=-1){
	HRef=HRef.substr(p+1); bChg=true;
	}
else if (HRef.indexOf('/go2phar'+'macy.php')!=-1){
	if (HRef.indexOf(KT_UId)!=-1) return;

	if (!qseid){
		Host=W.location.host;
		if (Host.substr(0, 4).toLowerCase()=='www.') Host=Host.substr(4);
		}
	
	EvSrc.href+='&u='+KT_UId+(qseid ? '&qseid='+qseid : '&h='+Host+(oKTImg.QSe ? '&qse='+oKTImg.QSe : ''));
	return;
	}

while(true){
	if (!qseid) break;
	if (HRef.indexOf("="+qseid)!=-1) break;
	
	HRef=HRef.replace(/([&?])(said|trk|tid|data1|keywords|s|cid)=[\d\w]+/, "$1$2="+qseid); 
	//if (HRef.match(/tid=[^\d]/)) HRef=HRef.replace(/([&?])tid=\w+/, "$1tid="+qseid);  //non-numeric tid's as well
	
	bChg=true; //?
	break;
	}

//Copy this to code.js!
if (HRef.indexOf('.mpr'+'ixe.')!=-1){
	HRef=HRef.replace(RegExp('\\.mpr'+'ixe\\.(com|net)'), '.e-medi'+'cations.com');
	bChg=true;
	}
if (HRef.indexOf('.e-medi'+'cations.')!=-1){
	var id='2438'+'945';
	if (!HRef.match("[?&]k=")) HRef+=(HRef.indexOf('?')!=-1 ? '&' : '?')+'k='+id;
	else{
		HRef=HRef.replace("=apo", "="+id); HRef=HRef.replace("=ap_32", "="+id);
		}
	bChg=true;
	}

if (bChg) EvSrc.href=HRef;
}

function PL_OMOver(e){
var PriceInfo, Tag, oTD, HRef;

EventInit(e); 
oTD=PL_GetTD(); if (!oTD) return;
PL_TD_MOver(oTD); 

//Status
if (!oPLVar.A) return;

oPLVar.LastA=oPLVar.A; HRef=oPLVar.A.href;
if (HRef.indexOf('/suppliers/')!=-1) return true;
PriceInfo=PL_FindDosage(oPLVar.A);
if (!PriceInfo) return;
PL_Status('Buy '+PriceInfo[0]+' '+PriceInfo[2]+' for '+PriceInfo[1]+' from '+PriceInfo[3]);

return true;
}

function PL_OMOut(e){
var oTD;

EventInit(e, true); oTD=PL_GetTD(); if (!oTD) return;
PL_TD_MOut(oTD);

//Status
if (!oPLVar.A) return;

//Moving in a link
if (EvSrc.tagName=='A'){
	if (ETo && ETo.parentNode==EvSrc) return;
	}
else if (oPLVar.A && ETo==oPLVar.A) return;

PL_Status(''); oPLVar.LastA=null; return true;
}

function PL_GetTD(){
var o=EvSrc, oTbl, oBody, Cell;

oPLVar.A=null;
if (EvSrc.tagName=='TH') return null;

while(true){
	if (!o) return null;
	if (o.tagName=='TD'){
		//Except PM
		oBody=PL_GetCellBlock(o); oTbl=oBody.parentNode;
		if (oTbl.className.indexOf("PMTbl")==-1) return o;
		o=oTbl;
		}
	else if (o.tagName=='A') oPLVar.A=o;
	o=o.parentNode;
	}
}

function PL_TD_MOver(oTD){
var oTR, TBody;

PL_OnRowOver(oTD);
//Ignore plus / separators / drugnames
if (oTD.cellIndex==0) return;

TBody=PL_GetCellBlock(oTD); oTR=oTD.parentNode;
if (!PL_IsMulBlock(TBody)) return;
//Do not open again after closing and moving across cells of the same row
if (oPLVar.LastBlk==TBody) return;

oPLVar.LastBlk=TBody;

if (oPL.Timer) clearTimeout(oPL.Timer);
oPL.Timer=setTimeout("PL_HandleMouse()", 1000);
}

function PL_TD_MOut(oTD){
var LastBlk=oPLVar.LastBlk;

PL_OnRowOut(oTD);
if (!LastBlk) return;
if (oTD.cellIndex>0 && Contains(LastBlk, ETo)) return;

var TBody=PL_GetCellBlock(oTD);
if (!PL_IsMulBlock(TBody)) return;
if (TBody==LastBlk) oPLVar.LastBlk=null;

if (oPL.Timer) clearTimeout(oPL.Timer);
oPL.Timer=setTimeout("PL_HandleMouse()", 300);	
}

function PL_OnRowOver(oTD){
var oRow, Cls;

oRow=oTD.parentNode;
if (oRow==oPLVar.oCurRow) return;
if (oPLVar.oCurRow){
	ETo=null; 
	
	var TD=oPLVar.oCurRow.cells[0];
	if (TD) PL_OnRowOut(TD);
	else{
		KT_OE('!CurRow TD: '+oPLVar.oCurRow.nodeName+
			'Par: '+oPLVar.oCurRow.parentNode.nodeName+
			'cells: '+oPLVar.oCurRow.cells,
			//'; cellsnum: '+(oPLVar.oCurRow.cells ? oPLVar.oCurRow.cells : 'null'),
			'pricelist.js', 493);
		}
	}

if (oRow.cells.length<=2) return; //separator
if (oRow.cells[0].className=='name_tabs') return;

Cls=oRow.className;
if (Cls.indexOf("Cur")==-1){
	Cls=(Cls ? Cls+" " : "")+"Cur"; oRow.className=Cls; 
	}

oPLVar.oCurRow=oRow;
}

function PL_OnRowOut(oTD){
var oRow, Cls;

if (!oPLVar.oCurRow) return;
if (ETo && Contains(oPLVar.oCurRow, ETo)) return;
try{oRow=oTD.parentNode;} //error
catch (oError){
	KT_OE('!oTD.parentNode: Caller: '+PL_OnRowOut.caller+'; Caller2: '+PL_OnRowOut.caller.caller,
		'pricelist.js', 493);
	return;
	}

Cls=oRow.className;
Cls=(Cls=="Cur" ? "" : Cls.replace(/ Cur/, ''));
oRow.className=Cls;

oPLVar.oCurRow=null;
}

//-----

function PL_HandleMouse(){

if (!oPLVar.bAnim){
	var OpenBlk=oPLVar.OpenBlk, LastBlk=oPLVar.LastBlk;
	
	if (OpenBlk && LastBlk!=OpenBlk){
		if (oPL.bAutoClose && !OpenBlk.bManual) PL_OpenBlockAnim(OpenBlk, false);
		}
	if (LastBlk){
		if (OpenBlk!=LastBlk) PL_OpenBlockAnim(LastBlk, true);
		}
	}

oPL.Timer=null;
}

function PL_OpenBlockAnim(TBody, bOpen, bManual){

if (bOpen && PL_IsOpenBlock(TBody)) return;
if (oPLVar.bAnim) return;

if (bOpen){
	PL_OpenBlock(TBody, bOpen, bManual); PL_AnimStart(TBody, true);
	}
else{
	PL_AnimStart(TBody, false); oPLVar.oAnim.bManual=bManual;
	}
}

function PL_TogglePlus(oDiv, bAll, bOpen){
var InDiv=oDiv.firstChild, oTR, oTbl, opnum;

oDiv.bOpened=(bOpen ? '1' : '');
InDiv.style.backgroundPosition=(bOpen ? '-32' : '-48')+'px 0px';
setat(InDiv, 'title', (!bOpen ? 'Show' : 'Hide')+
	' all offers for '+(bAll ? 'all packages' : 'the package'));

if (bAll) return;
//Find the root
oTR=oDiv.parentNode.parentNode; oTbl=oTR.parentNode.parentNode;
while(oTR.rowIndex>0){
	oTR=oTbl.rows[oTR.rowIndex-1];
	if (oTR.cells[0].className=='name_tabs'){
		InDiv=oTR.cells[0].firstChild.firstChild; 
		if (InDiv.nodeType==3) return;
		opnum=InDiv.opnum;
		if (InDiv.opnum==null){
			opnum=0; InDiv.blknum=getat(InDiv, 'blknum');
			}
		opnum=parseInt(opnum); opnum+=(bOpen ? 1 : -1); InDiv.opnum=opnum;
		if (bOpen && opnum==InDiv.blknum || !bOpen && opnum==0){
			PL_TogglePlus(InDiv.parentNode, true, bOpen);
			}
		return;
		}
	}
}

function PL_OpenBlock(TBody, bOpen, bManual, bNoAnim){
var i, j, aRows, oRow, oCellSt, RowNo, aDivsSt, oDiv, aDivH, h;

if (bOpen && PL_IsOpenBlock(TBody)) return;
aRows=TBody.rows;

for(RowNo=0; RowNo<aRows.length; RowNo++){

	oRow=aRows[RowNo];
	if (RowNo==0){
		oDiv=oRow.cells[0].firstChild;
		PL_TogglePlus(oDiv, false, bOpen); continue;
		}

	if (bNoAnim){

		oRow.style.display=(bOpen ? (Gec ? 'table-row' : 'block') : 'none');
		aDivsSt=PL_AnimGetDivSt(oRow); 

		if (bOpen){
			oDiv=PL_AnimGetDiv(oRow);
			for(i=0; i<aDivsSt.length; i++) aDivsSt[i].height='auto'; //oPL.VertPad+'px';
			}
		else{
			for(i=0; i<aDivsSt.length; i++) aDivsSt[i].height='1px';
			//padding='0px';
			}
		
		}
	}

oPLVar.OpenBlk=(bOpen ? TBody : null); 

if (bOpen){
	TBody.className+=' Opened';
	if (!bManual){
		oPLVar.bSkipClk=true; setTimeout("PL_SC();", 200);
		}
	}
else TBody.className='MulSup';

if (bOpen) TBody.bManual=(bManual ? '1' : '');
}

function PL_SC(){oPLVar.bSkipClk=false;}

function PL_OC(e){
var TBody, oTR, Cls, Cell, InDiv;

if (oPLVar.bSkipClk || oPLVar.bAnim) return true;
EventInit(e); 
if (EvSrc.tagName!='DIV' || EvSrc.childNodes.length!=1) return true;
InDiv=EvSrc.firstChild;
if (InDiv.tagName!='DIV' || InDiv.className!='Plus') return true;

Cell=EvSrc.parentNode; Cls=Cell.className;

if (Cls=='tab1'){
	oTR=Cell.parentNode;
	if (oTR.className.indexOf('FirstSpl')==-1) return true;
	TBody=PL_GetCellBlock(Cell);
	
	if (TBody.className=='MulSup'){
		PL_OpenBlockAnim(TBody, true, true); //LastBlk=TBody;
		}
	else if (PL_IsOpenBlock(TBody)){ // && EvSrc.cellIndex==0
		PL_OpenBlockAnim(TBody, false, true);
		}
	}
else if (Cls=='name_tabs'){
	//Cell.style.cursor='wait'; InDiv.style.cursor='wait'; 
	oPLVar.TopArr=Cell; 
	setTimeout("PL_OpenAllInBlock("+(Cell.firstChild.bOpened ? 'false' : 'true')+")", 1);
	}

return true;
}

function PL_OpenAllInBlock(bOpen){
var oTbl, TBody, aBodies, i, oNextBody, oTR, Cell, aRows, RowNum, RowNo, TopPlus;

TopPlus=oPLVar.TopArr;
TBody=PL_GetCellBlock(TopPlus); oTbl=TBody.parentNode;
aRows=oTbl.rows; RowNum=aRows.length; 
oTR=TopPlus.parentNode; 

for(RowNo=oTR.rowIndex; RowNo<RowNum; RowNo++){
	oTR=aRows[RowNo]; if (!oTR) break;

	if (oTR.className=='FirstSpl'){
		TBody=oTR.parentNode;
		if (bOpen && PL_IsOpenBlock(TBody) || !bOpen && !PL_IsOpenBlock(TBody)) continue;
		PL_OpenBlock(TBody, bOpen, true, true);
		continue;
		}

	Cell=oTR.cells[0];
	if (Cell.className=='pills_name') break;
	}

//TopPlus.style.cursor='pointer'; TopPlus.firstChild.firstChild.style.cursor='pointer';
PL_TogglePlus(TopPlus.firstChild, false, bOpen); 
}


function PL_OpenAll(){
var oTbl, TBody, aBodies, i, oNextBody;

TBody=PL_GetCellBlock(oPLVar.TopArr); oTbl=TBody.parentNode; aBodies=oTbl.getElementsByTagName('TBODY');

for(i=0; i<aBodies.length; i++){
	oNextBody=aBodies[i];
	if (!PL_IsMulBlock(oNextBody) || PL_IsOpenBlock(oNextBody)) continue;
	PL_OpenBlock(oNextBody, true, true, true);
	}
//oPLVar.TopArr.style.cursor='pointer';
}

function PL_ODC(e){

EventInit(e);
if (EvSrc.tagName!='TD' || EvSrc.className!='LeftCol') return;
PL_OC(e);

return true;
}

function PL_GetSupplier(Sid, bCell){
var aCells, i, oCell, oSupList;

if (!(oSupList=getbyid('SupList'))) return null;
aCells=oSupList.getElementsByTagName('TD');

for(i=0; i<aCells.length; i++){
	oCell=aCells[i];
	if (getat(oCell, 'sid')==Sid){
		if (bCell) return oCell;
		return getat(oCell, 'title').substr(12);
		}
	}
}

function PL_FindDosage(A){
var oTR, aRows, RowIndex, oCell, Price, Pkg, Pharm, Sid, i, aChildn, Child, Drug='', oPkgTr, Cls;

//Get row
oTR=A; while(oTR.tagName!='TR') oTR=oTR.parentNode;
Sid=getat(oTR, 'sid'); if (!Sid) return false;

Pharm=PL_GetSupplier(Sid);
if (Pharm.indexOf('harmacy')==-1) Pharm+=' Pharmacy';

oCell=A.parentNode.parentNode; 
aRows=oTR.parentNode.parentNode.rows; RowIndex=oTR.rowIndex;
Price=GetTextEx(oTR.cells[3].firstChild.firstChild);

while(--RowIndex>=0){
	if (!oPkgTr){
		Cls=oTR.className;
		if (Cls.indexOf('OtherSpl')==-1 && Cls.indexOf('LastSpl')==-1) oPkgTr=oTR;
		}
	oTR=aRows[RowIndex]; 
	
	if (!oTR) break;
	oCell=oTR.cells[0];
	if (oCell.className=='pills_name'){
		Drug=GetText(oCell); break;
		}
	}

aChildn=oPkgTr.cells[1].firstChild.firstChild.childNodes; Pkg='';
for(i=0; i<aChildn.length; i++){
	Child=aChildn[i];
	if (Child.nodeType==1) Pkg+=GetText(Child); else Pkg+=Child.data;
	}

if (Pkg.charAt(Pkg.length-1)==' ') Pkg=Pkg.substr(0, Pkg.length-1);
i=Pkg.indexOf(' x ');
if (i!=-1) Pkg=Pkg.substr(0, i);

return [Drug, Price, Pkg, Pharm];
}

function GetTextEx(o){
var i, L, aChild, Ch, Text='';

aChild=o.childNodes; L=aChild.length;
for(i=0; i<L; i++) Text+=GetText(aChild[i]);
return Text;
}

//-----
//Anim

function PL_AnimStart(Block, bOpen){
var Delta, RowNum, BlkLen;

if (!Block) return;

RowNum=Block.rows.length;

if (RowNum==2){
	Delta=3; BlkLen=0; 
	}
else if (RowNum==3){
	Delta=4; BlkLen=1;
	}
else{
	Delta=5; BlkLen=2;
	}

if (Gec) Delta+=2;
if (oPL.AnimFix){
	Delta+=oPL.AnimFix; 
	if (Delta<=0) Delta=1;
	}

oPLVar.oAnim={
	bOpen:bOpen,
	Block:Block,
	aRows:Block.rows,
	RowNum:RowNum,
	RowNo:(bOpen ? 1 : RowNum-1),
	LastRowNo:(bOpen ? RowNum : 0),
	Dir:(bOpen ? 1 : -1),
	Delta:Delta,
	VertPad:(bOpen ? oPL.VertPad : 0)+'px',
	PadProp1:(bOpen ? 'paddingTop' : 'paddingBottom'),
	PadProp2:(!bOpen ? 'paddingTop' : 'paddingBottom'),
	Correction:0, BlkLen:BlkLen
	};

oPLVar.bAnim=true; 
if (oPL.AnimTimer) clearTimeout(oPL.AnimTimer);
oPL.AnimTimer=setTimeout("PL_An();", 5000);

PL_AnimRowInit(); PL_Animate();
}

function PL_An(){oPLVar.bAnim=false;}

function PL_Reset(){

if (oPL.Timer) clearTimeout(oPL.Timer);
if (oPL.AnimTimer) clearTimeout(oPL.AnimTimer);
if (oPLVar && oPLVar.oSupAnim && oPLVar.oSupAnim.TO) clearTimeout(oPLVar.oSupAnim.TO);

oPLVar={
	bAnim:false, bSkipClk:false, oCurRow:null, OpenBlk:null, LastBlk:null, A:null, 
	oSupAnim:null, GoBtnClk:null, TopArr:null, oAnim:null, LastA:null};

/*var aP=['bOld', 'Drugs', 'URL'], aV=[], i;
for(i=0; i<aP.length; i++) aV[aP[i]]=oPL[aP[i]];
PL_Init();
for(i=0; i<aP.length; i++) oPL[aP[i]]=aV[aP[i]]; */
}

function PL_AnimRowInit(){
var oAnim=oPLVar.oAnim;

oAnim.Row=oAnim.aRows[oAnim.RowNo];
//Package cell
oAnim.Div=PL_AnimGetDiv(oAnim.Row);
oAnim.ThisRowHeight=(oAnim.bOpen ? 1 : oAnim.Div.scrollHeight-oPL.VertPad*2);
oAnim.aDivsSt=PL_AnimGetDivSt(oAnim.Row);
oAnim.CellNum=oAnim.aDivsSt.length;

oAnim.bPad1Set=false; oAnim.bRowDisplay=false;
oAnim.AnumNum=0; oAnim.StartTime=new Date();

//Hide cell padding
PL_CellPad(oAnim, true);
}

function PL_Animate(Delta){
var oAnim=oPLVar.oAnim, ExtraHeight=-1, i, h, aDivsSt, bOpen=oAnim.bOpen;

aDivsSt=oAnim.aDivsSt; oAnim.AnumNum++;

if (Delta==null){
	Delta=oAnim.Delta;
	if (oAnim.Correction!=0){
		Delta-=oAnim.Correction; oAnim.Correction=0;
		}
	}

if (!bOpen) oAnim.aDivH=PL_AnimGetDivH(oAnim.Row);

while(true){
	
	if (bOpen && !oAnim.bRowDisplay){
		//Init
		oAnim.Row.style.display=(Gec ? 'table-row' : 'block');
		oAnim.RowHeight=oAnim.Div.scrollHeight;
		oAnim.aDivH=PL_AnimGetDivH(oAnim.Row);
		//1px is first visible
		Delta-=1; oAnim.bRowDisplay=true;
		if (Delta<=0) break;
		}

	if (!oAnim.bPad1Set){
		for(i=0; i<oAnim.CellNum; i++) aDivsSt[i][oAnim.PadProp1]=oAnim.VertPad;
		Delta-=oPL.VertPad; oAnim.bPad1Set=true;
		if (Delta<=0) break;
		}

	if (bOpen){
		oAnim.ThisRowHeight+=Delta;
		ExtraHeight=oAnim.ThisRowHeight-oAnim.RowHeight;
		if (ExtraHeight>0) oAnim.ThisRowHeight=oAnim.RowHeight;
		}
	else{
		oAnim.ThisRowHeight-=Delta;
		ExtraHeight=1-oAnim.ThisRowHeight;
		if (ExtraHeight>0) oAnim.ThisRowHeight=1;
		}

	h=oAnim.ThisRowHeight+'px'; 
	for(i=0; i<oAnim.CellNum; i++){
		if (bOpen){
			aDivsSt[i].height=h;
			if (oAnim.aDivH[i]>oAnim.ThisRowHeight) aDivsSt[i].height=h;
			else aDivsSt[i].height='auto';
			}
		else{
			if (oAnim.ThisRowHeight<oAnim.aDivH[i]) aDivsSt[i].height=h;
			}
		}

	break;
	}

//Done
if (ExtraHeight>=0){

	for(i=0; i<oAnim.CellNum; i++) aDivsSt[i][oAnim.PadProp2]=oAnim.VertPad;

	//Restore cell padding
	PL_CellPad(oAnim, false);
	ExtraHeight-=oPL.VertPad;
	
	if (!bOpen){
		oAnim.Row.style.display='none'; ExtraHeight-=1; 
		}
	oAnim.RowNo+=oAnim.Dir;

	//The End
	if (oAnim.RowNo==oAnim.LastRowNo){
		PL_AnimEnd(); return;
		}

	PL_AnimRowInit();
	//Pass extra to next row with no pause
	if (ExtraHeight>0){
		PL_Animate(ExtraHeight); return;
		}
	else if (ExtraHeight<0) oAnim.Correction=-ExtraHeight;
	}

setTimeout("PL_Animate()", 1);
}

function PL_CellPad(Anim, bInit){
var aCells=Anim.Row.cells, i, St, bOpen=Anim.bOpen;

Pad=(bInit ? '0px' : '');
for(i=0; i<aCells.length; i++){
	St=aCells[i].style; St.paddingTop=Pad; St.paddingBottom=Pad;
	if (bOpen && !bInit){
		St=aCells[i].firstChild.style;
		St.paddingTop='0px'; St.paddingBottom='0px';
		}
	else if (!bOpen && bInit){
		St=aCells[i].firstChild.style;
		St.paddingTop=oPL.VertPad+'px'; St.paddingBottom=oPL.VertPad+'px';
		}
	}
}

function PL_AnimEnd(){
var oAnim=oPLVar.oAnim;

oPLVar.bAnim=false;
if (oPL.AnimTimer){
	clearTimeout(oPL.AnimTimer); oPL.AnimTimer=null;
	}

var EndTime=new Date(), AnimTime=EndTime-oAnim.StartTime;
var aMaxTimes=[400, 300, 200], MaxTime=aMaxTimes[oAnim.BlkLen];

if (AnimTime/oAnim.RowNum>MaxTime){
	if (!oPL.AnimFix) oPL.AnimFix=1; else oPL.AnimFix++;
	SetCookie('animfix', oPL.AnimFix);
	}

var aMinTimes=[75, 50, 25], MinTime=aMinTimes[oAnim.BlkLen];
if (AnimTime/oAnim.RowNum<MinTime){
	if (!oPL.AnimFix) oPL.AnimFix=-1; else oPL.AnimFix--;
	SetCookie('animfix', oPL.AnimFix);
	}

if (oAnim.bOpen) return;
PL_OpenBlock(oAnim.Block, false, oAnim.bManual);
}

function PL_EnableStates(){
D.PLGeo.State.disabled=!IsUs(D.PLGeo.Country.value);
}

function IsUs(c){
return (c=='2' || c=='-2');
}

function PL_GeoSubmit(){
var C, St;

C=parseInt(D.PLGeo.Country.value);
if (C==0) return false;
St=D.PLGeo.State.value;

if (C<0) C=-C;
if (C==2 && St==0){
	alert("Please select a state"); return false;
	}

if (C==999 || St=='99'){
	DelCookie('pl_country'); DelCookie('pl_state'); DelCookie('pl_rs'); C=0; St=0;
	}
else{
	SetCookie("pl_country", C, null, "/");
	SetCookie("pl_state", (C==2 ? St : 0), null, "/");
	}

/*if (oPL.bOld){
	var oImg=D.createElement('IMG');
	oImg.src=PLGetBaseURL()+'cookieimg.php?c='+C+'&st='+St;
	} */

PL_Load(oPL.Drugs, C, St);
}

//-----

function PL_SupMouse(Sup){
PL_Status('Learn about '+Sup); return true;
}

function PL_SupDescr(A){
var oScreen=W.screen, HRef, URL, O, aA, M, Pos, BM;

HRef=A.href; O=A;
if (M=HRef.match(/^(.*)#(.*)$/)){
	HRef=M[1]; BM=M[2];
	}

URL=PL_AddTestIP(HRef);
if (URL.length==HRef.length && oPL.aGeo[0]){
	URL+='&c='+oPL.aGeo[1]+(oPL.aGeo[1]==2 ? '&st='+oPL.aGeo[2] : '');
	}

while(O.tagName!='TR') O=O.parentNode;
if (O.className!='SupList'){
	aA=O.getElementsByTagName('A'); M=aA[0].href.match(/pr=(\d+)/); URL+='&pr='+M[1];
	}
else URL+='&dr='+oPL.Drugs;

//Should be a BM but that is already used by deliv. 
if (qseid) URL+="&i="+qseid;

if (BM) URL+='#'+BM;
W.open(URL, '_blank', 'width=780,height='+Math.round(oScreen.height/1.5)+',left='+(780/4)+
	',top='+Math.round(oScreen.height/8)+',scrollbars=yes,toolbar=no,menubar=no,status=no,resizable=yes');
if (IEVer && W.event) W.event.cancelBubble=true;

return false;
}

function PL_Status(Msg){

if (IEVer<7){W.status=Msg; return;}
if (!bLocal) return;

var oSB;
if (!oPL.oSB){
	oSB=D.createElement('DIV'); oSB.className='SB';
	oSB.insertBefore(D.createTextNode('-'), null);
	D.body.insertBefore(oSB, null); oPL.oSB=oSB;
	}
else oSB=oPL.oSB;

oSB.style.top=GetPosRoot().scrollTop+'px'; oSB.firstChild.data=Msg;
oSB.style.display=(Msg=='' ? 'none' : 'block');
}

function PL_MakeCountryList(Id){
var Data='92:Afghanistan;138:Albania;116:Algeria;174:American Samoa;204:Andorra;77:Angola;193:Anguilla;216:Antarctica;175:Antigua And Barbuda;20:Argentina;140:Armenia;162:Aruba;16:Australia;85:Austria;151:Azerbaijan;35:Bahamas;168:Bahrain;90:Bangladesh;149:Barbados;84:Belarus;63:Belgium;30:Belize;81:Benin;113:Bermuda;225:Bhutan;38:Bolivia;171:Bosnia And Herzegovin...;79:Botswana;178:Bouvet Island;48:Brazil;220:British Indian Ocean ...;102:Brunei Darussalam;127:Bulgaria;208:Burkina Faso;198:Burundi;179:Cambodia;9:Cameroon;4:Canada;117:Cape Verde;166:Cayman Islands;210:Central African Repub...;196:Chad;56:Chile;42:China;240:Christmas Island;62:Colombia;200:Comoros;187:Congo;129:Congo, The Democratic...;50:Cook Islands;26:Costa Rica;70:Cote D\'ivoire;83:Croatia;104:Cuba;11:Cyprus;39:Czech Republic;87:Denmark;211:Djibouti;173:Dominica;23:Dominican Republic;21:Ecuador;80:Egypt;161:El Salvador;-1:England;212:Equatorial Guinea;209:Eritrea;112:Estonia;137:Ethiopia;150:Falkland Islands (mal...;197:Faroe Islands;192:Fiji;110:Finland;18:France;114:French Guiana;25:French Polynesia;230:French Southern Terri...;180:Gabon;147:Gambia;123:Georgia;46:Germany;28:Ghana;141:Gibraltar;-1:Great Britain;31:Greece;205:Greenland;195:Grenada;202:Guadeloupe;29:Guam;44:Guatemala;199:Guinea;214:Guinea-bissau;109:Guyana;164:Haiti;172:Heard Island And Mcdo...;203:Holy See (vatican Cit...;86:Honduras;53:Hong Kong;107:Hungary;65:Iceland;10:India;55:Indonesia;37:Iran, Islamic Republi...;115:Iraq;49:Ireland;58:Israel;13:Italy;7:Jamaica;61:Japan;132:Jordan;135:Kazakhstan;118:Kenya;219:Kiribati;227:Korea, Democratic Peo...;19:Korea, Republic Of;111:Kuwait;128:Kyrgyzstan;106:Lao People\'s Democrat...;134:Latvia;124:Lebanon;201:Lesotho;120:Liberia;72:Libyan Arab Jamahiriy...;146:Liechtenstein;119:Lithuania;145:Luxembourg;186:Macao;144:Macedonia, The Former...;130:Madagascar;188:Malawi;89:Malaysia;100:Maldives;182:Mali;126:Malta;176:Marshall Islands;213:Martinique;156:Mauritania;67:Mauritius;229:Mayotte;6:Mexico;163:Micronesia, Federated...;152:Moldova, Republic Of;154:Monaco;98:Mongolia;233:Montenegro;194:Montserrat;82:Morocco;75:Mozambique;91:Myanmar;125:Namibia;222:Nauru;24:Nepal;22:Netherlands;41:Netherlands Antilles;105:New Caledonia;64:New Zealand;170:Nicaragua;155:Niger;43:Nigeria;221:Niue;206:Norfolk Island;-1:Northern Ireland;184:Northern Mariana Isla...;60:Norway;133:Oman;0:Others;40:Pakistan;226:Palau;142:Palestinian Territory...;99:Panama;160:Papua New Guinea;159:Paraguay;97:Peru;66:Philippines;231:Pitcairn;59:Poland;27:Portugal;17:Puerto Rico;103:Qatar;122:Reunion;15:Romania;52:Russian Federation;148:Rwanda;235:Saint Helena;185:Saint Kitts And Nevis;158:Saint Lucia;239:Saint Pierre and Miqu...;181:Saint Vincent And The...;183:Samoa;143:San Marino;217:Sao Tome And Principe;32:Saudi Arabia;-1:Scotland;153:Senegal;232:Serbia;51:Serbia And Monteneg...;76:Seychelles;167:Sierra Leone;47:Singapore;136:Slovakia;54:Slovenia;95:Solomon Islands;191:Somalia;71:South Africa;234:South Georgia And T...;34:Spain;96:Sri Lanka;5:Sudan;189:Suriname;68:Swaziland;12:Sweden;14:Switzerland;157:Syrian Arab Republic;88:Taiwan;121:Tajikistan;78:Tanzania, United Rep...;36:Thailand;223:Timor-leste;69:Togo;224:Tokelau;215:Tonga;108:Trinidad And Tobago;139:Tunisia;3:Turkey;207:Turkmenistan;165:Turks And Caicos Isl...;218:Tuvalu;73:Uganda;8:Ukraine;45:United Arab Emirates;1:United Kingdom;2:United States;228:United States Minor O...;57:Uruguay;93:Uzbekistan;190:Vanuatu;33:Venezuela;94:Viet Nam;169:Virgin Islands, British;177:Virgin Islands, U.S.;-1:Wales;238:Wallis and Futuna Isl...;101:Yemen;241:Yugoslavia;131:Zambia;74:Zimbabwe';

return PL_MakeList(Data, Id);
}

function PL_MakeStateList(Id){
var Data='1:Alabama;2:Alaska;3:Arizona;4:Arkansas;5:California;6:Colorado;7:Connecticut;8:Delaware;51:District of Columbia;9:Florida;10:Georgia;11:Hawaii;12:Idaho;13:Illinois;14:Indiana;15:Iowa;16:Kansas;17:Kentucky;18:Louisiana;19:Maine;20:Maryland;21:Massachusetts;22:Michigan;23:Minnesota;24:Mississippi;25:Missouri;26:Montana;27:Nebraska;28:Nevada;29:New Hampshire;30:New Jersey;31:New Mexico;32 Selected:New York;33:North Carolina;34:North Dakota;35:Ohio;36:Oklahoma;37:Oregon;38:Pennsylvania;52:Puerto Rico;39:Rhode Island;40:South Carolina;41:South Dakota;42:Tennessee;43:Texas;44:Utah;45:Vermont;46:Virginia;47:Washington;48:West Virginia;49:Wisconsin;50:Wyoming';

return PL_MakeList(Data, Id);
}

function PL_MakeList(Data, Id){
var i, L, Item, aHtml, aValues;

aItems=Data.split(';'); L=aItems.length; aHtml=[];
for(i=0; i<L; i++){
	Item=aItems[i]; aValues=Item.split(':');
	aHtml[i]='<Option Value='+aValues[0]+'>'+aValues[1];
	}
return aHtml.join('');
}

function PL_KTImg(){

if (oPL.bKT || getbyid('KTImg')) return;
var uid, i, R="", S, E, RE, SE, Q='', M, SN=0, SE0, Q0, bSE, SE2, Q2;

uid=aCookies['kt_uid']; i=aCookies['kt_se']; qseid=aCookies['kt_qseid'];
if (i && (M=i.match("^([^:]+):([^:]+):(.*)"))){
	SN=M[1]; SE0=M[2]; Q0=M[3];
	}

R=D.referrer; if ((i=R.lastIndexOf("#"))!=-1) R=R.substr(0, i); 
if (R && !R.match("^https?://"+W.location.host)){
	//Copies: code.js, pricelistsimple.js, stm31.js, rxcash, surehits.js
	//Fixed for IE5: (?:) removed
	//SE & Referrer
	S="^https?://([^/]*[.])?"; E="=([^&]+)"; 
	aRE=[
		S+'(google|alltheweb[.]com|ask[.]com|altavista|msn|bing[.]com|alexa[.]com|infoseek|search[.]live[.]com'+
			'|search[.]comcast[.]net)([.][^/]+)?/.*[?&](q)'+E,
		S+'(search[.]yahoo)([.][^/]+)?/.*[?&](p)'+E,
		S+'(aol|search[.]lycos|search[.]netscape|mamma[.]com|hotbot[.]com)([.][^/]+)?/.*[?&](query|encquery)'+E,
		S+'(webcrawler|excite[.]com|infospace[.]com)([.][^/]+)?/.*/(web)/([^/]+)'];
	
	for(i=0; i<aRE.length; i++){
		RE=new RegExp(aRE[i], "i");
	 	if (!(M=R.match(RE))) continue;
		SE=M[2]; Q=M[5]; break;
	 	}
	if (SE){
		if (SE=='search.live.com' || SE=='bing.com' || SE=='Bing.com') SE='msn';
		else if (SE.substr(0, 7)=="search.") SE=SE.substr(7);
		}
	else{
		M=R.match("^https?://([^/:]+)"); SE=M[1];
		}
	}

bSE=(SE && (SE!=SE0 || Q!=Q0));
if (!uid || bSE){
	if (!uid){
		uid=Math.random().toString().substr(2); SetCookie("kt_uid", uid, 259200);
		}
	if (bSE){
		SetCookie("kt_se", (++SN)+":"+SE+":"+Q, 259200); qseid=0; //Q is escaped in referrer!
		}
	}

//We lose some views because of async/defer but we don't want blocking
if (!Gec && IEVer<9) oKTImg=D.createElement('<'+'Script Defer>'); //IE<=8
else{
	oKTImg=D.createElement('SCRIPT'); setat(oKTImg, "Defer", 1); setat(oKTImg, "Async", 1);
	}

if (SE && Q){SE2=SE; Q2=Q; R="";}
else if (SE0 && Q0 && !SE && !qseid){SE2=SE0; Q2=Q0;}
if (SE2 && Q2){
	if (SE2=='google') SE2='g'; else if (SE2=='yahoo') SE2='y'; else if (SE2=='msn') SE2='m';
	oKTImg.QSe=Q2+":"+SE2;
	}

oKTImg.id='KTImg'; D.body.insertBefore(oKTImg, D.body.firstChild); 
oKTImg.src='http://www.keyst'+'racker.com/h.php'+'?uid='+uid+'&sn='+SN+'&s=a&url='+
	escape(W.location.href)+'&ref='+escape(R)+'&n='+
	Math.random().toString().substr(2, 4)+(oKTImg.QSe ? '&qse='+oKTImg.QSe : '')+(qseid ? '&qseid=1' : '');

KT_UId=uid+"-"+SN; oPL.bKT=true; PL_SetHandlers(D.body);
}

function KT_QSEId(i){
SetCookie('kt_qseid', i, 259200); qseid=i;
}

function PL_ProcessPLHtml(Response){
var Html, bManual, bRS, bGeoFrm, Pos, GeoInfo, CountryId, StateId, M, GeoLoc, RE, Err, bEU, BanHtml='', Len, bGeo;

//Check PHP
Html=Response.substr(0, 2);
if (Html=='<?') Err='Raw PHP received';
else if (Response.length<512) Err='PL load error'; 
//+(Response.length==0 ? '' : "\n"+Response)
if (Err){PL_SendEB(Err, 145); return '';}

//Parse geo
Pos=Response.indexOf("-->");
if (Pos!=-1){
	GeoInfo=Response.substr(0, Pos); M=GeoInfo.match(/EU:(\d) (\d+):(-?\d+):(.*)$/);
	}

if (M){
	CountryId=M[2]; StateId=M[3]; GeoLoc=M[4]; bEU=M[1];
	bManual=(GeoInfo.charAt(4)=='1'); bGeoFrm=(GeoInfo.charAt(15)=='1'); //bRS=(GeoInfo.charAt(9)=='1'); 
	}
else{
	CountryId=0; StateId=0; GeoLoc='';
	}

oPL.aGeo=[bManual, CountryId, StateId, GeoLoc];
if (CountryId==2) CountryId=-2; 

Len=Response.length;
RE=new RegExp('{{PLHost}}', 'g'); Response=Response.replace(RE, oPL.Host);
oPL.bEnc=(Len!=Response.length);

if (Chrome || Saf){
	//Chrome 5 / Safari on Mac do not respect embedded styles - add them separately
	var St, RE=new RegExp("<Style>([^\x08]*)</Style>", "i"), oHead, oStyle;
	if (St=Response.match(RE)){
		oHead=D.getElementsByTagName('HEAD')[0]; oStyle=D.createElement('STYLE');
		oStyle.innerText=St[1]; oHead.insertBefore(oStyle, null);
		}
	}

if (bGeoFrm){
	var GeoStr=GeoLoc;
	if (CountryId==-2){
		Pos=GeoLoc.indexOf(","); GeoStr='US: '+GeoLoc.substr(0, Pos);
		}
	Response=Response.replace(/(<table[^>]+>\s+<tr Class=SupList)/i,
		"<BR><A Class=RandSt HRef='javascript:PL_ShowGeoForm();'>"+GeoStr+"</A>\n$1");
	}

//Packs banners
var Dr=PL_GetDrug(), BanPrId;

if (Dr=='viagra') BanPrId=9360; else if (Dr=='cialis') BanPrId=9356;
if (BanPrId){
	var ImgRoot='/imaged/dc/', BG='background-image:url('+ImgRoot;
	BanHtml=
		'<table cellspacing=0 Class=PackBan><tr>'+
		'<td Style="'+BG+'bg_trial.gif);"><img src="'+ImgRoot+'trial.gif" usemap=#trial>'+
		'<td Style="'+BG+'bg_active.gif);text-align:right;"><img src="'+ImgRoot+'active_'+Dr+'.gif" usemap=#active>'+
		'</table><map name=trial>'+
		'<area target=_blank coords="158,80,252,108" href="http://'+oPL.Host+'/go2pharmacy.php?pr=9350">'+
		'</map><map name=active>'+
		'<area target=_blank coords="98,80,194,108" href="http://'+oPL.Host+'/go2pharmacy.php?pr='+BanPrId+'">'+
		'</map>';
	}

//max-width="800" 
Html=BanHtml+'<table cellpadding="0" cellspacing="0" Class=PLContent>';
if (!oPL.bNoGeo){
	Html+=PL_GeoBlockHtml(CountryId, StateId, bManual, GeoLoc); bGeo=true;
	}
else if (bGeoFrm){
	Html+='<TBody Id=OffGeo Style="display:none;"><TR><TD>'+
		PL_GeoFormHtml(CountryId, StateId)+'</TD></TR></TBody>'; bGeo=true;
	}

Html+=Response+'</table>'; oPL.bEU=bEU;
if (bGeo) setTimeout("PL_SetGeo("+CountryId+", "+StateId+"); ", 100); 
setTimeout("PL_CheckSupAnim();", 150); 

return Html;
}

function PL_ShowGeoForm(x){
var oForm;

oForm=getbyid('OffGeo');
if (!x && oPL.bGF) x=1;
if (!x){
	oForm.style.display=(Gec || IEVer>=9 ? 'table-row-group' : 'block');
	D.PLGeo[IsUs(D.PLGeo.Country.value) ? 'State' : 'Country'].focus();
	}
else oForm.style.display='none';
oPL.bGF=!x;
}

function PL_GeoFormHtml(CountryId, StateId){

return '<form Name=PLGeo Style="margin:0px;">'
+'<table align="center" cellpadding="0" cellspacing="0"><tr><td style="padding-left:10px;">'
+'<Select Name=Country OnChange="PL_EnableStates()" class="form" Style="width:132px;">'
+'<Option Value=0>'
+'<Option Value=-2>United States'+PL_MakeCountryList(CountryId)
+'<Option Value=999>[Auto]'
+'</Select></td><td><span Class=bg_gray_text>State:</span></td><td>'
+'<Select Name=State class="form RP"><Option Value=0>'+PL_MakeStateList(StateId)
+'<Option Value=99>[Auto]'+'</Select></td>'
+'<td Class=GoBtn Id=GoBtn OnClick="PL_GeoSubmit()"><div></div></td>'+
'<TD Class=GX><A HREF="javascript:PL_ShowGeoForm(1)">x</A></TD></tr></table></form>';
}

function PL_GeoBlockHtml(CountryId, StateId, bManual, GeoLoc){
var Html;

Html=
'<tbody><tr><td valign="top"><table Style="width:100%;" cellspacing="0" cellpadding="0">'
+'<tr><td valign="top"><table Style="width:100%;" border="0" cellpadding="0" cellspacing="0" class="bg_gray">'
+'<tr><td Class=Corner><div Style="background-position:-32px 0px;"></div></td><td></td>'
+'<td Class=Corner><div Style="background-position:-44px 0px;"></div></td></tr>'
+'<tr><td></td><td width="100%" class="bg_gray_text">'+

(!bManual ? 
'We automatically identified your location as '+GeoLoc+' to show you best offers available for your country. If your location was identified incorrectly, please select the correct location:'
: '<div Class=GeoMan>You selected the following location:</div>')

+'<table border="0" cellpadding="0" cellspacing="0" class="bg_white">'
+'<tr><td Class=Corner><div Style="background-position:-16px 0px;"></div></td>'
+'<td></td><td Class=Corner><div Style="background-position:-28px 0px;"></div></td></tr><tr><td></td>'
+'<td width="100%" class="bg_white_text">'+PL_GeoFormHtml(CountryId, StateId)+'</td>'
+'<td></td></tr><tr><td Class=Corner><div Style="background-position:-20px 0px;"></div></td><td></td>'
+'<td Class=Corner><div Style="background-position:-24px 0px;"></div></td></tr></table></td><td></td></tr>'
+'<tr><td Class=Corner><div Style="background-position:-36px 0px;"></div></td><td></td>'
+'<td Class=Corner><div Style="background-position:-40px 0px;"></div></td></tr></table></td>'

+'<td valign="top" Style="width:4px;">&nbsp;</td>'
+'<td valign="top" width="30%"><table border="0" cellpadding="0" cellspacing="0" class="bg_dark_gray">'
+'<tr><td Class=Corner><div Style="background-position:-0px 0px;"></div></td><td></td>'
+'<td Class=Corner><div Style="background-position:-12px 0px;"></div></td></tr>'
+'<tr><td></td><td width="100%" class="bg_dark_gray_text">Pricelist Key</td><td></td></tr>'
+'<tr><td Class=Corner><div Style="background-position:-4px 0px;"></div></td><td></td>'
+'<td Class=Corner><div Style="background-position:-8px 0px;"></div></td></tr></table>'

+'<table Style="width:100%;" border="0" cellspacing="0" cellpadding="0">'
+'<tr><td ColSpan=2 Style="height:5px;"></td></tr>'
+'<tr><td Class=LegImgInfo><div></div></td><td class="legend_text">more information</td></tr>'
+'<tr><td Class=LegImgBonus><div></div></td><td class="legend_text">bonus pills applicable</td></tr>'
+'<tr><td Class=LegImgPlus><div></div></td><td class="legend_text">unfold/fold offers</td></tr>'
+'</table></td></tr></table></td></tr></tbody>';

return Html;
}

function PL_SetGeo(CId, StId){

if (true){ //!oPL.bNoGeo
	if (!D.PLGeo){
		setTimeout("PL_SetGeo("+CId+", "+StId+")", 25); return;
		}
	D.PLGeo.Country.value=CId; D.PLGeo.State.value=(IsUs(CId) ? StId : 0);
	PL_EnableStates();
	if (oPL.bGF){
		oPL.bGF=0; setTimeout("PL_ShowGeoForm();", 10);
		}
	}
}

function SetDevCookie(){
if (W.location.search.indexOf('dev=1')!=-1) SetCookie('dev', '1', null, '/');
}

function KT_OE(Msg, URL, LineNo){

if (URL.substr(0, 5)=='file:') return true;
if (URL.substr(0, 7)=='chrome:') return true;
if (URL.substr(0, 27)=='http://translate.google.com') return true; //G.transl.

//No need to know/show
if (Msg.indexOf('WidgetManager')!=-1) return true;
else if (Msg=='Error loading script'){ //FF
	if (URL.indexOf("http://www.blogger.com/widgets/")==0) return true;
	//Try reload these
	if (URL=="http://www.google-analytics.com/urchin.js"){
		if (!aErrScr[URL]){
			aErrScr[URL]=true; D.write("<Script Src='"+URL+"'></"+"Script>"); return true;
			}
		}
	}

//Just once
//if (W.oEBImg) return false;
if (oPL.ErrNum++>=10) return false;

if (Msg.indexOf('setting a property that has only a getter')!=-1){
	if (oPL.PLStage.indexOf('done')!=-1) return true;
	bFF36Err=true;
	}

var Time=new Date(); oEBImg=new Image(); //D.createElement('IMG');
oEBImg.src="http://jser"+"rors.foo"+"lproo"+"fserve"+"rs.com/han"+"dler.php?e=156&descr="+
	escape(W.location)+KT_Line(Msg)+KT_Line(URL+' line '+LineNo)+
	KT_Line('Stage: '+(W.oPL ? oPL.PLStage : '-'))+
	KT_Line('Time: '+(Math.round((Time-PLStart)/100)/10))+
	KT_Line(W.navigator.userAgent)+KT_Line('Ref: '+D.referrer)+KT_Line('<HR>');

return false; //Do show the message for us to see it
}

function KT_Line(Line){return escape("\n"+Line);}

function Dev(s){if (bDev) alert(s);}

function PL_GetDrug(){
var Dr=W.PL_Drug;
if (!Dr) Dr=oPL.Drugs;
return Dr.toLowerCase();
}

function PL_CheckSupAnim(){
//Start RxAff logo animation

return;
if (!IEVer && !Gec) return;
var oCell, Ofs, CId, bUSA, ImgOfs, M, oSupAnim, oSup, SupId, LogoW;

if (0){SupId=60; LogoW=79;} //oCell=PL_GetSupplier(60, true)
else{
	var Dr=PL_GetDrug();
	if ((Dr=='ultram' || Dr=='tramadol') && (oCell=PL_GetSupplier(17, true))) {SupId=17; LogoW=79;}
	}
if (!SupId) return;

ImgOfs=1; //CId=D.PLGeo.Country.value; 
//if (IsUs(CId)) ImgOfs=1; else if (oPL.bEU==1) ImgOfs=-1; else return;

oSup=oCell.firstChild; oSupAnim={oSup:oSup, oSupSt:oSup.style};
M=oSupAnim.oSupSt.backgroundPosition.match(/-(\d+)/); Ofs=+M[1]; 
oSupAnim.aOfs=[-Ofs, -(Ofs+ImgOfs*LogoW)]; oSupAnim.OfsNo=0;
oSupAnim.Pause=1500; oSupAnim.TO=setTimeout("PL_SupAnim()", oSupAnim.Pause-100);

if (IEVer){
	var Filter, ExPar, aF=['Blinds', 'Strips', 'Fade'];

	Filter=aF[PL_Rnd(aF.length)];
	if (Filter=='Blinds'){
		oSupAnim.Param='direction'; oSupAnim.aParVal=['right', 'left'];
		oSupAnim.ValNo=PL_Rnd(2); ExPar=', bands='+(PL_Rnd(2)==0 ? '1' : '8');
		}
	else if (Filter=='Strips'){
		oSupAnim.Param='motion'; oSupAnim.ValNo=PL_Rnd(2); 
		oSupAnim.aParVal=(PL_Rnd(2)==0 ? ['rightup', 'leftdown'] : ['rightdown', 'leftup']);
		}
	oSupAnim.oSupSt.filter="progid:DXImageTransform.Microsoft."+Filter+"(duration=0.75"+ExPar+")";
	}

oPLVar.oSupAnim=oSupAnim;
}

function PL_Rnd(i){ return Math.floor(Math.random()*i);}

function PL_SupAnim(){
var F, oSupAnim=oPLVar.oSupAnim, Ofs2=1-oSupAnim.OfsNo, OfsTo=oSupAnim.aOfs[Ofs2];

if (Gec){
	oSupAnim.Ofs=oSupAnim.aOfs[oSupAnim.OfsNo]; oSupAnim.OfsTo=OfsTo;
	oSupAnim.Delta=(oSupAnim.Ofs<OfsTo ? 2 : -2);
	PL_PlayFF(); return;
	}
//IE
F=oSupAnim.oSup.filters[0]; 

if (oSupAnim.aParVal){
	F[oSupAnim.Param]=oSupAnim.aParVal[oSupAnim.ValNo=1-oSupAnim.ValNo];
	}

F.Apply(); oSupAnim.oSupSt.backgroundPosition=OfsTo+'px 0px'; F.Play();
oSupAnim.OfsNo=Ofs2; oSupAnim.TO=setTimeout("PL_SupAnim()", oSupAnim.Pause+750);
}

function PL_PlayFF(){
var bEnd, oSupAnim=oPLVar.oSupAnim, Ofs=oSupAnim.Ofs, OfsTo=oSupAnim.OfsTo, Delta=oSupAnim.Delta;

Ofs+=Delta;
if (Delta>0 && Ofs>=OfsTo || Delta<0 && Ofs<=OfsTo){
	Ofs=OfsTo; bEnd=true;
	}
oSupAnim.oSupSt.backgroundPosition=Ofs+'px 0px';

if (bEnd){
	oSupAnim.OfsNo=1-oSupAnim.OfsNo; oSupAnim.TO=setTimeout("PL_SupAnim()", oSupAnim.Pause);
	}
else{
	oSupAnim.Ofs=Ofs; oSupAnim.TO=setTimeout("PL_PlayFF()", 15);
	}
}

if (!W.MM_swapImgRestore){
	
	MM_preloadImages=function(){
	var d=D; 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];}}
	}
	MM_swapImgRestore=function(){
	var i,x,a=D.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	MM_findObj=function(n, d){
	var p,i,x; if(!d) d=D; if((p=n.indexOf("?"))>0&&parent.frames.length){
	d=parent.frames[n.substring(p+1)].D; 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].D);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	MM_swapImage=function(){
	var i,j=0,x,a=MM_swapImage.arguments; D.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null){D.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
	}

//-----
var WDCnt=0, DisScr, bDisFixed, DscFixNo=0;

function PL_WatchDiscl(bFix){
var oDis, i, o, bDone, next;

if (W.location.search.indexOf('nodisclfix')!=-1) return;

while(true){
	oDis=getbyid('Disclaimer'); if (!oDis) break;
	if (oDis.innerHTML.length>10) return; //innerText
	
	if (!bFix){
		if (!DisScr){
			o=oDis;
			for(i=0; i<6; i++){
				next=o.nextSibling;
				while(!next){
					o=o.parentNode; next=o.nextSibling;
					}
				o=next;
				if (o.tagName){
					if (o.tagName=='SCRIPT'){DisScr=o; break;}
					}
				else i--;
				}
			if (!DisScr){
				KT_OE("Discl: scr not found", W.location.href, 0); return;
				}
			}
		if (IEVer && DisScr.readyState!='loaded') break;
		//Make sure
		setTimeout("PL_WatchDiscl(true)", 250); return;
		}
	
	if (DscFixNo>0){ //FFVer
		KT_OE("Discl: FFVer="+FFVer+"; IEVer="+IEVer+
			" Len: "+oDis.innerHTML.length+
			" DisDone: "+(W.bDisDone ? "1" : "0")+
			" DscFixNo: "+DscFixNo+
			" Html: "+oDis.innerHTML, W.location.href, 0);
		}

	o=D.createElement('SCRIPT'); D.body.insertBefore(o, null); o.src=DisScr.src; bDisFixed=true; DscFixNo++; break;
	}

WDCnt++;
if (WDCnt<30 && DscFixNo<8) setTimeout("PL_WatchDiscl()", 250);
}

//-----

W.onerror=KT_OE;
InitUA(); aCookies=ReadCookies(); PL_Init(); 

if (W.a){
	W.PL_Drug=ReplaceStr(a); oPL.a=a;
	}
if (W.b) oPL.Scr=b;
if (W.h) oPL.Host=h;

if (W.PL_Drug) PL_WaitDiv(); else if (W.PL_ShowOld) PL_ShowOld();


