
function changeImages(id, d) {
	if (d=="on") img = "/images/Buttons/"+id+"_on.gif";
	else if (d=="over" || d=="down" || d=="nrml") img = "/images/editor/"+id+"_btn_"+d+".gif";
	else img = "/images/Buttons/"+id+".gif";
	document.getElementById(id).src = img;

}

function changeImageN(t) {
	ext = t.src.substr(t.src.lastIndexOf("."));
	if (t.src.indexOf("_on")!=-1) {
		img = t.src.substr(0,t.src.lastIndexOf("/")+1)+t.id+ext;
	} else {
		img = t.src.substr(0,t.src.lastIndexOf("."))+"_on"+ext;
	}
	document.getElementById(t.id).src = img;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function warning(wText, wType, wTop, wLeft, callbackYes, callbackNo) {
	dRef = document.getElementById('warningWindow');
	var warningInner = "";
	warningInner += "<div id=\"wwTop\"></div>";
	warningInner += "<div id=\"wwSide\"></div>";
	warningInner += "<div id=\"wwContent\">";
	warningInner += "<div style=\"margin-bottom: 10px;\">"+wText+"</div>";
	warningInner += "<div align=\"right\">";
	if (wType=="confirm") {
		warningInner += "<img onmouseover=\"this.style.cursor='hand';\" onmouseout=\"this.style.cursor='default';\" onclick=\"";
		
		if (callbackYes.indexOf("(")!=-1) {
			warningInner += "eval("+callbackYes+")";
		} else {
			warningInner += callbackYes;
		}
		
		warningInner += ";document.getElementById('warningWindow').style.display='none';\" src=\"/images/Edit_Buttons/Yes.jpg\">";
		warningInner += "<img style=\"z-index:99;\" onmouseover=\"this.style.cursor='hand';\" onmouseout=\"this.style.cursor='default';\" onclick=\"";
		
		if (callbackNo.indexOf("(")!=-1) {
			warningInner += "eval("+callbackNo+")";
		} else {
			warningInner += callbackNo;
		}
		
		warningInner += ";document.getElementById('warningWindow').style.display='none';\" src=\"/images/Edit_Buttons/No.jpg\">";
	} else {
		warningInner += "<img id=\"warningNoButton\" onmouseover=\"this.style.cursor='hand';\" onmouseout=\"this.style.cursor='default';\" onclick=\""+callbackYes+";document.getElementById('warningWindow').style.display='none';\" src=\"/images/Edit_Buttons/Ok.jpg\"></div>";
	}
	warningInner += "</div></div>";
	//var oNewNode = document.createElement("<div id=\"warningWindow\" style=\"top: "+wTop+"px; left: "+wLeft+"px;\">");
   	//document.body.applyElement(oNewNode, "inside");
	dRef.innerHTML = warningInner;
	dRef.style.top = wTop;
	dRef.style.left = wLeft;
	dRef.style.display = '';
	dRef.style.zIndex = 150;
	dRef.style.height = document.getElementById('wwContent').scrollHeight+45;
	
	//focus no button
	if (wType=="alert") {
		document.getElementById("warningNoButton").style.border = "1px dotted #000000";
		document.body.focus();
		document.body.onkeyup = function() {
			if (event.keyCode==13) {
				document.getElementById("warningNoButton").click();
			}
		}
	}
}


function mozillaConfirm(mcText,mcType,mcYES,mcYESvar,mcNO,mcNOvar,mcTop,mcLeft,mcWidth,mcHeight)
{
	dRef = document.getElementById('warningWindow');

	if(mcType == 'yn')
	{
		
		mcHTML = "<div style=\"position:absolute; left:0px; top:0px; z-index:99; width:100%; height:15px; background-image: url('/images/popup_white_triangle.gif'); background-repeat: no-repeat; background-color: #cacab8; overflow: hidden;\"></div><div style=\"position: absolute; top: 0px; left: 0px; height: 100%; width: 14px; border-right: 1px solid #cacab8;\"></div><div style=\"width:280px; padding-left:30px; padding-top:25px; margin-bottom: 5px;\">"+mcText+"</div><div style=\"padding-left:150px;\"><img onmouseover=\"this.style.cursor='pointer';\" onmouseout=\"this.style.cursor='default';\" onclick=\"dRef.style.display= 'none'; "+mcYES+"("+mcYESvar+");\" src=\"images/Edit_Buttons/Yes.jpg\" width=\"52\" height=\"22\" alt=\"Yes\" /><img onmouseover=\"this.style.cursor='pointer';\" onmouseout=\"this.style.cursor='default';\" onclick=\"dRef.style.display= 'none'; "+mcNO+"("+mcNOvar+");\" src=\"images/Edit_Buttons/No.jpg\" width=\"52\" height=\"22\" alt=\"No\" /></div>";

		dRef.innerHTML = mcHTML;
		dRef.style.top = mcTop;
		dRef.style.left = mcLeft;
		dRef.style.width = mcWidth;
		dRef.style.height = mcHeight;
		dRef.style.display = '';

		
	}
	else if (mcType == 'alert')
	{
	
		mcHTML = "<div style=\"position:absolute; left:0px; top:0px; z-index:5; width:100%; height:15px; background-image: url('/images/popup_white_triangle.gif'); background-repeat: no-repeat; background-color: #cacab8; overflow: hidden;\"></div><div style=\"position: absolute; top: 0px; left: 0px; height: 100%; width: 14px; border-right: 1px solid #cacab8;\"></div><div style=\"width:280px; padding-left:30px; padding-top:25px; margin-bottom: 5px;\">"+mcText+"</div><div style=\"padding-left:150px;\"><img id=\"yesImgButton\" onmouseover=\"this.style.cursor='pointer';\" onmouseout=\"this.style.cursor='default';\" onclick=\"dRef.style.display= 'none';\" src=\"images/Edit_Buttons/Ok.jpg\" width=\"52\" height=\"22\" alt=\"No\" /></div>";

		dRef.innerHTML = mcHTML;
		dRef.style.top = mcTop;
		dRef.style.left = mcLeft;
		dRef.style.width = mcWidth;
		dRef.style.height = mcHeight;
		dRef.style.display = '';

		document.getElementById('yesImgButton').focus;
		
	}
	

}

//cleans out content string with regular expressions
function cleanMozillaMess(theString)
{
 	//Move h1's and replace with divs
	theString = theString.replace(new RegExp("<h1","gi"),'<div');
	theString = theString.replace(new RegExp("</h1>","gi"),'</div>');

	//remove any <br>
	theString = theString.replace(new RegExp("<br />","gi"),' ');
	theString = theString.replace(new RegExp("<br>","gi"),' ');
	
	//convert &nbsp;
	theString = theString.replace(new RegExp("&nbsp;","gi"),' ');
			
	//Replace \n \r with spaces.  This is important otherwise we end up with
	//words squished together from a later operation after the POST
	theString = theString.replace(new RegExp("\n","g"),' ');
	theString = theString.replace(new RegExp("\r","g"),' ');
	theString = theString.replace(new RegExp("\r\n","g"),' ');
	theString = theString.replace(new RegExp("\n\r","g"),' ');

	//remove all blank id tags.  There are generated in the ie bold/italic styling process.
	theString = theString.replace(new RegExp('id=""','g'),'');

	//Remove all spaces between tags - </h1>     <h1> becomes </h1><h1>
	theString = theString.replace(new RegExp("h1> *<h1","g"),'h1><h1');
	theString = theString.replace(new RegExp("div> *<div","g"),'div><div');
	//Remove all spaces inside the start of a tag - <h1>    Text here</h1> becomes <h1>Text here</h1>
	theString = theString.replace(new RegExp("> + ","g"),'>');
	//Remove all spaces inside the end of a tag - <h1>Text here      </h1> becomes <h1>Text here</h1>
	theString = theString.replace(new RegExp(" + <","g"),'<');
	
	return theString;
}

//does a dom check and clean for ie and mozilla
function cleanOnSaveJS(theNode)
{
	//check if the node is the meEdit node for IE or the body node for Mozilla
	if(theNode.id == "meEdit" || theNode.nodeName.toLowerCase() == "body")
	{
		//loop through the nodes children
		for(k=0;k<theNode.childNodes.length;k++)
		{
			//setup the childnode we are looking at
			cN = theNode.childNodes[k];

			//if the node is a div or h1 we look at it
			if(cN.nodeName.toLowerCase() == "div" || cN.nodeName.toLowerCase() == "h1")
			{
				//if the node is blank we remove it
				if(cN.innerHTML == "" || cN.innerHTML == "\r\n" || cN.innerHTML == "<br>\r\n")
				{
					theNode.removeChild(cN);
					k--;
				}
			}
			//temp fix for content script hopping into the body? wth? This has been fixed by placing the javascript call in the body tag onload event. I will leave this here though.
			else if(cN.nodeName.toLowerCase() == "script")
			{
				theNode.removeChild(cN);
				k--;
			}
		}

		theNode.innerHTML = cleanPunctuation(theNode.innerHTML)
	}

}

//This function attempts to remove unwanted spaces before punctuation.
//For the most part it will clean up more errors then it creates.
//There are very few places that you want a space before these characters.
//Input: the text we are going to be looking at
function cleanPunctuation(content)
{
	//First we build a list of character we want to loop through
	var pArray = new Array();
	//
	pArray[0] = "!";pArray[1] = "?";pArray[2] = ".";pArray[3] = ",";pArray[4] = ":";pArray[5] = ";";
	pSize = pArray.length;

	//walk through each character type and fix any problems we find
	for (i=0;i<pSize;i++)
	{		
		//if we find these characters with a space before them we remove the space.
		content = content.replace(new RegExp(" \\"+pArray[i],"gi"),pArray[i]);
	}
	//return the string
	return content;
}