// JavaScript Document


// set when the page is finished loading!!! we do in the footer!!
var good_to_go = 0;
var mouse_y = 0;
var mouse_x = 0;

function search_clear(tbname) 
{
	var element = document.getElementById(tbname);
	element.value = "";
}

function search_clear_soft(tbname)
{
	var element = document.getElementById(tbname);
	if( element.value == 'Search' ) {
		element.value = '';	
	}
}

function search_reset_soft(tbname) 
{
	var element = document.getElementById(tbname);
	if( element.value == '' ) {
		element.value = "Search";	
	}
	
	
}



var offsetx = 12;
var offsety =  8;

function get_window_height() {
  //var myWidth = 0, myHeight = 0;
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    //myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    //myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    //myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  return myHeight;
}

function get_window_width() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    //myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    //myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    //myHeight = document.body.clientHeight;
  }
  return myWidth;
  //window.alert( 'Height = ' + myHeight );
}


function newelement(newid)
{ 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 

var ie7 = (window.XMLHttpRequest && document.all)?true:false;
var ie5 = (document.getElementById && document.all)?true:false; 
var ns6 = (document.getElementById && !document.all)?true:false; 

var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);

function getmouseposition(e)
{
	/*
	var mouse_pos_x = 0;
	var mouse_pos_y = 0;
	
	//alert(e.pageX+" , "+e.pageY);
	*/
    if(document.getElementById)
    {
    	/*
    	// if jquery listener is active, use jquery mouse position
    	if(mouse_y && mouse_x) {
    		mouse_pos_x = mouse_x;
    		mouse_pos_y = mouse_y;
    		//alert("running jquery");
    		
    	// if query isn't detected, use original javascript method
    	} else 
    	{
    		
    		//alert("NOT running jquery");
    		var iebody=(document.compatMode && 
        	document.compatMode != 'BackCompat') ? 
        		document.documentElement : document.body;
        		
	        pagex = (isapple == 1 ? 0:(ie7) ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
	        pagey = (isapple == 1 ? 0:(ie7) ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
	        
	        mouse_pos_x = (ie5)?event.clientX:(ns6)?clientX = e.clientX:false;
	        mouse_pos_y = (ie5)?event.clientY:(ns6)?clientY = e.clientY:false;
    	}
    	
        var lixlpixel_tooltip = document.getElementById('tooltip');
     	
        if(e.pageY == null || e.pageX == null)
        {
        	mouse_pos_x = e.clientX + document.body.scrollLeft + window.pageXOffset;
        	mouse_pos_y = e.clientY + document.body.scrollTop + window.pageYOffset;
        }
        
        else
        {
        	mouse_pos_x = e.pageX;
        	mouse_pos_y = e.pageY;
        }
        */
    	var lixlpixel_tooltip = document.getElementById('tooltip');
    	
		var curser = getPosition(e);
		mouse_pos_x = curser.x;
        mouse_pos_y = curser.y;
        
		lixlpixel_tooltip.style.top = (mouse_pos_y + 15) + 'px';
		lixlpixel_tooltip.style.left = (mouse_pos_x + 15) + 'px';
		
		/*lixlpixel_tooltip.style.top = (e.pageY + 15) + 'px';
		lixlpixel_tooltip.style.left = (e.pageX + 15) + 'px';*/
    }
}

var show_tooltip = true;
var redraw_tooltip = true;

function getmouseposition2(e)
{
    if(redraw_tooltip && document.getElementById)
    {
        var lixlpixel_tooltip = document.getElementById('tooltip');
        
		lixlpixel_tooltip.style.top = (mouse_y - 25 - 250) + 'px';
		lixlpixel_tooltip.style.left = (mouse_x + 15) + 'px';
		
		redraw_tooltip = false;
    }
}

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}



/*function tooltip(tip)
{
	if( good_to_go ) {
		//alert('good');
		tip = Base64.decode(tip);
		if(!document.getElementById('tooltip')) newelement('tooltip');
		
		$("#tooltip")
		var lixlpixel_tooltip = document.getElementById('tooltip');
		lixlpixel_tooltip.innerHTML = tip;
		lixlpixel_tooltip.style.zIndex = '1000';
		lixlpixel_tooltip.style.display = 'block';

		document.onmousemove = getmouseposition;
	} else {
		//alert('bad');
	}
	
}*/
function tooltip(tip)
{
	if( good_to_go ) {
		//alert('good');
		tip = Base64.decode(tip);
		if(!document.getElementById('tooltip')) 
		{
			//alert("blammy");
			newelement('tooltip');
		}
		
		
		var lixlpixel_tooltip = document.getElementById('tooltip');
		lixlpixel_tooltip.innerHTML = tip;
		
		lixlpixel_tooltip.style.zIndex = '1000';
		lixlpixel_tooltip.style.display = 'block';

		//document.onmousemove = getmouseposition(event);
		document.onmousemove = getmouseposition;
	} else {
		//alert('bad');
	}
	
}
function tooltip_freeze(tip)
{
	if( good_to_go ) {
		//alert('good');
//		show_tooltip = true;

		tip = Base64.decode(tip);
		if(!document.getElementById('tooltip')) newelement('tooltip');
		var lixlpixel_tooltip = document.getElementById('tooltip');
		lixlpixel_tooltip.innerHTML = tip;
		lixlpixel_tooltip.style.zIndex = '1000';
		lixlpixel_tooltip.style.display = 'block';

		document.onmousemove = getmouseposition2;
	} else {
		//alert('bad');
	}
}

function tooltip_page(page)
{
	if( good_to_go ) {
		//alert('good');
		show_tooltip = true;

		page = Base64.decode(page);
		if(!document.getElementById('tooltip')) newelement('tooltip');
		var lixlpixel_tooltip = document.getElementById('tooltip');
		lixlpixel_tooltip.innerHTML = "Retrieving...";
		ajax_get_page(page, 'tooltip');
		lixlpixel_tooltip.style.zIndex = '1000';
		lixlpixel_tooltip.style.display = 'block';

		document.onmousemove = getmouseposition2;
	} else {
		//alert('bad');
	}
}


function exit()
{
	if( good_to_go && document.getElementById('tooltip') ) {
  	  document.getElementById('tooltip').style.display = 'none';
	}
}

function exit_delay()
{
	if( good_to_go && document.getElementById('tooltip') && !show_tooltip ) {
  	  document.getElementById('tooltip').style.display = 'none';
	}
}

function my_highlight(hi)
{
	var myhi = document.getElementById('btn_' + hi);
	//alert(myhi);
	if( myhi ) {
		myhi.style.color = 'red';	
	}
	
}

function empty_check(val)
{
	var myval = document.getElementById(val);
	if(myval.value == '') {
		alert('You must specify keywords within your search');
		return false;
	}
	
}

function clearform(frm, allFields)
{
	for (var i=0;i<frm.length;i++) {
		switch(frm.elements[i].type) {
			case 'submit':
			case 'reset':
			case 'button':
			case 'hidden': if (allFields) frm.elements[i].value=''; break;
			default: frm.elements[i].value = ''; break;
		}
	}
}

var the_g_unique_id = '';
var the_db_new_value = '';

function makeRequest(url) {
//	alert('Connecting to: ' + url);
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				http_request = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {}
		}
	}
	
	if (!http_request) {
//		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
//				alert(http_request.responseText);
				updateByAJAX(the_g_unique_id, the_db_new_value);
				toggleToStatic(the_g_unique_id);
			} else {
//				alert('There was a problem with the request.');
			}
		}
	};
	
	http_request.open('GET', url, true);
	http_request.send(null);
}

function sendform(g_unique_id, db_field_name, db_new_value, url) {
	query = new Array();
	
	query.push(db_field_name + '=' + db_new_value);
	query = query.join('&');
	response = makeRequest(url + '&' + query);
} 

function toggleToEdit(g_unique_id) {
	document.getElementById('static_' + g_unique_id).style.display = 'none';
	document.getElementById('edit_' + g_unique_id).style.display = 'block';
}
function toggleToStatic(g_unique_id) {
	document.getElementById('static_' + g_unique_id).style.display = 'block';
	document.getElementById('edit_' + g_unique_id).style.display = 'none';
}
function saveByAJAX(g_unique_id, db_field_name, db_new_value, url) {
	the_g_unique_id = db_field_name + g_unique_id;
	the_db_new_value = db_new_value;
	sendform(g_unique_id, db_field_name, db_new_value, url);
}
function updateByAJAX(g_unique_id, db_new_value) {
	document.getElementById('static_text_' + g_unique_id).innerHTML = db_new_value;
}



function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o;
}

var g_ajax_http_object = createRequestObject(); 

function g_ajax_getResult(targetID, url)
{
	
	g_ajax_http_object.open('get', url, true);

	g_ajax_http_object.onreadystatechange = function() {
		if (g_ajax_http_object.readyState == 4) {
			if (g_ajax_http_object.status == 200) {
//				alert(g_ajax_http_object.responseText);
				document.getElementById(targetID).innerHTML = g_ajax_http_object.responseText;
			} else {
				alert('There was a problem with the request.');
			}
		}
	};

	g_ajax_http_object.send(null);
}

function ajax_get_page(url, targetID)
{
//	alert(url);
	g_ajax_http_object.open('get', url, true);

	g_ajax_http_object.onreadystatechange = function() {
		if (g_ajax_http_object.readyState == 4) {
//			if (g_ajax_http_object.status == 200) {
//				alert(g_ajax_http_object.responseText);
				document.getElementById(targetID).innerHTML = g_ajax_http_object.responseText;
//			} else {
//				alert('There was a problem with the request.');
//			}
		}
	};

	g_ajax_http_object.send(null);
}

function clear_form_elements(form_name, arr_form)
{
	
	var objForm=document.getElementById(form_name);
	for( var i=0 ; i < arr_form.length ; i++ ) {
		//var x = document.getElementById(arr_form[i]);
		
		var name = arr_form[i];
		//alert(name);
		//alert(objForm.elements[name].value);	
		//alert(objForm.elements[i].value);	
		//alert(objForm.element[name][0]);
		//alert(objForm.elements[name].value);
		objForm.elements[name].value = '';
	}
/*	
	var x=document.getElementById(form_id);
	for (var i=0;i<x.length;i++)
	{
		//alert(x.elements[i]);
		//alert(x.elements[i].name + ':' + x.elements[i].value);
		x.elements[i].value = '';
		
	}
*/
	
}



function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    }
    else {
        cursor.x = e.clientX +
            (document.documentElement.scrollLeft ||
            document.body.scrollLeft) -
            document.documentElement.clientLeft;
        cursor.y = e.clientY +
            (document.documentElement.scrollTop ||
            document.body.scrollTop) -
            document.documentElement.clientTop;
    }
    return cursor;
}
function urlencode( str ) {
    // URL-encodes string  
    // 
    // version: 905.1001
    // discuss at: http://phpjs.org/functions/urlencode
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brettz9.blogspot.com)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brettz9.blogspot.com)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // %          note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                             
    var histogram = {}, unicodeStr='', hexEscStr='';
    var ret = (str+'').toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    histogram['\u00DC'] = '%DC';
    histogram['\u00FC'] = '%FC';
    histogram['\u00C4'] = '%D4';
    histogram['\u00E4'] = '%E4';
    histogram['\u00D6'] = '%D6';
    histogram['\u00F6'] = '%F6';
    histogram['\u00DF'] = '%DF';
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);

    for (unicodeStr in histogram) {
        hexEscStr = histogram[unicodeStr];
        ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
}

function urldecode( str ) {
    // Decodes URL-encoded string  
    // 
    // version: 905.412
    // discuss at: http://phpjs.org/functions/urldecode
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brettz9.blogspot.com)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brettz9.blogspot.com)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // %          note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
    
    var histogram = {}, ret = str.toString(), unicodeStr='', hexEscStr='';
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urlencode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    histogram['\u00DC'] = '%DC';
    histogram['\u00FC'] = '%FC';
    histogram['\u00C4'] = '%D4';
    histogram['\u00E4'] = '%E4';
    histogram['\u00D6'] = '%D6';
    histogram['\u00F6'] = '%F6';
    histogram['\u00DF'] = '%DF'; 
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';

    for (unicodeStr in histogram) {
        hexEscStr = histogram[unicodeStr]; // Switch order when decoding
        ret = replacer(hexEscStr, unicodeStr, ret); // Custom replace. No regexing
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);

    return ret;
}

function classified_login(g_root,name,pass)
{

	var data = "list=user&method=login&name="+name+"&password="+pass;
	
	$.ajax({
	url:g_root+"classifieds/index.php",
	data:data,
	dataType:"html",
	type:"POST"
	});
	/*
	success:function(data)
	{
		alert("logged in to classified with " + data);
	},
	error:function(data)
	{
		alert("could not log into classified with " + data);
	},*/
}
function classified_create(g_root,user_id,email, firstname, lastname)
{
	var data = "list=user&method=create&name=user_"+user_id+"&email="+email+"&col_0="+firstname+"&col_1="+lastname+"";
	$.ajax({
	url:g_root+"classifieds/index.php",
	data:data,
	async: false,
	dataType:"html",
	type:"POST"
	});
	//alert(data);
	/*
	$.post(
	g_root+"classifieds/index.php",
	data,
	function(data)
	{
		//alert(data);
	},
	"html"
	);*/
	
	/*
		complete:function(data)
	{
		alert("mission complete");
	},
	*/
}
function j_var_dump(name, var_to_dump)
{
	try {
		console.log(name+': ', var_to_dump);
	} catch(e) {
		//alert("You don't have Firebug!\nFor shame...");
	}

}

// Add trim functions to String class
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function confirmTruncate(jquery_item, length)
{
	if(length == null)
		length = 255;
	var v = true;
	jquery_item.each(function() {
		if($(this).val().length > length)
			v = false;
	});
	
	if (v)
		return true;
	
	if (!v && !confirm("Max description limit "+length+" characters.  One or more of your descriptions exceeds this limit and will be truncated.  Continue?"))
		return false;
	
	jquery_item.each(function() {
		if($(this).val().length > length)
			$(this).val($(this).val().substring(0,length));
	});
	
	return true;
}

// use this function on a text field to give default text that gets erased when user clicks
//  -- degrades gracefully!
// example:
//  <input type="text" name="search" class="defaultText" value="" rel="Type search term in here" />
//  <input type="text" name="search2" class="defaultText" value="" rel="Help Text" />
//  <textarea name="taDesc" class="defaultText" rel="Help for textarea" /></textarea>
//  <script type="text/javascript">
//    $(document).ready(function() {
//		$("input[name=search]").addDefaultText(); // example 1: only the first search bar
//		$(".defaultText").addDefaultText(); // example 2: both search bars and the textarea
//    });
//  </script>
jQuery.fn.addDefaultText = function() {
	
	// loop over each object in collection
	this.each( function() {
		
		// store original style
		var origStyle = {
			'color':$(this).css('color'),
			'font-style':$(this).css('font-style')
		};
		
		// when input receives focus, set original style and clear title
	    $(this).focus( function() {
	        if ($(this).val() == $(this).attr('rel')) {
	            $(this).css(origStyle);
	            $(this).val("");
	        }
	    });
	    // when input loses focus, set custom style and add title IF input is empty
	    $(this).blur( function() {
	        if ($(this).val() == "") {
	            $(this).css({"color":"#a1a1a1","font-style":"italic"});
	            $(this).val($(this).attr('rel'));
	        }
	    });
	    
	    // blur by default to force title text to start
	    $(this).blur();
	    
	    // don't submit default text when form submitted
	    var t = $(this);
	    $(this).closest("form").submit( function() {
	    	if( $(t).val() == $(t).attr('rel') ) {
	    		$(t).val("");
	    	}
	    });
	});
	
	// return collection/object given for chaining
    return this;
};
