// This module contains all of the DHTML / JavaScript code needed to
// create the dynamic, external code section.

// Module Variables
var oList;
var oTable;
var sBackColor;
var sFontColor;
var sColor;
var sStyle;
var sWidth;

// Constants
var sRootURL = "http://www.oddMark.com/";
var sRootImagsURL = "http://images.oddMark.com";
// var sRootURL = "http://localhost/";

// perName is needed for use with masterpages
var preName = "ctl00_ContentPlaceHolder1_";
// var preName = "";


//------ jsEC_ClearRows -----------------------------------------------------
// Desc: This routine is used to clear all rows from the preview table.
//------------------------------------------------------- 05/05/2007 -- DC --
function jsEC_ClearRows() {
	
	// Loop and remove all items
	for (var nC = oTable.rows.length - 1; nC > -1; nC--) {
		oTable.deleteRow(nC);
	}

	// Set return value
	return true;

}

//------ jsEC_InsertHeader --------------------------------------------------
// Desc: This routine is used to create the header row.
//------------------------------------------------------- 05/05/2007 -- DC --
function jsEC_InsertHeader() {

	// Variables
	var oRow;
	var oCell1;

	// Set color codes
	jsEC_SetColors();
	
	// Insert new row
	oRow = oTable.insertRow(0);
	
	// Insert Cells
	oCell1 = oRow.insertCell(0);
	
	// Set colSpan & background color
	oCell1.colSpan = '3';
	oCell1.style.background = 'white';
	
	// Determine border set
	if (sStyle != 'none') {
		
		// Setup bottom border
		oCell1.style.borderBottomColor = sColor;
		oCell1.style.borderBottomStyle = sStyle;
		oCell1.style.borderBottomWidth = sWidth;
			
	}
	
	// Assign Header Text
	oCell1.innerHTML = '<a href="http://www.oddMark.com"><img border="0" src="' + sRootImagsURL + '/imgLogoMini.gif" width="140" height="35" align="right">'
	
	// Set return value
	return true;

}

//------ jsEC_LoadList ------------------------------------------------------
// Desc: This routine is used to load all list items into the preview table.
//------------------------------------------------------- 05/05/2007 -- DC --
function jsEC_LoadList() {

	// Variables
	var oRow;
	var oCell1;
	var oCell2;
	var oCell3;

	// Loop current list object	
	for (var nC = 0; nC < oList.options.length; nC++) {

		// Determine selected
		if (oList.options[nC].selected) {
		
			// Insert new row
			oRow = oTable.insertRow(oTable.rows.length);
			
			// Insert Cells
			oCell1 = oRow.insertCell(0);
			oCell2 = oRow.insertCell(1);
			oCell3 = oRow.insertCell(2);
			
			// Set Colors
			oCell1.style.background = sBackColor;
			oCell2.style.background = sBackColor;
			oCell3.style.background = sBackColor;
			oCell1.style.color = sFontColor;
			oCell2.style.color = sFontColor;
			oCell3.style.color = sFontColor;

			// Set Widths
			oCell1.style.width = '58px';
			oCell2.style.width = '7px';
			
			// Set CSS Info
			oCell3.className = 'ECLines';
			
			// Assign Button Text
			oCell1.innerHTML = '<a target="_blank" href="' + oList.options[nC].value + 
			'?vote=yes"><img border="0" src="' + sRootImagsURL + '/imgButtonOK.gif" width="28" height="28"></a>' + 
			'<a target="_blank" href="' + oList.options[nC].value + 
			'?vote=no"><img border="0" src="' + sRootImagsURL + '/imgButtonCancel.gif" width="28" height="28"></a>'
		
			// Assign Revolution Text
			oCell3.innerHTML = '<a href="' + oList.options[nC].value + '"><font color="' + sFontColor + '">' + oList.options[nC].text + '</font></a>';

		}
	}

	// Set return value
	return true;

}

//------ jsEC_RestoreBackColor ----------------------------------------------
// Desc: This routine is used to restore the back color of the page
//------------------------------------------------------- 05/05/2007 -- DC --
function jsEC_RestoreBackColor() {
  
	// Restore settings
	document.body.style.background = 'white';
	document.body.style.backgroundImage = 'url(images/imgTopBackDrop.gif)';
	document.body.style.backgroundRepeat = "repeat-x";

	// Set return value
	return true;

}

//------ jsEC_SelectAll ------------------------------------------------------
// Desc: This routine is used to select all items in the given list
//------------------------------------------------------- 05/06/2007 -- DC --
function jsEC_SelectAll(sTarget) {

	// Variables
	var oTarget;

	// Assign object value
	oTarget = document.getElementById(preName + sTarget);
	
	// Loop current list object	
	for (var nC = 0; nC < oTarget.options.length; nC++) {

		// selected
		oTarget.options[nC].selected = true;
		
	}

	// Set return value
	return true;

}

//------ jsEC_DESelectAll ------------------------------------------------------
// Desc: This routine is used to DEselect all items in the given list
//------------------------------------------------------- 06/13/2007 -- JA --
function jsEC_DESelectAll(sTarget) {

	// Variables
	var oTarget;

	// Assign object value
	oTarget = document.getElementById(preName + sTarget);
	
	// Loop current list object	
	for (var nC = 0; nC < oTarget.options.length; nC++) {

		// selected
		oTarget.options[nC].selected = false;
		
	}

	// Set return value
	return true;

}

//------ jsEC_SetBackColor --------------------------------------------------
// Desc: This routine is used to change the back color of the page
//------------------------------------------------------- 05/05/2007 -- DC --
function jsEC_SetBackColor() {

	// Variables
	var oPageBackColor;
	var sPageBackColor;
	
	// Assign object value
	oPageBackColor = document.getElementById(preName + 'ddlEC3');
	
	// Assign text value
	sPageBackColor = oPageBackColor.options[oPageBackColor.selectedIndex].text;
	
	// Set Colors
	document.body.style.background = sPageBackColor;

	// Set 3 second timer
	var oTim = setTimeout("jsEC_RestoreBackColor();", 3000)

	// Set return value
	return true;

}

//------ jsEC_SetColors -----------------------------------------------------
// Desc: This routine is used to retrieve the colors from the page
//------------------------------------------------------- 05/05/2007 -- DC --
function jsEC_SetColors() {

	// Variables
	var oBackColor;
	var oFontColor;
	var oColor;
	var oStyle;
	var oWidth;

	// Assign object values
	oBackColor = document.getElementById(preName + 'ddlEC1');
	oFontColor = document.getElementById(preName +'ddlEC2');
	oColor = document.getElementById(preName +'ddlEC6');
	oStyle = document.getElementById(preName +'ddlEC4');
	oWidth = document.getElementById(preName +'ddlEC5');
	
	// Assign text values
	sBackColor = oBackColor.options[oBackColor.selectedIndex].text;
	sFontColor = oFontColor.options[oFontColor.selectedIndex].text;
	sColor = oColor.options[oColor.selectedIndex].text;
	sStyle = oStyle.options[oStyle.selectedIndex].text;
	sWidth = oWidth.options[oWidth.selectedIndex].text;
	
	// Set return value
	return true;

}

//------ jsEC_UpdateBackAndFont ---------------------------------------------
// Desc: This routine is used to load all list items into the preview table.
//------------------------------------------------------- 05/05/2007 -- DC --
function jsEC_UpdateBackAndFont() {

	// Variables
	var oRow;
	var oCell1;
	var oCell2;
	var oCell3;

	// Set color codes
	jsEC_SetColors();
	
	// Assign object value
	oTable = document.getElementById('tblEC1');
	
	// Loop current list object	
	for (var nC = 1; nC < oTable.rows.length; nC++) {
		
		// Insert new row
		oRow = oTable.rows[nC];
		
		// Insert Cells
		oCell1 = oRow.cells[0];
		oCell2 = oRow.cells[1];
		oCell3 = oRow.cells[2];
		
		// Set Colors
		oCell1.style.background = sBackColor;
		oCell2.style.background = sBackColor;
		oCell3.style.background = sBackColor;
		oCell1.style.color = sFontColor;
		oCell2.style.color = sFontColor;
		oCell3.style.color = sFontColor;
		
	}

	// Update user code
	jsEC_UpdateCode();
		
	// Set return value
	return true;

}

//------ jsEC_UpdateBorders -------------------------------------------------
// Desc: This routine is used to update the borders of the preview table.
//------------------------------------------------------- 05/05/2007 -- DC --
function jsEC_UpdateBorders() {

	// Variables
	var oCell1;

	// Assign object value
	oTable = document.getElementById('tblEC1');
	
	// Set color codes
	jsEC_SetColors();
	
	// Set Borders
	oTable.style.borderColor = sColor;
	oTable.style.borderStyle = sStyle;
	oTable.style.borderWidth = sWidth;
	oTable.style.width = '420px';

	// Error trap
	try {

		// Determine set header
		if (oTable.cells.length > 0) {
		
			// Assign cell
			oCell1 = oTable.cells[0];

			// Setup bottom border
			oCell1.style.borderBottomColor = sColor;
			oCell1.style.borderBottomStyle = sStyle;
			oCell1.style.borderBottomWidth = sWidth;
				
		}
	} catch(e) {}

	// Update user code
	jsEC_UpdateCode();
		
	// Set return value
	return true;

}

//------ jsEC_UpdateCode ----------------------------------------------------
// Desc: This routine is used to update the use code for the table.
//------------------------------------------------------- 05/05/2007 -- DC --
function jsEC_UpdateCode() {

	// Variables
	var oDiv;
	var oText;

	// Assign Values
	oDiv = document.getElementById('pnlEC1');
	oText = document.getElementById(preName+'txtEC1');

	// Display Text
	oText.value = oDiv.innerHTML.replace('<TBODY>', '').replace('</TBODY>', '').replace('<tbody>', '').replace('</tbody>', '');
	
	// Select for user
	// oText.select();
	
	// Set return value
	return true;

}

//------ jsEC_UpdatePreview -------------------------------------------------
// Desc: This is the parent function used to update the preview table.
//------------------------------------------------------- 05/05/2007 -- DC --
function jsEC_UpdatePreview() {

	// Assign Value
	oTable = document.getElementById('tblEC1');

	// Clear Rows
	jsEC_ClearRows();
	
	// Insert Header
	jsEC_InsertHeader();

	// Assign and load from List 1
	oList = document.getElementById(preName+'lstEC1');
	jsEC_LoadList();
	
	// Assign and load from List 2
	oList = document.getElementById(preName+'lstEC2');
	jsEC_LoadList();
	
	// Update user code
	jsEC_UpdateCode();
		
	// Set return value
	return true;

}