var bPageIsLoaded = false;
/***********************************************************************
*
* setCookie -	Generic Set Cookie routine
*
* Input: sName	 -	Name of cookie to create
*	 sValue	 -	Value to assign to the cookie
*	 sExpire -	Cookie expiry date/time (optional)
*
* Returns: null
*
************************************************************************/

function setCookie(sName, sValue, sExpire) 
    {
    var sCookie = sName + "=" + escape(sValue) +"; path=/";	// construct the cookie
    if (sExpire)
    	{
    	sCookie += "; expires=" + sExpire.toGMTString();	// add expiry date if present
    	}
    document.cookie = sCookie;					// store the cookie
    return null;
    }

/***********************************************************************
*
* getCookie	-	Generic Get Cookie routine
*
* Input: sName	-	Name of cookie to retrieve
*
* Returns:		Requested cookie or null if not found
*
************************************************************************/

function getCookie(sName) 
    {
    var sCookiecrumbs = document.cookie.split("; "); 	// break cookie into crumbs array
    var sNextcrumb
    for (var i=0; i < sCookiecrumbs.length; i++) 
	{
	sNextcrumb = sCookiecrumbs[i].split("=");	// break into name and value
	if (sNextcrumb[0] == sName)			// if name matches
	    {
	     return unescape(sNextcrumb[1]); 		// return value
	    }
	}
	return null;
    }

/***********************************************************************
*
* saveReferrer -	Saves the referrer to a Cookie
*
* Input: 		nothing
*
* Returns:		null
*
************************************************************************/

function saveReferrer() 
    {
    if (window.name == 'ActPopup') return; // don't save if on popup page
    var bSetCookie = false;
    if (parent.frames.length == 0)					// No FrameSet
		{
		bSetCookie = true;
		}
    else														// FrameSet in use
		{
		var bCatalogFrameSet = false;
		for (var nFrameId = parent.frames.length; nFrameId > 0; nFrameId--)
			{
			if (parent.frames[nFrameId - 1].name == 'CatalogBody')	// Catalog FrameSet used
				{
				bCatalogFrameSet = true;
				break;
				}
			}
		if (bCatalogFrameSet)							// Catalog FrameSet
			{
			if (window.name=='CatalogBody')			// and this is the CatalogBody frame
				{
				bSetCookie = true;
				}
			}
		else													// Not Catalog FrameSet
			{
			bSetCookie = true;
			}
		}
    if (bSetCookie)
		{
		var sUrl = document.URL;
		var nHashPos = sUrl.lastIndexOf("#");		// Look for URL anchor
		if (nHashPos > 0)									// if it exists
		    {
		    sUrl = sUrl.substring(0,nHashPos);		// then remove it
		    }
		setCookie("ACTINIC_REFERRER", sUrl);		// Emulates HTTP_REFERER
		}
	    return null;
	    }

/***********************************************************************
*
* CreateArray	creates an array with n elements
*
* Input: n	-	number of elements
*
* Returns:		the created array
*
************************************************************************/

function CreateArray(n)
	{
	this.length = n;
	for (var i=1; i <= n; i++)							// for all ns
		{
		this[i] = new Section();						// create a section structure
		}
	return this;											// return the created array
	}

/***********************************************************************
*
* Section	-	creates the section structure for raw section lists
*
* Input: 				nothing
*
* Returns:				nothing
************************************************************************/

function Section()
	{
	this.sURL = null;
	this.sName = null;
	this.sImage = null;
	this.nImageWidth = null;
	this.nImageHeight= null;
	this.nSectionId	= null;
	this.pChild = null;
	}
	
/***********************************************************************
*
* SwapImage			-	swaps an image to the alternative
*
* Input:	sName		-	name of the image
*
*			sAltImage	-	filename of the alternative image
*
************************************************************************/

function SwapImage(sName, sAltImage)
	{
	var nCount = 0;
	document.aSource = new Array;						// array for images
	if (document[sName] != null)						// if image name exists
		{
		document.aSource[nCount++] = document[sName];	// store image
		if(null == document[sName].sOldSrc)
			{
			document[sName].sOldSrc = document[sName].src;	// store image source
			}
		document[sName].src = sAltImage;				// change image source to alternative
		}
	}

/***********************************************************************
*
* RestoreImage		-	restores an image to the original
*
* Input: 				nothing
*
* Returns:				nothing
************************************************************************/

function RestoreImage()
	{
	var nCount, aSource = document.aSource;
	if (aSource != null)									// if array of images exists
		{
		for(nCount=0; nCount < aSource.length; nCount++)	// restore all images
			{
			if ((aSource[nCount] != null) &&
				(aSource[nCount].sOldSrc != null))	// if we stored something for this image
				{
				aSource[nCount].src = aSource[nCount].sOldSrc;	// restore the original image
				}
			}
		}
	}

/***********************************************************************
*
* PreloadImages		-	restores an image to the original
*
* Input: 				nothing
*
* Returns:				nothing
*
************************************************************************/

function PreloadImages()
	{
	bPageIsLoaded = true;
	if(document.images)
		{
		if(!document.Preloaded)							// preload array defined?
			{
			document.Preloaded = new Array();		// no, define it
			}
		var nCounter , nLen = document.Preloaded.length, saArguments = PreloadImages.arguments;
		for(nCounter = 0; nCounter < saArguments.length; nCounter++)	// iterate through arguments
			{
			document.Preloaded[nLen] = new Image;
			document.Preloaded[nLen++].src = saArguments[nCounter];
			}
   	}
	}
	
/***********************************************************************
*
* ShowPopUp		-	creates pop up window
*
* Input: sUrl		-	URL o page to display
*			nWidth	-	Width of window
*			nHeight	-	Height of window
*
* Returns:				nothing
*
************************************************************************/

function ShowPopUp(sUrl, nWidth, nHeight)
  	{  
	window.open(sUrl, 'ActPopup', 'width=' + nWidth + ',height=' + nHeight + ',scrollbars, resizable');
	if (!bPageIsLoaded)
		{
		window.location.reload(true);
		}
	}

/***********************************************************************
*
* DecodeMail		-	decodes the obfuscated mail address in 'contactus' link
*
* Input: 				nothing
*
* Returns:				nothing
*
************************************************************************/

function DecodeMail()
	{
	var nIdx = 0;
	for( ; nIdx < document.links.length; nIdx++ )
		if ( document.links[ nIdx ].name == "contactus" )
		{
		var sOldRef = document.links[ nIdx ].href;

		while( sOldRef.indexOf( " [dot] " ) != -1 )
			sOldRef = sOldRef.replace( " [dot] ", "." );
			
		while( sOldRef.indexOf( " [at] " ) != -1 )
			sOldRef = sOldRef.replace( " [at] ", "@" );
			
		document.links[ nIdx ].href = sOldRef;
		}
	}

/***********************************************************************
*
* HtmlInclude		-	Parses the page for <a href> tags and if any found 
*							with rel="fragment" attribute then create an XMLHTTP
*							request to download the referenced file and insert the
*							file content in place of the referring tag.
*							In case of error just leave it as is.
*
*	NOTE: this function is automatically attached to the onload event handler
*	therefore this processing is done on all pages where this js file is included.
*
* Returns:				nothing
*
* Author:				Zoltan Magyar
*
************************************************************************/

function HtmlInclude() 
	{ 
	var req;
	//
	// Check browser type
	//
	if (typeof(XMLHttpRequest) == "undefined") 	// IE
		{ 
		try 
			{ 
			req = new ActiveXObject("Msxml2.XMLHTTP"); 
			} 
		catch(e) 
			{ 
			try 
				{ 
				req = new ActiveXObject("Microsoft.XMLHTTP"); 
				} 
			catch(e) 										// no luck?
				{ 
				return; 										// nothing to do then
				} 
			} 
		} 
	else 														// Mozzila
		{  
		req = new XMLHttpRequest(); 
		} 
	//
	// Get <a href> tags and iterate on them
	//
	var tags = document.getElementsByTagName("A"); 
	var i; 
	for (i = 0; i < tags.length; i++) 
		{ 
		//
		// Check if we got "fragment" as rel attribute
		//
		if (tags[i].getAttribute("rel") == "fragment") 
			{
			try
				{
				//
				// Try to pull the referenced file from the server
				//
				req.open('GET', tags[i].getAttribute("href"), false); 
				if (document.characterSet) 
					{
					req.overrideMimeType("text/html; charset=" + document.characterSet);
					}
				req.send(null); 
				if (req.status == 200) 					// got the content?
					{ 
					//
					// Replace the reference with the pulled in content
					//
					var span = document.createElement("SPAN"); 
					span.innerHTML = req.responseText; 
					tags[i].parentNode.replaceChild(span, tags[i]);
					} 
				}
			catch(e)											// couldn't pull it from the server (maybe preview)
				{
				return;										// don't do anything then
				}
			} 
		} 
	} 

//
// The following lines will automatically parse all the pages 
// where this script is included by attaching the HtmlInclude
// function to the onload event.
//
if (window.attachEvent) 								// IE 
	{ 
	window.attachEvent("onload", HtmlInclude); 
	} 
else 															// DOM
	{  
	window.addEventListener("load", HtmlInclude, false); 
	}


// START Multiple other info prompt support - V2.53
var formno;
var fieldno;
var docform;

function locatefield(fname){
  formno = '';
  fieldno = '';
  //  (V11) look through all forms 'till one containing field "fname"
  var tf = -1;
  var te = 0;
  var df = document.forms;
  var i = df.length - 1;
  for ( var j = 0; j <= i; j++ )
    {
    var k = df[j].length - 1; 
    for ( var l = 0; l <= k; l++ )
      {
      if ( df[j].elements[l].name == (fname) ) 
        {
        tf = j;
        te = l;
        }
      }
    }
  if ( tf < 0 )
    {
    alert('Cannot find product form ' + fname);
    return false;
    }
  else
    {
    formno = tf;
    fieldno = te;
    docform = df[tf];
    return true;
    }
}

function stripspecial( prodref ){
  // find the form with the order field.
  if (locatefield(prodref))
    {
    docform.elements[fieldno].value = docform.elements[fieldno].value.replace(/[¬\¦]/g, " ");
    } 
} 

function concat( prodref ){
  // find the form with the order field.
  if (locatefield('O_' + prodref))
    {
    var items = docform.elements[fieldno].value.split(' ¦ ');                     // fetch names
    docform.elements[fieldno].value = '';
    for (var i = 0; i < items.length; i++)   // add in all sub fields
      {
      var names = items[i].split('¬');
      if ( i > 0) docform.elements[fieldno].value += ' ¦ ';
      var inputtext = docform.elements[fieldno + i + 1].value.replace(/[¬\¦]/g, " ");
      inputtext = inputtext.replace(/"/g, "”");
      docform.elements[fieldno].value += names[0] + '¬' + inputtext;
      }
    }
}



function setotherinfo(pre, name, size, max) {
  pre = pre.replace(/&#124;/g, '|');		// fix |
  pre = pre.replace(/&#46;/g, '.');		// fix .		
  pre = pre.replace(/&#123;/g, '{');		// fix {		
  pre = pre.replace(/&#125;/g, '}');		// fix }		
  pre = pre.replace(/&#58;/g, ':');		// fix :		
  // alert('Pre ' + pre + ' Name ' + name + ' Size ' + size + ' Max ' + max);
  var prodref = name.substr(8);			// the product reference part start
  var prodref = prodref.slice(0, -1);		// lose the > char
  var p1 = prodref.indexOf('"');		// end of the text
  var prodvalue = prodref.substr(p1 + 1);	// any additional value text
  prodref = prodref.substring(0, p1);		// the actual prodref 
 // see if simple form
 if (pre.indexOf('|') == -1 ) 
  {
  // alert('Simple ' + name + ' Prodref-' + prodref + '-Value-' + prodvalue + '-');
	 document.write('<br/>' + pre + '<INPUT style="width:540px;" TYPE=text NAME="O_' + prodref + '" ' + prodvalue + ' SIZE="' + size + '" MAXLENGTH="' + max 
                     + '" onchange="stripspecial(\'O_' + prodref + '\')">'); // <br/>  and STYLE added to the front of this line by TOS
	// The 2 lines below need to replace the 2 above if the single prompt and box need to be on the same line - TOS
	// document.write('<table cols="2"><tr><td>' + pre + '</td><td width="70%"><INPUT style="text-align:center;" TYPE=text NAME="O_' + prodref + '" ' + prodvalue + ' SIZE="' + size + '" MAXLENGTH="' + max 
    //               + '" onchange="stripspecial(\'O_' + prodref + '\')"></td></tr></table>');
  }
 else
  {        // now have a complex selection
  //  alert('Complex-' + name + '- Prodref-' + prodref + '- Value-' + prodvalue + '-');
  if ( prodvalue == '')			  // we're not bouncing back with an error
    {
    var items = pre.split('|');	  // create default list from prompt text
    var S = ' value="'
    for (var I = 0; I < items.length - 1; I++) S += items[I] + '¬ ¦ '; 
    S += items[items.length - 1] + '¬';
    }
  else
    {
    p1 = prodvalue.indexOf(' VALUE="');    // we've had an error bounce
    var S = prodvalue.slice((p1 + 8), -1); // so extract the old data
    var items = S.split(' ¦ ');            // the items and their data
    S = prodvalue.slice(p1, -1);           // the value="..." substring
    }
 
// alert('<INPUT TYPE=hidden NAME="O_' + prodref + '"' + S + '">');
// alert('Prodvalue-' + prodvalue + '- Items-' + items);
  document.write('<INPUT style="width:540px;" TYPE=hidden NAME="O_' + prodref + '"' + S + '" MAXLENGTH="50">');  // the standard prompt but hidden
  // STYLE added to the front of the above  line by TOS
// make a table for a nice layout
  document.write('<table cols="2">');	
// now see how many sub fields there are
  for (var I = 0; I < items.length; I++)
    {
    if ( prodvalue == '')
      {				//  simple empty list
      var itemname = items[I];
      var itemvalue = '';

      // test for additional style code
      var itemstyle = '';
      var itemtest = itemname.match(/(.*)\{(.*)\}(.*)/);   // see if there's a {...}
      if ( itemtest != null )
        {
        itemname = itemtest[1] + itemtest[3];
        itemstyle = 'style="' + itemtest[2] + '" ';
        }
      }
    else
      { 
      var itembits = items[I].split('¬');                  // returned list with values
      itemname = itembits[0];
      itemvalue = ' value="' + itembits[1] + '"';

      // test for additional style code
      var itemstyle = '';
      var itemtest = itemname.match(/(.*)\{(.*)\}(.*)/);   // see if there's a {...}
      if ( itemtest != null )
        {
        itemname = itemtest[1] + itemtest[3];
        itemstyle = itemtest[2];
        }

      if ( (itemname.indexOf(':') == -1) && (itembits[1] == '') ) 
        {
        if ( itemstyle != '' ) itemstyle += ';';
        itemstyle += 'background-color: #ff0000';
        }      
      if ( itemstyle != '' ) itemstyle = 'style="' + itemstyle + '" ';
      }

    var fieldsize = size;
    var maxlength = '';
      var sizelook = itemname.match(/^(\d+)\.?(\d*)/);      // look for prefix nn or nn.nn
      if ( sizelook != null)
        {
        itemname = itemname.replace(/^\d+\.?\d*/, '');       // strip out any size / max prefix
        fieldsize = sizelook[1];
        if ( sizelook[2] != '' ) maxlength = ' maxlength="' + sizelook[2] + '"'; 
        }
    
    var spacer1 = '<tr><td colspan="2">';
    var spacer2 = '</td></tr><tr><td colspan=2>';
    if ( itemname.search(/ $/) > -1 )
      {
      spacer1 = '<tr><td>';
      //spacer2 = '</td><td width="100%">';
	  // The  line above is replaced with theline below by TOS
      spacer2 = '</td><td width="70%">';
      }

    if ( itemname.indexOf(':') > -1 )
      {
      document.write(spacer1 + '<font color="#000000">' + itemname + '</font>');
      }
    else
      {	
      document.write(spacer1 + '<SPAN>' + itemname + '</SPAN>');
	  // document.write(spacer1 + '<SPAN CLASS="actrequiredcolor">' + itemname + '<SPAN>'); This line replaced with the line above by TOS
      }
    // document.write(spacer2 + '<INPUT ' + itemstyle + 'TYPE=text autocomplete="off" NAME="O_' + (I + 1) + '_' + prodref + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength);
	// The line above is replaced by the line below by TOS
	document.write(spacer2 + '<INPUT style="text-align:center;width:540px;"' + itemstyle + 'TYPE=text autocomplete="off" NAME="O_' + (I + 1) + '_' + prodref + '"' + itemvalue + ' SIZE="' + fieldsize + '" MAXLENGTH="' + max + '"');
    document.write(' onchange="concat(\'' + prodref + '\')"></td></tr>');
    }
  document.write('</table>');
  }
}
// END Multiple other info prompt support - V2.50
