/*
 * GLOBAL VARS
 */

var last_clicked_at = 0;

/* ----------------------------------------------------------------------- */
// file: pagequery_api.js
// javascript query string parsing utils
// pass location.search to the constructor: var page = new PageQuery(location.search)
// get values like: var myValue = page.getValue("param1") etc.
/* ----------------------------------------------------------------------- */	

function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return -1;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }	
}

function queryString(key) {
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}

/* --------------------------------------------------------------------------- */

/*
 * Array handling
 */
function isInArray(needle, arrayHaystack) {
	for (var x in arrayHaystack) {
		
		if (arrayHaystack[x].split(":")[0] == needle)
			return true;
	}

	return false;
}

/*
 * Cookie handling
 */
function setCookie(_name, _value) {
	if (_value != null && _value != "")
		document.cookie = _name + "=" + _value;
}	

function getCookie(_name) {
	var cookieStr = document.cookie;
	var arr = cookieStr.split(";");
	
	for (var i = 0; i < arr.length; i++) {
		var cookieArr = arr[i].split("=");
		var cookieName = cookieArr[0].replace(" ", "");
		if (cookieName == _name) {
			return unescape(cookieArr[1]);
		}	
	}	

	return null;
}	

/*
 * Check if the given category has non default types
 */
function categoryHasNonDefaultTypes(_cat) {
	var result = false;

	// If no types
	if ( !categoryList[_cat] || !categoryList[_cat]['type']) return false;

	// Type array
	var typeArray = categoryList[_cat]['type'].split(",");

	// For every feature in category
	for (var t in typeArray) {
		// For this type check if its not part of the defaults
		if (!isInArray(typeArray[t], defaultTypes))
			result = true;
	}

	// Has only default types
	return result;
}

/*
 * Check if the given category has the given feature
 */
function categoryHasFeature(_cat, _feature, _type) {
	// Get category
	if (!_type) {
		return categoryList[_cat] && categoryList[_cat]['features'] && categoryList[_cat]['features'].indexOf(_feature) >= 0;
	} else {
		var category_type = category_params[_cat] ? category_params[_cat][_type] : null;
		return (category_type && isInArray(_feature, category_type["include"]));
	}
}

/*
 * Check if the given  category has a price list, and return it
 */
function categoryHasPriceList(_cat) {
	if (categoryHasFeature(_cat, "pricelist")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
		return categoryList[_cat]['features'].substr(categoryList[_cat]['features'].indexOf('pricelist:')+10, 1);
	} else if (categoryHasFeature(_cat, "Real Estate")) {
		showField('Real Estate', 'block');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Car Accessories")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Car Plate Number")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Trucks & Buses")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Motorcycles")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Boats")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Mobile Phones")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Mobile Phone Number")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Computer & Networking")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Consumer Electronics")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "DVD & Movies")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Education")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Video Games")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Furniture")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Garden")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Home Appliances")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Books")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Clothing/Shoes & Accessories")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Gift Certificates")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Health & Beauty")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Horses")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Hunting & Fishing")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Watches & Jewelry")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Music & Instruments")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Maintenance")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Pets")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Sporting Goods")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Stamps")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'none');
		showField('hidetxta', 'none');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Tickets")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Travel & Holidays")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'none');
		showField('hidetxta', 'none');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Business for Sale")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'none');
		showField('hidetxta', 'none');
		showField('hidetxtb', 'none');
		showField('hideprice', 'none');
	} else if (categoryHasFeature(_cat, "Investment Opportunities")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Office Equipment")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Car Lifts")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Miscellaneous")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Lost & Found")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Matrimonial")) {
		showField('Real Estate', 'none');
		showField('Jobs', 'none');
		showField('hide', 'block');
		showField('hidetxta', 'block');
		showField('hidetxtb', 'block');
		showField('hideprice', 'block');
	} else if (categoryHasFeature(_cat, "Jobs")) {
		showField('Real Estate', 'none');
		showField('hide', 'none');
		showField('hidetxta', 'none');
		showField('hidetxtb', 'none');
		showField('hideprice', 'none');
		showField('Jobs', 'block');
	}
	return false;
}

/*
 * Check if the given category has a warning message, and return it
 */
function categoryHasWarning(_cat, _warning_type) {
	if (!categoryList[_cat]) return false;
	
	if (categoryHasFeature(_cat, _warning_type)) {
		var warning_code = parseInt(categoryList[_cat]['features'].substr(categoryList[_cat]['features'].indexOf(_warning_type+':')+_warning_type.length+1));
		return eval(_warning_type+"["+warning_code+"]");
	} else if (typeof(categoryList[_cat][_warning_type]) != "undefined" && categoryList[_cat][_warning_type].length > 0) {
		return categoryList[_cat][_warning_type];
	}
	
	return false;
}


/*
 * Check if the given feature has been selected
 */
function setFeatureVal(_feat) {
	if (!document.getElementById(_feat)) return false;

	var cookie_str = getCookie('features');
	var feat_elements = document.getElementById(_feat).length;
	if (cookie_str && cookie_str.indexOf(_feat) >= 0) {
		var feature = parseInt(cookie_str.substr(cookie_str.indexOf(_feat+':')+_feat.length+1));
		for (var i = 0; i < feat_elements; i++) {
			if (feature == document.getElementById(_feat).options[i].value)
				document.getElementById(_feat).options[i].selected = true;
		}	
	}
}


/*
 * Check if the given feature has been selected
 */
function setRadioVal() {
	var cookie_str = getCookie('features');
	if (cookie_str && cookie_str.indexOf("st") >= 0) {
		var feature = cookie_str.substr(cookie_str.indexOf('st:')+3);
	        for (var j = 0; j < document.f.st.length; j++) {
	                if (document.f.st[j].value == feature) {
	                        document.f.st[j].checked = true;
	                }
	        }
	}
}


/*
 * Gets the ad type from caller argument
 */
function getAdTypeFromCaller(){
	var type;

	if (queryString('ca') < 0) {
		type = defaultTypes[0];
	} else {	
		var caller = queryString('ca');
		var split_ca = caller.split("_");
		type = split_ca[split_ca.length - 1]
	} 

	return type;
}

/*
 * Layer handling
 */
function showField() {
	var ShowItem = document.getElementById(showField.arguments[0]);
	if (ShowItem)
		ShowItem.style.display = showField.arguments[1];
	if (showField.arguments.length == 3) {
		ShowItem.innerHTML = showField.arguments[2];
	}	
		
}

function scrollToTop() {
	window.scrollTo(0, 0);
}

function scrollToBottom() {
	window.scrollTo(0, 4000);
}

function scrollToObject(offsetTrail) {
	var offsetLeft = 0;
	var offsetTop = 0;

	// Calculate the position
	while (offsetTrail) { 
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}               

	if (typeof(document.body.leftMargin) != "undefined") {
		offsetLeft += document.body.leftMargin;
		offsetTop += document.body.topMargin;
	}       

	// Scroll
	window.scrollTo(0, offsetTop);
}

var focused = false;
function scrollToError(elemId) {
	if (focused) return;
	var offsetTrail = document.getElementById(elemId);

	scrollToObject(offsetTrail);
	
	document.getElementById(elemId).focus();
	focused = true;
} 


function setFocus(_field) {
	document.getElementById(_field).focus();
}

function setChecked(_Id, _check) {
	var Item = document.getElementById(_Id);
	if (Item == null) return;
	Item.checked = _check;
}

function setValue(_Id, _check) {
	var Item = document.getElementById(_Id);
	if (Item == null) return;

	Item.value = _check;
}

/*
 * Popup
 */
//window.name = "shl";
var newWin;
function popUp(page, name, details) {
	newWin=window.open(page, name, details);
	newWin.focus();
}

/*
 * Table row hiliting for IE
 */
function tableRowHilite() {
	if (document.getElementById("hl") == null) return;
	
	var table = document.getElementById("hl");
	var rows = table.getElementsByTagName('tr');
	
	for (var i = 0; i < rows.length; i++)	{
		rows[i].onmouseover = function() {
			this.className += 'hilite';
		}
		
		rows[i].onmouseout = function()	{
			this.className = this.className.replace('hilite', '');
		}
	}
}

/*
 * Disable and enable input fields in forms
 */
function enable_field(_name) {
	var Item = document.getElementById(_name);

	if (Item == null) return;

	if (Item.disabled)
		Item.disabled = false;
}

function disable_field(_name) {
	var Item = document.getElementById(_name);

	if (Item == null) return;

	if (!Item.disabled)
		Item.disabled = true;
}

function check_dc(_key) {
	var date = new Date;
	var time = date.getTime();

	if ((last_clicked_at + 2500) >= time) {
		document.getElementById(_key).value = 1;
	} else {
		document.getElementById(_key).value = 0;
	}	
	
	last_clicked_at = time;
}

/*
 * Text area limit
 */
function maxlength(e, obj, max) {
	if (!e) e = window.event; // IE

	if (e.which) {
		var keycode = e.which; // Mozilla
		var ie = false;
	} else {
		var keycode = e.keyCode; // IE
		var ie = true;
	}

	x = obj.value.length;

	if (x > max) {
		obj.value = obj.value.substr(0, max);
		x = max;
	}

	if (keycode == 0 && ie) { // PASTE ONLY FOR IE
		var select_range = document.selection.createRange();	
		var max_insert = max - x + select_range.text.length;
		var data = window.clipboardData.getData("Text").substr(0, max_insert);
		select_range.text = data;
	} else if (x == max && (keycode != 8 && keycode != 46)) {
		return false;
	}

	return true;
}

/*
 * Positioning of elements
 */
function findPosX(obj, end) {
	var curleft = 0;
	var width = obj.clientWidth;

	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x)
		curleft += obj.x;

	return curleft + (end?width:0);
}

function findPosY(obj, end) {
	var curtop = 0;
	var height = obj.clientHeight;

	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
				obj = obj.offsetParent;
		}
	} else if (obj.y)
		curtop += obj.y;

	return curtop + (end?height:0);
}

/*
 * Progress bar
 */
function progressBar(text) {
	document.write('<div id="loading" class="progressBar">'+text+'<span id="loading_dots"></span></div>');
}

function startProgressBar(pos) {
	var dots = "";

	pos %= 4;
	for (var i = 0; i < pos; i++)
		dots += ".";
	
	document.getElementById('loading_dots').innerHTML = dots;

	pos++;
	setTimeout('startProgressBar('+pos+')', 500);
}

/*
 * Position progress bar
 */
function showProgressBar(obj) {
	startProgressBar(1);
	document.getElementById('loading').style.top = '' + (findPosY(obj, true)) + 'px';
	document.getElementById('loading').style.left = '' + (findPosX(obj, true) + 20) + 'px';
	document.getElementById('loading').style.display = "inline";
}

function displayFeatures (_cat, _type) {
	var category_type = category_params[_cat] ? category_params[_cat][_type] : null;
	var added = false;
	
	for (var feature in features) {
		if (category_type && isInArray(feature,category_type["include"])) {
			var label = "l" + feature;	
			var labelid = document.getElementById(label);
			var inner_html = "";
			
			labelid.innerHTML = "";
			if (category_type["labels"] && category_type["labels"][feature]) {
				inner_html = category_type["labels"][feature] + ":";
			} else {
				inner_html = features[feature] + ":";
			
			}	

			labelid.innerHTML = inner_html;
			
			showField("d" + feature, "block");
			showField("l" + feature, "block");
			
			// XXX Fix this later in html
			if (feature == "gearbox") {
				showField("car_fix", "block");
				added = true;
			}	
		} else	{
			showField("d" + feature, "none");
			showField("l" + feature, "none");
			if (!added)
				showField("car_fix", "none");
		}	
	}
}

/*
 * Check if the given category/feature has a message, and return it
 */
function showMessages(_cat, _type) {
	try {
		var feature_arr = category_params[_cat][_type]['include'];

		for (var i = 0; i < feature_arr.length; i++) {
			if (typeof messages[_cat] != 'undefined' &&
			    typeof messages[_cat][feature_arr[i]] != 'undefined' &&
			    typeof messages[_cat][feature_arr[i]][_type] != 'undefined') {
				showField("m" + feature_arr[i], "inline", messages[_cat][feature_arr[i]][_type]);
				showField("d" + feature_arr[i], "inline");
				showField("l" + feature_arr[i], "inline");
				showPrice('none', 'dprice', 'lprice');
			} else if (typeof messages['default'][feature_arr[i]] != 'undefined' &&
				   typeof messages['default'][feature_arr[i]][_type] != 'undefined') {

				showField("m" + feature_arr[i], "inline", messages['default'][feature_arr[i]][_type]);
				showField("d" + feature_arr[i], "inline");
				showField("l" + feature_arr[i], "inline");
				showPrice('none', 'dprice', 'lprice');
			}
		}
	} catch (e) {
	}	
}

function select_all_weeks(_name, _form, _select) {
	for (var i = 1; i < 53; i++) {
		var week = eval("document." + _form + "." + _name + i);

		week.checked = _select;
	}	
}	

/*
 * Display images. Show border and display large image
 */
var next_image;
function waitForNextImage(next_image, ad_id) {
	var ad_id = ad_id ? ad_id : "";
	var image = document.getElementById("display_image" + ad_id).firstChild;

	if (next_image.width > 0) {
		image.width = next_image.width;
		image.height = next_image.height;
		next_image = null;
	} else {
		setTimeout("waitForNextImage(next_image, ad_id)", 100);
	}
}

function resizeImage(image, path, next_image, admin) {
	if (!next_image) {
		next_image = new Image;
		next_image.src = path;
	}

	if (next_image.width == 0) {
		next_image.onload = setTimeout(function () { resizeImage(image, path, next_image, admin); }, 0);
		return;
	}

	image.src = next_image.src;

	if (admin && next_image.width > 400) {
		var factor = (next_image.width - 400) / next_image.width;
		image.height = next_image.height * (1 - factor);
		image.width = 400;
	} else {
		image.width = next_image.width;
		image.height = next_image.height;
	}
}

function showLargeImage(strDisplayPath, ad_id, admin) {
	var ad_id = ad_id ? ad_id : "";
	var admin = admin ? admin : false;
	var image = document.getElementById("display_image" + ad_id).firstChild;

	if (admin) {
		resizeImage(image, strDisplayPath, null, admin);
	} else {
		if (navigator.userAgent.toLowerCase().indexOf('safari') > 0) {
			next_image = new Image;
			next_image.src = strDisplayPath;

			image.src = next_image.src;
			waitForNextImage(next_image, ad_id);
		} else {
			image.src = strDisplayPath;
		}
	}
}

var styles = [];
function thumbnailBorder(thumb, image_num, ad_id) {
	var ad_id = ad_id ? ad_id : "";

	if (typeof(thumb.style) == 'undefined') {
		return false;
	}

//	for (i = 0; i < image_num; i++) {
//		var thumb_obj = document.getElementById('thumb' + i + ad_id);
//		if (!styles[i]) {
//			styles[i] = thumb_obj.className;
//			if (styles[i].indexOf('ad_border_solid_black') > 0) {
//				styles[i] = styles[i].substring(0, styles[i].indexOf('ad_border_solid_black')) + 'ad_border_solid_grey';
//			}
//		}
//		thumb_obj.className = styles[i];

//		if (thumb.id == thumb_obj.id) {
//			thumb_obj.className = "ad_thumb ad_border_solid_black";
//			document.getElementById('display_image' + ad_id).className = 'ad_pict' + ((styles[i].indexOf('ad_border_dotted') > 0)?' ad_border_dotted':'');
//		}
//	}
}
