// -----------------------------------------------------------
// Globals
// -----------------------------------------------------------
var enableWatchdog=false;
var vtLocn="/mainframes/vt/";
var vtBase="/vt/";
var perlBase="/cgi-bin/";
var vtLog=vtBase+"vt3.gif?";
var vtMailer="/servlet/FormReceiver";
var vtDogHouse="http://mainframes.com"; //d2.htm
var vtBug=false;
   if(location.toString().indexOf(vtBase)>0)vtBug=true;
   if(location.toString().toLowerCase().indexOf("test")>0)vtBug=true;
var vtIE=false; if(navigator.userAgent.toLowerCase().indexOf("msie")>-1)vtIE=true;
var vtGotData=false; var vtAtCode="-a2t2-";
var vtGroupID, vtEmail, vtFname, vtUrl, vtString, vtSetLog;
var vtRemoteHost, vtRemoteAddr, vtWin3;
var vtDelay=window.setInterval("vtGetData()",200);

// -----------------------------------------------------------
// GetData
// -----------------------------------------------------------
function vtGetData(){
   if(!document)return; window.clearInterval(vtDelay);
   if(!vtWatchDog()){if(!vtBug)return;}
   if(vtIsReload()){if(!vtBug)return;}
   if(vtGotData){if(!vtBug)return;}
   if(vtSuccessOrFailure())return;
   vtString=vtGetHash();
   if(!vtString)vtString=vtReadCookie();
   if(!vtString)vtString="anonymous,anon."+vtGetUserID()+"@unknown.com";
   vtString=vtSwap(vtString,vtAtCode,"@");
   var dog=vtString.indexOf(",");
   vtGroupID=vtString.slice(0,dog);
   vtEmail=vtString.slice(dog+1);
   vtUrl=vtGetUrl();
   vtFname=vtGetFname(vtUrl);
   vtLogThis();
   vtWriteCookie();
   if(document.f1){if(document.f1.email){if(vtGroupID!="anonymous")document.f1.email.value=vtEmail;}}
   vtGotData=true;
   dog=window.setTimeout("vtStatus()",500);
}//getdata
// -----------------------------------------------------------
function vtSuccessOrFailure(){
   var srch=location.search;
   if(srch=="?success")srch="yes";
   if(srch=="success")srch="yes";
   if(srch=="?failure")srch="no";
   if(srch=="failure")srch="no";
   if((srch!="yes")&&(srch!="no"))return false;
   if(srch=="yes")alert("Thank you for your message.");
   if(srch=="no")alert("Your message failed to send for some reason.\nPlease try again.\nOr write to webmaster@sdsusa.com");
   location.search="";
   return true;
}//vtSuccessOrFailure
// -----------------------------------------------------------
// Read, Write Data
// -----------------------------------------------------------
function vtLogThis(fname){
   if(!fname)fname=vtFname;
   vtSetLog=vtLog+vtGroupID+","+vtEmail+","+vtRemoteHost+","+vtRemoteAddr+","+fname;
   var dog=new Image(); dog.src=vtSetLog;
}//logthis
//-----------------------------------------------------------
function vtWriteCookie(){
   document.cookie="vt3="+vtGroupID+","+vtEmail+vtGetEndCookie();
   document.cookie="vt3Target="+vtUrl+"||; path=/";
}//writecookie
//----------------------------------------------------------------
function vtReadCookie(){
   var ck=document.cookie;
   if(!ck)return null;
   if(ck.indexOf("vt3=")<0)return null;
   ck=ck.slice(ck.indexOf("vt3=")+4);
   ck=ck.slice(0,ck.indexOf("||"));
   return ck;
}//readcookie
//----------------------------------------------------------------
function vtGetUrl(){
   var fish=window.location.toString();
   if(fish.indexOf(vtBase)>-1)fish=null;
   if((!fish)&&(vtHasOpener()))fish=opener.location.toString();
   if(fish){if(fish.indexOf(vtBase)>-1)fish=null;}
   if((!fish)&&(top!=window))fish=top.location.toString();
   if(fish){if(fish.indexOf(vtBase)>-1)fish=null;}
   if((!fish)&&(parent!=window))fish=parent.location.toString();
   if(fish){if(fish.indexOf(vtBase)>-1)fish=null;}
   if(!fish)fish=window.location.toString();
   return fish;
}//getfish
//----------------------------------------------------------------
function vtGetFname(url){
   if(!url)url=window.location.toString();
   //if((url.lastIndexOf("/")>url.lastIndexOf("."))&&(url.slice(-1)!="/"))url=url+"/";
   //if(url.slice(-1)=="/")url=url+"index.htm";
   if(url.indexOf("//")>-1)url=url.slice(url.indexOf("//")+2);
   //if(url.indexOf("/")>-1)url=url.slice(url.indexOf("/")+1);
   return url;
}//getfname

// -----------------------------------------------------------
// Watchdog => remoteHost, remoteAddr
// -----------------------------------------------------------
function vtWatchDog(fish){
   if(!fish)fish=vtFetch(perlBase+"vt3.pl");
   if(!fish)fish="bark;host;addr";
   fish=fish.split(";");
   if(fish.length!=3)return true;
   vtRemoteHost=fish[1];
   vtRemoteAddr=fish[2];
   if(!enableWatchdog)fish[0]="exception";
   if(fish[0]=="bad"){vtDogBark();return false;}
   return true;
}//watchdog
//-----------------------------------------------------------------
function vtDogBark(){
   var subj ="Dog Barked at "+vtRemoteHost;
   var bdy ="The guard dog at%0A"+location.toString()
           +"%0Ajust chased away a visitor from%0A"
           +vtRemoteHost+"%0A"+vtRemoteAddr;
   var bk="%0A";
   var url=vtMailer;
   url=url+"?to=webmaster@sdsusa.com";
   url=url+"&from=watchdog@sdsusa.com";
   url=url+"&subject="+subj;
   url=url+"&body="+bdy;
   url=url+"&log="+vtFname+bk+vtGroupID+", "+vtEmail+bk+vtRemoteAddr+", "+vtRemoteHost;
   vtPost(url);
   location.replace(vtDogHouse);
}//dogbark
//-----------------------------------------------------------------
function vtSendMail(msg,subject,to,from){
   if(!msg)return;
   if(!subject)subject="Message from web site";
   if(!to)to="webmaster@sdsusa.com";
   if(!from)from=location.hostname+"@sdsusa.com"
   var bk="%0A";
   var url=vtMailer;
   url=url+"?to="+to;
   url=url+"&from="+from;
   url=url+"&subject="+subject;
   url=url+"&message="+msg;
   url=url+"&log="+vtFname+bk+vtGroupID+", "+vtEmail+bk+vtRemoteAddr+", "+vtRemoteHost;
   vtPost(url);
}//vtSendMail
//-------------------------------------------------------------------
function vtNotify(fname,addr){
   if(!fname)return;
   if(!addr)addr="downloads@sdsusa.com";
   var subj="Download of "+fname;
   var bdy ="Someone just downloaded the file "+fname;
   var id="They came from "+vtRemoteAddr+"   "+vtRemoteHost;
   var msg="For a better ID, search tomorrow's logs for "
          +vtGroupID+", "+vtEmail+", and "+vtRemoteAddr;
   var bk="%0A";
   var url=vtMailer;
   url=url+"?to="+addr;
   url=url+"&subject="+subj;
   url=url+"&body="+bdy;
   url=url+"&id="+id;
   url=url+"&msg="+msg;
   url=url+"&log="+vtFname+bk+vtGroupID+", "+vtEmail+bk+vtRemoteAddr+", "+vtRemoteHost;
   vtPost(url);
}//notify
//---------------------------------------------------------------

// -----------------------------------------------------------
// Sign On
// -----------------------------------------------------------
function requireSignOn(url){
   if(url.indexOf("http://")<0){
      var base=location.toString();
      base=base.slice(0,base.lastIndexOf("/"));
      if(url.indexOf("/")==0){base=location.protocol+"//"+location.host;}
      if(url.indexOf("./")==0)url=url.slice(1);
      if(url.indexOf("../")==0){
         url=url.slice(2);
         dog=base.lastIndexOf("/");
         if(dog>-1)base=base.slice(0,dog);
      }//if
      if(url.indexOf("/")!=0)url="/"+url;
      url=base+url;
   }//if
   if(vtGroupID=="anonymous"){
      url=vtBase+"vtSignon.htm#"+url;
      if(vtWin3){if(!vtWin3.closed){
         vtWin3.location.replace(url);
         vtWin3.location.reload(true);
         vtWin3.focus();
         return false;
      }}//if if
      vtWin3=window.open(url,"vtWin3",vtGetFlist());
      return false;
   }//if
   location=url;
   return false;
}//requiresignon
//----------------------------------------------------------------
function preLoadSignOn(){
   vtGetData();
   vtUrl=location.hash;
   if(vtUrl.indexOf("#")==0)vtUrl=vtUrl.slice(1);
   vtFname=vtGetFname(vtUrl);
   if(vtGroupID!="anonymous")document.f1.email.value=vtEmail;
   document.f1.name.focus();
}//preloadsignon
//----------------------------------------------------------------
function vtSubmit(nd){
   var df=document.f1; var err="";
   if(df.name.value.length<1)err=err+"Please provide your name.\n";
   if(df.company.value.length<1)err=err+"Please provide your company's name.\n";
   if(df.phone.value.length<10)err=err+"Please provide your phone number.\n";
   if(!vtIsAddr(df.email.value))err=err+"Please provide your e-mail address.\n";
   if(!vtIsCommercial(df.email.value))err=err+"Please provide a company address,\nrather than a public one.\nThank you.";
   if(err.length>0){alert(err);return;}

   vtGroupID="SdsSignOn";
   vtEmail=df.email.value;
   vtWriteCookie();

   if(vtHasOpener()){try{opener.vtGotData=false; opener.vtGetData();} catch(e){} }
   vtOK=true;
   if(vtIsCompetitor(df.email.value))vtOK=false;

   df.to.value="websales@sdsusa.com";
   df.subject.value="Visitor Signed On for "+vtFname;
   df.visited.value="Visitor signed on at link to "+vtFname;
   df.success.value=vtBase+"vtClose.htm#success";
   df.failure.value=vtBase+"vtClose.htm#failure";

   if(vtHasOpener()){
      if(vtOK)opener.location=vtUrl;
      if(!vtOK)try{opener.vtDogBark();} catch(e){}
      opener.focus();
   }//if
   vtFormReceiver(nd);
}//submit
//-----------------------------------------------------
function vtFormReceiver(nd){
   while(nd.nodeName.toLowerCase()!="form"){nd=nd.parentNode;}
   var form=eval("document."+nd.getAttribute("name"));
   nd.setAttribute("action","/servlet/FormReceiver");
   nd.setAttribute("method","post");
   var inp;
   var url=location.toString();
   if(url.indexOf("#")>-1)url=url.slice(0,url.indexOf("#"));
   if(url.indexOf("?")>-1)url=url.slice(0,url.indexOf("?"));
   if(!form.success){
      inp=document.createElement("input");
      inp.setAttribute("type","hidden");
      inp.setAttribute("name","success");
      nd.appendChild(inp);
      form.success.value=url+"?success";
   }//if
   if(!form.failure){
      inp=document.createElement("input");
      inp.setAttribute("type","hidden");
      inp.setAttribute("name","failure");
      nd.appendChild(inp);
      form.failure.value=url+"?failure";
   }//if
   if(!form.log){
      inp=document.createElement("input");
      inp.setAttribute("type","hidden");
      inp.setAttribute("name","log");
      nd.appendChild(inp);
   }//if
   form.log.value=vtFname+"\n"+vtGroupID+", "+vtEmail+"\n"+vtRemoteAddr+", "+vtRemoteHost;
   form.submit();
   return false;
}//vtFormReceiver
//-----------------------------------------------------

// -----------------------------------------------------------
// Utilities
// -----------------------------------------------------------
function $(id){return document.getElementById(id);}
// -----------------------------------------------------------
function vtFetch(url){
   var req=vtGetHttpReq(); if(req==null)return;
   req.open("get",url,false);
   try{req.send(null);} catch(e){return null;}
   if((req.readyState!=4)||(req.status!=200))return null;
   return req.responseText;
}//fetch
//---------------------------------------------------------------
function vtPost(url){
   var req=vtGetHttpReq(); if(req==null)return;
   req.open("get",url,false);
   try{req.send(null);} catch(e){return null;}
}//post
//-------------------------------------------------------------------
function vtGetHttpReq(){
   if(typeof XMLHttpRequest!="undefined")return new XMLHttpRequest();
   try{return new ActiveXObject("Microsoft.XMLHTTP");} catch(e){}
   try{return new ActiveXObject("msxml2.XMLHTTP");} catch(e){}
   try{return new ActiveXObject("msxml2.xmlhttp.5.0");} catch(e){}
   try{return new ActiveXObject("msxml2.xmlhttp.4.0");} catch(e){}
   try{return new ActiveXObject("msxml2.xmlhttp.3.0");} catch(e){}
   return null;
}//gethttpreq
// -----------------------------------------------------------
function vtGetHash(){
   try{if(!window.location)return null;} catch(e){return null;}
   var hash=window.location.toString();
   var dog=hash.indexOf("#");
   if(dog<0)return null;
   hash=hash.slice(dog+1);
   dog=hash.indexOf("?");
   if(dog>-1)hash=hash.slice(0,dog);
   if(hash=="")return null;
   if(hash.indexOf(vtAtCode)<3)return null;
   return hash;
}//gethash
//-------------------------------------------------------------
function vtStatus(){
   var fish="vt3 OK";
   if((!vtRemoteHost)&&(!vtRemoteAddr))fish="vt3 no";
   top.defaultStatus=fish;window.defaultStatus=fish;defaultStatus=fish;status=fish;
   if(vtBug)try{vtTest(fish+"; "+status);} catch(e){}
}//status
//-------------------------------------------------------------
function vtIsReload(){
   var dog=document.cookie.indexOf("vt3Target=");
   if(dog<0)return false;
   var fish=document.cookie.slice(dog);
   fish=fish.slice(0,fish.indexOf("||"));
   if(fish=="vt3Target="+location.toString())return true;
   return false;
}//isreload
//-------------------------------------------------------------
function vtGetUserID(){
   var today=new Date();
   var year=today.getUTCFullYear();
   var month=today.getUTCMonth();
   var day=today.getUTCDate();
   var hr=today.getUTCHours();
   var min=today.getUTCMinutes();
   var sec=today.getUTCSeconds();
   var yr=year-2000;
   month=month+1;
   if(yr<10)yr="0"+yr;
   if(month<10)month="0"+month;
   if(day<10)day="0"+day;
   if(hr<10)hr="0"+hr;
   if(min<10)min="0"+min;
   if(sec<10)sec="0"+sec;
   return yr+month+day+"."+hr+min+sec;
}//getuserid
//-------------------------------------------------------------
function vtGetEndCookie(){
   var expDate=new Date();
   expDate.setTime( expDate.getTime() + (180 * 24 * 60 * 60 * 1000) );
   expDate=expDate.toGMTString();
   return "||; expires=" +expDate +"; path=/";
}//getendcookie
//-------------------------------------------------------------
function vtGetFlist(){
   var flist='status=yes,scrollbars=auto,resizable=yes,toolbar=no,menubar=no';
   var w=360; var h=300; var x=340; var y=340;
   var sizelist='width='+w +',height='+h +',top='+y +',screenY='+y +',left='+x +',screenX='+x;
   return flist+","+sizelist;
}//getflist
//-------------------------------------------------------------
function vtSwap(ss,os,ns){
   if(ss==null)return ss; if(ss=="")return ss;
   if(os==null)return ss; if(os=="")return ss;
   if(ns==null)ns=""; if(ns.indexOf(os)>-1)return ss;
   if(ss.indexOf(os)<0)return ss;
   while(ss.indexOf(os)>-1){
      ss=ss.split(os);
      ss=ss.join(ns);
   }//while
   return ss;
}//swap
//===VERIFY==========================================================
var pA=["`","~","!","#","$","%","^","&","*","+","=","(",")","{","}","[","]","<",">","|","\\",":",";","\"","'","\,","/"];
function vtIsAddr(ss){
   if(!ss)return false;
   if(ss.length<5)return false;
   while((ss.indexOf(" ")==0)&&(ss.length>1)){ss=ss.slice(1);}
   while((ss.indexOf(" ")==ss.length-1)&&(ss.length>1)){ss=ss.slice(0,-1);}
   if(ss.length<5)return false;
   if(ss.indexOf("@")<1)return false;
   if(ss.indexOf("@")>ss.lastIndexOf("."))return false;
   if(ss.indexOf("@")!=ss.lastIndexOf("@"))return false;
   if(ss.lastIndexOf(".")<0)return false;
   if(ss.lastIndexOf(".")>ss.length-2)return false;
   for(i=0;i<pA.length;i++){if(ss.indexOf(pA[i])>-1)return false};
   return true;
}//isaddr()
//----------------------------------------------------------------
var publicAddrs=["rediffmail.com","msn.com","@abc.","@aol.","@dsl.","@earthlink.","@excite.","@flash.","@hotmail.","@lollimail.","@mgemail.","@mindspring.","@netzero.","@uslink.","@uswest.","@verizon.","@yahoo."];
function vtIsCommercial(ss){
   for(i=0;i<publicAddrs.length;i++){if(ss.indexOf(publicAddrs[i])>-1)return false;}
   return true;
}//iscommercial
//----------------------------------------------------------------
function vtIsCompetitor(addr){
   var nam=addr.slice(0,addr.indexOf("@"));
   addr=addr.slice(addr.indexOf("@"));
   for(var i=0;i<vtCompetitors.length;i++){
      if(addr==vtCompetitors[i]){vtGoAway(nam,addr);return true;}
      if(nam==vtCompetitors[i]) {vtGoAway(nam,addr);return true;}
   }//for
   return false;
}//iscompetitor
//----------------------------------------------------------------
var vtCompetitors=new Array();
   vtCompetitors.push("@aes.com");
   vtCompetitors.push("@aesclever.com");
   vtCompetitors.push("@asg.com");
   vtCompetitors.push("@becom.com");
   vtCompetitors.push("@bmc.com");
   vtCompetitors.push("@ca.com");
   vtCompetitors.push("@concord.com");
   vtCompetitors.push("@coupers.co.kr");
   vtCompetitors.push("@gaia-si.com");
   vtCompetitors.push("@inautix.com");
   vtCompetitors.push("@indosat.com");
   vtCompetitors.push("@jmr.co.za");
   vtCompetitors.push("@mackinney.com");
   vtCompetitors.push("@mainsoft.dk");
   vtCompetitors.push("@netcsc.com");
   vtCompetitors.push("@opensolutions.esp");
   vtCompetitors.push("@patni.com");
   vtCompetitors.push("@selesta.com");
   vtCompetitors.push("@spectrum-software.com.au");
   vtCompetitors.push("@tivoli.com");
   vtCompetitors.push("@willdata.com");
   vtCompetitors.push("@workers.com.br");
   vtCompetitors.push("jimkeo");
   vtCompetitors.push("@multi-platforms.com");
   vtCompetitors.push("HCLTechnologies");
   vtCompetitors.push("HCL Technologies");
   vtCompetitors.push("jacques.gabay@groovysoft.com");


//================================================================
function vtGoAway(){
   if(vtHasOpener()){
      try{opener.vtDogBark();} catch(e){}
      window.close(); return false;
   }//if
   window.close(); return false;
}//goaway
//----------------------------------------------------------------
function vtHasOpener(){
   if(!opener)return false;
   if(opener.closed)return false;
   try{if(opener.location.toString())return true;}
   catch(e){return false;}
   return false;
}//hasopener
//----------------------------------------------------------------

function vtValCheck(frm){
   while(frm.nodeName.toLowerCase()!="form")frm=frm.parentNode;
   var ara=new Array();
   var ins=frm.getElementsByTagName("input");
   for(var i=0;i<ins.length;i++){ara.push(ins[i]);}
   var tas=frm.getElementsByTagName("textarea");
   for(var t=0;t<tas.length;t++){ara.push(tas[t]);}
   for(var a=0;a<ara.length;a++){
      if(ara[a].value){
         for(var f=0;f<fouls.length;f++){
            if(ara[a].value.indexOf(fouls[f])>-1){
               vtGoAway(); return false;
   }}}}//for if for if

   frm="document."+frm.getAttribute("name");
   var sub=eval(frm+".about");
   var sds=eval(frm+".sdsok");
   if((sds)&&(sub)){
      sub.value=sub.value+" "+sds.value;
      sub=eval(frm+".subject"); if(sub)sub.value="";
      sub=eval(frm+".subjectbox"); if(sub)sub.value="";
   }//if
   frm=frm+".submit();"
   eval(frm);
   return false;
}//vtValCheck
//----------------------------------------------------------------
var fouls="buymeds,netfirms,xanex,drugs,porno,girls, sex,fuck";
fouls=fouls+",adultmovies,adult movies,mybb.ru,bigcocks, cocks,lesbian";
fouls=fouls+"sex machine,sex toy, [URL, [/URL, wiki.cs.uic.edu:8080";
fouls=fouls.split(",");
//================================================================
