//this script replaces all the < and > chr$ from html
//WHY? - well so you can put html code on your page properly :)

//Written By Andrew Holt 01/07/2002
// http://www.webdevtips.co.uk
//last updated 02-dec-2002
//Set the text if preview is clicked before update
var newText="Nothing to display";

function replace(form){
//get the original text and colors from the form
var origText = form.originaltext.value;
var acol= form.atagcolor.options[form.atagcolor.selectedIndex].value;
var imgcol= form.imgtagcolor.options[form.imgtagcolor.selectedIndex].value;
var metagcol= form.metatagcolor.options[form.metatagcolor.selectedIndex].value;
var scripttagcol= form.scripttagcolor.options[form.scripttagcolor.selectedIndex].value;
var commenttagcol= form.commenttagcolor.options[form.commenttagcolor.selectedIndex].value;
var othertagcol= form.othertagcolor.options[form.othertagcolor.selectedIndex].value;
var formtagcol= form.formtagcolor.options[form.formtagcolor.selectedIndex].value;

//Strart replacing stuff

//<
var re= /</g;
newText = origText.replace(re,"openatag&lt;");
//> 
var re= />/g;
newText = newText.replace(re,"&gt;closeatag");


//A TAG
var re= /openatag&lt;a/gi;
newText = newText.replace(re,"<b sTyLe='color:"+acol+";font-weight:normal;'>&lt;a");
///A TAG
var re= /openatag&lt;\/a/gi;
newText = newText.replace(re,"<b sTyLe='color:"+acol+";font-weight:normal;'>&lt;/a");


//META
var re= /openatag&lt;meta/gi;
newText = newText.replace(re,"<b sTyLe='color:"+metagcol+";font-weight:normal;'>&lt;meta");

//IMG TAG
var re= /openatag&lt;img/gi;
newText = newText.replace(re,"<b sTyLe='color:"+imgcol+";font-weight:normal;'>&lt;img");

//script 
var re= /openatag&lt;script/gi;
newText = newText.replace(re,"<b sTyLe='color:"+scripttagcol+";font-weight:normal;'>&lt;script");
///script TAG
var re= /openatag&lt;\/script/gi;
newText = newText.replace(re,"<b sTyLe='color:"+scripttagcol+";font-weight:normal;'>&lt;/script");


//COMMENT
var re= /openatag&lt;!--/gi;
//replace all the > chr$ with &gt;
newText = newText.replace(re,"<b sTyLe='color:"+commenttagcol+";font-weight:normal;'>&lt;!--");


//FORM
var re= /openatag&lt;form/gi;
newText = newText.replace(re,"<b sTyLe='color:"+formtagcol+";font-weight:normal;'>&lt;form");
//Regular Expression to replace /form TAG
var re= /openatag&lt;\/form/gi;
newText = newText.replace(re,"<b sTyLe='color:"+formtagcol+";font-weight:normal;'>&lt;/form");


//INPUT
var re= /openatag&lt;input/gi;
newText = newText.replace(re,"<b sTyLe='color:"+formtagcol+";font-weight:normal;'>&lt;input");


//SELECT
var re= /openatag&lt;select/gi;
newText = newText.replace(re,"<b sTyLe='color:"+formtagcol+";font-weight:normal;'>&lt;select");
var re= /openatag&lt;\/select/gi;
newText = newText.replace(re,"<b sTyLe='color:"+formtagcol+";font-weight:normal;'>&lt;/select");

//OPTION
var re= /openatag&lt;option/gi;
newText = newText.replace(re,"<b sTyLe='color:"+formtagcol+";font-weight:normal;'>&lt;option");
var re= /openatag&lt;\/option/gi;
newText = newText.replace(re,"<b sTyLe='color:"+formtagcol+";font-weight:normal;'>&lt;/option");

//Textarea
var re= /openatag&lt;textarea/gi;
newText = newText.replace(re,"<b sTyLe='color:"+formtagcol+";font-weight:normal;'>&lt;textarea");
var re= /openatag&lt;\/textarea/gi;
newText = newText.replace(re,"<b sTyLe='color:"+formtagcol+";font-weight:normal;'>&lt;/textarea");


//PHP OPEN
var re= /openatag&lt;\?/g;
newText = newText.replace(re,"<b sTyLe='color:"+scripttagcol+";font-weight:normal;'>&lt;?</b>");
//PHP CLOSE
var re= /\?&gt;closeatag/g;
newText = newText.replace(re,"<b sTyLe='color:"+scripttagcol+";font-weight:normal;'>?&gt;</b>");

//asp OPEN
var re= /openatag&lt;\%/g;
newText = newText.replace(re,"<b sTyLe='color:"+scripttagcol+";font-weight:normal;'>&lt;%</b>");
//asp CLOSE
var re= /\%&gt;closeatag/g;
newText = newText.replace(re,"<b sTyLe='color:"+scripttagcol+";font-weight:normal;'>%&gt;</b>");


//openatag&lt;
var re= /openatag&lt;/gi;
newText = newText.replace(re,"<b sTyLe='color:"+othertagcol+";font-weight:normal'>&lt;");

//&gt;closeatag
var re= /&gt;closeatag/gi;
newText = newText.replace(re,"&gt;</b>");

/////////////////nomoreedit//////////////
//newline chr$
var re= /\n/g;
newText = newText.replace(re,"\n<br>\n");

//tab chr$
var re= /\t/g;
newText = newText.replace(re,"&nbsp;&nbsp;&nbsp;&nbsp;");

//replace all the spaces(use 2 spaces to preserve formatting) chr$
var re= /\s\s/g;
newText = newText.replace(re,"&nbsp;");

//Put the new text into the bottom textarea
var finaltext="<!-- start html writer code -->\n\n"+newText+"\n\n<!-- http://www.webdevtips.com/webdevtips/codegen/html.shtml -->\n<!-- end html writer code -->\n";
form.newtext.value = finaltext;
//location.href="#codeme";
}

function all2black(form){
form.atagcolor.options.selectedIndex=2;
form.imgtagcolor.options.selectedIndex=2;
form.metatagcolor.options.selectedIndex=2;
form.scripttagcolor.options.selectedIndex=2;
form.formtagcolor.options.selectedIndex=2;
form.commenttagcolor.options.selectedIndex=2;
form.othertagcolor.options.selectedIndex=2;
}
function all2color(form){
form.atagcolor.options.selectedIndex=0;
form.imgtagcolor.options.selectedIndex=0;
form.metatagcolor.options.selectedIndex=0;
form.scripttagcolor.options.selectedIndex=0;
form.formtagcolor.options.selectedIndex=0;
form.commenttagcolor.options.selectedIndex=0;
form.othertagcolor.options.selectedIndex=0;
}



//preview the text in a browser window
function preview() {
	msg=open("","","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=640,height=480");
msg.document.write('<html><head><title>test page</title><style type=text/css>body,TD{font : 9pt verdana, sans-serif;}</style></head><body bgcolor=white><b>This is how your code will appear in a browser.</b><hr><table bgcolor="#ffffff" border="1" width="95%" align="center"><tr><td>'+newText+'</td></tr></table><hr>');
msg.document.write('</body></html>');
	return false;}

