var ie6;
var ie7;
var firefox;
if (navigator.userAgent.indexOf("Firefox") != -1){
	firefox = true;
}

function create_ajax(){
	if (window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	}
	else{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}

function run_ajax(obj,type,url,vars){
	if (type == "GET"){
		obj.open(type,url+"?"+vars);
		obj.send();
	}
	else{
		obj.open(type,url,true);
		obj.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		obj.send(vars);
	}
}

function newwindow_links(){
	var e = new Array();
	var i;
	e = document.getElementsByTagName("a");
	for(i=0;i<e.length;i++){
		if(e[i].className.indexOf("newwindow") > -1){
			e[i].target="_blank";
		}
	}
}

function browser_fixes(){
	if (ie6){
		var theCorner = document.getElementById("imgCorner");
		if (theCorner){
			var theParent = theCorner.parentNode;
			theParent.removeChild(theCorner);
		}
		var theInputs = document.getElementsByTagName("input");
		for (i=0;i<theInputs.length;i++){
			if (theInputs[i].type == "button" || theInputs[i].type == "submit"){
				theInputs[i].className += " ie6_button";
			}
		}
	}
}

function clean_text(){
	var rem_tags = new Array("caption","marquee","script");
	for (i=1;i<=3;i++){
		var theDiv = document.getElementById("divUserContent"+i);
		if (theDiv){
			for (j=0;j<rem_tags.length;j++){
				var theTags = document.getElementById("divUserContent"+i).getElementsByTagName(rem_tags[j]);
				for (k=0;k<theTags.length;k++){
					theTags[k].parentNode.removeChild(theTags[k]);
				}
			}
			var theTags = document.getElementById("divUserContent"+i).getElementsByTagName("td");
			for (j=0;j<theTags.length;j++){
				theTags[j].innerHTML = theTags[j].innerHTML.replace(/<p>/gi,"");
			}
			/*
			var theTables = document.getElementById("divUserContent"+i).getElementsByTagName("table");
			for (j=0;j<theTables.length;j++){
				theTables[j].id = "tblUser"+j;
				var theRows = document.getElementById(theTables[j].id).getElementsByTagName("tr");
				for (k=0;k<theRows.length;k++){
					if (k%2 != 0){
						theRows[k].className = "alt";
					}
				}
			}
			*/
		}
	}
}

function getElementsByClassName(class1){
	
	theElements = document.getElementsByTagName("*");
	
	theReturn = new Array();
	
	for (i=0;i<theElements.length;i++){
		if (theElements[i].className.indexOf(class1) > -1){
			theReturn.push(theElements[i]);
		}
	}
	
	return theReturn;
	
}

function follow_link(element){
	for(i = 0;element.childNodes[i]; i++ ){
	    if(element.childNodes[i].tagName == 'A'){ 
			window.location = element.childNodes[i].href; 
		}
	}
}

var ind_accepted = false;

function registration_checks(){
	
	if (reg_type == "ind"){
		validate1 = validate_form('frmRegister_ind','/users/procs/register_proc.php','white','pink','1');
	}
	else{
		validate1 = validate_form('frmRegister_comp','/users/procs/register_proc.php','white','pink','1');
	}
	if (validate1){
		if (!reg_username_valid()){
			alert ("Usernames must be between 6 and 12 character, and only contain alphanumeric characters, along with dashes and underscores.");
			return false;
		}
		if (!reg_emails_same()){
			alert ("Please ensure your email address is the same in both fields.");
			return false;
		}
		if (!reg_passwords_same()){
			alert ("Please ensure your password is the same in both fields.");
			return false;
		}
		if (!reg_tandc_checked()){
			alert ("You must accept our terms and conditions before registering.");
			return false;
		}
		reg_email_used();
	}
		
}

function reg_username_valid(){

	var theUsername = document.getElementById("fmUsername").value;
	
	var valid_reg = /^[0-9a-zA-Z_-]{6,12}$/;
	
	if (theUsername.match(valid_reg)){
		return true;
	}
	
	return false;
	
}

function reg_emails_same(){
	
	var theFirst = document.getElementById("fmEmail").value;
	var theConfirm = document.getElementById("fmConfirmEmail").value;
	
	if (theFirst != theConfirm){
		return false;
	}
	
	return true;
	
}

function reg_passwords_same(){
	
	var theFirst = document.getElementById("fmPassword").value;
	var theConfirm = document.getElementById("fmConfirmPassword").value;
	
	if (theFirst != theConfirm){
		return false;
	}
	
	return true;
	
}

function reg_tandc_checked(){
	
	var theCheckbox = document.getElementById("fmTandC");
	
	if (theCheckbox.checked != true){
		return false;
	}
	
	return true;
	
}

function reg_email_used(){
	
	var theEmail = document.getElementById("fmEmail").value;
	
	ajax = create_ajax();
	
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4 && ajax.status==200){
			response = ajax.responseText;
			if (response != "OK"){
				alert ("Your email is already in use - please use another.");
				return false;
			}
			else{
				reg_username_used();
			}
		}
	}
	
	if (theEmail != ""){
		run_ajax(ajax,"POST","/_ajax/check_email.php","fmEmail="+theEmail);
	}
	
}

function reg_username_used(){
	
	var theUsername = document.getElementById("fmUsername").value;
	var theForm = document.getElementById("frmRegister");
	
	ajax = create_ajax();
	
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4 && ajax.status==200){
			response = ajax.responseText;
			if (response != "OK"){
				alert ("Your username is already in use - please use another.");
				return false;
			}
			else{
				if (reg_type == "ind"){
					$.colorbox({width:"50%", inline:true, href:"#divTerms", overlayClose: false,escKey:false, onOpen:function(){ $("#cboxClose").remove(); }});
				}
				else{
					theForm.action = "/users/procs/register_proc.php";
					theForm.submit();
				}
			}
		}
	}
	
	if (theUsername != ""){
		run_ajax(ajax,"POST","/_ajax/check_username.php","fmUsername="+theUsername);
	}
	
}

function change_pass_checks(){
	
	var theForm = document.getElementById("frmChangePassword");
	
	if (validate_form('frmChangePassword','/users/procs/change_password_proc.php','white','pink','1')){
		if (!change_pass_same()){
			alert("Please ensure your passwords match.");
			return false;
		}
		theForm.submit();
	}

}

function change_pass_same(){
	
	var theFirst = document.getElementById("fmPassword").value;
	var theConfirm = document.getElementById("fmPassword2").value;
	
	if (theFirst != theConfirm){
		return false;
	}
	
	return true;

}

function info_edit_checks(){

	if (reg_type == "individual"){
		validate1 = validate_form('frmInfoEdit_ind','/users/procs/info_edit_proc.php','white','pink','1');
	}
	else{
		validate1 = validate_form('frmInfoEdit_comp','/users/procs/info_edit_proc.php','white','pink','1');
	}
	
	if (validate1){
		if (!info_edit_emails_same()){
			alert ("Please ensure your email address is the same in both fields.");
			return false;
		}
		info_edit_email_used();
	}
	
}

function info_edit_emails_same(){
	
	var theFirst = document.getElementById("fmEmail").value;
	var theConfirm = document.getElementById("fmConfirmEmail").value;
	
	if (theFirst != theConfirm){
		return false;
	}
	
	return true;
	
}

function info_edit_email_used(){
	
	var theEmail = document.getElementById("fmEmail").value;
	var theForm = document.getElementById("frmInfoEdit");
	
	ajax = create_ajax();
	
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4 && ajax.status==200){
			response = ajax.responseText;
			if (response != "OK" && theEmail != original_email){
				alert ("Your email is already in use - please use another.");
				return false;
			}
			else{
				theForm.action = "/users/procs/info_edit_proc.php";
				theForm.submit();
			}
		}
	}
	
	if (theEmail != ""){
		run_ajax(ajax,"POST","/_ajax/check_email.php","fmEmail="+theEmail);
	}
		
}

function hide_auction_info(info_text){
	
	var theTable = document.getElementById("tblAuctionInfo");
	var theChildren = theTable.getElementsByTagName("tr");
	var theButton = document.getElementById("tdHide");
	
	if (theButton.innerHTML.match("show")){
		for (i=0;i<theChildren.length;i++){
			if (ie6 || ie7){
				theChildren[i].style.display = "block";
			}
			else{
				theChildren[i].style.display = "table-row";
			}
		}
		theButton.innerHTML = "Click here to hide "+info_text+" information and purchaser's notes";
	}
	else{
		for (i=0;i<theChildren.length;i++){
			if (theChildren[i].className != "hide"){
				theChildren[i].style.display = "none";
			}
		}
		theButton.innerHTML = "Click here to show "+info_text+" information and purchaser's notes";		
	}
	
}

function refresh_listing(id,perPage,sort,search,cat,order_by,thisPage){
		
	var theTableDiv = document.getElementById("divAuctionTableContainer");
	var thePaging = document.getElementById("spnPaging");
	var theDiv = document.getElementById("divRefreshing");

	ajax = create_ajax();
	
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4 && ajax.status==200){
			clearTimeout(ajax_timeout1);
			try{
				response = ajax.responseText;
			}
			catch(e){
				ajax_error();
				return false;
			}
			response_parts = response.split("*@*@*");
			if (response_parts[4]){
				if (response_parts[4] == 0){
					theDiv.innerHTML = '<p>Sale Closed</p><p class="small">Close this box to return to the sales homepage.</p>';
				}
				else{
					theDiv.innerHTML = '<p>Page Expired</p><p class="small">Close this box to return to the listings.</p>';
				}
				$.colorbox({width:"50%", inline:true, href:"#divRefreshing", onClosed:function(){ document.location = "/auction.php?id="+response_parts[2]; }});
			}
			else{
				theTableDiv.innerHTML = response_parts[0];
				thePaging.innerHTML = response_parts[1];
				if (response_parts[2] != "NO_USER"){
					eval(response_parts[2]);
				}
				if (response_parts[3] != "NOT_PAUSED"){
					document.getElementById("divPaused").style.display = "block";
					document.getElementById("spnPaused").innerHTML = response_parts[3];
				}
				else{
					document.getElementById("divPaused").style.display = "none";
				}
				$.colorbox.close()
				t = setTimeout("goto_refresh_listing()",refresh_interval);
				
			}
		}
	}

	var post_vars = "id="+id+"&perPage="+perPage+"&sort="+sort+"&search="+search+"&cat="+cat+"&order_by="+order_by+"&thisPage="+thisPage;
	
	run_ajax(ajax,"POST","/_ajax/refresh_listing.php",post_vars);
	
	ajax_timeout1 = setTimeout("ajax_timeout();",20000);
	
}

function refresh_account_listing(action1,perpage,thispage){
		
	var theTableDiv = document.getElementById("divLotsTableContainer");
	var theDiv = document.getElementById("divRefreshing");
	var thePaging = document.getElementById("spnPaging");
	var theDiv = document.getElementById("divRefreshing");

	ajax = create_ajax();
	
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4 && ajax.status==200){
			clearTimeout(ajax_timeout1);
			try{
				response = ajax.responseText;
			}
			catch(e){
				ajax_error();
				return false;
			}
			response_parts = response.split("*@*@*");
			if (response_parts[3]){
				theDiv.innerHTML = '<p>Page Expired</p><p class="small">Close this box to return to the listings.</p>';
				$.colorbox({width:"50%", inline:true, href:"#divRefreshing", onClosed:function(){ document.location = "/users/lots.php?"+action1; }});
			}
			else{
				theTableDiv.innerHTML = response_parts[0];
				thePaging.innerHTML = response_parts[1];
				if (response_parts[2] != "NO_USER"){
					eval(response_parts[2]);
				}
				$.colorbox.close()
				t = setTimeout("goto_refresh_listing()",refresh_interval);
			}
		}
	}

	var post_vars = "action="+action1+"&perPage="+perpage+"&thisPage="+thispage;
	
	run_ajax(ajax,"POST","/_ajax/refresh_account_listing.php",post_vars);
	
	ajax_timeout1 = setTimeout("ajax_timeout();",20000);
	
}

function highlight_nav(id1){
	var theLink = document.getElementById("aAuction_"+id1);
	theLink.className = "on";
}

var messages_on = false;

function ajax_error(){
	

	if (t){
		clearTimeout(t);
	}
	try{
		clearTimeout(t2);
	}
	catch(e){
		
	}

	$.colorbox({width:"50%", inline:true, href:"#divAjaxError", onClosed:function(){ document.location = "/sales.php"; }});

	
}

function ajax_timeout(){
	
	if (t){
		clearTimeout(t);
	}
	try{
		clearTimeout(t2);
	}
	catch(e){
		
	}

	$.colorbox({width:"50%", inline:true, href:"#divTimeout", onClosed:function(){ document.location = document.location; }});
	
	t_refresh = setTimeout("document.location = document.location;",5000);
	
}

function refresh_lot(l_id){

	try{
		clearTimeout(t2);
	}
	catch(e){
		
	}

	var theLot = new Array();
	var theElements = new Array();
	
	theElements["current_bid"] = document.getElementById("spnCurrentBid");
	theElements["days_remaining"] = document.getElementById("spnDays");
	theElements["hours_remaining"] = document.getElementById("spnHours");
	theElements["mins_remaining"] = document.getElementById("spnMins");
	theElements["secs_remaining"] = document.getElementById("spnSecs");
	theElements["high_bidder"] = document.getElementById("tdHighBidder");
	theElements["bids"] = document.getElementById("tdBids");
	theElements["next_bid"] = document.getElementById("tdNextBid");
	theElements["start_price"] = document.getElementById("tdStartPrice");
	theElements["closes"] = document.getElementById("tdLotCloses");
	theElements["alt_price"] = document.getElementById("spnAltCurrency");
	
	theSpan = document.getElementById("spnIcons");
	theSpanBestOffer = document.getElementById("spnBestOfferIcons");
	theTime = document.getElementById("tdTimeleft");

	ajax = create_ajax();
	
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4 && ajax.status==200){
			clearTimeout(ajax_timeout1);
			//alert (ajax.responseText);
			//alert (ajax.responseXML);
			try{
				response = ajax.responseXML.documentElement.getElementsByTagName("values");
			}
			catch(e){
				ajax_error();
				return false;
			}
			children = response[0].childNodes;
			for (i=0;i<children.length;i++){
				if (children[i].firstChild){
					theLot[children[i].tagName] = children[i].firstChild.nodeValue;
					if (theElements[children[i].tagName]){
						theElements[children[i].tagName].innerHTML = children[i].firstChild.nodeValue;
					}
				}
				else{
					if (theElements[children[i].tagName]){
						theElements[children[i].tagName].innerHTML = '';
					}
				}
			}
			//document.getElementById("spnTime1").innerHTML = theLot["time1"]
			/*
			if (theLot["alt_price"]){
				document.getElementById("spnAltCurrency").innerHTML = theLot["alt_price"];
			}
			*/
			if (theLot["closed"] == "YES"){
				if (t){
					clearTimeout(t);
				}
				try{
					clearTimeout(t2);
				}
				catch(e){
					
				}
				$.colorbox({width:"50%", inline:true, href:"#divRefreshing", onClosed:function(){ document.location = "/auction.php?id="+theLot["auction_id"]; }});
			}
			else{
				if (t){
					clearTimeout(t);
				}
				try{
					clearTimeout(t2);
				}
				catch(e){
				
				}
				if (theLot["rerun"] == "YES"){
					goto_refresh_lot();
				}
				else{
					if (theLot["credit_percentage"] != "NONE"){
						document.getElementById("divCreditBar").style.width = theLot["credit_percentage"] + "%";
						document.getElementById("spnCredit").innerHTML = theLot["symbol"] + theLot["credit_remaining"];
						if (theLot["credit_percentage"] <= 20){
							credit_class = "red";
						}
						else{
							credit_class = "green";
						}
						document.getElementById("spnCredit").className = credit_class;
					}
					if (theLot["auc_paused"] == "1"){
						document.getElementById("divPaused").style.display = "block";
						document.getElementById("divAuctionPaused").style.display = "block";
						document.getElementById("divLotPaused").style.display = "none";
						document.getElementById("spnAuctionPaused").innerHTML = theLot["auc_paused_time"];
						if (messages_on){
							document.getElementById("divLotNav").style.top = "140px";
						}
						else{
							document.getElementById("divLotNav").style.top = "105px";
						}
					}
					else if (theLot["paused"] == "1"){
						document.getElementById("divPaused").style.display = "block";
						document.getElementById("divLotPaused").style.display = "block";
						document.getElementById("divAuctionPaused").style.display = "none";
						document.getElementById("spnLotPaused").innerHTML = theLot["paused_time"];
						if (messages_on){
							document.getElementById("divLotNav").style.top = "140px";
						}
						else{
							document.getElementById("divLotNav").style.top = "105px";
						}
					}
					else{
						document.getElementById("divPaused").style.display = "none";
						if (messages_on){
							document.getElementById("divLotNav").style.top = "55px";
						}
						else{
							document.getElementById("divLotNav").style.top = "20px";
						}
					}
					if (theLot["icon_highbid"] == "YES"){
						theSpan.innerHTML = '<img src="/_images/lots/icon_highbidder.jpg" alt="High Bidder" title="High Bidder" />';
					}
					else if (theLot["icon_outbid"] == "YES"){
						theSpan.innerHTML = '<img src="/_images/lots/icon_outbid.jpg" alt="Outbid" title="Outbid" style="margin-right: 3px;" />';
						theSpan.innerHTML += '<span class="small" title="Your last bid">'+ theLot["symbol"] + theLot["outbid"] +'</span>';
					}
					else{
						theSpan.innerHTML = '';
					}
					if (theLot["icon_proxy"] == "YES"){
						theSpan.innerHTML += '<img src="/_images/lots/icon_proxy.jpg" alt="Proxy Bid Placed" title="Proxy Bid Placed" class="proxy" />';
						theSpan.innerHTML += '<span class="small" title="Your maximum bid">'+ theLot["symbol"] + theLot["proxy"] +'</span>';
					}
					if (theLot["icon_tender"] == "YES"){
						theSpan.innerHTML += '<img src="/_images/lots/icon_tender.jpg" alt="Blind Bid" title="Blind Bid" class="tender" />';
						theSpan.innerHTML += '<span class="small" title="Your bid">'+ theLot["symbol"] + theLot["tender"] +'</span>';
					}
					if (theLot["icon_bestoffer"] == "YES"){
						if (theLot["icon_bestofferrejected"] == "NO"){
							theSpanBestOffer.innerHTML = '<img src="/_images/lots/icon_tender.jpg" alt="Best Offer" title="Best Offer" style="margin-left: 5px;margin-right: 3px;vertical-align: middle;" />';
							theSpanBestOffer.innerHTML += '<span class="small" title="Your best offer">'+ theLot["symbol"] + theLot["bestoffer"] + '</span>';
						}
						else{
							theSpanBestOffer.innerHTML = '<img src="/_images/lots/icon_outbid.jpg" alt="Best Offer Rejected" title="Best Offer Rejected" style="margin-left: 5px;margin-right: 3px;vertical-align: middle;" />';
							theSpanBestOffer.innerHTML += '<span class="small" title="Best Offer Rejected">'+ theLot["symbol"] + theLot["bestoffer"] + '</span>';
						}
					}
					if (theLot["show_bestoffer"] == "YES")
						$("#trBestOffer").show();
					else
						$("#trBestOffer").hide();
					if (theLot["show_buyitnow"] == "YES")
						$("#trBuyItNow").show();
					else
						$("#trBuyItNow").hide();
					if (theLot["reservemet"] == "NO")
						$("#divReserveNotMet").show();
					else
						$("#divReserveNotMet").hide();
					t = setTimeout("goto_refresh_lot()",refresh_interval);
					if (theLot["time_left"] == "N/A"){
						theTime.innerHTML = "N/A";
					}
					else{
						t2 = setTimeout("timeleft_countdown()",1000);
					}
				}
			}
		}
	}

	var post_vars = "l_id="+l_id;
	
	run_ajax(ajax,"POST","/_ajax/refresh_lot.php",post_vars);
	
	ajax_timeout1 = setTimeout("ajax_timeout();",20000);
	
}

function timeleft_countdown(){
	
	var spnSecs = document.getElementById("spnSecs");
	
	var theSecs = (spnSecs.innerHTML.replace(" secs","")) - 1;

	if (theSecs <= 0){
		if (t2){
			clearTimeout(t2);
		}
		goto_refresh_lot();
	}
	else{
		spnSecs.innerHTML = theSecs + " secs";
		t2 = setTimeout("timeleft_countdown()",1000);
	}
	
}

function agree_tandc(auction_id,lot_id){

	ajax = create_ajax();
	
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4 && ajax.status==200){
			$.colorbox.close();
		}
	}

	var post_vars = "id="+auction_id+"&l_id="+lot_id;
	
	run_ajax(ajax,"POST","/_ajax/accept_tandc.php",post_vars);
	
}

function email_to_friend(){
	
	var yourName = document.getElementById("fmYourName");
	var theName = document.getElementById("fmName");
	var theEmail = document.getElementById("fmEmail");
	var theDiv = document.getElementById("divEmailToFriend");
	var theSpan = document.getElementById("spnEmailToFriend");
	var l_id = document.getElementById("l_id");
	var id = document.getElementById("id");
	
	if (yourName.value == "" || theName.value == "" || theEmail.value == ""){
		alert ("Please complete all the details");
		return false;
	}
	
	if (!validate_email("fmEmail")){
		alert ("Please enter a valid email address");
		return false;
	}
	
	theDiv.style.display = "none";
	theSpan.style.display = "block";
	theSpan.innerHTML = "Sending Message...";
	
	ajax_email = create_ajax();
	
	ajax_email.onreadystatechange=function(){
		if (ajax_email.readyState==4 && ajax_email.status==200){
			response = ajax_email.responseText;
			//alert(response);
			theSpan.innerHTML = "Message Sent";
		}
	}

	var post_vars = "your_name="+yourName.value+"&name="+theName.value+"&email="+theEmail.value+"&id="+id.value+"&l_id="+l_id.value;
	
	run_ajax(ajax_email,"POST","/_ajax/email_to_friend.php",post_vars);
	
}

var map_postcode;

function change_lotbox(box){
	
	for (i=1;i<=7;i++){
		var theBox = document.getElementById("divLotBox_"+i);
		var theLink = document.getElementById("aLotBox_"+i);
		if (i == box){
			theBox.style.display = "block";
			theLink.className = "on";
		}
		else{
			theBox.style.display = "none";
			theLink.className = "";
		}
	}
	
	if (box == 6 && map_postcode){
		create_map();
		codeAddress(map_postcode);
	}
	
}

var reg_type = "bus";

function change_reg_type(){
	
	if (reg_type == "bus"){
		reg_type = "ind";
		display_var = "none";
	}
	else{
		reg_type = "bus";
		if (ie6 || ie7){
			display_var = "block";
		}
		else{
			display_var = "table-row";
		}
	}
	
	theRows = getElementsByClassName("trComp");
	for (i=0;i<theRows.length;i++){
		if (theRows[i].className.indexOf("trRegAddress") == -1){
			theRows[i].style.display = display_var;
		}
	}
	
}

function show_reg_address(checked1){
	
	if (!checked1){
		if (ie6 || ie7){
			display_var = "block";
		}
		else{
			display_var = "table-row";
		}
	}
	else{
		display_var = "none";
	}
	
	theRows = getElementsByClassName("trRegAddress");
	for (i=0;i<theRows.length;i++){
		theRows[i].style.display = display_var;
	}
	
}

function changeLotImgsColorbox(){
	var theImg = document.getElementById("imgLotImgsColorbox");
	$("aLotImgsColorbox").colorbox.resize({width:lot_images_width[currentLotImageColorbox] + 50,height:lot_images_height[currentLotImageColorbox] + 70});
	theImg.src = "/_assets/auctions/"+img_auction_id+"/images/"+lot_images[currentLotImageColorbox];
	if (currentLotImageColorbox == (lot_images.length - 1)){
		currentLotImageColorbox = 0;
	}
	else{
		currentLotImageColorbox++;
	}
}

function startLotColorbox(){
	
	var theDiv = document.getElementById("divHiddenColorboxLinks");
	
	theDiv.innerHTML = '';
	
	for (i=currentLotImage;i<lot_images.length;i++){
		theDiv.innerHTML += '<a href="/_assets/auctions/'+img_auction_id+'/images/'+lot_images[i]+'" rel="lot_images_colorbox"><img src="/_assets/auctions/'+img_auction_id+'/images/'+lot_images[i]+'" alt="" /></a>';
	}
	
	for (i=0;i<currentLotImage;i++){
		theDiv.innerHTML += '<a href="/_assets/auctions/'+img_auction_id+'/images/'+lot_images[i]+'" rel="lot_images_colorbox"><img src="/_assets/auctions/'+img_auction_id+'/images/'+lot_images[i]+'" alt="" /></a>';
	}
	
	$("a[rel='lot_images_colorbox']").colorbox({open:true});
	
}

function changeLotMainImg(id1){
	
	var theLink = document.getElementById("aLotMainImg");
	var theImg = document.getElementById("imgLotMain");
	var theContainer = document.getElementById("divLotThumb_"+id1);
	var theMainDiv = document.getElementById("divLotMainImg");
	var theThumbDiv = document.getElementById("divLotThumbnails");
	
	theImg.src = '/_assets/auctions/'+img_auction_id+'/images/thumbs/'+lot_images[id1];
	//theLink.href = '/_includes/lot_images_colorbox.php?id='+id1+'&forcerefresh='+Math.floor(Math.random()*10);
	
	theMainDiv.style.width = lot_images_thumb_width[id1] + 2 +'px';
	theThumbDiv.style.width = lot_images_thumb_width[id1] + 2 +'px';
	
	for (i=0;i<lot_images.length;i++){
		document.getElementById("divLotThumb_"+i).className = "container";
	}
	theContainer.className = "container on";
	
	currentLotImage = id1;
	
}

var zoom_on = false;
var zoom_timeout = false;

function startZoomer(){
	
	var theDiv = document.getElementById("divLotZoomer");
	var theLink = document.getElementById("aLotZoomer");
	var theImg = document.getElementById("imgLotZoomer");
	var theCancelLink = document.getElementById("aCancelZoom");
	
	theImg.src = '/_assets/auctions/'+img_auction_id+'/images/thumbs/'+lot_images[currentLotImage];
	theLink.href = '/_assets/auctions/'+img_auction_id+'/images/'+lot_images[currentLotImage];
	theDiv.style.display = 'block';
	
	if (!ie6){
		$('a#aLotZoomer').jqzoom(options); 
	}
	
	zoom_on = true;
	
	theCancelLink.style.display = "block";
	
	//t = setTimeout("zoom_timeout = true",2000);
	
}

function clearZoomer(){
	if (zoom_on){
		var theDiv = document.getElementById("divLotZoomer");
		var theCancelLink = document.getElementById("aCancelZoom");
		theCancelLink.style.display = "none";
		//var theDiv = document.getElementById("divLotMainImg");
		theDiv.innerHTML = '<a href="" id="aLotZoomer"><img id="imgLotZoomer" src="" alt="Zoomer" /></a>';
		theDiv.style.display = 'none';
		//theDiv.innerHTML += '<a href="" class="zoom_cancel"></a>';
	}
}
