/*


*/

// URL ENCODER

// ==========================================================================
// JavaScript Tool for URL Encoding/Decoding
// Copyright (C) 2006 Netzreport (netzreport.googlepages.com)
//
// Website: http://netzreport.googlepages.com/online_tool_for_url_en_decoding.html
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
//
// The GNU General Public License is also available from:
// http://www.gnu.org/copyleft/gpl.html
//
// A local copy of the GNU General Public License is available here:
// http://netzreport.googlepages.com/gpl.txt
// ==========================================================================
//
// --------------------------------------------------------------------------
// 2006-12-18: Changed character encoding. Now, one can choose between URL
//             encoding/decoding strings that are character encoded as ASCII
//             or UTF-8.
// 2006-11-19: First release
// --------------------------------------------------------------------------


// According to RFC 3986, only characters from a set of reserved and a set
// of unreserved characters are allowed in a URL:
var unreserved = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.~";
var reserved = "!*'();:@&=+$,/?%#[]";
var allowed = unreserved + reserved;
var hexchars = "0123456789ABCDEFabcdef";

// --------------------------------- Encoding -------------------------------

// This function returns a percent sign followed by two hexadecimal digits.
// Input is a decimal value not greater than 255.
function gethex(decimal) {
  return "%" + hexchars.charAt(decimal >> 4) + hexchars.charAt(decimal & 0xF);
}

function encode(sToDecode, encoding) { // encoding: one of [ascii, utf8]

  // Some variables:
  var decoded = sToDecode;
  var encoded = "";

  // ---------------- If ASCII character encoding was chosen: ----------------

  if (encoding == "ascii") {

    // Remember non-ASCII characters, which will not be encoded:
    var notascii = "";

    for (var i = 0; i < decoded.length; i++ ) {
      var ch = decoded.charAt(i);
      // Check if character is an unreserved character:
      if (unreserved.indexOf(ch) != -1) {
        encoded = encoded + ch;
      } else {
        // If position in the Unicode table is smaller than 128, then we have
        // an ASCII character:
        var charcode = decoded.charCodeAt(i);
        if (charcode < 128) {
          encoded = encoded + gethex(charcode);
        } else {
          encoded = encoded + ch;
          notascii = notascii + ch + " ";
        }
      }
    }

    // Display warning message if necessary:
    if (notascii != "") alert("Warning: Non-ASCII characters in decoded text!\n\nThus, these characters have not been encoded:\n" + notascii);

    // return result:
    return encoded;
  }

  // ---------------- If UTF-8 character encoding was chosen: ----------------

  if (encoding == "utf8") {
    for (var i = 0; i < decoded.length; i++ ) {
      var ch = decoded.charAt(i);
      // Check if character is an unreserved character:
      if (unreserved.indexOf(ch) != -1) {
        encoded = encoded + ch;
      } else {

        // The position in the Unicode table tells us how many bytes are needed.
        // Note that if we talk about first, second, etc. in the following, we are
        // counting from left to right:
        //
        //   Position in   |  Bytes needed   | Binary representation
        //  Unicode table  |   for UTF-8     |       of UTF-8
        // ----------------------------------------------------------
        //     0 -     127 |    1 byte       | 0XXX.XXXX
        //   128 -    2047 |    2 bytes      | 110X.XXXX 10XX.XXXX
        //  2048 -   65535 |    3 bytes      | 1110.XXXX 10XX.XXXX 10XX.XXXX
        // 65536 - 2097151 |    4 bytes      | 1111.0XXX 10XX.XXXX 10XX.XXXX 10XX.XXXX

        var charcode = decoded.charCodeAt(i);

        // Position 0 - 127 is equal to percent-encoding with an ASCII character encoding:
        if (charcode < 128) {
          encoded = encoded + gethex(charcode);
        }

        // Position 128 - 2047: two bytes for UTF-8 character encoding.
        if (charcode > 127 && charcode < 2048) {
          // First UTF byte: Mask the first five bits of charcode with binary 110X.XXXX:
          encoded = encoded + gethex((charcode >> 6) | 0xC0);
          // Second UTF byte: Get last six bits of charcode and mask them with binary 10XX.XXXX:
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

        // Position 2048 - 65535: three bytes for UTF-8 character encoding.
        if (charcode > 2047 && charcode < 65536) {
          // First UTF byte: Mask the first four bits of charcode with binary 1110.XXXX:
          encoded = encoded + gethex((charcode >> 12) | 0xE0);
          // Second UTF byte: Get the next six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex(((charcode >> 6) & 0x3F) | 0x80);
          // Third UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

        // Position 65536 - : four bytes for UTF-8 character encoding.
        if (charcode > 65535) {
          // First UTF byte: Mask the first three bits of charcode with binary 1111.0XXX:
          encoded = encoded + gethex((charcode >> 18) | 0xF0);
          // Second UTF byte: Get the next six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex(((charcode >> 12) & 0x3F) | 0x80);
          // Third UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex(((charcode >> 6) & 0x3F) | 0x80);
          // Fourth UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

      }

    }  // end of for ...

    // return result:
    return encoded;
  }
}

// --------------------------------- Decoding -------------------------------

// This function returns the decimal value of two hexadecimal digits.
// Input is a percent sign followed by two hexadecimal digits. If the input
// string is shorter than three characters, the percent sign is missing or if
// not a hexadecimal numeral is used, then the decimal value 256 is returned:
function getdec(hexencoded) {
  if (hexencoded.length == 3) {
    if (hexencoded.charAt(0) == "%") {
      if (hexchars.indexOf(hexencoded.charAt(1)) != -1 && hexchars.indexOf(hexencoded.charAt(2)) != -1) {
        return parseInt(hexencoded.substr(1,2),16);
      }
    }
  }
  return 256;
}

function decode(sToDecode, encoding) { // encoding: one of [ascii, utf8]

  // Some variables:
  var encoded = sToDecode;
  var decoded = "";
  // Remember characters that are not allowed in a URL:
  var notallowed = "";
  // Remember illegal percent encoding:
  var illegalencoding = "";

  // ---------------- If ASCII character encoding was chosen: ----------------
  if (encoding == "ascii") {
    var i = 0;
    while (i < encoded.length) {
      var ch = encoded.charAt(i);
      // Check for percent-encoded string:
      if (ch == "%") {
        // Check if percent-encoded string represents an ASCII character:
        if (getdec(encoded.substr(i,3)) < 128) {
          decoded = decoded + unescape(encoded.substr(i,3));
        } else {
          decoded = decoded + encoded.substr(i,3);
          illegalencoding = illegalencoding + encoded.substr(i,3) + " ";
        }
        i = i + 3;
      } else {
        // Check if character is an allowed character:
        if (allowed.indexOf(ch) == -1) notallowed = notallowed + ch + " ";
        decoded = decoded + ch;
        i++;
      }
    }

    // Display warning message if necessary:
    var warning = "";
    if (notallowed != "") warning = warning + "Characters not allowed in a URL:\n" + notallowed + "\n\n";
    if (illegalencoding != "") warning = warning + "Illegal percent-encoding (for ASCII):\n" + illegalencoding  + "\n\n";
    if (warning != "") alert("Warning: Illegal characters/strings in encoded text!\n\n" + warning);

    // return result:
    return decoded;
  }

  // ---------------- If UTF-8 character encoding was chosen: ----------------
  if (encoding == "utf8") {
    // UTF-8 bytes from left to right:
    var byte1, byte2, byte3, byte4 = 0;

    var i = 0;
    while (i < encoded.length) {
      var ch = encoded.charAt(i);
      // Check for percent-encoded string:
      if (ch == "%") {

        // Check for legal percent-encoding of first byte:
        if (getdec(encoded.substr(i,3)) < 255) {

          // Get the decimal values of all (potential) UTF-bytes:
          byte1 = getdec(encoded.substr(i,3));
          byte2 = getdec(encoded.substr(i+3,3));
          byte3 = getdec(encoded.substr(i+6,3));
          byte4 = getdec(encoded.substr(i+9,3));

          // Check for one byte UTF-8 character encoding:
          if (byte1 < 128) {
            decoded = decoded + String.fromCharCode(byte1);
            i = i + 3;
          }

          // Check for illegal one byte UTF-8 character encoding:
          if (byte1 > 127 && byte1 < 192) {
            decoded = decoded + encoded.substr(i,3);
            illegalencoding = illegalencoding + encoded.substr(i,3) + " ";
            i = i + 3;
          }

          // Check for two byte UTF-8 character encoding:
          if (byte1 > 191 && byte1 < 224) {
            if (byte2 > 127 && byte2 < 192) {
              decoded = decoded + String.fromCharCode(((byte1 & 0x1F) << 6) | (byte2 & 0x3F));
            } else {
              decoded = decoded + encoded.substr(i,6);
              illegalencoding = illegalencoding + encoded.substr(i,6) + " ";
            }
            i = i + 6;
          }

          // Check for three byte UTF-8 character encoding:
          if (byte1 > 223 && byte1 < 240) {
            if (byte2 > 127 && byte2 < 192) {
              if (byte3 > 127 && byte3 < 192) {
                decoded = decoded + String.fromCharCode(((byte1 & 0xF) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F));
              } else {
                decoded = decoded + encoded.substr(i,9);
                illegalencoding = illegalencoding + encoded.substr(i,9) + " ";
              }
            } else {
              decoded = decoded + encoded.substr(i,9);
              illegalencoding = illegalencoding + encoded.substr(i,9) + " ";
            }
            i = i + 9;
          }

          // Check for four byte UTF-8 character encoding:
          if (byte1 > 239) {
            if (byte2 > 127 && byte2 < 192) {
              if (byte3 > 127 && byte3 < 192) {
                if (byte4 > 127 && byte4 < 192) {
                  decoded = decoded + String.fromCharCode(((byte1 & 0x7) << 18) | ((byte2 & 0x3F) << 12) | ((byte3 & 0x3F) << 6) | (byte4 & 0x3F));
                } else {
                  decoded = decoded + encoded.substr(i,12);
                  illegalencoding = illegalencoding + encoded.substr(i,12) + " ";
                }
              } else {
                decoded = decoded + encoded.substr(i,12);
                illegalencoding = illegalencoding + encoded.substr(i,12) + " ";
              }
            } else {
              decoded = decoded + encoded.substr(i,12);
              illegalencoding = illegalencoding + encoded.substr(i,12) + " ";
            }
            i = i + 12;
          }

        } else {  // the first byte is not legally percent-encoded
          decoded = decoded + encoded.substr(i,3);
          illegalencoding = illegalencoding + encoded.substr(i,3) + " ";
          i = i + 3;
        }

      } else {  // the string is not percent encoded
        // Check if character is an allowed character:
        if (allowed.indexOf(ch) == -1) notallowed = notallowed + ch + " ";
        decoded = decoded + ch;
        i++;
      }
    }  // end of while ...

    // Display warning message if necessary:
    var warning = "";
    if (notallowed != "") warning = warning + "Characters not allowed in a URL:\n" + notallowed + "\n\n";
    if (illegalencoding != "") warning = warning + "Illegal percent-encoding (for UTF-8):\n" + illegalencoding  + "\n\n";
    if (warning != "") alert("Warning: Illegal characters/strings in encoded text!\n\n" + warning);

    // return result:
    return decoded;
  }
}

// EOF URL ENCODER

// XML
function getDomDocumentPrefix() {
	if (getDomDocumentPrefix.prefix) return getDomDocumentPrefix.prefix;
	var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
	var o;
	for (var i = 0; i < prefixes.length; i++) {
		try {
			o = new ActiveXObject(prefixes[i] + ".DomDocument");
			return getDomDocumentPrefix.prefix = prefixes[i];
		}
		catch (ex) {};
	}
	throw new Error("Could not find an installed XML parser");
}

function getXmlHttpPrefix() {
	if (getXmlHttpPrefix.prefix) return getXmlHttpPrefix.prefix;
	var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
	var o;
	for (var i = 0; i < prefixes.length; i++) {
		try {
			o = new ActiveXObject(prefixes[i] + ".XmlHttp");
			return getXmlHttpPrefix.prefix = prefixes[i];
		}
		catch (ex) {};
	}
	throw new Error("Could not find an installed XML parser");
}

function XmlHttp() {}
XmlHttp.create = function () {
	try {
		if (window.XMLHttpRequest) {
			var req = new XMLHttpRequest();
			if (req.readyState == null) {
				req.readyState = 1;
				req.addEventListener("load", function () {
					req.readyState = 4;
					if (typeof req.onreadystatechange == "function") req.onreadystatechange();
				}, false);
			}
                        return req;
		}
		if (window.ActiveXObject) {
			return new ActiveXObject(getXmlHttpPrefix() + ".XmlHttp");
		}
	}
	catch (ex) {}
	throw new Error("Your browser does not support XmlHttp objects");
};

function XmlDocument() {}

XmlDocument.create = function () {
	try {
		if (document.implementation && document.implementation.createDocument) {
			var doc = document.implementation.createDocument("", "", null);
			if (doc.readyState == null) {
				doc.readyState = 1;
				doc.addEventListener("load", function () {
					doc.readyState = 4;
					if (typeof doc.onreadystatechange == "function") doc.onreadystatechange();
				}, false);
			}
			return doc;
		}
		if (window.ActiveXObject) return new ActiveXObject(getDomDocumentPrefix() + ".DomDocument");
	}
	catch (ex) {}
	throw new Error("Your browser does not support XmlDocument objects");
};

if (window.DOMParser && window.XMLSerializer && window.Node && Node.prototype && Node.prototype.__defineGetter__) {
	XMLDocument.prototype.loadXML = Document.prototype.loadXML = function(s) {
		var doc2 = (new DOMParser()).parseFromString(s, "text/xml");
		while (this.hasChildNodes()) this.removeChild(this.lastChild);
		for (var i = 0; i < doc2.childNodes.length; i++) this.appendChild(this.importNode(doc2.childNodes[i], true));
	};
	XMLDocument.prototype.__defineGetter__("xml", function () {return (new XMLSerializer()).serializeToString(this);});
	Document.prototype.__defineGetter__("xml", function () {return (new XMLSerializer()).serializeToString(this);});
}

function doXmlRequest(url, onSuccessHandler, onStartHandler, onErrorHandler, requestBody) {
	var xmlHttp = XmlHttp.create();
	xmlHttp.open("POST", url, true); // async
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	if (onStartHandler) {
		onStartHandler(url);
	}
	xmlHttp.onreadystatechange = function () {
	    if (xmlHttp.readyState == 4) {
			var oXmlDoc = xmlHttp.responseXML;
			if(!oXmlDoc || (oXmlDoc.parserError && oXmlDoc.parseError.errorCode != 0) || !oXmlDoc.documentElement) {
			    	var error = "An error has occured.";
                                try
                                {
				 if (!oXmlDoc || oXmlDoc.parseError.errorCode == 0) {
					error = "An error has occurred while loading data.\n\nResource URL: " + url + "\nStatus: " + xmlHttp.status + ", " + xmlHttp.statusText + "\n\nData:\n" + xmlHttp.responseText;
				 } else {
					error = "An error has occurred while parsing data.\n\nResource URL: " + url + "\nReason: " + oXmlDoc.parseError.reason + "\nSource: " + oXmlDoc.parseError.srcText + "\nError code: " + oXmlDoc.parseError.errorCode + "\n\nData:\n" + oXmlDoc.responseText;
				 }
                                }
			        catch(ex)
                                {
                                }
				if (onErrorHandler) {
					onErrorHandler(url, error);
				}
				return;
			}
			onSuccessHandler(oXmlDoc);
		}
	};
	
	// call in new thread to allow ui to update - does not send body in Mozilla
	//window.setTimeout(function() {xmlHttp.send(requestBody ? requestBody : null);}, 10);
	xmlHttp.send(requestBody ? requestBody : "");
}

function doHtmlRequest(url, onSuccessHandler, onStartHandler, onErrorHandler, requestBody) {
	var xmlHttp = XmlHttp.create();
        xmlHttp.open("GET", url, true); // async
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xmlHttp.setRequestHeader('Cache-Control', 'max-age=1800');
        //xmlHttp.setRequestHeader('If-Modified-Since', 'Wed, 28 Jan 2009 14:53:52 GMT');


	if (onStartHandler) {
		onStartHandler(url);
	}
	xmlHttp.onreadystatechange = function () {
	    if (xmlHttp.readyState == 4) {
                        var oXmlDoc = xmlHttp.responseText;
                        if(xmlHttp.getResponseHeader("Status") == "error") {
				var error = "An error has occured.";
				if (oXmlDoc != null && oXmlDoc != "") {
					error += "\n\n" + oXmlDoc;
				}
				if (onErrorHandler) {
					onErrorHandler(url, error);
				}
				return;
			}
			onSuccessHandler(oXmlDoc);
		}
	};
	
	// call in new thread to allow ui to update - does not send body in Mozilla
	//window.setTimeout(function() {xmlHttp.send(requestBody ? requestBody : null);}, 10);
	xmlHttp.send(null);
}

// EOF XML

// HANDLERS

function requestStartHandler() {
	//switchCssClass(document.body, "busy", true);
}

function requestEndHandler() {
	//switchCssClass(document.body, "busy", false);
}

function errorHandler(url, e) {
	requestEndHandler();
	throw new Error("Error in" + url + ":" + e);
}

function getListNode(oXmlDoc, tagName) {

		var statusMessage, errorMessage, stacktrace = false;
		if (!oXmlDoc || !oXmlDoc.childNodes) return;
		var rootNode = false;
		for (var i = 0; i < oXmlDoc.childNodes.length; i++) {
			if (oXmlDoc.childNodes.item(i).nodeName == tagName) rootNode = oXmlDoc.childNodes.item(i);
		}
		if (!rootNode || !rootNode.childNodes) {
			return;
		}
                return rootNode;
}

function switchCssClass(obj, name, turnOn) {
	var clazz = obj.className ? obj.className : "";
	if (turnOn == undefined) {
		turnOn = clazz.indexOf(name) == -1
	}
	if (turnOn === false) {
		obj.className = clazz.replace(new RegExp("\s?" + name, "g"), "");
	} else if (turnOn === true) {
		obj.className = obj.className ? (obj.className + " " + name) : name;
	}
}

var lastListName = new Array();
var lastListIndex = 0;

var lastListExt = new Array();
var lastListIndeX = 0;



function outPutData(text,container) { 
	document.getElementById(container).innerHTML = text; 
}


// Function add data to selector
function treeAction(uid, listnum, listindex, locale) 
{

    if (uid != "") {
		var list1 = document.getElementById("List1");
		var list2 = document.getElementById("List2");
		var list3 = document.getElementById("List3");
		var list4 = document.getElementById("List4");
		var pic2 = document.getElementById("dd2");
		var pic3 = document.getElementById("dd3");
		var pic4 = document.getElementById("dd4");
        var requestBody = "nodeId=" + uid;
        
        // clear option list
       		
		if (listnum == 1) {
			list2.length = null;
			list3.length = null;
			pic2.style.visibility = "hidden";
			pic3.style.visibility = "visible";
			pic4.style.visibility = "hidden";
			list4.length = null;
		} else if (listnum == 2) {
			list3.length = null;
			pic2.style.visibility = "hidden";
			pic3.style.visibility = "hidden";
			pic4.style.visibility = "visible";
			list4.length = null;
		} else if (listnum == 3) {
			pic2.style.visibility = "hidden";
			pic3.style.visibility = "hidden";
			pic4.style.visibility = "hidden";
			list4.length = null;
            lastListName = new Array();
		} else if (listnum == 4) {
			//List4.length = null;
			pic2.style.visibility = "hidden";
			pic3.style.visibility = "hidden";
			pic4.style.visibility = "hidden";
		} 		
 		        
		var onSuccess = function(oXmlDoc) {
		
		//requestEndHandler();
		var listNode = getListNode(oXmlDoc, "trees");
                if (!listNode) {
			return;
		}
		
		var nodes = listNode.childNodes;
                for (var j = 0; j < nodes.length; j++) {
			var node = nodes.item(j);
			if (node.nodeName == 'tree') {   
			
                       	if (listnum == 1 ) {
                       		list2.options[list2.options.length] = new Option(node.getAttribute('text'),node.getAttribute('customId') + '|' + node.getAttribute('extId') + '_products');
                       	} else if (listnum == 2) {
                       		list3.options[list3.options.length] = new Option(node.getAttribute('text'),node.getAttribute('customId') + '|' + node.getAttribute('extId'));
                       	} else if (listnum == 5) {
                 			list4.options[list4.options.length] = new Option("Axelavstånd " + lastListName[listindex] + "mm " + node.getAttribute('text') + "m3",node.getAttribute('customId') + "|" + lastListExt[listindex] + "|" + node.getAttribute('extId'));
                 		} else if (listnum == 3) {
                 		            lastListName[lastListName.length] = node.getAttribute('text');
                 		            lastListExt[lastListExt.length] = node.getAttribute('extId');
                   					treeAction(node.getAttribute('customId'), 5, lastListName.length - 1);                 			    
		    			} else if (listnum == 4) {
							// see #treeActionSearch()							
                 		} 
                 		
              }
            }
          }
          
         
          
 		doXmlRequest('/system/modules/com.gridnine.opencms.modules.ms/elements/treedata.xml?curLocale=' + locale + '&stage=' + listnum + '',
		onSuccess,
		requestStartHandler,
		errorHandler,
		requestBody
		);

	}

}

// This function generate output data to page.
function treeActionSearch(uid,listnum,pageNum,locale,addInfo) {

	if (uid != "") {

		var s = "";
		
		if (listnum == 2 && document.getElementById("List1").selectedIndex == 0) {
			s +="<form name='compare_items' action='product_compare.html' method='post'><input type='hidden' name='currentUid' value='" + uid + "'><table border='0' cellspacing='0' cellpadding='0' width='100%' height='100%'><tr><td valign='top' width='150'>&nbsp;</td><td valign='top' width='195'  style='text-align:right;'><table cellspacing='0' cellpadding='0' width='108'><tr><td width='12'><img src='../../../galleries/pics/content_images/common/blue_b_left.gif'></td><td style='background: url(../../../galleries/pics/content_images/common/blue_b_bg.gif) repeat-x;text-align:center;'><a href=\"javascript:checkCompare();\" class='compare_button'>Jämför</a></td><td width='13'><img src='../../../galleries/pics/content_images/common/blue_b_right.gif'></td></tr></table></td><td width='155' style='padding-left:20px;'>&nbsp;</td><td width='210'>&nbsp;</td></tr>";
       	} else {
       		s +="<form name='compare_items' action='product_compare.html' method='post'><input type='hidden' name='currentUid' value='" + uid + "'><table border='0' cellspacing='0' cellpadding='0' width='100%' height='100%'><tr><td valign='top' width='150'><h3>Vänster</h3></td><td valign='top' width='195'  style='text-align:right;'><table cellspacing='0' cellpadding='0' width='108'><tr><td width='12'><img src='../../../galleries/pics/content_images/common/blue_b_left.gif'></td><td style='background: url(../../../galleries/pics/content_images/common/blue_b_bg.gif) repeat-x;text-align:center;'><a href=\"javascript:checkCompare();\" class='compare_button'>Jämför</a></td><td width='13'><img src='../../../galleries/pics/content_images/common/blue_b_right.gif'></td></tr></table></td><td width='155' style='padding-left:20px;'><h3>Höger</h3></td><td width='210'>&nbsp;</td></tr>";
       	}
       	var vl = "";
       	var perPage = ""; // Per page out variables
       	var startPage = ""; 
		var endPage ="";
       	
       	// art numbers array
       	var artNumArray = new Array();
       	var quantitiesArray = new Array();
       	
       	// make request Uri (list or perpage list)
       	if (listnum == 2 && pageNum != null) {
       		 var requestBody = "nodeId=" + uid + "&showPerPage=yes&pageNum=" + pageNum;
        } else {
       		 var requestBody = "nodeId=" + uid;
       	}

		var onSuccess = function(oXmlDoc) {
		
		//requestEndHandler();
		
		var listNode = getListNode(oXmlDoc, "trees");
                if (!listNode) {
			return;
		}

		// parse xml data
		var nodes = listNode.childNodes;
            for (var j = 0; j < nodes.length; j++) {
				var node = nodes.item(j);
				if (node.nodeName == 'tree') {  
					
					startPage = node.getAttribute('startPage');
					endPage = node.getAttribute('endPage');
                    // generate artNumbers array
					artNumArray[j] = node.getAttribute('artNum');
					quantitiesArray[j] = 1;
						
                   // get results
					if (j % 2 == 0) { 
						s += "<tr>"; 
						vl="class=\"compare_vert_line\""; 
						leftpadding = ""; 
						group = "name=\"group1\"";
					 } else { 
					 	vl=""; 
					 	leftpadding = "style=\"padding-left:20px;\"";
					 	group = "name=\"group2\""; 
					 }
					 
					 // get image path
					 if (node.getAttribute('imageIndex') != "-1") {
					 	
					 	if (node.getAttribute('side') != null) {
					 	
					 		myImage = node.getAttribute('imageIndex');
					 	
					 	} else {
					 		
					 		myImage = "/ms/opencms/system/modules/com.gridnine.opencms.catalogue/admin/frames/getbin.jsp?index=" + node.getAttribute('imageIndex') + "&attr=image&itemId=" + node.getAttribute('customId') + "&width=70&height=70";
					 	
					 	}
					 	
					 	
                  	 } else {
                  	 	myImage = "/export/g/pics/catalogue_default.jpg";
                  	 }	
                  	 
                  	 s += "<td " + leftpadding + "><a href='product.html?productId=" + node.getAttribute('customId') + "'><img src='" + myImage + "' width='70' height='70' border='0' alt='" + node.getAttribute('text') + "'></a><br><br><div style='margin-left:7px;'><input type='radio' value='" + node.getAttribute('customId') +  "' " + group + "> Jämför</div><br></td><td " + vl + " valign=\"top\"><div style='margin-left:5px;margin-top:10px;'><strong>"  + node.getAttribute('artNum') +  " - " + node.getAttribute('text') + "</strong><br><br><strong>Pris (exkl. moms): </strong><div id=\"myprice_" + node.getAttribute('artNum') + "\" style=\"display:inline\"><strong>n/a</strong></div><br><br><a href='product.html?productId=" + node.getAttribute('customId') + "'>Läs mer</a><br><br><br></div><table border='0' cellspacing='0' cellpadding='0' width='90'><tr><td width='9'><img src='../../../system/modules/com.gridnine.opencms.modules.ms/resources/pics/cart_form_left2.gif' width='9' height='19'></td><td style='background: url(../../../system/modules/com.gridnine.opencms.modules.ms/resources/pics/cart_form_bg2.gif) 0 0 repeat-x #c0c0c0;'><a href='#' onclick=\"updateShoppingCart(new Array(new ShoppingCartRequestItem('" + node.getAttribute('customId') + "',1)),false,false); return false;\" onFocus='blur();' class='cart_btn'>Lägg till</a></td><td width='27'><img src='../../../system/modules/com.gridnine.opencms.modules.ms/resources/pics/cart_form_btn2.gif' width='27' height='19' border='0'></td></tr></table></td>";
         			 
         			if (j % 2 == 1 || j == nodes.length - 1) s += "</tr>";
	                        	
	              }
            } 
            
	            		// output product search results
			if (listnum == 4 || listnum == 2) {
			
				if (listnum == 2 && document.getElementById("List1").selectedIndex == 0) {
	
					var linkstyle="underline";
					var p = 0;
					
					if (pageNum != 0) {
						perPage += "<a href=\"javascript: treeActionSearch('" + uid + "',2," + (new Number(pageNum)-1) + ");\">Föregående</a>&nbsp;&nbsp;&nbsp;";				
					}
						
					for ( p = (new Number(startPage)); p < endPage; p++){
								
						if (p == pageNum) 
							linkstyle = "none;color:#000000;font-weight:bold;"; 
						else
							linkstyle = "underline";
						
						perPage += "<a href=\"javascript: treeActionSearch('" + uid + "',2," + p + ");\" style=\"text-decoration:" + linkstyle  + "\">" + (new Number(p)+1) + "</a>&nbsp;";
		
					}
					if (pageNum != (new Number(endPage)-1)) {
						perPage += "&nbsp;&nbsp;<a href=\"javascript: treeActionSearch('" + uid + "',2," + (new Number(pageNum)+1) + ");\">Nästa</a>&nbsp;";
					}
				}
			
				s += "<tr><td><p>&nbsp;</p></td><td style='text-align:right;'><br><table cellspacing='0' cellpadding='0' width='108'><tr><td width='12'><img src='../../../galleries/pics/content_images/common/blue_b_left.gif'></td><td style='background: url(../../../galleries/pics/content_images/common/blue_b_bg.gif) repeat-x;text-align:center;'><a href=\"javascript:checkCompare();\" class='compare_button'>Jämför</a></td><td width='13'><img src='../../../galleries/pics/content_images/common/blue_b_right.gif'></td></tr></table><br></td><td><p>&nbsp;</p></td><td><p>&nbsp;</p></td></tr>";
				s += "</table><br><br><center>" + perPage + "</center></form>";
				
				// put data to div's
				
				outPutData(s, "product_selector_result");
				document.getElementById("products_footer_news").style.display = "none";
				document.getElementById("products_footer_stages").style.display = "none";
				document.getElementById("results_area").style.paddingBottom = "20px";
						
				updatePrices(artNumArray, quantitiesArray);						
			}    
            	
          }
         
          
		doXmlRequest('/system/modules/com.gridnine.opencms.modules.ms/elements/treedata_search.xml?curLocale=' + locale + '&addInfo=' + addInfo + '',
		onSuccess,
		requestStartHandler,
		errorHandler,
		requestBody
	);
	

	

	}

}

// EOF HANDLERS
