/* ********************************************************************
Javascript Utilities Library
Author : Kedar R. Bhave (c) 2000, All rights reserved.
Notes  : This javascript source file should always be loaded FIRST.

Modification History :-
v1.0	15th July 2000.
******************************************************************** */

var doc = window.document;
var isNav, isIE;

// Or we can also determine this as -
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

// *** Popup Help ***
function Help(pNum) {
	// Assumes 2 variables to be available in the source document
	// hlp_text[pNum] & hlp_title[pNum]
	
	pText = eval("hlp_text" + pNum);
	pTitle = eval("hlp_title" + pNum);
	
	var hWin = window.open("", "Help", "scrollbars=yes,width=250,height=250,status=no");
	hWin.document.writeln("<HTML><HEAD><TITLE>Softricks.com: Help</TITLE></HEAD><BODY>");
	hWin.document.writeln("<TABLE BORDER=0 CELLPADDING=0 WIDTH='100%' BGCOLOR='#000099'><TR><TD>");
	hWin.document.writeln("<TABLE BORDER=0 WIDTH='100%' CELLPADDING=1 BGCOLOR='#ffffff'>");
	hWin.document.writeln("<TR><TD BGCOLOR='#000099'><FONT FACE=Verdana SIZE=2 COLOR=white><B>",
		pTitle, "</B></FONT></TD></TR>");
	hWin.document.writeln("<TR><TD>");
	hWin.document.writeln("<FONT FACE=Verdana SIZE=2>");
	hWin.document.writeln(pText);
	hWin.document.writeln("</FONT>");
	hWin.document.writeln("</TD></TR></TABLE></TABLE></BODY></HTML>");
	hWin.document.close();
}

// *** Image Preloading ***
function preLoad(pVar, pImageOff, pImageOn) {
	if (doc.images) {
		eval(pVar + " = new Image();");
		eval(pVar + '.src  = "' + pImageOff + '";');
		eval(pVar + "On = new Image();");
		eval(pVar + 'On.src = "' + pImageOn + '";');
	}
}

// *** Image Rollover functions ***
function changeOn(Name) {
	if (document.images)
		document [Name].src = eval(Name + "On.src");
}

function changeOff(Name) {
	if (document.images)
		document [Name].src = eval(Name + ".src");
}

// *** General Layer Functions with layer names as the key ***
function getLObject(LayerName) {
	if (isNav)
		return document.layers[LayerName];
	else if (isIE)
		return document.all[LayerName].style;
}

function show(object) {
	if (document.layers && document.layers[object] != null)
		document.layers[object].visibility = 'show';
	else if (document.all)
	        document.all[object].style.visibility = 'visible';
}

function hide(object) {
	if (document.layers && document.layers[object] != null)
		document.layers[object].visibility = 'hide';
	else if (document.all)
		document.all[object].style.visibility = 'hidden';
}

function Lrewrite(pLayer, pText, pParent) {
	if (isIE) {
		document.all[pLayer].innerHTML = pText;
	} else if (isNav) {
		// For nested layers we should use the pParent argument which has format as follows-
		// [Outermost parent layer].{[inner layer]..}

		var lyr = (pParent) ? 
					eval("document." + pParent + ".document." + this.lName + ".document") : 
					document.layers[pLayer].document;
		lyr.open();
		lyr.write(pText);
		lyr.close();
	}
}

// *** Some useful string utility functions
function padL(pString, pLength, pChar) {
	// Will pad the input string on left to make it to the required length using the pChar string.
	var i;
	var retStr = "";

	if ((pLength <= pString.length) || (pChar.length > 1))
		return pString;

	for (i=0; i<(pLength-pString.length); i++)
		retStr = retStr + pChar;
	retStr = retStr + pString;
	return retStr;
}

function swipe_replace(p_str, p_char, p_swipe) {
	var i;
	var v_str = "";
	var char_replaced = false;

	for (i=0; i<p_swipe; i++) {
		for (j=0; j<p_str.length; i++) {
			if (substr(p_str, j, 1) == p_char) {
				if (!char_replaced) {
					v_str = p_str.replace(p_char, "");
					char_replaced = true;
				}
			} else char_replaced = false;
		}
	}
}

// *** Some useful Javascript utility functions
function arrayElt(pArr, pElt) {
	// Will return the position of an element in an array.
	for (j=0; j<pArr.length; j++) {
		if (pArr[j] == pElt)
			return j;
	}
	
	return "-1";
}

var dTimer;
var dFlag;
function sleep(pInt) {
	var x;
	
	// alert("Sleeping for " + pInt + " Seconds");
	dFlag = false;
	set_sleep(parseInt(pInt));
	for (dFlag=false; dFlag!=true; x=0) {}
}

function set_sleep(pInt) {
	dTimer = setTimeout("clear_sleep()", pInt);
}

function clear_sleep() {
	dFlag = true;
	clearTimeout(dTimer);
	// alert("Waking up..");
}

// *** Some useful HTML Formatting functions/Objects
// *** Displays a date in your HTML document.
function showToday(prompt, frmtOpen, frmtClose) {
	// frmtOpen can be <FONT FACE=Verdana><B> and frmtClose can be </B></FONT>...
	// Default prompt is 'Date: '
	var vDate = new Date();
	var vDay = vDate.getDate();
	var vMonth = vDate.getMonth();
	vDay = (vDay.toString().length < 2) ? "0" + vDay : vDay;
	vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
	
	var vOutString = 
		((frmtOpen != null && frmtOpen != "") ? 
				frmtOpen : "<FONT FACE=Verdana SIZE=2 COLOR=Black><B>") + 
		((prompt != null) ? prompt : "Date: ") + 
		vMonth + "\/" + vDay + "\/" + vDate.getFullYear() + 
		((frmtClose != null && frmtClose != "") ? 
				frmtClose : "<\/B><\/FONT>");
	document.writeln(vOutString);
}

// *** Shadow Table Object ***
function shadowTable(strText, iDir, cColor, sColor, pWidth) {
	if (arguments.length < 1)
		return;

	this.content = strText;
	this.imgDir = (iDir == null) ? "" : iDir;
	this.shadowColor = (sColor == null) ? "#000000" : sColor;
	this.contentColor = (cColor == null) ? "#b7b7c7" : cColor;
	this.width = (pWidth == null) ? 491 : pWidth;
	
	this.tblString = "";
	this.tblString += "<table border=0 width='" + this.width + "' cellpadding=0 cellspacing=0>";
	this.tblString += "<tr>";
	this.tblString += "<td bgcolor=\"" + this.contentColor + "\" colspan=2 rowspan=2 valign=top align=right><img src=\"" + iDir + "corner-g-tl.gif\" width=8 height=8></td>";
	this.tblString += "<td bgcolor=\"" + this.shadowColor + "\"><img src=\"" + iDir + "clear.gif\" width=1 height=1></td>";
	this.tblString += "<td bgcolor=\"" + this.contentColor + "\" colspan=2 rowspan=2 align=right valign=top width=8><img src=\"" + iDir + "corner-g-tr.gif\" width=8 height=8></td>";
	this.tblString += "</tr>";
	this.tblString += "<tr>";
	this.tblString += "<td bgcolor=\"" + this.contentColor + "\"><img src=\"" + iDir + "clear.gif\" width=1 height=7></td>";
	this.tblString += "</tr>";
	this.tblString += "<tr>";
	this.tblString += "<td bgcolor=\"" + this.shadowColor + "\" width=1><img src=\"" + iDir + "clear.gif\" width=1 height=1></td>";
	this.tblString += "<td bgcolor=\"" + this.contentColor + "\" width=7><img src=\"" + iDir + "clear.gif\" width=7 height=1></td>";
	this.tblString += "<td bgcolor=\"" + this.contentColor + "\">";
	this.tblString += "<FONT COLOR=\"#000099\">";
	this.tblString += "<!-- Contents in this cell only -->";
	this.tblString += strText;
	this.tblString += "</td>";
	this.tblString += "<td bgcolor=\"" + this.contentColor + "\" width=6><img src=\"" + iDir + "clear.gif\" width=6 height=1></td>";
	this.tblString += "<td bgcolor=\"" + this.shadowColor + "\" width=2><img src=\"" + iDir + "clear.gif\" width=2 height=1></td>";
	this.tblString += "</tr>";
	this.tblString += "<tr>";
	this.tblString += "<td bgcolor=\"" + this.contentColor + "\" colspan=2 rowspan=2 valign=bottom align=right><img src=\"" + iDir + "corner-g-bl.gif\" width=8 height=8></td>";
	this.tblString += "<td bgcolor=\"" + this.contentColor + "\"><img src=\"" + iDir + "clear.gif\" width=1 height=6></td>";
	this.tblString += "<td bgcolor=\"" + this.contentColor + "\" colspan=2 rowspan=2 valign=bottom align=left><img src=\"" + iDir + "corner-g-br.gif\" width=8 height=8></td>";
	this.tblString += "</tr>";
	this.tblString += "<tr>";
	this.tblString += "<td bgcolor=\"" + this.shadowColor + "\"><img src=\"" + iDir + "clear.gif\" width=1 height=2></td>";
	this.tblString += "</tr>";
	this.tblString += "</table>";
}

new shadowTable();

shadowTable.prototype.output = function() {
	document.writeln(this.tblString);
}

// *** Block Table Object ***
function blockTable(pText, pTitle, pWidth, pFont, pFontSize, pBorderColor, pContentColor) {
	if (arguments.length < 1)
		return;

	this.title = (pTitle == null || pTitle == "") ? null : pTitle;
	this.width = (pWidth == null) ? "100%" : pWidth;
	this.borderColor = (pBorderColor == null) ? "#000099" : pBorderColor;
	this.contentColor = (pContentColor == null) ? "#b7b7c7" : pContentColor;
	this.font = (pFont == null) ? "Verdana" : pFont;
	this.fontSize = (pFontSize == null) ? 2 : pFontSize;

	this.tblString = "";
	this.tblString += "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=1";
	
	if (this.width != "AUTO")
		this.tblString += " WIDTH=\"" + this.width + "\"";
	
	this.tblString += " BGCOLOR=\"" + this.borderColor + "\"><TR><TD>";
	this.tblString += "<TABLE BORDER=0 WIDTH=\"100%\" CELLSPACING=0 CELLPADDING=0 BGCOLOR=\"" + this.contentColor + "\">";
	if (this.title != null) {
		this.tblString += "<TR>";
		this.tblString += "<TD BGCOLOR=\"" + this.borderColor + "\">";
		this.tblString += "<FONT FACE='" + this.font + "' SIZE=" + this.fontSize + " COLOR=white>" + this.title + "</FONT>";
		this.tblString += "</TD>";
		this.tblString += "</TR>";
	}
	this.tblString += "<TR>";
	this.tblString += "<TD>";
	this.tblString += pText;
	this.tblString += "</TD>";
	this.tblString += "</TR>";
	this.tblString += "</TABLE>";
	this.tblString += "</TD></TR></TABLE>";
}

new blockTable();

blockTable.prototype.output = function() {
	document.writeln(this.tblString);
}
// *** --------------------------------------------------------- ***