	_tux_cache_xml = false;

    function get_cwd(rawloc) {
        if(!rawloc) {
            rawloc = location.href;
        }

        var expl_loc = rawloc.split("/");
        if(expl_loc[expl_loc.length-2]) {
            return expl_loc[expl_loc.length-2];
        }

        return "";
    }
	
	function get_states(country) {
        var req = xml_request();
    
        req.onreadystatechange = function() {
            if(req.readyState == 4) {
                if(req.status == 200) {
					var textResponse = req.responseText;
					
					var states = textResponse.split("\r\n");
					var state_select_box = document.getElementById("rslr_state");
		
					state_select_box.options.length = 3;
		
					for(var s = 0; s < states.length; s++) {
						var cur_state = states[s];
						
						var state_code = cur_state.substr(0,2);
						var state_name = cur_state.substr(3);
						
						var cur_opt_index = state_select_box.options.length;
						state_select_box.options[cur_opt_index] = new Option(state_name,state_code);
						/* The following line is needed to use ASCII numbers to display German characters */
						state_select_box.options[cur_opt_index].innerHTML = state_name;
					}
                }
            }
        }
	
        req.open("GET","/general/scripts/resellers/get_states.php?country="+escape(country),true);
        req.send("");
	}
	
	function in_array(string,ary) {
		for(var x = 0; x < ary.length; x++) {
			if(ary[x] == string) {
				return true;
			}
		}
		
		return false;
	}
	
	function reseller_form_handler() {
		/*var usa_name = "United States";*/
		
		var state_countries = new Array("United States","Germany","United Kingdom");
			
		var country_select_box = document.getElementById("rslr_location");
		if(!country_select_box) { return false; }
		
		var state_select_box = document.getElementById("rslr_state");
		
		if(!state_select_box) {	return false;}

		country_select_box.onchange = function() {
			var country_name = this.value;
		
			if(in_array(country_name,state_countries)) {
				state_select_box.disabled = false;
				get_states(country_name);
				
			}
			else {
				state_select_box.selectedIndex = 0;
				state_select_box.disabled = true;
			}
		}
		
		
		
		/*			
		if(country_select_box.value == usa_name) {
			state_select_box.disabled = false;
		}
		else {
			state_select_box.disabled = true;
		}
	*/	
/*
		country_select_box.onchange = function() {

			if(this.value == usa_name) {
				state_select_box.disabled = false;
			}
			else {
				state_select_box.disabled = true;
			}
		}*/
	}
	
	/* 
	    Will first convert the class names to those set to use JS. 
	    If JS is not enabled then the class names remane the same and the tooltip will use the CSS method.
	 */
	function resolution_tooltip_handler() {
	    var all_spans = document.body.getElementsByTagName("span");
	    var tooltip_spans = new Array;
	    for(var a = 0; a < all_spans.length; a++) {
	        if(all_spans[a].className == "resolution_tooltip") {
	            all_spans[a].className = "res_tooltip";
	            tooltip_spans[tooltip_spans.length] = all_spans[a];
	        }
	        if(all_spans[a].className == "resolution_text") {
	            all_spans[a].className = "res_text";
	        }
	    }
	    
	    for(var a = 0; a < tooltip_spans.length; a++) {
	        var elm = tooltip_spans[a];

   	    
	        elm.onmouseover = function() {
	            var spans = this.getElementsByTagName('span');
	            var tooltip_txt_elm = spans[0];
	            var tooltip_txt = "";
    	    
	            if(tooltip_txt_elm) {
	                tooltip_txt = tooltip_txt_elm.innerHTML;    
	            }
	            tooltip.show(tooltip_txt, 220);
	        }
    	    
	        elm.onmouseout = function() {
	            tooltip.hide();
	        }
	    }
	}
	
	//A function to get the list of newsletters - not used
	function get_newsletter(){
	    var page_location = window.location.pathname;
	    //use last index of or just count the number of letters is 'newsletter'
        //var page_directory = page_location.substring(page_location.indexOf('/') + 1, page_location.lastIndexOf('/'));
        var match_directory = "newsletter";
        //var page_directory = page_location.substring(page_location.indexOf('/') + 1);
        
        
        if (page_location.search(match_directory) >= 0){
	        //Load the XML document into an XMLDOM
	        xhttp = xml_request();
            xhttp.open("GET","http://www.2x.com/general/scripts/newsletter/newsletter.xml",false);
            xhttp.send("");
            xmlDoc=xhttp.responseXML; 
            
            //Load the newsletter xml file into a variable
            var newsletter_xml_file=xmlDoc.getElementsByTagName("newsletter");
            //Declare the variables needed
            var newsletter_html = "", author, year;
           
            for (i=0;i<newsletter_xml_file.length;i++) {
                //Create an new newsletter entry
                var list_item = document.createElement("li");//<li></li>
                
                var anchor = document.createElement("a"); // <a></a>
                
                //var anchor_href = document.createAttribute("href");
                
                
                var title_node = newsletter_xml_file[i].getElementsByTagName("title")[0]; //Load the 'title' node in a variable
                var title = (title_node.childNodes[0].nodeValue); //Get the title text
                
                var link_node = newsletter_xml_file[i].getElementsByTagName("link")[0];
                var link = (link_node.childNodes[0].nodeValue);
                
                anchor.setAttribute("href", link);
                
                var anchor_text = document.createTextNode(title);
                
                anchor.appendChild(anchor_text);                
                
                list_item.appendChild(anchor); // <li>the text</li>
                
                
                document.getElementById("previous_newsletter").appendChild(list_item);
              }
        }
	}

    function init() {
		reseller_form_handler();
		retrieve_quotes();
		resolution_tooltip_handler();
		setInterval("retrieve_quotes()", 15000);
		
        var obj = document.getElementById('product_sidebar');
        if(!obj) return false;
        var link_container = obj.getElementsByTagName('ul');
        link_container = link_container[0];

        var all_links = link_container.getElementsByTagName('a');
        var x;
        var linkFound = false;

        for(x = 0; x < all_links.length; x++) {
            if((all_links[x].href) == (location.href)) {
                all_links[x].className = 'selected';
                linkFound = true;
                break;
            }
        }

        if(!linkFound) {    // if link not found, highlight FIRST entry (only if current folder is identical)
            if(all_links.length > 0) {
                if(get_cwd(all_links[0].href) == get_cwd()) {
                    all_links[0].className = 'selected';
					linkFound = true;
                }
            }
        }

		if(!linkFound) {	// link still not found, highlight first link with folder that matches current page
			if(all_links.length > 0) {
				for(x = 0; x < all_links.length; x++) {
					if(get_cwd(all_links[x].href) == get_cwd()) {
						all_links[x].className = 'selected';
						break;
					}
				}
			}
		}
    }

    function xml_request() {
    
        if(window.XMLHttpRequest) {
            try {
                var req = new XMLHttpRequest();
            } catch(e) {
                var req = false;
            }
        } else if(window.ActiveXObject) {
            try {
                var req = new ActiveXObject("Msxml2.XMLHTTP");
            } catch(e) {
                try {
                    var req = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(e) {
                    var req = false;
                }
            }
        }
        return req;
    }
    
    
    function retrieve_quotes() {
    	if(_tux_cache_xml) {
    		display_quote(_tux_cache_xml);
    		return true;
    	}
    
        // only run this script if a quote needs to be displayed
        // on this page
    
        // get all divs
        var all_divs = document.getElementsByTagName('div');
        var x;
    
        // go through divs, and check for class named 'quote'
        var foundQuote = false;
        for(x = 0; x < all_divs.length; x++) {
            if(all_divs[x].className == 'quote') {
                foundQuote = true;
                break;
            }
        }
    
        // quote holder not found, die
        if(!foundQuote) { return false; }
    
        var req = xml_request();
    
        req.onreadystatechange = function() {
            if(req.readyState == 4) {
                if(req.status == 200) {
                	_tux_cache_xml = req.responseXML;
                    display_quote(req.responseXML);
                }
            }
        }
    
        req.open("GET","/general/data/quotes.xml",true);
        req.send("");
    }
    
    function display_quote(xml) {
        // get all divs
        var all_divs = document.getElementsByTagName('div');
        var x;


        var root = xml.documentElement;
        var all_quotes = root.getElementsByTagName('quote');

        // go through quote divs, and insert quote
    
        for(x = 0; x < all_divs.length; x++) {
            if(all_divs[x].className == 'quote') {

                var randChild = Math.floor(Math.random()*all_quotes.length);

                parse_quote(all_divs[x],all_quotes[randChild]);
            }
        }
    
    }

    function parse_quote(quoteObj,quoteNode) {
        // message value
        var quote_message = quoteNode.getElementsByTagName('message');
        quote_message = quote_message[0].childNodes[0].nodeValue;

        // author value
        var quote_author = quoteNode.getElementsByTagName('author');
        quote_author = quote_author[0].childNodes[0].nodeValue;

        var x;
        var did_msg = false;
        var did_aut = false;

        // message container div
        var all_divs = quoteObj.getElementsByTagName('div');
        for(x = 0; x < all_divs.length; x++) {
            if(all_divs[x].className == 'msg') {
                all_divs[x].innerHTML = quote_message;
                did_msg = true;
            }
            if(all_divs[x].className == 'author') {
                all_divs[x].innerHTML = quote_author;
                did_aut = true;
            }
        }

        if((did_msg) && (did_aut)) { 

            quoteObj.style.display = 'block';

        }
    }