DOM = (document.getElementById) ? 1 : 0;
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
OPERA = (navigator.userAgent.indexOf("Opera 5") > -1 || navigator.userAgent.indexOf("Opera/5") > -1 || navigator.userAgent.indexOf("Opera 6") > -1 || navigator.userAgent.indexOf("Opera/6") > -1 || navigator.userAgent.indexOf("Opera 7") > -1 || navigator.userAgent.indexOf("Opera/7") > -1) ? 1 : 0;

function trapkey(evt) {var c = document.layers ? evt.which : document.all ? event.keyCode : evt.keyCode; return c; };

function do_update(keystroke) {
	var myc = trapkey(keystroke);
	if(DOM && !OPERA) {
		var zk = "10";
		} else {
		var zk = "17";
	}
	//alert(myc);
	if(myc == zk) {
		var resp = document.getElementById("returngraph");
		var dtext = document.getElementById("wrt");
		var blogsub = document.getElementById("blogsub");
		var subtext = blogsub.value;
		if(subtext != "") {
			blogsubprint = "<span class=blogtitle>" + subtext + "</span>";
			} else {
			blogsubprint = "";
		}
		var cont = resp.innerHTML;
		var tonk = dtext.value;
		tonk = tonk.replace(/  /g, "&nbsp;&nbsp;");
		var dotext = tonk.replace(/\n/g,"<br>");
		for(i=0;i<smiliecode.length;i++) {
			var tr = '/' + smiliecode[i] + '/gi';
			dotext = dotext.replace(eval(tr), smiliename[i]);
			tr = "";
		}
  	resp.innerHTML = blogsubprint + "<br><br>" + dotext + "";
		if(DOM && !OPERA) {
			resp.scrollIntoView(false);
		}
		document.realmsg.realsub.value = escape(subtext);
		document.realmsg.realpost.value = escape(tonk);
	}
}
		
function do_blogpost() {
	var resp = document.getElementById("returngraph");
	var dtext = document.getElementById("wrt");
	var blogsub = document.getElementById("blogsub");
	var subtext = blogsub.value;
	if(subtext != "") {
		blogsubprint = "<span class=blogtitle>" + subtext + "</span>";
		} else {
		blogsubprint = "";
	}
	var cont = resp.innerHTML;
	//var ronk = dtext.value;
	//var dotext = ronk.replace(/\n/g,"<br>");
	var tonk = dtext.value;
	tonk = tonk.replace(/  /g, "&nbsp;&nbsp;");
	var dotext = tonk.replace(/\n/g,"<br>");
	for(i=0;i<smiliecode.length;i++) {
			var tr = '/' + smiliecode[i] + '/gi';
			dotext = dotext.replace(eval(tr), smiliename[i]);
			tr = "";
		}
  resp.innerHTML = blogsubprint + "<br><br>" + dotext;
	if(DOM && !OPERA) {
		resp.scrollIntoView(false);
	}
	document.realmsg.realsub.value = escape(subtext);
	document.realmsg.realpost.value = escape(tonk);
	
	if(authc.load()) {
		var linkauth = authc.dset;
		document.realmsg.exec.value = linkauth;
		document.realmsg.submit();
	}
}

// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}



function insertCode_blog(text) {
	text = text.replace(/\*/g,"\"");
	var orgtext = text;
	text = '' + text + '';
	if (document.rmsg.run_messages.createTextRange && document.rmsg.run_messages.caretPos) {
		var caretPos = document.rmsg.run_messages.caretPos;
		var theSelection = document.selection.createRange().text;
		if (theSelection) {
			var newtext = orgtext.split("</a>");
			var pretext = orgtext.split("\">");
			var text = pretext[0] + "\">" + theSelection + "</a>"; 
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.rmsg.run_messages.focus();
			} else {
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.rmsg.run_messages.focus();
		}
	} else {
	document.rmsg.run_messages.value  += text;
	document.rmsg.run_messages.focus();
	}
}

function insertCode_blogt(text,tag) {
	var orgtext = text;
	text = '' + text + '';
	if (document.rmsg.run_messages.createTextRange && document.rmsg.run_messages.caretPos) {
		var caretPos = document.rmsg.run_messages.caretPos;
		var theSelection = document.selection.createRange().text;
		if (theSelection) {
			var newtext = orgtext.split("</" + tag + ">");
			var pretext = orgtext.split("<" + tag + ">");
			var text = "<" + tag + ">" + theSelection + "</" + tag + ">"; 
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.rmsg.run_messages.focus();
			} else {
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.rmsg.run_messages.focus();
		}
	} else {
	document.rmsg.run_messages.value  += text;
	document.rmsg.run_messages.focus();
	}
}

function insertCode_blogchap(text) {
	text = text.replace(/\*/g,"\"");
	var orgtext = text;
	text = '' + text + '';
	if (document.chapter_input.paragraph_text.createTextRange && document.chapter_input.paragraph_text.caretPos) {
		var caretPos = document.chapter_input.paragraph_text.caretPos;
		var theSelection = document.selection.createRange().text;
		if (theSelection) {
			var newtext = orgtext.split("</a>");
			var pretext = orgtext.split("\">");
			var text = pretext[0] + "\">" + theSelection + "</a>"; 
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.chapter_input.paragraph_text.focus();
			} else {
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.chapter_input.paragraph_text.focus();
		}
	} else {
	document.chapter_input.paragraph_text.value  += text;
	document.chapter_input.paragraph_text.focus();
	}
}

function insertCode_blogchapt(text,tag) {
	var orgtext = text;
	text = '' + text + '';
	if (document.chapter_input.paragraph_text.createTextRange && document.chapter_input.paragraph_text.caretPos) {
		var caretPos = document.chapter_input.paragraph_text.caretPos;
		var theSelection = document.selection.createRange().text;
		if (theSelection) {
			var newtext = orgtext.split("</" + tag + ">");
			var pretext = orgtext.split("<" + tag + ">");
			var text = "<" + tag + ">" + theSelection + "</" + tag + ">"; 
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.chapter_input.paragraph_text.focus();
			} else {
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.chapter_input.paragraph_text.focus();
		}
	} else {
	document.chapter_input.paragraph_text.value  += text;
	document.chapter_input.paragraph_text.focus();
	}
}

function insertCode_blogart(text) {
	text = text.replace(/\*/g,"\"");
	var orgtext = text;
	text = '' + text + '';
	if (document.art_regform.ingress.createTextRange && document.art_regform.ingress.caretPos) {
		var caretPos = document.art_regform.ingress.caretPos;
		var theSelection = document.selection.createRange().text;
		if (theSelection) {
			var newtext = orgtext.split("</a>");
			var pretext = orgtext.split("\">");
			var text = pretext[0] + "\">" + theSelection + "</a>"; 
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.art_regform.ingress.focus();
			} else {
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.art_regform.ingress.focus();
		}
	} else {
	document.art_regform.ingress.value  += text;
	document.art_regform.ingress.focus();
	}
}

function insertCode_blogartt(text,tag) {
	var orgtext = text;
	text = '' + text + '';
	if (document.art_regform.ingress.createTextRange && document.art_regform.ingress.caretPos) {
		var caretPos = document.art_regform.ingress.caretPos;
		var theSelection = document.selection.createRange().text;
		if (theSelection) {
			var newtext = orgtext.split("</" + tag + ">");
			var pretext = orgtext.split("<" + tag + ">");
			var text = "<" + tag + ">" + theSelection + "</" + tag + ">"; 
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.art_regform.ingress.focus();
			} else {
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.art_regform.ingress.focus();
		}
	} else {
	document.art_regform.ingress.value  += text;
	document.art_regform.ingress.focus();
	}
}

function insertCode_blogartvideo(type) {
	if(type == 'google') {
		var text = '<embed src="http://video.google.com/googleplayer.swf?docid=DOCID" width="425" height="350" type="application/x-shockwave-flash" wmode="transparent" /></embed />';
		} else if(type == 'youtube')  {
		var text = '<embed src="http://www.youtube.com/v/DOCID" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed>';
	}
	if (document.art_regform.ingress.createTextRange && document.art_regform.ingress.caretPos) {
		var caretPos = document.art_regform.ingress.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
		document.art_regform.ingress.focus();
	} else {
	document.art_regform.ingress.value  += text;
	document.art_regform.ingress.focus();
	}
}

function insertCode(text) {
	text = '' + text + '';
	if (document.chapter_input.paragraph_text.createTextRange && document.chapter_input.paragraph_text.caretPos) {
		var caretPos = document.chapter_input.paragraph_text.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
		document.chapter_input.paragraph_text.focus();
	} else {
	document.chapter_input.paragraph_text.value  += text;
	document.chapter_input.paragraph_text.focus();
	}
}

function insertCodebcomm(text) {
	text = '' + text + '';
	if (document.pblogcomment.blogcomment.createTextRange && document.pblogcomment.blogcomment.caretPos) {
		var caretPos = document.pblogcomment.blogcomment.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
		document.pblogcomment.blogcomment.focus();
	} else {
	document.pblogcomment.blogcomment.value  += text;
	document.pblogcomment.blogcomment.focus();
	}
}

function insertCodeindexwrpsss(text) {
	text = '' + text + '';
	if (document.indexit.indextext.createTextRange && document.indexit.indextext.caretPos) {
		var caretPos = document.indexit.indextext.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
		document.indexit.indextext.focus();
	} else {
	document.indexit.indextext.value  += text;
	document.indexit.indextext.focus();
	}
}

function insertCodeindexwrp(text,tag) {
	var orgtext = text;
	text = '' + text + '';
	if (document.indexit.indextext.createTextRange && document.indexit.indextext.caretPos) {
		var caretPos = document.indexit.indextext.caretPos;
		var theSelection = document.selection.createRange().text;
		if (theSelection) {
			var newtext = orgtext.split("</" + tag + ">");
			var pretext = orgtext.split("<" + tag + ">");
			var text = "<" + tag + ">" + theSelection + "</" + tag + ">"; 
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.indexit.indextext.focus();
			} else {
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.indexit.indextext.focus();
		}
	} else {
	document.indexit.indextext.value  += text;
	document.indexit.indextext.focus();
	}
}

function insertCodeindex(text, tag) {
	text = text.replace(/\*/g,"\"");
	var orgtext = text;
	text = '' + text + '';
	if (document.indexit.indextext.createTextRange && document.indexit.indextext.caretPos) {
		var caretPos = document.indexit.indextext.caretPos;
		var theSelection = document.selection.createRange().text;
		if (theSelection) {
			var newtext = orgtext.split("</"+tag+">");
			var pretext = orgtext.split("\">");
			var text = pretext[0] + "\">" + theSelection + "</"+tag+">"; 
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.indexit.indextext.focus();
			} else {
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
			document.indexit.indextext.focus();
		}
	} else {
	document.indexit.indextext.value  += text;
	document.indexit.indextext.focus();
	}
}

function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function insertAtCursor(myField, myValue) {
  //IE support
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
                  + myValue
                  + myField.value.substring(endPos, myField.value.length);
  } else {
    myField.value += myValue;
  }
}

/*DOM = (document.getElementById) ? 1 : 0;
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
OPERA = (navigator.userAgent.indexOf("Opera 5") > -1 || navigator.userAgent.indexOf("Opera/5") > -1 || navigator.userAgent.indexOf("Opera 6") > -1 || navigator.userAgent.indexOf("Opera/6") > -1 || navigator.userAgent.indexOf("Opera 7") > -1 || navigator.userAgent.indexOf("Opera/7") > -1) ? 1 : 0;

if(DOM) {
alert(navigator.userAgent + '\n' + OPERA);
}*/
