/*

Initialise imgDir to images directory before including file.
	<SCRIPT LANGUAGE="JavaScript1.2" SRC="library.js"></SCRIPT>
Add preloadImages in Body tag.
	onLoad="preloadImages(
		'image1.jpg','image2.jpg',
	);
*/

function error(errObject,errMessage) {
	alert(errMessage);
	errObject.focus();
	return false;
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function findObj(imgName, doc) {
	var p,i,x;
	if(!doc)
		doc=document;
	if((p=imgName.indexOf("?"))>0&&parent.frames.length) {
		doc=parent.frames[imgName.substring(p+1)].document;
		imgName=imgName.substring(0,p);
	}
	if(!(x=doc[imgName])&&doc.all)										x=doc.all[imgName];
	for(i=0;!x&&i<doc.forms.length;i++) 							x=doc.forms[i][imgName];
	for(i=0;!x&&doc.layers&&i<doc.layers.length;i++)
	x=findObj(imgName,doc.layers[i].document);
	if(!x && document.getElementById)									x=document.getElementById(imgName);
	return x;
}

function imgRoll() {
	if ((preloadFlag == true)) {
		imgTemp = findObj(imgRoll.arguments[0]);
		imgTemp.src = imgRoll.arguments[1];
	}
}

var preloadFlag = false;
img = new Array();
function preloadImages() {
	if (document.images) {
		if (preloadImages.arguments.length == 1 && preloadImages.arguments[0].indexOf(",") > -1) {
			var args = preloadImages.arguments[0].split(",");
		}
		else 
			args = preloadImages.arguments;
		for (i=0; i<args.length; i++)
			img[i] = newImage(args[i+1]);
		preloadFlag = true;
	}
}

sPreLoadImgs="";
function GetButton(id, sHref, sImage, sImageOver) {
	sPreLoadImgs = sPreLoadImgs + sImageOver + ",";
	document.write("<TR><TD><A HREF='" + sHref + "'");
	document.write(" onfocus=\"imgRoll('img" + id + "', 'images/" + sImageOver + "')\"");
	document.write(" onMouseOver=\"imgRoll('img" + id + "', 'images/" + sImageOver + "')\"");
	document.write(" onblur=\"imgRoll('img" + id + "', 'images/" + sImage + "')\"");
	document.write(" onMouseOut=\"imgRoll('img" + id + "', 'images/" + sImage + "')\">");
	document.write("<IMG NAME='img" + id + "' SRC='images/" + sImage + "' ALT='' border='0'></A></TD></TR>");
}

var OpenWindows = new Object();
function OpenWin(sPath, w, h) {
	l = (screen.width - w)/2-5;
	t = (screen.height - h)/2-20;
	if (l<1) l=0;
	if (t<1) t=0;
	sWindowName = "mainwin_" + w + "_" + h;
  if(OpenWindows[sWindowName]) {
    if(!OpenWindows[sWindowName].closed) OpenWindows[sWindowName].close();
  }
	OpenWindows[sWindowName] = window.open(sPath, sWindowName, "left=" + l + ",top=" + t + ",width=" + w + ",height=" + h + ",scrollbars=no,menubar=no,toolbars=no,status=no");
	return OpenWindows[sWindowName];
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var isHTMLMode=false
function button_over(eButton) {
	eButton.style.backgroundColor = "#B5BDD6";
	eButton.style.borderColor = "darkblue darkblue darkblue darkblue";
}
function button_out(eButton) {
	eButton.style.backgroundColor = "threedface";
	eButton.style.borderColor = "threedface";
}
function button_down(eButton) {
	eButton.style.backgroundColor = "#8494B5";
	eButton.style.borderColor = "darkblue darkblue darkblue darkblue";
}
function button_up(eButton) {
	eButton.style.backgroundColor = "#B5BDD6";
	eButton.style.borderColor = "darkblue darkblue darkblue darkblue";
	eButton = null; 
}
function cmdExec(cmd,opt) {
		if (isHTMLMode){alert("Please uncheck 'Edit HTML'");return;}
		idContent.document.execCommand(cmd,"",opt);idContent.focus();
}
function setMode(bMode) {
	var sTmp;
		isHTMLMode = bMode;
		if (isHTMLMode){
			sTmp=idContent.document.body.innerHTML;
			idContent.document.body.innerText=sTmp;
	} 
	else {
		sTmp=idContent.document.body.innerText;
		idContent.document.body.innerHTML=sTmp;
	}
	idContent.focus();
}
function createLink() {
	if (isHTMLMode){alert("Please uncheck 'Edit HTML'");return;}
	cmdExec("CreateLink");
}
function insertImage() {
	if (isHTMLMode){alert("Please uncheck 'Edit HTML'");return;}
	var sImgSrc=prompt("Insert Image File (You can use your local image file) : ", "Paste full path to the emage file here.");
	if(sImgSrc!=null) cmdExec("InsertImage",sImgSrc);
}
function foreColor() {
	var arr = showModalDialog("selcolor.asp","","font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:34em" );
	if (arr != null) cmdExec("ForeColor",arr);
}
hSpace=3;
function tdbutton(sOnClick, sIMG, sALT) {
	document.write("<TD><div class=cbtn onClick=\"" + sOnClick + "\" ");
	document.write("onmouseover='button_over(this);' onmouseout='button_out(this);' onmousedown='button_down(this);' ");
	document.write("onmouseup='button_up(this);'><IMG hspace=" + hSpace + " vspace=1 align=absmiddle ");
	document.write("src='../images/" + sIMG + "' alt='" + sALT + "'></div></TD>\n");
}

function ReplaceImages() {
	sString = idContent.document.location.href;
	sString = sString.substring(0,sString.lastIndexOf("/")) + "/thumbnail.php?image=";
	aString = idContent.document.body.innerHTML.split(sString);
	idContent.document.body.innerHTML = aString.join("../articles/");
}

function GetOnlineEditor() {
	document.write("<TABLE border='0' cellpadding='0' cellspacing='0'><TR><TD>");
	document.write("<TABLE border='1' cellpadding='0' cellspacing='0'><TR><TD>");
	document.write("<TABLE id=tblCoolbar width=520 cellpadding='0' cellspacing='0'><TR valign=middle><TD colspan=12>");
	document.write("<select onchange=\"cmdExec('formatBlock',this[this.selectedIndex].value);this.selectedIndex=0\"><option selected>Style<option value=Normal>Normal<option value='Heading 1'>Heading 1<option value='Heading 2'>Heading 2<option value='Heading 3'>Heading 3<option value='Heading 4'>Heading 4<option value='Heading 5'>Heading 5<option value='Address'>Address<option value='Formatted'>Formatted<option value='Definition Term'>Definition Term</option></select> ");
	document.write("<select onchange=\"cmdExec('fontname',this[this.selectedIndex].value);\"><option selected>Font<option value='Arial'>Arial<option value='Arial Black'>Arial Black<option value='Arial Narrow'>Arial Narrow<option value='Comic Sans MS'>Comic Sans MS<option value='Courier New'>Courier New<option value='System'>System<option value='Tahoma'>Tahoma<option value='Times New Roman'>Times New Roman<option value='Verdana'>Verdana<option value='Wingdings'>Wingdings</select> ");
	document.write("<select onchange=\"cmdExec('fontsize',this[this.selectedIndex].value);\"><option selected>Size<option value='1'>1<option value='2'>2<option value='3'>3<option value='4'>4<option value='5'>5<option value='6'>6<option value='7'>7<option value='8'>8<option value='10'>10<option value='12'>12<option value='14'>14</select> ");
//	document.write("<INPUT name=EditHTML type='checkbox' onclick='setMode(this.checked)'> Edit HTML");
	document.write("</TD><TD colspan=3 align='right'>");
	document.write("<INPUT type=submit name=submit value=Save class=frmButton>&nbsp; ");
	document.write("</TD></TR><TR>");

	tdbutton("cmdExec('cut')"									, "cut.gif"			, "Cut");
	tdbutton("cmdExec('copy')"								, "copy.gif"		, "Copy");
	tdbutton("cmdExec('paste')"								, "paste.gif"		, "Paste");
	tdbutton("cmdExec('bold')"								, "bold.gif"		, "Bold");
	tdbutton("cmdExec('italic')"							, "italic.gif"	, "Italic");
	tdbutton("cmdExec('underline')"						, "under.gif"		, "Underline");
	tdbutton("cmdExec('justifyleft')"					, "left.gif"		, "Justify Left");
	tdbutton("cmdExec('justifycenter')"				, "center.gif"	, "Center");
	tdbutton("cmdExec('justifyright')"				, "right.gif"		, "Justify Right");
	tdbutton("cmdExec('insertorderedlist')"		, "numlist.gif"	, "Ordered List");
	tdbutton("cmdExec('insertunorderedlist')"	, "bullist.gif"	, "Unordered List");
	tdbutton("cmdExec('outdent')"							, "deindent.gif", "Decrease Indent");
	tdbutton("cmdExec('indent')"							, "inindent.gif", "Increase Indent");
	tdbutton("foreColor()"										, "fgcolor.gif"	, "Forecolor");
	document.write("</TR></TABLE>");
	document.write("<iframe width=520 id=idContent height=320 marginheight=0 marginwidth=2 style=\"word-wrap:break-word;\" onfocus='ReplaceImages();'></iframe>");
	document.write("</TD></TR></TABLE>");
	document.write("</TD><TD VALIGN=bottom>");
		document.write("<TABLE border='1' cellpadding='0' cellspacing='0'><TR><TD>");
		document.write("<TABLE width='115' id='tblCoolbar' cellpadding='0' cellspacing='0'>");
		document.write("<TR><TD height='52'>&nbsp;</TD></TR>");
		document.write("</TABLE>");
		document.write("<iframe width='115' id='idImages' height='320' marginheight='0' marginwidth='2' style=\"word-wrap:break-word;\"></iframe>");
		document.write("</TD></TR></TABLE>");
	document.write("</TD></TR></TABLE>");
}

function retChecked(sOpt) {
	sOpt = "" + sOpt;
	sOpt = sOpt.toUpperCase();
	if((sOpt == "TRUE") || (sOpt == "ON") || (sOpt>=0)) 
		return " CHECKED";
	return "";
}

 function addvalues()
  {
	//  document.hdnfrm.s_title.value=document.title;
  	document.hdnfrm.referrer.value=document.referrer;
	  document.hdnfrm.useragent.value=navigator.userAgent ;
	  document.hdnfrm.url.value=document.URL;
  	document.hdnfrm.iwidth.value=screen.width;
	  document.hdnfrm.iheight.value=screen.height;
		document.hdnfrm.submit();
 }

function OpenScrollWin(sPath, w, h) {
	l = (screen.width - w)/2-5;
	t = (screen.height - h)/2-20;
	if (l<1) l=0;
	if (t<1) t=0;
	sWindowName = "mainwin_" + w + "_" + h;
  if(OpenWindows[sWindowName]) {
    if(!OpenWindows[sWindowName].closed) OpenWindows[sWindowName].close();
  }
	OpenWindows[sWindowName] = window.open(sPath, sWindowName, "left=" + l + ",top=" + t + ",width=" + w + ",height=" + h + ",scrollbars=yes,menubar=no,toolbars=no,status=no");
	return OpenWindows[sWindowName];
}
