// start of dynamic style helper routines
var selcode;						// we'll keep the <select...> code in here.
var cprodref;    					// global for product reference (set in Product Template)
var currentradio = '';					// the name of current radio button
var firstselect = false;				// flag for first <option> stement
var defers = new Array();				// initial style values go here

function makeclickcode(params){				// generate the JavaScript code for onchange event
  var clickcode = '';
  var objs = params.split('|');				// get list of objects we want to play with
  for ( var j = 0; j < objs.length; j++)
    {  
    var items = objs[j].split(';');			// get the fragments
    var currentid = items.shift() + '_' + cprodref;	// the objects ID
    for ( var i = 0; i < items.length; i++ )
      {
      thisstyle = items[i].replace(/:/g,"='");		// convert color:red into color='red
      clickcode += 'document.getElementById(\'' + currentid + '\').style.' + thisstyle + '\';';
      }
    }
return clickcode;
}

function defereval(clickcode){				// save initial style values
defers.push(clickcode);					//  in case tag is still loading
}

function RadioStyle(attribref,choicesel,checked,choicename){
  var styleval = choicename.match(/(.*)\{(.*)\}(.*)/);	// have we a "{" and "}" in the text?
  var clicktext = '';
  if ( styleval != null )
    {
    
    var clickcode = makeclickcode(styleval[2]);

    if(currentradio != attribref) defereval(clickcode);	// must be first time so set initial value
    currentradio = attribref;
    clicktext = ' onclick="' + clickcode + '"';		// make the onclick line
    choicename = styleval[1] + styleval[3];		// strip out style info
    }
  document.write('<INPUT TYPE=RADIO NAME="' + attribref + '" VALUE="'  // the original <RADIO> statement
                 + choicesel + '" ' + checked 
		 + clicktext + '>'
                 + choicename);
}

function selectstyle(prodref, attrib, index){
  eval(eval(attrib + '[' + index + ']'));
}

function StartStyleSelect(attribname){			// the <SELECT...> statement from Act_VariantListHeader.html
  selcode='<SELECT NAME="' + attribname + '" onchange="selectstyle(\'' + cprodref + '\',\'' + attribname + '\', this.selectedIndex);">';  // recreate HTML
  eval(attribname + ' = new Array();');	// make an array for the style values
  firstselect = true;
  currentselect = attribname;
}

function SelectStyleOption(choice,selected,value){	// the <OPTION...> statement from Act_VariantListChoice.html
  var styleval = value.match(/(.*)\{(.*)\}(.*)/);	// have we a "{" and "}" in the text?
  if ( styleval != null )
    {
    var clickcode = makeclickcode(styleval[2]);
    if(firstselect) defereval(clickcode);		// must be first time so set initial value
    firstselect = false;
    eval('var thisarray = ' + currentselect);
    thisarray.push(clickcode);				// save the style code
    value = styleval[1] + styleval[3];			// strip out style info
    }
  selcode += '<OPTION VALUE=' + choice + ' ' + selected + '>' + value;	// recreate original <OPTION..> statement
}
 
function EndStyleSelect(){				// the </SELECT> statement from Act_VariantListFooter.html
  document.write(selcode + '</SELECT>');		// write the HTML out
}
// end of dynamic style helper routines