//---------------------  Start makeHTML V 2------------------------------
center   = false
bq       = false
bbq      = false
emailSubject          = "email"
SHTML_backgroundColor = "white"
//------------------------------------------------------
function makeHTML(e,op,piclib,esub) //e= text op=1 short HTML
{
emailSubject = "email"
if (esub != "undefined")(emailSubject = esub)
if (piclib+"" == "undefined"){piclib=""}
if (e+"" == "undefined"){return}
e = checkWWW(e)
e = checkEmail(e)
if (op == 1){e = shortHTML(e,piclib)}
e = e.replace(/\x0d/g,"<BR>") 
e = e.replace(/  /g," &nbsp;")
return e
}
//------------------------------------------------------------------------------
function shortHTMLObj(Obj) 
{ 
Obj.innerHTML = shortHTML(Obj.innerHTML)
}
//-----------------------------------------------------------------------------
function shortHTML(e,piclib)
{	 
   count = 1
   diag   = 0
   while (count != 0 && diag < 50)
   {
     e=shortProcess(e,piclib)
   }
    if (diag > 49)
   {
   Response.Write("<BR>SHTML - Too many operands or syntax error")
   Response.end
   }
   return e
}
//--------------------------------------------------------------
function shortProcess(e,piclib)
{
   var cArray  = e.split("[")
   count = 0
   diag ++
   for (var i=0;i<cArray.length;i++)
   { 
       ptype= "Null"
	   center = false
	   bq      = false
       bbq    = false
	   box    = false
        var end = cArray[i].indexOf("]")
    	if (end != -1)
		{
		 
		    var entry = cArray[i]
			entry = entry.substr(0,end)
			var sh = "["+entry+"]"
			var s = entry.search(/[\s ]/)
			var textdata = entry.substr(s)
			entry = entry.toLowerCase()
		    var array = entry.split(/[\s ]/)
			var array = array[0].split(",")
        	switch(true)
        	  {
        	    case (array[0].indexOf(".") != -1) :
        		         var out = fileSpec(array,textdata,piclib)
						 textdata = ""
	                     endrep = ""
        				 break;
    			case (array[0] == "map") :
    			         out =  "<A Class=map href=Javascript:showMap('"+array[1]+"') title='Click to show MAP of the area'>"+textdata+"</A>"
						 textdata =""
						 endrep=""
    					 break;
                default :
				         endrep="<\/Span>"
                	     var out = shortStyle(array,e)	
						
        	  } // End switch
			  if (ptype == "ul"  || ptype =="ol"){textdata=textdata.replace(/~l/gi,"<LI>")}
			  out = out+textdata+endrep
			  if (ptype =="ul") {out="<UL>"+out+"<\/UL>"}
			  if (ptype =="ol"){out="<OL>"+out+"<\/OL>"}
			  if (bq){out="<Blockquote>"+out+"<\/Blockquote>"}
			  if (bbq){out="<Blockquote><Blockquote>"+out+"<\/Blockquote><\/Blockquote>"}
			  if (center){out="<Center>"+out+"<\/Center>"}
        	  e=e.replace(sh,out)
        	  count ++
		}
	} // End for
return e
}
//----------------------------------------------------------------
function fileSpec(array,textdata,piclib)
{
var a = array[0].split(".")
switch(a[1])
  {
  case "gif":
  case "png":
  case "jpg":return shortPicture(array,piclib);break
  case "htm":
  case "asp":
  case "txt":
  case "html":return shortLink(array,textdata);break
  }
}
//------------------------------------------------------------------
function shortPicture(array,piclib)
{
    var out = "<img src='"+piclib+array[0]+"' align="+array[1]+" hspace=8 vspace=4 alt='"+array[0]+"''>"
	if (array[1] == "center"){out = "<Center>"+out+"<\/center>"}
	return out
	}
	//------------------------------------------------------------------
function shortLink(array,textdata)
{
  var out = "<A href ='"+array[0]+"'>"+textdata+"</a>"
  return out
}
//------------------------------------------------------------------
function shortStyle(array,e)
{
    var out = "<span style=\""
	var styleObj = new Object()
    styleObj["h1"] = "text-align:center;font-size:48pt;color:blue;text-decoration:underline;font-weight:bold;"
	styleObj["h2"] = "text-align:center;font-size:36pt;color:black;text-decoration:underline;font-weight:bold;"
	styleObj["h3"] = "text-align:left;font-size:24pt;color:blue;text-decoration:underline;font-weight:bold;"
	styleObj["h4"] = "text-align:left;font-size:16pt;color:black;text-decoration:;font-weight:bold;"
	styleObj["h5"] = "text-align:left;font-size:14pt;color:blue;text-decoration:;font-weight:bold;"
	styleObj["h6"] = "text-align:left;font-size:12pt;color:blue;text-decoration:;font-weight:bold;"
	for (i=0;i<array.length;i++)
	{
	 var command = array[i].toLowerCase()
	 switch(command)
	 {
	  case "i" : out=out+"font-style:italic;";break
	  case "u" : out= out+"text-decoration:underline;";break
	  case "b" : out= out+"font-weight:bold;";break
	  case "blue" : out= out+"color:blue;";break
	  case "red" : out= out+"color:red;";break
	  case "green" : out= out+"color:green;";break
	  case "white" : out= out+"color:white;";break
	  case "yellow" : out= out+"color:yellow;";break
	  case "black" : out= out+"color:black;";break
	  case "brown" : out= out+"color:#780000;";break
	  case "arial"      : out= out+"font-family:arial;";break
	  case "brush"    : out= out+"font-family:'brush script';";break
	  case "comic"   : out= out+"font-family:'comic strip';";break
	  case "georgia"   : out= out+"font-family:georgia;";break
	  case "verdana"  : out= out+"font-family:'verdana';";break  
	  case "c" :  center=true;break
	  case "q"  :  bq=true;break
	  case "qq" :  bbq=true;break
	  case "ul"  :  ptype="ul";break
	  case "ol"  :  ptype="ol";break
	  case "h1" :  out=out+styleObj.h1;break;
	  case "h2" :  out=out+styleObj.h2;break;
	  case "h3" :  out=out+styleObj.h3;break;
	  case "h4" :  out=out+styleObj.h4;break;
	  case "h5" :  out=out+styleObj.h5;break;
	  case "h6" :  out=out+styleObj.h6;break;
	  case "hr" :  out = "<HR>";break
	  default   :
 //-------------------------------------------------------------
	  if (command.indexOf("pt") != -1)
	    {
		pt = parseInt(command)
		out= out+"font-size:"+pt+"pt;"
	    }
//----------------------------------------------------
	  if (command.substr(0,2) == "in")
	    {
		var col=parseInt(command.substr(2))
		out = out+"position:absolute;left:"+col+"px;"
		out=out.replace("<span","<div")
		endrep = "<\/Div>"
	    }
//----------------------------------------------------
		if (command.substr(0,5) == "width")
	    {
		var w=parseInt(command.substr(5))
		out = out+"width:"+w+"%;text-align:left;"
	    }
//----------------------------------------------------
		if (command.substr(0,2) == "bg")
	    {
		SHTML_backgroundColor = command.substr(2)
		out = out+"background-color:"+command.substr(2)+";"
		out=out.replace("<span","<div")
		endrep = "<\/Div>"
	    }
//----------------------------------------------------
		if (command.substr(0,3) == "box")
	    {
		 box =true;
		 var w=parseInt(command.substr(3))
		 if (isNaN(w)){w=1}
         out=out.replace("<span","<div")
         out=out+"border-style:ridge;border-width:"+w+";padding:5;"
         endrep = "<\/Div>"
	    }  
//----------------------------------------------------------------
	 } 
	if (command.substr(0,2) == "hr")
	  { 
	   return "\<HR\>"
	  }
	}
	out = out+"\">"
	return out
}
//-----------------------------------------------------------------------------
function checkWWW(e)
{
   var count=0
   var Index1 = e.search(/www\.|http:\/\//i)  // Find www OR http://
   while (Index1 != -1 && count < 4)
   { 
	www =  extractWord(e,Index1)
    legend = www
	awww  =  www.toLowerCase()
	A = www.split(",")
	if (A[1]+"" != "undefined")
	{
	legend = A[1].replace(/\+/g," ")
	awww  = A[0]
	}
	awww = awww.replace("http://","")
	out = "<A href=http://"+awww+" target=_Blank>"+legend+"</A>"
	e=e.replace(www,out)
	Index1  += out.length-1	
	Index1 = e.indexOf("www",Index1)
	count ++
   }
return e
}
//-----------------------------------------------------------------------------------------------------------------------
function checkEmail(e)
{
   var count=0
   var Index1 = e.indexOf("@")
   while (Index1 != -1 && count < 4)
   { 
	email =  extractWord(e,Index1)
	legend = email
	aemail = email
	A = email.split(",")
	if (A[1]+"" != "undefined")
	{
	legend = A[1].replace(/\+/g," ")
	aemail = A[0].replace(/\x0d/g,"")
	}
	out = "<A href=mailto:"+aemail+"?Subject=Bishops%20Waltham.net%20"+escape(emailSubject)+"&cc=BW-Support@bishopswaltham.net title='Send E-mail'>"+legend+"</A>"
	e=e.replace(email,out)
	Index1  += out.length-1	
	Index1 = e.indexOf("@",Index1)
	count ++
   }
return e
}
//--------------------------------------------
crlf    = 13
blank = 32
//-------------------------------------------------------------------------
function extractWord(e,start)
{
    var startIndex = findStart(e,start)
	var endIndex =  findEnd(e,start)
	if (endIndex  == -1){endIndex =e.length}
	len    = endIndex-startIndex-1
	return  e.substr(startIndex,len)
}
//-----------------------------------------------------------------------------------------------------
function findStart(e,start)
{
crlf    = 13
cronly = 10
blank = 32
endBrac = 93
var s = start
if (s==0){return s}
while (s > 0 && e.charCodeAt(s) != blank && e.charCodeAt(s) != crlf && e.charCodeAt(s) != cronly)
{
s --
}
if (s <= 0){return 0}
return s+1
}
//-----------------------------------------------------
function findEnd(e,start)
{
var s = start
while (s <= e.length && e.charCodeAt(s) != blank && e.charCodeAt(s) != crlf && e.charCodeAt(s) != cronly && e.charCodeAt(s) != endBrac)
{
s ++
}
if (s==-1){s=0}
return s+1
}
//--------------- End of makeHTML ----------------------------------------


