//
//	evalHtmlTableCells.js	
//
//	initializes all the eval.pl stuff
//


	// css class names refered to in  eval.css
var normalWordDisplaySpanClass		= 'normalWordDisplaySpanClass'		;	//
var phoneticWordDisplayDivClass		= 'phoneticWordDisplayDivClass'		;	//
var phoneticWordDisplaySpanClass	= 'phoneticWordDisplaySpanClass'	;	//	

var evalTargetSoundDivClass		= 'evalTargetSoundDivClass'		;	//
var langSpecNameTdClass			= 'langSpecNameTdClass'			;	//
var selectSpecLetterSpanClass		= 'selectSpecLetterSpanClass'		;	//
var selectSpecLangDivClass		= 'selectSpecLangDivClass'		;	//
var selectSpecLangMouseoverDivClass	= 'selectSpecLangMouseoverDivClass'	;	//


var globalPrefixSuffixSeparatorCharacter	=	'';	// probably a double underscore
var globalErrorSoundHandle			=	'';	// probably  set to 'ErrorSound'
var globalErrorSoundNormalCss			=	'';	// holds the name of the normal (non replicate) class
var globalErrorSoundReplicCss			=	'';	// holds the name of the replicate class
var globalFormName				=	'';	// probably set to myEvalForm

function createGlobalVariables
		(	paramErrorSoundHandle		// 01
		,	paramPreSufSepChar		// 02
		,	paramErrorSoundNormalCss	// 03
		,	paramErrorSoundReplicCss	// 04
		,	paramFormName			// 05
		)
{
	globalErrorSoundHandle			=	paramErrorSoundHandle		;
	globalPrefixSuffixSeparatorCharacter	=	paramPreSufSepChar		;
	globalErrorSoundNormalCss		=	paramErrorSoundNormalCss	;
	globalErrorSoundReplicCss		=	paramErrorSoundReplicCss	;
	globalFormName				=	paramFormName			;
};

function htmlSpecLanguage(paramDivNbr, paramSpecLanguage, paramBackgroundColor, dummy)
{
    var startOfSounds = 3 ;	// this indicates where 'dummy' starts (zero relative)

    var deBug	= 0;

    var outPut	= '';	// variable to store all the output

    outPut	+=	'<tr>';					// start the table row

    outPut	+=	'<td'
		+	' class='			// start of td class
		+	'"'				// double quote
		+	langSpecNameTdClass		// class name
		+	'"'				// double quote
		+	' align="right"'
		+	' colspan="5">'
//		+	'<small><small>'
		+	paramSpecLanguage
//		+	'</small></small>'
		+	'</td>'						// end of table cell
		;

    outPut	+=	'<td colspan="4">';				// start of teble cell

    var divVars	= '';		//	variable to hold all letters
    var displayedErrorSounds	= '';

								// starting at position TWO, where the
								// 
    for ( var x=startOfSounds; x < htmlSpecLanguage.arguments.length; x++ ) 	{
	if  ( divVars != '' )	{				// not first time through this ??
		divVars	+=	"','"	;			// delimit each with single-quote-comman-single-quote
	}
	//divVars	+=	unescape(htmlSpecLanguage.arguments[x]) ;	// remove the escaped stuff 2008-02-09
	divVars	+=	htmlSpecLanguage.arguments[x] ;	

	if  ( htmlSpecLanguage.arguments[x] )	{
		displayedErrorSounds	+=	''
			+	'<span class='
			+	'"'
			+	selectSpecLetterSpanClass
			+	'"'
			+	'>'
			//+	unescape(htmlSpecLanguage.arguments[x])	// remove the escape stuff 2008-02-09
			+	htmlSpecLanguage.arguments[x]
			+	'</span>'
			;
	};
    };

    outPut	+=	''
		+	'<div'				//	start div
		+	' class='			//	start div class
		+	'"'				//	double quote
		+	selectSpecLangDivClass		//	class name
		+	'"'				//	double quote

		+	'onMouseOver='
		+	'"'				//	double quote
		+	'javascript: this.className='
		+	"'"
		+	selectSpecLangMouseoverDivClass
		+	"'"
		+	';'
		+	'"'				//	double quote

		+	'onMouseOut='
		+	'"'				//	double quote
		+	'javascript: this.className='
		+	"'"
		+	selectSpecLangDivClass
		+	"'"
		+	';'
		+	'"'				//	double quote

		+	' onClick='
		+	'"'
		+	'changeSpan('
		+	paramDivNbr
		+	','
		+	"'"						// starting single quote
		+	divVars
	        +	"'"						// ending single quote
		+	');">'
		+	displayedErrorSounds
		+	'</div>'
		;

    outPut	+=	'</td>';					// end the table cell

    outPut	+=	'</tr>';					// end the table row

    if  ( deBug == 0 )	{
	    //document.write (outPut);
	    return (outPut);
    } else {

	    while (outPut.indexOf("<") > -1 )
		outPut = outPut.replace("<", "&lt;");
	    while (outPut.indexOf(">") > -1 )
		outPut = outPut.replace(">", "&gt;");
	    document.write ('<pre>' + outPut + '</pre>' );
    };

};

function htmlFirstColumn(paramRowSpan, paramRowWord, dummy )
{

    var startOfSounds = 2 ;	// this indicates where 'dummy' starts (zero relative)
    var deBug	= 0;

    var outPut	= '';	// variable to store all the output


    outPut	+=	'<tr>';					// start the table row

    outPut	+=	''
		+	'<td rowspan="'				// start the table cell
		+	( paramRowSpan + 1 )			// add one because now the
								// first column is alone in the row!  (i hope)
		+	'" align="center" valign="middle">'
		;

    outPut	+=	'<span'					// start span tag
    		+	' class='				// span class
		+	'"'					// double quote
		+	normalWordDisplaySpanClass		// class name
		+	'"'					// double quote
		+	'>'					// end start of span tag
		+	paramRowWord				// actual word
		+	'</span>'				// end of span tag
		;

    outPut	+=	'<br />';

    outPut	+=	'<div'					// start div
    		+	' class='				// div class
		+	'"'					// double quote
		+	phoneticWordDisplayDivClass		// class name
		+	'"'					// double quote
		+	'>'					// end start-of-div-tag
		;

    for ( var x=startOfSounds ; x < htmlFirstColumn.arguments.length; x++ ) 	{
			// foreach error sound, mane an image
	outPut	+=	''
		+	'<span class='
		+	'"'					// double quote
		+	phoneticWordDisplaySpanClass		// class name
		+	'"'					// double quote
		+	'>'
		+	htmlFirstColumn.arguments[x]
		+	'</span>'
		;
    };

    outPut	+=	'</div>';

    outPut	+=	'</td>';				// end the table cell
    outPut	+=	'</tr>';				// end the table row

    if  ( deBug == 0 )	{
	    // document.write (outPut);
	    return (outPut);
    } else {
	    while (outPut.indexOf("<") > -1 )
		outPut = outPut.replace("<", "&lt;");
	    while (outPut.indexOf(">") > -1 )
		outPut = outPut.replace(">", "&gt;");
	    document.write ('<pre>' + outPut + '</pre>' );
    };
};



function htmlWorkTableRow
	(	paramEvalMastAutoIncr		// one		- the Evaluation Master Auto Increment
	,	paramReplicateFlag		// two		- replication flag, one for replicate, zero for nonReplic

	,	paramEvalMastPosition		// three	- position (initial, middle, dipthong, final)
	,	paramEvalMastContext		// four		- context (sentence, word, reading)

	,	paramTargetSound1		// five		- target sounds
	,	paramTargetSound2		// six
	,	paramTargetSound3		// seven

	,	paramErrorSound1		// eight	- error sounds
	,	paramErrorSound2		// nine
	,	paramErrorSound3		// ten
	,	paramErrorSound4		// eleven

	,	paramBackgroundColor		// twelve
	,	paramBdrColor			// thirteen
	,	paramBdrStyle			// fourteen
	,	paramBdrThickness		// fifteen
	)
{
    var deBug	= 0;

    var targetSoundArray	=new Array(paramTargetSound1, paramTargetSound2, paramTargetSound3);
    var errorSoundArray		=new Array(paramErrorSound1, paramErrorSound2, paramErrorSound3, paramErrorSound4);

    if  ( deBug > 5 ) {
	alert  ( paramTargetSound1 +  '<-->' 
		+	paramTargetSound2 +  '<-->'
		+	paramTargetSound3 +  '<----->'
		+	paramErrorSound1  +  '<-->'
		+	paramErrorSound2  +  '<-->'
		+	paramErrorSound3  +  '<-->'
		+	paramErrorSound4  +  '<-->' 
		);
    };


    var target_sound_cell_css =	''			//	2007-02-16

		+	' background-color:'		//	2007-02-16
		+	paramBackgroundColor		//	2007-02-16	
		+	';'				//	2007-02-16

		+	' border-top-color:'		//	2007-02-16
		+	paramBdrColor			//	2007-02-16
		+	';'				//	2007-02-16

		+	' border-top-style:'		//	2007-02-16
		+	paramBdrStyle			//	2007-02-16
		+	';'				//	2007-02-16
		;


    if  ( paramBdrThickness ) {
	    target_sound_cell_css	+=	''
			+	' border-top-width: '
			+	paramBdrThickness
			+	';'
			;
    };


    var outPut = '';	// initial output

    outPut	+=	'<tr>';

    outPut	+=	''
		+	'<td align="center"'
		+	' class="evalTargetSoundTdCss" '
		+	' style='
		+	'"'			//	double quote
		+	target_sound_cell_css
		+	'"'			//	closing quote
		+	'>'
		+	'<small>'
		+	paramEvalMastPosition
		+	'</small>'
		+	'</td>'
		+	'<td align="center"'
		+	' class="evalTargetSoundTdCss" '
		+	' style='
		+	'"'			//	double quote
		+	target_sound_cell_css
		+	'"'			//	closing quote
		+	'>'
		+	'<small>'
		+	paramEvalMastContext
		+	'</small>'
		+	'</td>'
		;

    for ( var x=0; x<targetSoundArray.length; x++ ) 	{
	outPut +=	''
		+	'<td'
		+	' style='		//	2007-02-15
		+	'"'			//	double quote
		+	target_sound_cell_css	//	2007-02-15
		+	'"'			//	double quote
		+	'>'
		+	'<div'
		+	' class='
		+	'"'			//	double quote
		+	evalTargetSoundDivClass	//	class name
		+	'"'			//	double quote
		+	'>'			//	close divOpen tag
		+	targetSoundArray[x]
		+	'</div>'
		+	'</td>'
		//+	"\n"
		;
    };

    for ( var x=0; x<errorSoundArray.length; x++ ) 	{
	var myErrorSoundVar
		=	''
		+	globalErrorSoundHandle					// constant passed in from perl
		+	(x + 1)
		+	globalPrefixSuffixSeparatorCharacter			// constant passed in from perl
		+	paramEvalMastAutoIncr
		;

	var myPhonemeGridPopupCommand
		=	''
		+	'return evalErrorSoundsFunction'
		+	'('				// open paren
		+	"'"				// quote
		+	myErrorSoundVar			// parm one
		+	"'"				// quote

				// parm two
		+	','				// comma
		+	'this'				//		we have to pass the htmlAnchorEmelement  value, othewise

				// parm three
							//		we cannot determine its value in the function
		+	','				// comma
		+	'mouseX(event)'			//		gotta pass the x/y values here, since the function cant
							//		seem to determine this value

				// parm four
		+	','				// comma
		+	'mouseY(event)'			//		ditto
		+	')'				// close param
		;
		
	var tmpErrorCell =	''
		+	'<td'
		//+	' style='		//	2007-02-15
		//+	target_sound_cell_css	//	2007-02-15
		+	'>'							// end of td cell

		+	'<input'						// start of text tag
		+	' type='
		+	'"'							// quote
		+	'text'
		+	'"'							// quote
		
		+	(	( paramReplicateFlag )				// if we are replicating, use 'disable'
			?	' disable="true"  readonly="false"'		// otherwise use 'readonly'
			:	' readonly="true" disable="false"'
			)

		+	' onClick='						// begin of onClick command
		+	'"'							// single quote
		+	myPhonemeGridPopupCommand
		+	'"'							// single quote

		+	' name='						// name property
		+	'"'							// double quote
		+	myErrorSoundVar
		+	'"'							// double quote

		+	' id='							// id property
		+	'"'							// double quote
		+	myErrorSoundVar
		+	'"'							// double quote

//		+	' name='					// name property
//		+	'"'							// double quote
//		+	myErrorSoundVar
//		+	'"'							// double quote

		+	' class='
		+	'"'							// double quote
		+	(	( errorSoundArray[x] && paramReplicateFlag )
			?	globalErrorSoundReplicCss
			:	globalErrorSoundNormalCss
			)
		+	'"'							// double quote

		+	' value= '
		+	'"'							// double quote
		+	errorSoundArray[x]					// assign a value to the hidden variable
		+	'"'							// double quote

		+	' />'							// end of text tag

//		+	'<div '							// start of div
//
//		+	' onClick='						// begin of onClick command
//		+	'"'							// single quote
//		+	myPhonemeGridPopupCommand
//		+	'"'							// single quote
//
//		+	' id='						// id property
//		+	'"'							// double quote
//		+	myErrorSoundVar
//		+	'"'							// double quote
//
//		+	' name='					// name property
//		+	'"'							// double quote
//		+	myErrorSoundVar
//		+	'"'							// double quote
//
//		+	' class='
//		+	'"'							// double quote
//		+	(	( errorSoundArray[x] && paramReplicateFlag )
//			?	globalErrorSoundReplicCss
//			:	globalErrorSoundNormalCss
//			)
//		+	'"'							// double quote
//
//		+	'>'							// close span tag
//
//		+	(	errorSoundArray[x]				// error symbol
//			?	errorSoundArray[x]
//			:	'&nbsp;'
//			)
//
//		+	'</div>'						// end of div
		+	'</td>'
		;

	//	alert ( tmpErrorCell );

	outPut +=	tmpErrorCell;
    };

    outPut	+=	'</tr>';	// end table row tag
    
    if  ( deBug == 0 )	{
		
	    //	alert (outPut);

	    for ( var x=0; x<errorSoundArray.length; x++ ) 	{
		var myErrorSoundVar
			=	''
			+	globalErrorSoundHandle					// constant passed in from perl
			+	(x + 1)
			+	globalPrefixSuffixSeparatorCharacter			// constant passed in from perl
			+	paramEvalMastAutoIncr
			;
									// unfortunately, the 'hidden' wont override
									// what javascript does..  sigh......
		outPut	+=	''
			+	'<script language="javascript" type="text/javascript">'
			//+	'document.myform["'
			+	'document[globalFormName]["'
			+	myErrorSoundVar
			+	'"].value = "'
			+	(	paramReplicateFlag
				?	''
				:	errorSoundArray[x]
				)	// only store value if replicate is off
			+	'";'
			+	'</script>'
			;
		
	    };
	    //		alert ( outPut ) ;
	    return outPut;

    } else {
	    while (outPut.indexOf("<") > -1 )
		outPut = outPut.replace("<", "&lt;");
	    while (outPut.indexOf(">") > -1 )
		outPut = outPut.replace(">", "&gt;");
	    document.write ('<pre>' + outPut + '</pre>' );
    };
};


function buildWorkTableSpacer()	{

    var deBug	= 0;

    var sizeArray
		= new Array
			( 130	//	word
			, 60	//	position (blend, dipthong, final
			, 60	//	context (word, sentence, etc)
			, 20	//	target sound one
			, 20	//	target sound two
			, 20	//	target sound three
			, 20	//	error sound one
			, 20	//	error sound two
			, 20	//	error sound three
			, 20	//	error sound four
			)	
			;
    var outPut ='<tr>';

    var transparent_image
	= '/images/transparent.gif'   ;

    for ( x in sizeArray )	{
	outPut +=	'<td>'
		+	'<img height='
		+	"'"		// single quote
		+	'1px'
		+	"'"		// single quote
		+	' src='
		+	"'"		// single quote
		+	transparent_image
		+	"'"		// single quote
		+	' width='
		+	"'"		// single quote
		+	sizeArray[x]
		+	'px'
		+	"'"		// single quote
		+	' alt='
		+	"'"		// single quote
		+	' '		// space for the alt attribute
		+	"'"		// single quote
		+	' />'
		+	'</td>'
		;
    };
    outPut +='</tr>';

    if  ( deBug == 0 )	{
	    // document.write (outPut);
	    return outPut;
    } else {
	    while (outPut.indexOf("<") > -1 )
		outPut = outPut.replace("<", "&lt;");
	    while (outPut.indexOf(">") > -1 )
		outPut = outPut.replace(">", "&gt;");

	    document.write ('<pre>' + outPut + '</pre>' );
    };


};



