// JS file (c)J.P.Lee for SouthportNews.Com Aug2000 - 

// Anyone copying and/or using this file or derivatives based on it
// for unauthorised domains
// by doing so agrees to having their computer network probed
// and the works removed forcibly by any means possible.
// They also agree to indemnify us against any damage caused 
// to their systems.
// Reverse engineering of this code is expressly forbidden also.
// I'll also prosecute you.













debug=false; 
//debug=true; 
nomenu=false;
var d_nn4 = (document.layers);
var d_nn6 = (document.getElementById && !document.all);
var d_ie4 = (document.all && !document.getElementById);
var d_ie5 = (document.all && document.getElementById);
var d_ie =d_ie5||d_ie4;

 ie4 = (document.all) ? true : false;
 ns4 = (document.layers) ? true : false;
 ns6 = (document.getElementById && !document.all) ? true : false;
 isNS=(ns4|ns6);


window.ondragdrop = function (evt) { return false; };
 var mouseX = 0;
 var mouseY = 0;
 var mouseB = 0;
 var oldX = 0;
 var oldY = 0;
 dragging = false;

function getMouseXYB(e) //onMouseMove read mousecoords
{ if (isNS) {mouseX=e.pageX;mouseY=e.pageY;mouseB=e.which; }
  else {mouseX=window.event.clientX;mouseY=window.event.clientY; mouseB=window.event.button;}
}

function mousewentdown(e)
{ getMouseXYB(e) ; //get currrent pos
  if ((mouseB==2) || (mouseB==3))
  { oldX = mouseX; oldY = mouseY;
    if(d_ie&&(window.event.srcElement.tagName=="INPUT"))
    {  return false;    }
    else
    if(d_ie&&(window.event.srcElement.custommenu))
    { dnx="";dny="";
      EventElement=window.event.srcElement;
      showmenubyname(EventElement.custommenu);
       return false; 
    }
    else 
    {if (!nomenu) {dnx="";dny="";     showmenu(M_0);    };//hide menu
     return false;
    }
  }  
  window.status=" "; 
  if (debug)  { show('tag:'+window.event.srcElement.tagName+' Name: '+window.event.srcElement.name+' ID: '+window.event.srcElement.id+'\nSize: '+window.event.srcElement.width+' * '+window.event.srcElement.height+'\nSrc: '+window.event.srcElement.src);} 
}
function mousemoved(e)
{getMouseXYB(e); 
}
function mousewentup(e)
{dragging=false;window.status=""; 
 if (d_nn6) return false; //disable context in NS6
}
function nocontextmenu(e)
{ //event.cancelBubble = true; event.returnValue = false; 
 return false;
}

// capture events, set function
if(d_nn4) 
{
  window.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP );
  window.onmousedown = mousewentdown;
  window.onmouseup = mousewentup;
  window.onmousemove = mousemoved;
}

if(document.addEventListener)// W3C version .. NS6 & Mozilla
{ document.addEventListener("mousedown",mousewentdown,false);
  document.addEventListener("mouseup",mousewentup,false);
  document.addEventListener("mousemove",mousemoved,false);
}
 else //(ie)
{ document.onmousedown = mousewentdown;
  document.onmouseup = mousewentup;
  document.onmousemove = mousemoved;
  document.oncontextmenu = nocontextmenu;
}

function show(m){window.status=m; return true;}

//  ********** Layer functions  ********
layervisible=false;
function writelayer(layer, html)
{if (ie4) eval(layer+'.innerHTML=html;');
 if (ns4) {  document.layers[layer].document.write(html);   document.layers[layer].document.close();}
 if (ns6) document.getElementById(layer).innerHTML=html;;
}

function movelayer(layer,x,y,w,h)
{ var ref;
  if(ie4) {eval('ref='+layer+'.style;');}
  else if(ns4) ref=document.layers[layer];
  else if(ns6) ref=document.getElementById(layer).style;
  else show("Menu error: Unknown browser; cannot render.");
  eval('ref.top='+y+';');
  eval('ref.left='+x+';');
  eval('ref.width='+w+';');
  eval('ref.height='+h+';');
}
// *** menu settings

//#527A93


//var menucol1="#708992";//bg frame
//var menucol2="#83A2AD";//bg cells
//var menucol4="#49595F";//bg cellover
//var menucol3="white";  //text

//var menucol1="#708992";//bg frame
//var menucol2="#FFFFFF";//bg cells
//var menucol4="#C0DDE7";//bg cellover
//var menucol3="#214862";  //text

var menucol1="#708992";//bg frame
var menucol2="#FFFFFF";//bg cells
var menucol4="#D5E7FF";//bg cellover
var menucol3="#214862";  //text




var menufademin=10; //start val
var menufademax=100; //end val
var menufadestepup=25;//inc by every .1 sec
var menufadestepdn=20;//dec by every .1 sec

function hidelayer(layername)
{if (ie4) {document.all[layername].style.visibility = "hidden";}
 if (ns4) {document.layers[layername].visibility = "hide";}
 if (ns6) {document.getElementById([layername]).style.display = "none";}
 window.status='';
 layervisible=false;
}
function showlayer(layername)
{if (ie4) {document.all[layername].style.visibility = "visible";   
  filter="Alpha(Opacity="+menufademax+")";
  eval(layername+".style.filter=filter;");
 }
 if (ns4) {document.layers[layername].visibility = "show";}
 if (ns6) {document.getElementById([layername]).style.display = "block";}
 layervisible=true;
}
// *********** layer effects ************
var thetimer=0;
var thefadetimer=0;
function fadeup(layername,curval,topval)
{curval+=menufadestepup;
 filter="Alpha(Opacity="+curval+")";
 eval(layername+".style.filter=filter;");
 if (curval<topval) thefadetimer=setTimeout("fadeup('"+layername+"',"+curval+","+topval+")",10);
}
function fadedown(layername,curval,botval)
{if (isNS)   hidelayer(layername);
 else // use fx
 {curval-=menufadestepdn;
  filter="Alpha(Opacity="+curval+")";
  eval(layername+".style.filter=filter;");
  if (curval>botval) thefadetimer=setTimeout("fadedown('"+layername+"',"+curval+","+botval+")",10);
  else  hidelayer(layername);
 }
}
// ********** menu functions **********
MouseOnMenu=false; // set to true on mouse over, false on mouse out
function menutimeout(menutimeoutcounter)
{window.clearTimeout(thetimer);
 thetimer=setTimeout("fadedown('menulayer',90,0)",4000);
}
function over(ob)
{if (ie4|ns6) ob.style.backgroundColor=menucol4;
 MouseOnMenu=true;// document.f1.status.value='On';
 window.clearTimeout(thetimer);
layername="menulayer";
if (ie4) {document.all[layername].style.visibility = "visible";   
 window.clearTimeout(thefadetimer);
 filter="Alpha(Opacity="+menufademax+")";
 eval(layername+".style.filter=filter;");
 //   fadeup(layername,menufademin,menufademax)
 }
}
function out(ob)
{if (ie4|ns6) ob.style.backgroundColor=menucol2;
 MouseOnMenu=false;// document.f1.status.value='Off';
 window.clearTimeout(thetimer);
 thetimer=setTimeout("fadedown('menulayer',menufademax,5)",150);
}
dxy="0";dny="0";
function showmenu(m,e)
{if (menuloaded==true)
 {//m of array containing all menu items,preceded by x,y,w,h
  layername="menulayer";
  numitems=(m.length-4)/2;
  //first make sure layer is hidden
  var htm="<table cellpadding=1 cellspacing=0  bgcolor='"+menucol1+"' border=0 width="+m[2]+" height="+m[3]+">";
  htm=htm+"<TR><TD><table cellpadding=2 cellspacing=1  bgcolor='"+menucol1+"' border=0 width="+m[2]+" height="+m[3]+">";
  //make the html to load into layer
  for(i=0;i<numitems;i++)
  { label=m[i*2+4];
    balign="left";
    title=label;
    if (label.indexOf("BC:")==0) {title=label.slice(3); label="<B>"+title+"</b>"; balign="center";}
    if (label.indexOf("C:")==0) {title=label.slice(2); label=title; balign="center";}
    if (label.indexOf("B:")==0) {title=label.slice(2); label="<B>"+title+"</B>"}
    if (label=="-") label="<HR noshade width=90%>";
    link=m[i*2+5];
    if (link.indexOf("dbcat:")==0) link=dburl+link.slice(6)+'&sln='+sln;
    else
    if (link.indexOf("base:")==0) link=baseurl+link.slice(5)+'&sln='+sln;
    if (link.indexOf("sec:")==0) link="index.php?sec="+link.slice(4)+'&sln='+sln;
    htm=htm+"<TR><TD bgcolor='"+menucol2+"' width="+m[2]+" align="+balign+" ";
    if (ie4|ns6) htm=htm+"onMouseOver =\"over(this);window.status=' "+title+" ';return true;\" onmouseout=\"out(this);window.status='';return true\"";
    htm=htm+">";
    htm=htm+"<a href='" +link+ "' ";
    if (ns4) htm=htm+"onMouseOver =\"over(this);window.status=' "+title+" ';return true;\" onmouseout=\"out(this);window.status='';return true\"";
    htm=htm+"><font face='verdana,helvetica' size=2 color='"+menucol3+"' class='sitemenu'>" +label+"</font></a>";
    htm=htm+"</td></tr>";
  }
  htm=htm+"</table></td></tr></table>";
  //write the layer
  writelayer(layername,htm);
  px=mouseX-8; py=mouseY-12;
//add the amount that the document has scrolled by ...
if (ie4)
{ py=py+document.body.scrollTop;
  px=(px+document.body.scrollLeft)-20;
}
//  lx= m[0] ? m[0] : px; ly= m[1] ? m[1] : py;
  lx= dnx ? dnx : px;
  ly= dny ? dny : py;
  lx= (lx>0) ? lx : 0;
  ly= (ly>0) ? ly : 0;
  movelayer(layername,lx,ly,0,0);
  MouseOnMenu=false;
  showlayer(layername);  // show the layer
//  menutimeout(0); //close menu if no activity over 1 second
 }
}
function showmenubyname(m,e)
{ eval("showmenu(" +m+ "," +e+ ")" );
}

// ** ** ** ** ** ** ** ** **
function openwindow(width, height, url, title,scroll)
{ windowpointer=window.open(url, title, "toolbar=no,location=no,directories=no,dependent=yes,status=no,menubar=no,scrollbars="+scroll+",width="+width+",height="+height);
  windowpointer.focus();
}

function showHelp(helpfile,subject)
{  if (helpfile=="") helpfile="mhp_help";
 openwindow(400,300,"help/"+helpfile+".htm#"+subject,"helpwin","yes")
}

function showimg(url)
{
 openwindow(500,200,"showimg.php?imgsrc="+url,"showimg","no")
}
function openmodal(width, height, url, title)
{ if(document.all)
  {windowpointer=window.showModalDialog(url,self,"dialogWidth:"+width+"px; dialogHeight:"+height+"px; status:0; help:0;border:thin;center:yes;systemMenu=no");  
   returnvalue=true;
  } 
  else {openwindow(width, height, url, title, 'no');  returnvalue=false;}
  return returnvalue;
}

function closelogin()//called if window was not modal
{windowpointer.close();if(document.fhl.SiteID.value!="")document.fhl.submit();
}
function closeuserlogin()//called if window was not modal
{windowpointer.close();
 if (document.userlogin.loginpass.value!="")   document.userlogin.submit();
}

function douserlogout()
{document.userlogin.loginname.value="";document.userlogin.loginpass.value="";
 document.userlogin.utf.value="logoutuser";
 document.userlogin.submit();
}

function douserlogin()
{document.userlogin.loginname.value="";document.userlogin.loginpass.value="";
 log('login');
 if (openmodal(270, 140, "userlogin.php", "Login"))
 { // must of recieved login details from modal window
  if (document.userlogin.loginpass.value!="")   document.userlogin.submit();

 } 
}
function douserchatlogin()
{document.userlogin.loginname.value="";document.userlogin.loginpass.value="";
 if (openmodal(270, 140, "../userlogin.php", "Login"))
 { if (document.userlogin.loginpass.value!="")   document.userlogin.submit();
 } 
}

function dofreelogo(sln)
{ url="freelogo.php?sln="+sln;
 openwindow(400, 300, url, "wndfl",'no');
 log("FreeLogo");
}

function dosendinfo(cat,rec,sln)
{ url="sendinfo.php?sln="+sln+"&catID="+cat+"&recID="+rec;
  openwindow(490, 300, url, "wndsi",'no');
 log("sendinfo");
}
function closefindnearest()//called if window was not modal
{windowpointer.close();
 if (document.findnearest.dist.value!="")   document.findnearest.submit();
}
function dofindnearest(pc,x,y,c,sln)
{  fnu="findnearest.php?sln="+sln+"&cx="+x+"&cy="+y+"&pc="+pc+"&cat="+c;
  document.findnearest.func.value="findnearest";
  document.findnearest.sec.value="";
  document.findnearest.mapcat.value=c;
  if (openmodal(320, 140, fnu, "findnearest"))
  { // must of recieved login details from modal window
   if (document.findnearest.dist.value!="")   document.findnearest.submit();
  } 
}
function dofindonmap()
{
 document.findnearest.func.value="shownearest";
 document.findnearest.sec.value="map";
 document.findnearest.submit();
}
// ** ** ** form checking functions ** ** **
function limittext(ob,mn){  p =ob.value; l=p.length; if (l>mn) {ob.value=p.substring(0,l-1);}}

function dosearch()  
{ if (document.search.kw.value.length<3) return(false);
  else  return(true); 
} 

// ** Formatting **
function mb(st,sc,nc)//string,startchar,length
{ res=st; // make substring bold
   if (sc!=-1)
   {res=st.substring(0,sc)+'<b>';
   res=res+st.substring(sc,sc+nc)+'</b>';
   res=res+st.substring(sc+nc,st.length);
   } else res=st;
  return(res);
}
wndvid=0;
function openVid(n)
{log('EasyMedia['+n+']');
 var win='easymedia.php?category='+n+'&sln='+sln;
  wnvid = window.open(win, 'wnvid', 'height=360,width=260,left=0,top=0,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no'); 
 //wnvid = window.open(win, 'wnvid', 'height=360,width=260,left=0,top=0,menubar=yes,resizable=yes,scrollbars=no,status=yes,toolbar=no,addressbar=yes'); 
  wnvid.focus();
}
function postcard()
{document.location='index.php?sec=virtualpostcard&sln='+sln;
}
function discuss()
{document.location='index.php?sec=discuss&sln='+sln;
}
function map(pc)// map window code
{wndMI = window.open('http://uk2.multimap.com/map/browse.cgi?scale=10000&pc='+pc+'&title=SouthportClubs.coms+Maps+by+Multimap &nbsp ', 'wndMI', 'height=460,width=600,top=0,left=0,alwaysRaised,dependent,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no'); 
 wndMI.focus();
}


function lgo(tlp){ log('Language['+tlp+']');
 if (tlp=='en') top.location="http://southportnews.com/index.php";
 document.tr.lp.value="en_"+tlp;
 document.tr.url.value="http://www.johnleenwuk.uklinux.net/southport/index.php?lang="+tlp;
 document.tr.submit();
}
adserveloaded=true;
