f=[["a","\u0c05",""],["aa","\u0c06","\u0c3E"],["A","\u0c06","\u0c3E"],["i","\u0c07","\u0c3F"],["ii","\u0c08","\u0c40"],["I","\u0c08","\u0c40"],["u","\u0c09","\u0c41"],["uu","\u0c0A","\u0c42"],["U","\u0c0A","\u0c42"],["e","\u0c0F","\u0c47"],["ee","\u0c08","\u0c40"],["ai","\u0c10","\u0c48"],["o","\u0c13","\u0c4B"],["oo","\u0c0A","\u0c42"],["O","\u0c11","\u0c49"],["au","\u0c14","\u0c4C"],["aM","\u0c05\u0c02","\u0c02"],["aH","\u0c05\u0c03","\u0c03"],["aa.c","\u0c11","\u0c49"],["a.c","\u0c05","\u0c45"],["RRi","\u0c0B","\u0c43"],["R^i","\u0c0B","\u0c43"],["Ru","\u0c0B","\u0c43"],["RRI","\u0c60","\u0c44"],["R^I","\u0c60","\u0c44"],["LLi","\u0c0C","\u0c62"],["L^i","\u0c0C","\u0c62"],["LLI","\u0c61","\u0c63"],["L^I","\u0c61","\u0c63"],["k","\u0c15"],["kh","\u0c16"],["g","\u0c17"],["gh","\u0c18"],["~N","\u0c19"],["ch","\u0c1A"],["chh","\u0c1B"],["Ch","\u0c1B"],["j","\u0c1C"],["jh","\u0c1D"],["~n","\u0c1E"],["T","\u0c1F"],["Th","\u0c20"],["D","\u0c21"],["Dh","\u0c22"],["N","\u0c23"],["t","\u0c24"],["th","\u0c25"],["d","\u0c26"],["dh","\u0c27"],["n","\u0c28"],["p","\u0c2A"],["ph","\u0c2B"],["b","\u0c2C"],["bh","\u0c2D"],["m","\u0c2E"],["y","\u0c2F"],["r","\u0c30"],["R","\u0c30\u0c4D\u200D"],["l","\u0c32"],["v","\u0c35"],["w","\u0c35"],["sh","\u0c36"],["Sh","\u0c37"],["shh","\u0c37"],["s","\u0c38"],["h","\u0c39"],["ld","\u0c33"],["L","\u0c33"],["kSh","\u0c15\u0c4D\u0c37"],["x","\u0c15\u0c4D\u0c37"],["GY","\u0c1C\u0c4D\u0c1E"],["j~n","\u0c1C\u0c4D\u0c1E"],["dny","\u0c1C\u0c4D\u0c1E"],["shr","\u0c36\u0c4D\u0c30"],["R","\u0c31\u0c4d\u0c2f"],["q","\u0c58"],["K","\u0c59"],["G","\u0c5A"],["z","\u0c5B"],["J","\u0c5B"],["f","\u0c5E"],[".D","\u0c5C"],[".Dh","\u0c5D"],["AUM","\u0c50"],["OM","\u0c50"],[".r","\u0c30\u0c4D"],[".n","\u0c02"],["M","\u0c02"],["m","\u0c02"],[".c","\u0c45"],[".N","\u0c01"],[".h","\u0c4D"],["H","\u0c03"],[".a","\u0c3D"],["0","\u0c66"],["1","\u0c67"],["2","\u0c68"],["3","\u0c69"],["4","\u0c6A"],["5","\u0c6B"],["6","\u0c6C"],["7","\u0c6D"],["8","\u0c6E"],["9","\u0c6F"]];

w="\u0c4d";

k=/^0|1|2|3|4|5|6|7|8|9|(AUM)|(LLI)|(LLi)|(L\^I)|(L\^i)|(OM)|(RRI)|(RRi)|(R\^i)|(R\^i)|(\.N)|(\.a)|(\.c)|(\.h)|(\.n)|(\.r)|(\H)|R|A|I|U|(aH)|(aM)|(a\.c)|(aa)|(aa\.c)|(Ru)|(ai)|(au)|(ee)|(ii)|(oo)|(uu)|a|e|i|o|O|u/;

n=/^((AUM)|(Ch)|(Dh)|(GY)|(LLI)|(LLi)|(L\^I)|(L\^i)|(OM)|(RRI)|(RRi)|(R\^i)|(R\^I)|(Sh)|(Th)|(\.D)|(\.Dh)|(\.N)|(\.a)|(\.c)|(\.h)|(\.n)|(\.r)|(aa\.c)|(Ru)|(aa)|(ee)|(ai)|(au)|(aH)|(aM)|(a\.c)|(chh)|(bh)|(ch)|(dny)|(dh)|(gh)|(ii)|(oo)|(jh)|(j~n)|(kSh)|(shh)|(kh)|(ph)|(shr)|(sh)|(th)|(uu)|(~N)|(~n)|A|D|G|H|I|J|K|L|N|O|R|T|U|Y|a|b|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|0|1|2|3|4|5|6|7|8|9)/;


function b(e,r){var i=0;for(i=0;i<f.length;i++){if(f[i][0]==e){if(r&&f[i].length==3)return f[i][2];else return f[i][1];}}return e;}

function j(e){l="";d=0;a=0;g=false;h=false;while(e.length){c=n.exec(e);if(c&&!(h)){d=k.test(c[0]);if(l.length&&g){if(!(d||a))l=l+w+b(c[0],0);else if(!a&&d&&c[0]!="a")l=l+b(c[0],1);else if(a&&d)l=l+b(c[0],0);else if(a&&!d)l=l+b(c[0],0);}else l=l+b(c[0],0);e=e.substr(c[0].length);g=true;a=d;}else{if(e.charAt(0)=="<"){h=true;}else if(e.charAt(0)==">"){h=false;}else{l=l+e.charAt(0);}e=e.substr(1);g=false;}}return l;}


function trans_tel(textin) {
	textout=j(textin);
	if(textout.length) {
	 	return textout;
	}
}

//---------------------------   popup script { -------------------------------------------

// ************************
// layer utility routines *
// ************************

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.left = newXCoordinate;
	styleObject.top = newYCoordinate;
	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject


// popup script

// ********************************
// application-specific functions *
// ********************************

// store variables to control where the popup will appear relative to the cursor position
// positive numbers are below and to the right of the cursor, negative numbers are above and to the left
var xOffset = 30;
var yOffset = -5;
function displayClipartPopup1 (imgsrc, popupTitle) {
	return displayClipartPopup (imgsrc, popupTitle, window.event);
}

function displayClipartPopup (imgsrc, popupTitle, eventObj) {
	if (!eventObj) {
		var eventObj = window.event;
	}
	
	var popupDiv = document.getElementById('clipartPopup');
	var imageNode = document.getElementById('popupClipartImg');
	
	imageNode.src = imgsrc;
	imageNode.alt = popupTitle;
	popupDiv.style.width = (imageNode.width + 5)+'px';
	popupDiv.style.height = (imageNode.height + 5)+'px';
	
	
	showPopup ('clipartPopup', eventObj);
}

function showPopup (targetObjectId, eventObj) {
    if(eventObj) {
	// hide any currently-visible popups
	hideCurrentPopup();
	// stop event from bubbling up any farther
	eventObj.cancelBubble = true;
	// move popup div to current cursor position 
	// (add scrollTop to account for scrolling for IE)
	var newXCoordinate = (eventObj.pageX)?eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);
	var newYCoordinate = (eventObj.pageY)?eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);
	moveObject(targetObjectId, newXCoordinate, newYCoordinate);
	// and make it visible
	if( changeObjectVisibility(targetObjectId, 'visible') ) {
	    // if we successfully showed the popup
	    // store its Id on a globally-accessible object
	    window.currentlyVisiblePopup = targetObjectId;
	    return true;
	} else {
	    // we couldn't show the popup, boo hoo!
	    return false;
	}
    } else {
	// there was no event object, so we won't be able to position anything, so give up
	return false;
    }
} // showPopup

function hideCurrentPopup() {
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
    if(window.currentlyVisiblePopup) {
	changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
	window.currentlyVisiblePopup = false;
    }
} // hideCurrentPopup



// ***********************
// hacks and workarounds *
// ***********************

// initialize hacks whenever the page loads
window.onload = initializeHacks;

// setup an event handler to hide popups for generic clicks on the document
document.onclick = hideCurrentPopup;

function initializeHacks() {
    // this ugly little hack resizes a blank div to make sure you can click
    // anywhere in the window for Mac MSIE 5
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	window.onresize = explorerMacResizeFix;
    }
    resizeBlankDiv();
    // this next function creates a placeholder object for older browsers
    createFakeEventObj();
}

function createFakeEventObj() {
    // create a fake event object for older browsers to avoid errors in function call
    // when we need to pass the event object to functions
    if (!window.event) {
	window.event = false;
    }
} // createFakeEventObj

function resizeBlankDiv() {
    // resize blank placeholder div so IE 5 on mac will get all clicks in window
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	getStyleObject('blankDiv').width = document.body.clientWidth - 20;
	getStyleObject('blankDiv').height = document.body.clientHeight - 20;
    }
}

function explorerMacResizeFix () {
    location.reload(false);
}

//---------------------------   popup script } -------------------------------------------



function readUserPrefCookie(name) {
	var i = 0; var lookfor = name + "=";
	while (i < document.cookie.length) {
		var j = i + lookfor.length;
		if (document.cookie.substring(i,j) == lookfor) {
			var endstr = document.cookie.indexOf(";", j);
			if (endstr == -1) {
				endstr = document.cookie.length;
			}
			return unescape(document.cookie.substring(j, endstr));
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) {
			break;
		}
	}
	return "";
}


// clipart related methods
var hideClipart =  readUserPrefCookie('hideClipart');
var hideClipart2 =  readUserPrefCookie('hideClipart2');
var hideClipart3 =  readUserPrefCookie('hideClipart3');
var showClipartPopup =  readUserPrefCookie('showClipartPopup');


function checkPageSettings() {
	checkClipartPrefs();
}

function checkClipartPrefs() {
	var isHideClipart =  ( (hideClipart != null) && (hideClipart == 'true') );
	var isHideClipart2 =  ( (hideClipart2 != null) && (hideClipart2 == 'true') );
	var isHideClipart3 =  ( (hideClipart3 != null) && (hideClipart3 == 'true') );
	var isShowClipartPopup =  ( (showClipartPopup != null) && (showClipartPopup == 'true') );
	
	if ( ! (isHideClipart || isHideClipart2 || isHideClipart3) ) {
		return;
	}
	
	var objs = document.getElementsByTagName("img");
	var imgsCount = objs.length;
	var imageNode = null;

	for (var i=(imgsCount-1); i >=0; i--){
		imageNode = objs[ i ];
		
		var strTagname = "";
		if (imageNode.src.indexOf('discus/clipart/') != -1) {
			if ( !isHideClipart ) {
				continue;
			}
			strTagname = "clipart";
		} else if (imageNode.src.indexOf('discus/clipart2/') != -1) {
			if ( !isHideClipart2 ) {
				continue;
			}
			strTagname = "clipart2";
		} else if (imageNode.src.indexOf('discus/clipart3/') != -1) {
			if ( !isHideClipart3 ) {
				continue;
			}
			strTagname = "clipart3";
		} else {
			continue;
		}
		

		var nameStart = imageNode.src.lastIndexOf('/');
		var nameEnd = imageNode.src.lastIndexOf('.');
		var strSrc = imageNode.src.substring(nameStart+1, nameEnd);

		var strImgName = "\\"+strTagname+"{"+strSrc+"}";
		var imgNameNode = document.createTextNode( strImgName );
		
		var newClipartNode = null;

		if( isShowClipartPopup ) {
			var strImgUrl = encodeURI( imageNode.src );
			
			var spanTag = document.createElement("span"); 
			spanTag.innerHTML = '<a href="#" onclick="displayClipartPopup(\''+strImgUrl+'\', \'\\'+strImgName+'\', event); return false;">'+strImgName+'</a>';
			
			newClipartNode = spanTag;
		} else {
			var fontTag = document.createElement("font");
			fontTag.style.color = 'darkBlue';
			fontTag.style.fontSize = 'medium';
			fontTag.style.fontFamily = 'courier';

			fontTag.appendChild(imgNameNode);

			newClipartNode = fontTag;
		}

		var imgParent = imageNode.parentNode;
		var imgClone = imageNode.cloneNode(true);
		if ( imgParent != null ) {
			imgParent.replaceChild(newClipartNode, imageNode);
		}
	
	}
}
