/////////////////////////////////////////////////////////////////////////////
// editing.js
// (c) Antoine LEROY 2006
// 
// >> Provides a few functions to write HTML ancors 
/////////////////////////////////////////////////////////////////////////////

//************** Format

function w(text) {
	document.write(text);
}

function p() {
  w("<p>");
}

function p_class(style) {
  w("<p class='"+style+"'>");
}

function endP() {
  w("</p>");
}

function span(style, text) {
	w("<span class='"+style+"'>"+text+"</span>");
}

function c() {
	w("<center>");	
}

function endC() {
	w("</center>");
}

function h(size, text) {
	w("<h"+size+">"+text+"</h"+size+">");
}

//**************** Breaks

function sp(n) {
  w("&nbsp;");
	for (i=1 ; i<n ; i++)
		w("&nbsp;");
}

function br(n) {
  w("<br/>");
	for (i=1 ; i<n ; i++)
		w("<br/>");
}

function hr(width) {
	w("<hr width='"+width+"'/>");
}

//**************** Image

function img(src, alt, name, width, height, align, border, usemap) {
  var str = "<img ";
  if (alt) {str += "alt='"+alt+"' ";} else;
  if (name) {str += "name='"+name+"' ";} else;
  if (width) {str += "width='"+width+"' ";} else;
  if (height) {str += "height='"+height+"' ";} else;
  if (align) {str += "align='"+align+"' ";} else;
  if (border) {str += "border='"+border+"' ";} else;
  if (usemap) {str += "usemap='#"+usemap+"' ";} else;
  
  str +=  "src='"+src+"'/>";
  w(str);
	//w("<img name='"+name+"' width='"+width+"' height='"+height+"' src='"+src+"' alt='"+alt+"' align='"+align+"' border='"+border+"'/>");
}

function map(name) {
  w("<map name='"+name+"'>");
}

function endMap() {
  w("</map>");
}

function area(href, coords, alt) {
  var str = "<area href='"+href+"' coords='"+coords+"' ";
  if (alt) {str += "alt='"+alt+"' ";} else;
  str += "/>";
  w(str);
}

//**************** Anchor

function a_ref(href) {
	w("<a href='"+href+"'>");	
}

function a_click(action) {
	w("<a href='javascript:"+action+"'>");	
}

function a_over(action, over, out) {
	w("<a href='javascript:"+action+"' onmouseover='"+over+"' onmouseout='"+out+"'>");	
}

function endA() {
	w("</a>");	
}

//***************** Table

function table(border, width, height, cellspacing, cellpadding, bgcolor) {
	w("<table border='"+border+"' width='"+width+"' height='"+height+"' cellspacing='"+cellspacing+
	  "' cellpadding='"+cellpadding+"' bgcolor='"+bgcolor+"'>");
}

function endT() {
	w("</table>");	
}

function tr() {
	w("<tr>");	
}

function rt() {
	w("</tr>");	
}

function td(style) {
	w("<td class='"+style+"'>");	
}

function td_class(style) {
	w("<td class='"+style+"'>");	
}

function td_width(width) {
	w("<td width='"+width+"'>");	
}

function td_height(height) {
	w("<td height='"+height+"'>");	
}

function td_colspan(col) {
	w("<td colspan='"+col+"'>");	
}

function td_rowspan(row) {
	w("<td rowspan='"+row+"'>");	
}

function td_rowsclass(row, style) {
	w("<td rowspan='"+row+"' class='"+style+"'>");	
}

function td_colsheight(col, height) {
	w("<td colspan='"+col+"' height='"+height+"'>");	
}

function td_colswidth(col, width) {
	w("<td colspan='"+col+"' width='"+width+"'>");	
}

function td_align(pos) {
	w("<td align='"+pos+"'>");	
}

function dt() {
	w("</td>");	
}

//***************** Form

function form(name) {
	w("<form name='"+name+"'>");	
}

function form(name, email) {
	w("<form name='"+name+"' method='POST' action='mailto:"+email+"'>");	
}

function endF() {
	w("</form>");	
}

function select(name, size, options, action) {
	w("<select name='"+name+"' size='1' onchange='"+action+"'>");
	
	for(i=0 ; i<size ; i++)
		w("<option value='option"+i+"'/>"+options[i]);
	
	w("</select>");
}

function text(name, size) {
	w("<input type='text' name='"+name+"' size='"+size+"'/>");
}

function textarea(name, rows, cols) {
	w("<textarea name='"+name+"' rows='"+rows+"' cols='"+cols+"'></textarea>");	
}

function textarea(name, rows, cols, data) {
	w("<textarea readonly name='"+name+"' rows='"+rows+"' cols='"+cols+"'>"+data+"</textarea>");	
}

function send(value) {
	w("<input type='submit' value='"+value+"'/>");
}

//****************** List

function ul() {
  w("<ul type='circle'>")
}

function lu() {
  w("</ul>")
}

function ol() {
  w("<ol>")
}

function lo() {
  w("</ol>")
}

function li() {
  w("<li>")
}

function il() {
  w("</li>")
}

///////////////////
// String methods

function bold() {
	this.text = "<b>"+this.toString()+"</b>";
	return this.text;
}
String.prototype.b = bold;

function underline() {
	this.text = "<u>"+this.toString()+"</u>";
	return this.text;
}
String.prototype.u = underline;

function italic() {
	this.text = "<i>"+this.toString()+"</i>";
	return this.text;
}
String.prototype.i = italic;

function fontify(face, size, colour) {
	this.text = "<font face='"+face+"' size='"+size+"' color='"+colour+"'>"+this.toString()+"</font>";
	return this.text;
}
String.prototype.f = fontify;
