// DO NOT CHANGE THIS CODE
/**
* eWebEditPro.js
* Copyright 1999-2000, Ektron, Inc
* Author: Bill Rogers
* Date: 06/07/2000
* Revision: 2.0
*

* Wed. 06/28/00
* Modify by: Alpesh Patel

*/

// DO NOT CHANGE THIS CODE
var ua = window.navigator.userAgent;
var isIE = (ua.indexOf("MSIE ") != -1);
var numEditors = 0;
var numEditorButtons = 0;
var eWebEditor = "eWebEditor";
var editorName = eWebEditor + numEditors;
var objClassId = "CLSID:7B1A430D-F9B9-11D3-A435-0050DA5D9D44"	//Class id of the .ocx
var version = "1,8,0,11";										//Version # of the eWebEdit Pro.

mainFormName = new Array(32);
mainFormTextareaName = new Array(32);
mainFormHiddenfieldName = new Array(32);
mainFormeWebEditProParametersName = new Array(32);

docFormName = new Array(32);
docHiddenFieldName = new Array(32);
docMaxContentSize = new Array(32);

function ActiveX () {
       this.netscape = (window.navigator.appName == "Netscape");
       this.installation = this.netscape && !navigator.plugins ["Esker ActiveX Plug-in"];
       this.width = 100;
       this.height = 100;
       this.parameters = new Array (0);
       this.events = new Array (0);
       this.defineParam = ActiveX_defineParam;
       this.handleEvent = ActiveX_handleEvent;
       this.instantiate = ActiveX_instantiate;
}

function ActiveX_defineParam (name, value) {
	if (this.netscape) {
    	this.parameters [this.parameters.length] = '\n' + name + '="' + value + '"';
    } else {
        this.parameters [this.parameters.length] = '\n<param name="' + name + '" value="' + value + '">';
    }
}
function ActiveX_handleEvent (name, value) {
	if (this.netscape) {
    	this.events [this.events.length] = '\n' + name + '="' + value + '"';
    } else if (this.id) {
        this.events [this.events.length] = '\n<scr' + 'ipt language=javascript for="' + this.id + '" event="' + name + '">\n' + value + '\n<' + '/sc' + 'ript>';
    }
}

function ActiveX_instantiate () {
   var tag = "";
   if (!this.installation) {
       if (this.netscape) {
           tag += '<embed type="application/x-eskerplus"';
       } else  {
           tag += '<object';
       }
       if (this ["id"]) {
           tag += '\nid="' + this.id + '"';
       }
       else if (this ["name"]) {
           tag += '\nid="' + this.name + '"';
       }
       if (this ["classid"]) {
           tag += '\nclassid="' + this.classid + '"';
       }
       if (this ["codebase"]) {
           if (this.netscape) {
               if (this ["deployer"]) {
                   this.codebase = this.deployer;
               } else {
                   var extension = this.codebase.indexOf (".CAB");
                   if (extension >= 0) {
                       this.codebase = this.codebase.substring (0, extension) + ".OCX" + this.codebase.substring (extension + 4, this.codebase.length);
                   }
               }
           }
           tag += '\ncodebase="' + this.codebase + '"';
       }
       if (this.width == null || this.width == 0 || this.width == "0") {
           this.width = 2;
       }
       tag += '\nwidth="' + this.width + '"';
       if (this.height == null || this.height == 0 || this.height == "0") {
           this.height = 2;
       }
       tag += '\nheight="' + this.height + '"';
       if (!this.netscape) {
           tag += '>';
       }
       for (var index = 0; index < this.parameters.length; index++) {
           tag += this.parameters [index];
       }
       if (this.netscape) {
           for (var index = 0; index < this.events.length; index++) {
               tag += this.events [index];
           }
           tag += '>';
       } else {
           tag += '\n</object>';
           for (var index = 0; index < this.events.length; index++) {
               tag += this.events [index];
           }
       }
   }
   return tag;
}

function saveContentToHiddenField() {
	var fieldName = "";
	var editName = "";
	var formName = "";
	var maxContentSize = 0;
	var isValidSizeContent = true;
	for (var index = 1; index < (numEditors + 1); index++) {
		editName = eWebEditor + index;
		fieldName = docHiddenFieldName[index];
		formName = docFormName[index];
		maxContentSize = docMaxContentSize[index];
		if (isIE)
			document.forms[formName].elements[fieldName].value = document.forms[formName].elements[editName].TextHTML;
		else
			eval(editorName).get_TextHTML();
			document.forms[formName].elements[fieldName].value = eval(editorName).get_TextHTML();
		isValidSizeContent = checkContentSize(document.forms[formName].elements[fieldName].value, maxContentSize);
		if(isValidSizeContent)
			return false; //Content exceeds maxContentSize
	}
	return true; //Content Saved
}

function eWebEditProEditor(eWebEditProParameters, formName, fieldName, width, height, wddx, htmlContent) {
	wddxdata = wddx;  // It is a Global, just reset this.
	if (eWebEditProParameters.autoField){
		document.write("<input type='Hidden' name='" + fieldName + "' value >");
		}
	if ((numEditors == 0) & (eWebEditProParameters.autoSubmit)){
		document.forms[formName].onsubmit = new Function("return saveContentToHiddenField();");
		}
	numEditors = numEditors + 1; //numbers of editors
	docHiddenFieldName[numEditors] = fieldName;
	docFormName[numEditors] = formName;
	docMaxContentSize[numEditors] = eWebEditProParameters.MaxContentSize;
	editorName = eWebEditor + numEditors;
	pasteHtml(formName,editorName);
	defineeWebEditProParameters(width, height);
	var delay = 2100;
	if (isIE) {
	delay = 1000;
	}
	var myload = setTimeout('LoadContent("' + editorName + '","' + formName + '","'  + htmlContent + '")', delay);

}
function pasteHtml(formName,editorName){
	if (eWebEditProParameters.pasteexample){
	var urlvalue = '<input type="button" value="Paste" onclick="PopUpWindow(';
		urlvalue += "'pasttest.htm?formname=" + formName + "&editorName=" + editorName + "', 'imageUpload'";
		urlvalue += ', 300, 200, 0);"><br>';
		document.writeln(urlvalue);
		}
}

function defineeWebEditProParameters(width, height)
{


	if (isIE) {
		var msie = ua.indexOf("MSIE ");
		var ver = parseInt(ua.substring(msie+5, ua.indexOf(".", msie)));
		if (ver == 4)
			{
			document.write("<OBJECT CLASSID='clsid:2D360201-FFF5-11D1-8D03-00A0C959BC0A' ID=DHTMLSafe1 HEIGHT=0 WIDTH=0 CODEBASE='" + eWebEditProDefaultPath + "DHTMLED.CAB#Version=6,1,0,8243'></OBJECT>");
			}
	} else  {
		//  Netscape
		plugins = navigator.plugins;
		if(!plugins["Esker ActiveX Plug-in"])
		    document.writeln('<FONT face=Verdana size=2>eWebEditPro Netscape Plug-in is <b>not</b> installed. <A href="http://www.ektron.com/software/released/installation/ewebeditpro/ewebeditproclient.exe"><STRONG>Click Here</STRONG></A> to run the eWebEditPro Client Install <p></FONT>');
	}

	var NfsdlgActiveX = new ActiveX;
    NfsdlgActiveX.id = editorName;
    NfsdlgActiveX.classid = objClassId;
	if(isIE)
	{
		 NfsdlgActiveX.codebase = eWebEditProDefaultPath + 'ewebeditpro.cab#version=' + version;
		 NfsdlgActiveX.defineParam ("Wddx", wddxdata);
	}
	else {
		 NfsdlgActiveX.codebase = "eWebEditPro.ocx#version=" + version;
		 NfsdlgActiveX.defineParam ("href", document.location.href);
	}
   	NfsdlgActiveX.width = width;
   	NfsdlgActiveX.height = height;
	NfsdlgActiveX.defineParam ("License", eWebEditProParameters.License);
	NfsdlgActiveX.defineParam ("License2", eWebEditProParameters.License2);
	NfsdlgActiveX.defineParam ("License3", eWebEditProParameters.License3);
	NfsdlgActiveX.defineParam ("Locale", eWebEditProParameters.Locale);
	NfsdlgActiveX.defineParam ("Options", eWebEditProParameters.Options);
	NfsdlgActiveX.defineParam ("BackColor", eWebEditProParameters.BackColor);
	NfsdlgActiveX.defineParam ("ForeColor", eWebEditProParameters.ForeColor);
	NfsdlgActiveX.defineParam ("FontName", eWebEditProParameters.FontName);
	NfsdlgActiveX.defineParam ("FontSize", eWebEditProParameters.FontSize);
	NfsdlgActiveX.defineParam ("FTPServer", eWebEditProParameters.FTPServer);
	NfsdlgActiveX.defineParam ("FTPUsername", eWebEditProParameters.FTPUsername);
	NfsdlgActiveX.defineParam ("FTPPassword", eWebEditProParameters.FTPPassword);
	NfsdlgActiveX.defineParam ("ImagesPath", eWebEditProParameters.ImagesPath);
	NfsdlgActiveX.defineParam ("PostingAcceptor", eWebEditProParameters.PostingAcceptor);
	NfsdlgActiveX.defineParam ("Username", eWebEditProParameters.Username);
	NfsdlgActiveX.defineParam ("Password", eWebEditProParameters.Password);
	NfsdlgActiveX.defineParam ("AllowCustomize", eWebEditProParameters.AllowCustomize);
	NfsdlgActiveX.defineParam ("ButtonsAbout", eWebEditProParameters.ButtonsAbout);
	NfsdlgActiveX.defineParam ("ButtonsAlign", eWebEditProParameters.ButtonsAlign);
	NfsdlgActiveX.defineParam ("ButtonsBullets", eWebEditProParameters.ButtonsBullets);
	NfsdlgActiveX.defineParam ("ButtonsEdit", eWebEditProParameters.ButtonsEdit);
	NfsdlgActiveX.defineParam ("ButtonsFind", eWebEditProParameters.ButtonsFind);
	NfsdlgActiveX.defineParam ("ButtonsFontColor", eWebEditProParameters.ButtonsFontColor);
	NfsdlgActiveX.defineParam ("ButtonsFontSize", eWebEditProParameters.ButtonsFontSize);
	NfsdlgActiveX.defineParam ("ButtonsFontStyle", eWebEditProParameters.ButtonsFontStyle);
	NfsdlgActiveX.defineParam ("ButtonsHyperlink", eWebEditProParameters.ButtonsHyperlink);
	NfsdlgActiveX.defineParam ("ButtonsIndent", eWebEditProParameters.ButtonsIndent);
	NfsdlgActiveX.defineParam ("ButtonsPicture", eWebEditProParameters.ButtonsPicture);
	NfsdlgActiveX.defineParam ("ButtonsSpelling", eWebEditProParameters.ButtonsSpelling);
	NfsdlgActiveX.defineParam ("ButtonsTable", eWebEditProParameters.ButtonsTable);
	document.write (NfsdlgActiveX.instantiate());
	NfsdlgActiveX=null;
}

function LoadContent(editorName,formName,HTMLcontent) {
	if (isIE)  {
		document.forms[formName].elements[editorName].TextHTML = HTMLcontent;
	} else {
		// Netscape
		eval(editorName).put_TextHTML(HTMLcontent);
		eval(editorName).put_WDDX(wddxdata);
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Functions are for WYSIWYG Button Only
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function PopUpWindow (url, hWnd, nWidth, nHeight, nScroll) {
	var cToolBar = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + nScroll + ",resizable=0,width=" + nWidth + ",height=" + nHeight;
	var popupwin = window.open(url, hWnd, cToolBar);
}

function find_element (myformName,textFieldName, wddxdataName, hiddenParametersField) {
	var elementID = 0;
	var WddxID = 0;
	var ParID = 0;

	for (i = 0; i < document.forms[myformName].elements.length; i++){
		if ( document.forms[myformName].elements[i].name == textFieldName){
			ContentID = i;
		}
		if ( document.forms[myformName].elements[i].name == wddxdataName){
			WddxID = i;
		}
		if ( document.forms[myformName].elements[i].name == hiddenParametersField){
			ParID = i;
		}
	}
	PopUpWindow(eWebEditProDefaultPath + 'popupeditor.htm?MainFormName=' + myformName + '&MainTextAreaID=' + ContentID + '&WddxDataID=' + WddxID + '&eWebEditProParametersID=' + ParID , 'MyEditor', 740, 550, 0);
}

function saveContentToHiddenFieldButton() {
	var fieldName = "";
	var editName = "";
	var formName = "";
	var maxContentSize = 0;
	var isValidSizeContent = true;

	for (var index = 1; index < (numEditors + 1); index++) {
		editName = eWebEditor + index;
		fieldName = docHiddenFieldName[index];
		formName = docFormName[index];
		maxContentSize = docMaxContentSize[index];
		mainTextarea = mainFormTextareaName[index];
		mainForm = mainFormName[index];

		if (isIE) //Copy content from text area to eWebEditor in popup window
			top.opener.document.forms[mainForm].elements[mainTextarea].value = document.forms[formName].elements[editName].TextHTML;
		else
			top.opener.document.forms[mainForm].elements[mainTextarea].value = eval(editName).get_TextHTML();
		isValidSizeContent = checkContentSize(top.opener.document.forms[mainForm].elements[mainTextarea].value, maxContentSize);
		if(!isValidSizeContent)
			return isValidSizeContent;
	}
	return true;
}
function LoadContentButton(editorName,formName, mainFormId, mainTextareaId, wddxdataId) {
	if (isIE)  {
			document.forms[formName].elements[editorName].TextHTML = (top.opener.document.forms[mainFormId].elements[mainTextareaId].value);
		} else {
// Netscape
			eval(editorName).put_TextHTML(top.opener.document.forms[mainFormId].elements[mainTextareaId].value);
			eval(editorName).put_WDDX(top.opener.document.forms[mainFormId].elements[wddxdataId].value);

		}
}

function eWebEditProEditorButton(eWebEditProParameters, myformName, textFieldName, wddxdata, buttonValue) {

	numEditorButtons = numEditorButtons + 1;
	var wddxdataName = "wddxdata" + numEditorButtons;
	var hiddenParametersFieldName = "hiddenParametersField" + numEditorButtons;
	document.write('<INPUT TYPE = "hidden" NAME = "' + wddxdataName + '" VALUE = "' + wddxdata + '">');
	document.write("<INPUT TYPE = 'hidden' NAME = '" + hiddenParametersFieldName + "' VALUE = '" + eWebEditProParameters.toString() + "'>");
	document.write("<INPUT onclick=" + '"JavaScript:find_element (' + "'" + myformName + "','" + textFieldName  + "', '" + wddxdataName + "', '" + hiddenParametersFieldName + "');" + '" type=button value="' + buttonValue + '">');

}

function eWebEditProEditorB(eWebEditProParametersID, formName, mainFormId, wddxdataId, mainTextareaId) {

	eval(top.opener.document.forms[mainFormId].elements[eWebEditProParametersID].value);
	if ((numEditors == 0) & (objPar.autoSubmit))
		document.forms[formName].onsubmit = new Function("return saveContentToHiddenFieldButton();");
	numEditors = numEditors + 1;
	editorName = eWebEditor + numEditors;
 	docFormName[numEditors] = formName;
	docMaxContentSize[numEditors] = objPar.MaxContentSize;
	mainFormTextareaName[numEditors] = mainTextareaId;
	mainFormHiddenfieldName[numEditors] = wddxdataId;
	mainFormeWebEditProParametersName[numEditors] = eWebEditProParametersID;
	mainFormName[numEditors] = mainFormId;

	width = 720;
	height = 460;
	pasteHtml(formName,editorName);
	defineeWebEditProParameters(width, height);
	var myload = setTimeout('LoadContentButton("' + editorName + '","' + formName + '","' + mainFormId + '","' +  mainTextareaId + '","' +  wddxdataId + '");', 1400);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// End of functions for WYSIWYG Button
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function checkContentSize(content, maxContentSize){
	if(content.length > maxContentSize){
		alert(content.length + " " + sMaxContentSizeMessage1 + " " + sMaxContentSizeMessage2 + " " + maxContentSize);
		//alert('Your document is ' + content.length + ' bytes. This document is greater than the max limit ' + maxContentSize + ' bytes in size, set by your admin via parameters.js');
		return true;
	}
	else
		return false;
}

// Brings the editor in a popup window
function popUpEditor()
{
	// Need to get the URL parameters, i.e. the form name and the text area name
	var queryString = document.location.search.substring(1);
	queryArray = queryString.split("&");
	for (i=0; i < queryArray.length; i++) {
		pairSplit = queryArray[i].indexOf("=");
		if (pairSplit != -1){
			pairKey = queryArray[i].substring(0,pairSplit);
			pairValue = queryArray[i].substring(pairSplit+1);
			pairEval = pairKey + "=\"" + pairValue + "\"";
			eval(pairEval);
		}
	}
	//IDs are passed from the originate windows through popup window's url.
	MainTextAreaID = unescape(MainTextAreaID);
	MainFormName = unescape(MainFormName);
	WddxDataID = unescape(WddxDataID);
	eWebEditProParametersID = unescape(eWebEditProParametersID);
	eWebEditProEditorB(eWebEditProParametersID, "frmname", MainFormName, WddxDataID, MainTextAreaID);
}

//Sends the content form the editor in a popup window back to the textarea feild
function PassContent() {
	var continueOn = true;
	if (!top.opener.closed) {
		eval(top.opener.document.forms[MainFormName].elements[eWebEditProParametersID].value);
		continueOn = saveContentToHiddenFieldButton();
	}
	else {
		if(confirm(sCanNotSave)){
			continueOn = false;
		}
		else {
			continueOn = true;
		}
	}
	if(continueOn == false){
		self.close()
	}
}
