document.writeln('<script type="text/javascript" src="/javascript/string.js"></script>');

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function insert_option(select_object, text, value)
{
	var an_option = new Option(text, value, true, true);
	var select_object_length = select_object.length;
	select_object.options[select_object_length] = an_option;
}

function unique_insert_sort_option(select_object, text, value)
{
	var an_option = new Option(text, value, true, true);
	var select_object_length = select_object.length;
	
	var i;
	
	if (select_object_length == 0){
		insert_option(select_object, text, value);
		return;
	}
	
	for (i = 0; i < select_object_length; i++){
		if (text < select_object.options[i].text){
			try {
				select_object.add(an_option, select_object.options[i]); // standards compliant; doesn't work in IE
			}
			catch(ex) {
				select_object.add(an_option, i); // IE only
			}
			return;
		} else if (text == select_object.options[i].text) {
			return;
		}
	}
	
	insert_option(select_object, text, value);
	return;
}

function delete_option(select_object, index)
{ 
	var select_object_length = select_object.length;
	if(select_object_length>0)
	{
		select_object.options[index] = null;
	}
}

function move_selected_options(select_object_from, select_object_to)
{
  
	var select_object_from_length = select_object_from.length;
	var selected_texts = new Array();
	var selected_values = new Array();
	var selected_count = 0;
  
	var i;
  
	// Find the selected Options in reverse order
	// and delete them from the 'from' Select.
	for(i=select_object_from_length-1; i>=0; i--)
	{
    	if(select_object_from.options[i].selected)
    	{
			selected_texts[selected_count] = select_object_from.options[i].text;
			selected_values[selected_count] = select_object_from.options[i].value;
			delete_option(select_object_from, i);
			selected_count++;
		}
	}
  
	// Add the selected text/values in reverse order.
	// This will add the Options to the 'to' Select
	// in the same order as they were in the 'from' Select.
	for(i=selected_count-1; i>=0; i--)
	{
		insert_option(select_object_to, selected_texts[i], selected_values[i]);
	}
  
	if(NS4) history.go(0);
}

function copy_selected_options(select_object_from, select_object_to){
	var select_object_from_length = select_object_from.length;
	var selected_texts = new Array();
	var selected_values = new Array();
	var selected_count = 0;
  
	var i;
  
	// Find the selected Options in reverse order
	// and delete them from the 'from' Select.
	for(i=select_object_from_length-1; i>=0; i--)
	{
    	if(select_object_from.options[i].selected)
    	{
			selected_texts[selected_count] = select_object_from.options[i].text;
			selected_values[selected_count] = select_object_from.options[i].value;
			// delete_option(select_object_from, i);
			selected_count++;
		}
	}
  
	// Add the selected text/values in reverse order.
	// This will add the Options to the 'to' Select
	// in the same order as they were in the 'from' Select.
	for(i=selected_count-1; i>=0; i--)
	{
		insert_option(select_object_to, selected_texts[i], selected_values[i]);
	}
  
	if(NS4) history.go(0);
}


/*
 * uniquely insert selected categories options from select_object_from to select_object_to in a sorted order
 */

function copy_selected_categories_options(select_object_from, select_object_to){
	var select_object_from_length = select_object_from.length;
	var selected_texts = new Array();
	var selected_values = new Array();
	var selected_count = 0;
  
	var i;
  
	// Find the selected Options in reverse order
	for(i=select_object_from_length-1; i>=0; i--)
	{
    	if(select_object_from.options[i].selected)
    	{
			selected_texts[selected_count] = select_object_from.options[i].text;
			selected_values[selected_count] = select_object_from.options[i].value;
			// delete_option(select_object_from, i);
			selected_count++;
		}
	}
  
	// Add the selected text/values in reverse order.
	// This will add the Options to the 'to' Select
	// in the same order as they were in the 'from' Select.
	for(i=selected_count-1; i>=0; i--)
	{
		unique_insert_sort_option(select_object_to, trim(selected_texts[i]), selected_values[i]);
	}
  
	if(NS4) history.go(0);
}

function copy_selected_item_desc_options(select_object_from, hidden_object_from, select_object_to){
	var select_object_from_length = select_object_from.length;
	var selected_texts = new Array();
	var selected_values = new Array();
	var selected_count = 0;
  
	var i;
  
	// Find the selected Options in reverse order
	for(i=select_object_from_length-1; i>=0; i--)
	{
    	if(select_object_from.options[i].selected)
    	{
			selected_texts[selected_count] = hidden_object_from.options[i].text;
			selected_values[selected_count] = hidden_object_from.options[i].value;
			// delete_option(select_object_from, i);
			selected_count++;
		}
	}
  
	// Add the selected text/values in reverse order.
	// This will add the Options to the 'to' Select
	// in the same order as they were in the 'from' Select.
	for(i=selected_count-1; i>=0; i--)
	{
		select_object_to.value = selected_texts[i];
	}
  
	if(NS4) history.go(0);
}

function delete_selected_options(select_object){
	var select_object_length = select_object.length;
	  
	var i;
  
	// Find the selected Options in reverse order
	// and delete them from the 'from' Select.
	for(i=select_object_length-1; i>=0; i--)
	{
    	if(select_object.options[i].selected)
    	{
			delete_option(select_object, i);
		}
	}
	if(NS4) history.go(0);
}

function select_all(select_object){
	var select_object_length = select_object.length;
	  
	var i;
	
	for(i=select_object_length-1; i>=0; i--)
	{
    	select_object.options[i].selected = true;
	}
	if(NS4) history.go(0);
}

var ns4 = document.layers;
var ns6 = document.getElementById && !document.all || (navigator.userAgent.indexOf('Opera') >= 0);
var ie4 = document.all;
var requester = null;

var offsetX = 0;
var offsetY = 20;
var toolTipSTYLE="";
var CAPTION='cap';
var FG='fg';
var BG='bg';
var TEXTCOLOR='tc';
var CAPTIONCOLOR='cc';
var WIDTH='tw';
var HEIGHT='th';
var FONT='font';
var POSITIONY='posy';
var hideToolTip=true;
var cap, fg, bg, tc, cc, tw, th, font, posy = 0;

function initToolTips() {
    if(ns4||ns6||ie4) {
        if(ns4) toolTipSTYLE = document.toolTipLayer;
        else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
        else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;
        if(ns4);
        else {
            toolTipSTYLE.visibility = "visible";
            toolTipSTYLE.display = "none";
        }
    }
}

function showLoadedData() {
    var msg = 'ERROR';
    if (requester.readyState == 4) { 
        if (requester.status == 200) {
            msg = requester.responseText;
        } else { 
            msg = "ERROR loading details";
        }
    } 
    document.getElementById('infoDivTextRow').innerHTML = msg;
    return true;
}

function toolTipHide() {
    if(ns4) {
        toolTipSTYLE.visibility = "hidden";
    } else {
        toolTipSTYLE.display = "none";
        var IfrRef = document.getElementById('DivShim');
        IfrRef.style.display = "none";
    }
}

function toolTip() {
    if(arguments.length < 1) { // hide
        if (hideToolTip == false) {
            return;
        }
        if(ns4) {
            toolTipSTYLE.visibility = "hidden";
        } else {
            toolTipSTYLE.display = "none";
            var IfrRef = document.getElementById('DivShim');
            IfrRef.style.display = "none";
        }
    } else { // show
        e = arguments[0];
        var msg = arguments[1];
        var type = arguments[2];
        fg = "#000000";
        bg = "#DDDDDD";
        tc = "#000000";
        cc= "#FFFFFF";
        font = "Verdana,Arial,Helvetica";
        tw = '';
        th = '';
        cap = '';
        posy = 0;
		title = 'Help';
        for(var i = 3; i < arguments.length; i+=2) {
            switch (arguments[i]) {
                case "cap": cap = arguments[i+1]; break;
                case "font": font = arguments[i+1]; break;
                case "fg": fg = arguments[i+1]; break;
                case "bg": bg = arguments[i+1]; break;
                case "tc": tc = arguments[i+1]; break;
                case "cc": cc = arguments[i+1]; break;
                case "tw": tw = arguments[i+1]; break;
                case "th": th = arguments[i+1]; break;
                case "posy": posy = arguments[i+1]; break;
				case "title": title = arguments[i+1]; break;
            }
        }
        var imgdir = '/images/';
        var content = '';
        switch (type) {
            case '2':
                titletext = 'Quick Info';
                break;
            case '3':
                titletext = 'Color picker';
                msg = msg.replace(/{SLASH}/g, '\"');
                break;
            case '4':
                titletext = 'Details';
                try { 
                    requester = new XMLHttpRequest(); 
                } 
                catch (error) { 
                    try { 
                        requester = new ActiveXObject("Microsoft.XMLHTTP");
                    } 
                    catch (error) { 
                        msg = "Error initialising AJAX";
                        break;
                    } 
                }
                requester.open("GET", msg);
                requester.send(null);
                requester.onreadystatechange = showLoadedData;
                msg = "Loading ...";
                break;
            default:
                titletext = title;
                break;
        }
        content =
                '<table border="0" cellspacing="0" cellpadding="0" width="' + tw + '" height="' + th + '">' + 
                '<tr><td width="8"></td><td background="' + imgdir + 'help_top_left.gif" width="10"></td>' +
                '    <td background="' + imgdir + 'help_top_middle.gif" align="left"><b>' + titletext + '</b></td>' +
                '    <td background="' + imgdir + 'help_top_right.gif" width="145" align="right">' + 
                '        <a href="javascript:toolTipHide();">Close</a>&nbsp;&nbsp;&nbsp;</td></tr>' + 
                '</table>' +
                
				'<table border="0" cellspacing="0" cellpadding="0" width="' + tw + '" height="' + th + '">' + 
                '<tr><td width="8"></td><td background="' + imgdir + 'help_middle_left.gif" width="6" height="15"></td>' +
                '    <td bgcolor="#ffffe1" id="infoDivTextRow">' + msg + '</td>' + 
                '    <td background="' + imgdir + 'help_middle_right.gif" width="6"></td></tr>' +
                '</table>' +
                
				'<table border="0" cellspacing="0" cellpadding="0" width="' + tw + '" height="9">' + 
                '<tr><td width="8"></td><td background="' + imgdir + 'help_bottom_left.gif" width="9" height="9"><td>' +
                '    <td background="' + imgdir + 'help_bottom_middle.gif" width="' + (tw-20) + '" height="9"></td>' +
                '    <td background="' + imgdir + 'help_bottom_right.gif" width="9" height="9"></td></tr>' + 
                '</table>';
        if(!ns4 && !ns6 && ie4) {
            content =
                '<table border="0" cellspacing="0" cellpadding="0" width="' + tw + '" height="' + th + '">' + 
                '<tr><td width="8"></td><td background="' + imgdir + 'help_top_left.gif" width="10"></td>' +
                '    <td background="' + imgdir + 'help_top_middle.gif" align="left"><b>' + titletext + '</b></td>' +
                '    <td background="' + imgdir + 'help_top_right.gif" width="145" align="right">' + 
                '        <a href="javascript:toolTipHide();">Close</a>&nbsp;&nbsp;&nbsp;</td></tr>' + 
                '</table>' +
                
				'<table border="0" cellspacing="0" cellpadding="0" width="' + tw + '" height="' + th + '">' + 
                '<tr><td width="8"></td><td background="' + imgdir + 'help_middle_left.gif" width="6" height="15"></td>' +
                '    <td bgcolor="#ffffe1" id="infoDivTextRow">' + msg + '</td>' + 
                '    <td background="' + imgdir + 'help_middle_right.gif" width="6"></td></tr>' +
                '</table>' +
                '<table border="0" cellspacing="0" cellpadding="0" width="' + tw + '" height="9">' + 
                '<tr><td width="8"></td><td background="' + imgdir + 'help_bottom_left.gif" width="9" height="9"><td>' +
                '    <td background="' + imgdir + 'help_bottom_middle.gif" width="' + (tw-20) + '" height="9"></td>' +
                '    <td background="' + imgdir + 'help_bottom_right.gif" width="9" height="9"></td></tr>' + 
                '</table>';
        }
              
        if(ns4) {
            toolTipSTYLE.document.write(content);
            toolTipSTYLE.document.close();
            toolTipSTYLE.visibility = "visible";
        } else if(ns6) {
            moveToMouseLoc(e);
            document.getElementById("toolTipLayer").innerHTML = content;
            toolTipSTYLE.display='block';
        } else if(ie4) {
            moveToMouseLoc(e);
            document.all("toolTipLayer").innerHTML=content;
            toolTipSTYLE.display='block';
            var IfrRef = document.getElementById('DivShim');
            var DivRef = document.getElementById('toolTipLayer');
            IfrRef.style.width = DivRef.offsetWidth;
            IfrRef.style.height = DivRef.offsetHeight;
            IfrRef.style.top = DivRef.style.top;
            IfrRef.style.left = DivRef.style.left;
            IfrRef.style.zIndex = DivRef.style.zIndex - 1;
            IfrRef.style.display = "block";
        }
	}
}

function moveToMouseLoc(e, tw, th) {
    if(ns4||ns6) {
        x = e.pageX;
        y = e.pageY;
    } else {
        x = event.x + document.documentElement.scrollLeft;
        y = event.y + document.documentElement.scrollTop;
    }
    toolTipSTYLE.left = x+"px";
    toolTipSTYLE.top  = y+"px";
    return true;
}
