var photoData = new Array();
var shownPhoto = new Array();
var photoBlock = new Array();
var photoArray = new Array();
var realmCurrency = null;
var isAdminString = document.location.search.indexOf("do=1") > -1;


// Magnify a thumbnail image in its block's medium-sized header.
function magnify(id)
{
	var block = photoBlock[id];
	if (block == null)
		return;

	var img = document.getElementById('photoBlock' + block);
	var caption = document.getElementById('caption' + block);	

	var data = photoData[id];
	if (img != null)
	{	
		if(document.all && img.filters) {
		    img.filters.blendTrans.apply();
		}
				
		img.src = data[1];
		img.width = data[3];
		img.height = data[4];
		
		if(document.all && img.filters) {
		    img.filters.blendTrans.play();
		}		
	}
	
	if (caption != null && data[0] != null)
	{
		caption.innerHTML = data[0];
	}
	
	var t1 = document.getElementById("thumb" + shownPhoto[block]);
	if(t1 != null)
	    t1.className = "smallPhoto";
	
	var t2 = document.getElementById("thumb" + id);
	if(t2 != null)
	    t2.className = "smallPhotoSelected"; 


	shownPhoto[block] = id;
}

// Show the full-sized version of an image in a popup window.
function showFull(block)
{
	var data = photoData[shownPhoto[block]];
	var w = window.open("", "showFull",
			"width=720" +
			",height=650" +
			",resizable,scrollbars", true);
	w.document.open();
	w.document.write('<html><head><title>');
	if (eqDesc != null)
		w.document.write(eqDesc);
	w.document.write(" "+JS_photoGalle_PhotoEq_6850);	
	w.document.write('</title><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"></head><body bgcolor=#3F3F3F>');
	w.document.write('<table border=0 cellpadding=1 cellspacing=0 width=95% align=center><tr valign=top><td bgcolor=#333333><table border=0 cellpadding=5 cellspacing=10 width=100% bgcolor=ffffff><tr><td><table border=0 cellpadding=0 cellspacing=0 width=100% bgcolor=FFFFFF><tr valign=top><td>');
	
	w.document.write('<table border=0 cellpadding=3 cellspacing=0><tr bgcolor=e7effa><td valign=top bgcolor=#DFDFDF>');
	if(data[6] > 480) {
		w.document.write('<img id=fullPhoto src="' + data[2] + '" height=480 lowsrc="' + data[1] + '" style="filter:blendTrans(duration=1)" />');	
	} else {
		w.document.write('<img id=fullPhoto src="' + data[2] + '" width="' + data[5] +
						'" height="' + data[6] + '" lowsrc="' + data[1] + '" style="filter:blendTrans(duration=1)" />');	
	}					
	w.document.write('</td></tr></table>');
		
	var fullPhotoIndex = -1;
	var total = photoArray.length;
	for(i=0; i<total; i++) {
		if(photoArray[i] == shownPhoto[block]) {
		   fullPhotoIndex = i;
		}
	}			
			
	w.document.write('<table cellpadding=0 cellspacing=0 width=100%><tr valign=top><td><table border=0 cellpadding=1 cellspacing=1 width=100% bgcolor=#ffffff><tr><td><table border=0 cellpadding=5 cellspacing=4 width=100%><tr><td valign=top width=27% align=right>');	
	w.document.write('<input type=image title="'+JS_photoGalle_PhotoEq_6851+'" id=prev src=/images/button_prev.gif border=0 onClick="prev();">');
	w.document.write('&nbsp;&nbsp;&nbsp;');
	w.document.write('<input type=image title="' + JS_photoGalle_PhotoEq_6853 + '" id="play" src="/images/button_play.gif" border=0 onClick="play();">');
	w.document.write('&nbsp;&nbsp;&nbsp;');
	w.document.write('<input type=image title="' + JS_photoGalle_PhotoEq_6852 + '" id=next src=/images/button_next.gif border=0 onClick="next();">');	
	w.document.write('<span id="slideTimer">&nbsp;</span>');
	w.document.write('</td><td valign=top width=72%><table border=0 cellpadding=0 cellspacing=0 width=100% style="font-family: Tahoma, Verdana, Arial, Helvetica; font-size: 11px;">');
	
	if (data[0] != null && data[7] != null) {
		w.document.write('<tr><td valign=top><span id=fullPhotoText1>');
		w.document.write((fullPhotoIndex+1) +" ");
		w.document.write(JS_photoGalle_PhotoEq_6855);
		w.document.write(" "+total+" | ");
  		w.document.write('<b>'+data[7]+'</b>' + data[0]);
		w.document.write('</span></td></tr>');	
	}
  	
  	if (data[8] != null) {  		
	  	w.document.write('<tr><td><table style="font-family: Tahoma, Verdana, Arial, Helvetica; font-size: 11px;" valign=top cellpadding=0 cellspacing=0><tr><td width=49></td><td><span id=fullPhotoText2>');	  	
  		w.document.write('<i>'+data[8]+'</i>');
		w.document.write('</span></td></tr></table></td></tr>');			
  	} 	
  	
	w.document.write('<script language="Javascript"> var playCounter=0; var timer; var timerSecs = 3; var running=false; var t = window.opener.photoArray.length; var photoIndex ='+fullPhotoIndex+';');
	w.document.write('disablePrev(); disableNext();');		
	w.document.write('function next() { ');		
	w.document.write(' if(running) { running = false; disableTimerCount(); } ');		
	w.document.write(' ++photoIndex; ');		
	w.document.write('if( (photoIndex) == 1) { enablePrev(); }');
	w.document.write('if( (photoIndex+1) == t) { disableNext(); running = false;  }');
	w.document.write('display(photoIndex);');				
	w.document.write('}');				
	w.document.write('function prev() { ');
	w.document.write(' if(running) { running = false; disableTimerCount(); } ');			
	w.document.write('enableNext();');
	w.document.write('--photoIndex;');
	w.document.write('disablePrev();');
	w.document.write('display(photoIndex);');
	w.document.write('}');				
	
	w.document.write('function display(j) { ');
	w.document.write('if (window.opener != null && !window.opener.closed) { } else { window.close(); }');
	w.document.write('var d = window.opener.photoData[window.opener.photoArray[j]];');						
	w.document.write('if (d == null) {return;} ');
	w.document.write('var img = document.getElementById(\'fullPhoto\');');
	w.document.write('if (img != null) { if(document.all && img.filters) { img.filters.blendTrans.apply(); }');
	w.document.write('img.src = d[2];');
	w.document.write(' if(d[6] > 480) { img.height = 480; } else { img.width = d[5]; img.height = d[6]; }  '); 
	w.document.write('if(document.all && img.filters) { img.filters.blendTrans.play(); } ');	
	w.document.write('}');		
    w.document.write('var text1 = document.getElementById(\'fullPhotoText1\');');
    w.document.write('if (text1 != null && d[7] != null && d[0] != null) { text1.innerHTML = (j+1)+\' '  + JS_photoGalle_PhotoEq_6855+  ' \' +t+" | "+"<b>"+d[7]+"</b>"+d[0]; }');
    w.document.write('var text2 = document.getElementById(\'fullPhotoText2\');');
    w.document.write('if (text2 != null && d[8] != null) { text2.innerHTML = "<i>"+d[8]+"</i>"; }');	
	w.document.write('}');				
	
	w.document.write('function play() { var text3 = document.getElementById(\'slideTimer\'); if((photoIndex+1) == t) {enableNext(); photoIndex=-1;  } if(photoIndex == 0) {enablePrev(); } ');
	w.document.write('if(playCounter++%2==0) { document.getElementById("play").src="/images/button_pause.gif"; document.getElementById("play").title="'+ JS_photoGalle_PhotoEq_6854 +'"; running=true; ');			
   	w.document.write('\nif (text3 != null) { text3.innerHTML = "<table cellpadding=0 cellspacing=0 align=center style=\'font-family: Tahoma, Verdana, Arial, Helvetica; font-size: 11px; \'><tr><td width=9></td><td><img src=/images/button_incr_minus.gif onClick=decrTimer();></td><td width=63 align=center><span id=timerCountText>"+timerSecs+"</span> ');
	w.document.write(JS_ir_seconds_8701);
	w.document.write('</td><td align=left><img src=/images/button_incr_plus.gif onClick=incrTimer();></td><tr></table>"; }');		
	w.document.write('slideShow();');		
	w.document.write('} else { ');			
	w.document.write('if (text3 != null) { text3.innerHTML = "" }');
	w.document.write('clearTimeout(timer);');	
	w.document.write('document.getElementById("play").src="/images/button_play.gif"; document.getElementById("play").title="'+ JS_photoGalle_PhotoEq_6853 +'"; running=false;');		
	w.document.write('} }');		
	
	w.document.write('function slideShow() { ');		
	w.document.write('if(running) { ');		
	w.document.write('nextSlide();');		
	w.document.write('timer = setTimeout("slideShow()", timerSecs * 1000);');					
	w.document.write('} else { playCounter++; ');
	w.document.write('clearTimeout(timer);');	
	w.document.write('document.getElementById("play").src="/images/button_play.gif"; document.getElementById("play").title="'+ JS_photoGalle_PhotoEq_6853 +'"; running=false; disableTimerCount();');			
	w.document.write('}');
	w.document.write('}');
	
	w.document.write('function nextSlide() { ');		
	w.document.write(' ++photoIndex; ');		
	w.document.write('if( (photoIndex) == 1) { enablePrev(); }');
	w.document.write('if( (photoIndex+1) == t) { disableNext(); running = false; }');
	w.document.write('display(photoIndex);');				
	w.document.write('}');	


	w.document.write('function enableNext() { ');
	w.document.write('if( (photoIndex+1) == t) { document.getElementById("next").src = "/images/button_next.gif"; document.getElementById("next").disabled = false; }');
	w.document.write('}');

	w.document.write('function disableNext() { ');
	w.document.write('if( (photoIndex+1) == t ) { document.getElementById("next").src = "/images/button_next_disabled.gif"; document.getElementById("next").disabled = true; }');	
	w.document.write('}');

	w.document.write('function enablePrev() { ');
	w.document.write('if( (photoIndex) == 1) { document.getElementById("prev").src = "/images/button_prev.gif"; document.getElementById("prev").disabled = false; }');
	w.document.write('}');

	w.document.write('function disablePrev() { ');
	w.document.write('if( (photoIndex) == 0 ) { document.getElementById("prev").src = "/images/button_prev_disabled.gif"; document.getElementById("prev").disabled = true; }');	
	w.document.write('}');
	
	w.document.write('function decrTimer() { ');
	w.document.write('if(timerSecs > 1) { timerSecs--;');
	w.document.write('var timerText = document.getElementById(\'timerCountText\');');
   	w.document.write('if (timerText != null) { timerText.innerHTML = timerSecs; }');	
	w.document.write('clearTimeout(timer);');   	
	w.document.write('timer = setTimeout("slideShow()", timerSecs * 1000);');					
	w.document.write('} }');		
	
	w.document.write('function incrTimer() { ');
	w.document.write('if(timerSecs < 20) { timerSecs++;');
	w.document.write('var timerText = document.getElementById(\'timerCountText\');');	
   	w.document.write('if (timerText != null) { timerText.innerHTML = timerSecs; }')	
	w.document.write('clearTimeout(timer);');   	
	w.document.write('timer = setTimeout("slideShow()", timerSecs * 1000);');					
	w.document.write('} }');	
	
	w.document.write('function disableTimerCount() { ');
	w.document.write('var text4 = document.getElementById(\'slideTimer\'); if (text4 != null) { text4.innerHTML = ""; }');		
	w.document.write('}');

	w.document.write('</script>');	  	  	  		
	w.document.write('</table></td></tr></table></td></tr></table>');	
	w.document.write('</td></tr></table></td></tr></table></td></tr></table></td></tr><tr><td><table style="font-family: Tahoma, Verdana, Arial, Helvetica; border: #cccc99 solid 1px; background: #FFFFCC; font-size: 11px;"><tr><td>'+ JS_photoGalle_PhotoEq_6856 +'</td></tr></table></td></tr></table>');	
	w.document.write('</body></html>');
	w.document.close();
	
	if (w != null)
		w.focus();			
}

// Highlight an inspection line item and (possibly) its associated photo.
function highlightLineItem(id)
{
	var lineItemRow = document.getElementById("lineItem" + id);
	if (lineItemRow != null) {
		lineItemRow.oldClass = lineItemRow.className;
		lineItemRow.className = "tableDataHighlighted";
	}

	var thumb = document.getElementById("thumb" + id);
	if (thumb != null) {
		var block = photoBlock[id];
		if (shownPhoto[block] != id)
			thumb.className = "smallPhotoHighlighted";
	}
}

// Unhighlight an inspection line item and (possibly) its associated photo.
function unhighlightLineItem(id)
{
	var lineItemRow = document.getElementById("lineItem" + id);
	if (lineItemRow != null) {
		lineItemRow.className = lineItemRow.oldClass;
	}

	var thumb = document.getElementById("thumb" + id);
	if (thumb != null) {
		var block = photoBlock[id];
		if (shownPhoto[block] == id)
			thumb.className = "smallPhotoSelected";
		else
			thumb.className = "smallPhoto";
	}
}

function showUser(userid) {
	var ww = window.open('/jsp/cca/detailuser.jsp?userId='+userid,'du','width=450,height=425,resizable,scrollbars,dependent');
	if (ww != null)
		ww.focus();
}

function administer(equipId) {
	var ww = window.open('/jsp/acct/administer.jsp?equipId='+equipId,'admin'+equipId,'width=750,height=590,resizable,scrollbars,dependent');
	if (ww != null)
		ww.focus();
}

function emailFriend(equipId,serialNo) {
	var ww = window.open('/jsp/mail/emailFriend.jsp?equipId='+equipId+'&serialNo='+serialNo,'emailFriend'+equipId,'width=500,height=500,resizable,scrollbars,dependent');
	if (ww != null)
		ww.focus();
}

function printWindow(equipId) {
	var ww=window.open('/jsp/equip/printBrochure.jsp?equipId='+equipId,
					'printWindow'+equipId,
					'width=680,height=500,directories=yes,location=no,'+
						'menubar=yes,scrollbars=yes,status=yes,toolbar=yes,'+
						'resizable=yes');
    if (ww!=null)
		ww.focus();
}

function showCarfax(equipId) {
	var ww=window.open('/jsp/equip/showCarfax.jsp?equipId='+equipId,
					'carfax'+equipId,
					'width=780,height=580,directories=yes,location=no,'+
						'menubar=yes,scrollbars=yes,status=yes,toolbar=yes,'+
						'resizable=yes');
    if (ww!=null)
		ww.focus();
}

function editTitle(eqId, flag, titleStr){
	if(titleStr.length > 0)
		titleStr = titleStr.replace(/#/g,"%23");

	var w2 = window.open('/jsp/include/editTitle.jsp?from=equip&eqId='+eqId+'&titleFlag='+flag+'&titleFlag2='+flag+'&title='+titleStr, 'EditTitle', 'width=500,height=320,resizable,scrollbars');
	if (w2!=null)
		w2.focus();
}

function editCanExport(eqId, sellerId) {
	var w2 = window.open('/jsp/include/editCanExport.jsp?equipId='+eqId+'&sellerId='+sellerId, 'EditCanExportFlag', 'width=500,height=320,resizable,scrollbars');
	if (w2!=null)
		w2.focus();
}

function editARBDisclosureFlag(eqId) {
	var w2 = window.open('/jsp/include/editARBDisclosure.jsp?equipId='+eqId, 'EditCaARBFlag', 'width=500,height=320,resizable,scrollbars');
	if (w2!=null)
		w2.focus();
}

function showPriorAucHistory(eq, sId) {
	var ww=window.open('/jsp/equip/priorAucHistory.jsp?equipId=' + eq + '&sellerId=' + sId,'ah','width=540,height=390,resizable,scrollbars,dependent');
	if (ww!=null)
		ww.focus();
}

function loaded() {
	if (self.init_page)
		init_page();
	initShippingEstimate();
}

function requireRegistration(equipId, h) {

	if (!getCookie("login") && !getCookie("loggedin") && !isTrialValid(equipId) && !isLandingPage() && (!document.URL || document.URL.search(/\/011907/i) < 0)) {
		window.parent.location.replace("/jsp/acct/reg_login.jsp?page=equip&id="+equipId+"&h="+h);
	}
}

function isLandingPage() {

	if (!document.referrer) return true;

	if (document.referrer.search(/http:\/\/.*\.(ironplanet|ironplanetmotors)\./i) == 0) return false;

	return true;
}

function tipsWindow(url, name, w, h) {
	ww=window.open(url, name, 'width='+w+',height='+h);
    if (ww!=null) ww.focus();
}

function timeRemaining (milliseconds, extflag) {
   var seconds = Math.floor(milliseconds / 1000);
   var rem_sec1 = Math.floor(seconds % 86400);
   var rem_sec2 = Math.floor(rem_sec1 % 3600);
   var days =  Math.floor(seconds / 86400);
   var hours = Math.floor(rem_sec1 / 3600);

   var min = Math.floor(rem_sec2 / 60);
   var sec = Math.floor(rem_sec2 % 60);

   if (days > -1) {
        if (days == 1 && hours == 0) {
           days = 0;
           hours = 24;
           }

        else if (days == 0 && hours == 1 && min == 0) {
           hours = 0;
           min = 60;
           }

        else if (days == 0 && hours == 0 && min == 1 && sec == 0) {
           min = 0;
           sec = 60;
           }

        dayString  = days  + (days == 1 ? " "+JS_ir_day_8705 : " "+JS_ir_days_8706);
        hourString = hours + (hours== 1 ? " "+JS_ir_hour_8696: " "+JS_ir_hours_8697);
        minuteString = min + ( min == 1 ? " "+JS_ir_minute_8698 : " "+JS_ir_minutes_8699);

        if (days == 0) {
            if (hours == 0) {
                if (min == 0) return JS_item_Lesstha_6464;
                return minuteString + (extflag == 1 ? " "+JS_bidHistory_extende_8883 : "");
                }
            else
                return hourString + (min > 0 ? ", "+minuteString : "");
            }
        else
            {
            //return dayString;
            if (min > 0) {
               hours = hours + 1;
               hourString = hours + (hours== 1 ? " hour": " hours");
            }
            
            return dayString + (hours > 0 ? ", "+hourString : "");
        }
    }
   return (JS_item_Notimel_8718);
}

function showControlPanel2(wname,fname, eqId) {
	
	if (fname.indexOf('?') > -1)
		fname += '&equipId='+eqId;
	else
		fname += '?equipId='+eqId;
	

	wname = wname.replace(/ /g, '');	
	
	ww = window.open(fname, wname, 'width=700,height=680,resizable,scrollbars,status');
			
	if (ww!=null) {
		ww.focus();
		ww.location.href = fname;
	}
}

function currConvert(eqId, curr) {
	var w = window.open('/jsp/equip/currConverter.jsp?calculate=yes&equipId='+eqId+'&fromCurrency='+curr,'convert',
		'width=425,height=80,scrollbars,resizable');
	if (w != null) 
		w.focus();

}

function getConvRate(fromCurrency, toCurrency)
{
	var d = 0.0;
	var usdEQ = 1;
	
	if ("USD" != fromCurrency) {
		if ("AUD" == fromCurrency)
			usdEQ = 1 / currRates["AUD"];
		else if ("EUR" == fromCurrency)
			usdEQ = 1 / currRates["EUR"];
		else if ("GBP" == fromCurrency)
			usdEQ = 1 / currRates["GBP"];
		else if ("CAD" == fromCurrency)
			usdEQ = 1 / currRates["CAD"];
		else if ("MXN" == fromCurrency)
			usdEQ = 1 / currRates["MXN"];
		else if ("AED" == fromCurrency)
			usdEQ = 1 / currRates["AED"];
		else if ("SAR" == fromCurrency)
			usdEQ = 1 / currRates["SAR"];
	}
	
	if ("USD" != toCurrency) {
		if ("AUD" == toCurrency)
			d = usdEQ * currRates["AUD"];
		else if ("EUR" == toCurrency)
			d = usdEQ * currRates["EUR"];
		else if ("GBP" == toCurrency)
			d = usdEQ * currRates["GBP"];
		else if ("CAD" == toCurrency)
			d = usdEQ * currRates["CAD"];
		else if ("MXN" == toCurrency)
			d = usdEQ * currRates["MXN"];
		else if ("AED" == toCurrency)
			d = usdEQ * currRates["AED"];
		else if ("SAR" == toCurrency)
			d = usdEQ * currRates["SAR"];
	}
	else {
		d = usdEQ;
	}
	
	return d;
}

function convDollarStr(value, ic, pc, rc)
{
	var convRate = getConvRate(ic, pc);
	var newValue = Math.floor(value * convRate);
	return dollarString(newValue, getPrefCurrency(rc));
}

function getPrefCurrency(rc) {
	pc = getCookie("curr");
	if (pc == null) {
		return rc;
	}
	
	if (pc.indexOf("US") != -1) {
		return "USD";
	}
	else if (pc.indexOf("GB") != -1) {
		return "GBP";
	}
	else if (pc.indexOf("AU") != -1) {
		return "AUD";
	}
	else if (pc.indexOf("CA") != -1) {
		return "CAD";
	}
	else if (pc.indexOf("MX") != -1) {
		return "MXN";
	}
	else if (pc.indexOf("AE") != -1) {
		return "AED";
	}
	else if (pc.indexOf("SA") != -1) {
		return "SAR";
	}
	else if (pc.indexOf("IE") != -1) {
		return "EURO-IE";
	}
	else if (pc.indexOf("NL") != -1) {
		return "EURO-NL";
	}
	else if (pc.indexOf("DE") != -1) {
		return "EURO-DE";
	}
	else if (pc.indexOf("FR") != -1) {
		return "EURO-FR";
	}
}

function getCurrInfoForRealm()
{
	var cvc = getCookie("curr");
	if (cvc == null) {	
		cvc = realmCurrency;
		if (cvc.match(/^EURO/))
			return 'EUR';
		else 
			return cvc;
	}
	
	var pc = '';
	if (cvc.indexOf("EUR") != -1) 
		pc = 'EUR';
	else if (cvc.indexOf("GB") != -1)
		pc = 'GBP';
	else if (cvc.indexOf("AU") != -1)
		pc = 'AUD';
	else if (cvc.indexOf("CA") != -1)
		pc = 'CAD';
	else if (cvc.indexOf("MX") != -1)
		pc = 'MXN';
	else if (cvc.indexOf("AE") != -1)
		pc = 'AED';
	else if (cvc.indexOf("SA") != -1)
		pc = 'SAR';
	else
		pc = "USD";
	
	return pc;
}

function dollarString(value, currency)
{
   var price = formatNum(value);

   var currencyCode = '';
   var currencySign = '$';
   var rs = currencySign + price;

   if (currency.toString() == "USD".toString()) {
   	  currencyCode = 'US ';
      currencySign = '$';
   }
   else if (currency.toString() == "AUD".toString()) {
   	  currencyCode = 'AU ';
      currencySign = '$';
   }
   else if (currency.toString() == "CAD".toString()) {
   	  currencyCode = 'C';
      currencySign = '$';
   }
   else if (currency.toString() == "MXN".toString()) {
   	  currencyCode = 'MX ';
      currencySign = '$';
   }
   else if (currency.toString() == "AED".toString()) {
      currencyCode = 'AED ';
      currencySign = '';
   }
   else if (currency.toString() == "SAR".toString()) {
	currencyCode = 'SAR ';	      
	currencySign = '';
   }
   else if (currency.toString() == "GBP".toString()) {
      currencySign = '&pound;';
   }
   else if (currency.toString().indexOf('EURO') > -1) {
      currencySign = '&euro;';
   }

   if (JS_ir_formatLocale.indexOf('es_ES') > -1 
   		|| JS_ir_formatLocale.indexOf('de_') > -1 
   		|| JS_ir_formatLocale.indexOf('fr_') > -1
   		|| JS_ir_formatLocale.indexOf('pl_') > -1
   		|| JS_ir_formatLocale.indexOf('ru_') > -1) {
      rs = currencyCode + price + ' ' + currencySign;
   } else if(JS_ir_formatLocale.indexOf('it_') > -1) {
   	  rs = currencyCode + currencySign + ' ' + price;
   } else {
   	  rs = currencyCode + currencySign + price;
   }

	return rs;
}

function threeDigitize(s, c)
{
   var sep = ",";
   if (JS_ir_formatLocale.indexOf('fr_') > -1) {
      sep = " ";
   }
   else if (JS_ir_formatLocale.indexOf('de_') > -1 || JS_ir_formatLocale.indexOf('it_') > -1 || JS_ir_formatLocale.indexOf('es_ES') > -1) {
      sep = "."
   }

   switch (s.length % 4) {
	case 0:
		return s;
	case 1:
		return sep + "00" + s;
	case 2:
		return sep + "0" + s;
	case 3:
		return sep + s;
	}
}

function formatNum(s) {
	var sep = ",";
	if (JS_ir_formatLocale.indexOf('fr_') > -1) {
		sep = " ";
	} else if (JS_ir_formatLocale.indexOf('de_') > -1 || JS_ir_formatLocale.indexOf('it_') > -1 || JS_ir_formatLocale.indexOf('es_ES') > -1) {
		sep = "."
	}
	
	s += '';
	n = s.split('.');
	n1 = n[0];
	n2 = n.length > 1 ? '.' + n[1] : '';
 	
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(n1)) {
		n1 = n1.replace(rgx, '$1' + sep + '$2');
	}
	return n1 + n2;
}

function dispCurrConv(ic, amt, rc, eqId) {
	var hasConverted = 0;
	realmCurrency = rc;
	var pfc = getCurrInfoForRealm();
	var iamt = parseInt(amt, 10);
	
	if (p = document.getElementById("IP$"+eqId+"_price")) {
		iamt = parseInt(p.innerHTML.replace(/[^0-9]/g,''), 10);
	}
	
	if (p = document.getElementById("IP_ConvPriceBox")) {
		if (ic.match(/^EURO/))
			ic = "EUR";
		
		if (ic != pfc) {
			p.innerHTML = '<i>(*' + convDollarStr(iamt, ic, pfc, rc) + ')</i>';
			hasConverted = 1;
		}
	}
	
	if (hasConverted == 1) {
		document.getElementById("cfn").style.display='inline';
	}
}

function dispClassifiedsCurrConv(ic, amt, invId) {
	var hasConverted = 0;
	realmCurrency = ic;
	var pfc = getCurrInfoForRealm();
	var iamt = parseInt(amt, 10);
	
	if (p = document.getElementById("IPInv$"+invId+"_price")) {
		iamt = parseInt(p.innerHTML.replace(/[^0-9]/g,''), 10);
	}
	
	if (p = document.getElementById("IPInv$"+invId+"_currConv")) {
		if (ic.match(/^EURO/))
			ic = "EUR";
		
		if (ic != pfc) {
			p.innerHTML = '<i>(*' + convDollarStr(iamt, ic, pfc, realmCurrency) + ')</i>';
			hasConverted = 1;
		}
	}
	
	if (hasConverted == 1) {
		document.getElementById("cfnInv").style.display='inline';
	}
}

function getOriginalPhotos(equipId) {
  var ww = window.open('/jsp/insp/getOriginalPhotos.jsp?equipId='+equipId,'Photos'+equipId,'width=750,height=800,resizable,scrollbars');
  if (ww != null) {
    ww.focus();
  }
  return false;
}

function base64Decode(input) {
	var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
	var output = '';
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;

	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	while (i < input.length) {
		enc1 = keyStr.indexOf(input.charAt(i++));
		enc2 = keyStr.indexOf(input.charAt(i++));
		enc3 = keyStr.indexOf(input.charAt(i++));
		enc4 = 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);
		}
	}
	return output;

}

function showTab(sectionNum) {
	document.getElementById('section'+sectionNum+'Tab').className = 'activetab';
	document.getElementById('section'+sectionNum).style.display = 'block';
	for(var i = 1; i <= 4; i++) {
		if(i != sectionNum) {
			var sTab = document.getElementById('section'+i+'Tab'); 
			if(sTab != null) {
				sTab.className = 'tab';
			}
			var section = document.getElementById('section'+i);
			if(section != null) {
				section.style.display = 'none';
			}
		}
	}
	return false;
}

function handleDestinationSelect(postalCode,countryCode,city,province,countryName,lat,lng) {
	var args = 'eqId=' + equipId 
		+ '&model=' + modelNm 
		+ '&make=' + makeNm 
		+ '&oriPc=' + oriPc 
		+ '&oriCntry=' + oriCntry 
		+ '&defpc='+encodeURIComponent(unescape(postalCode)) 
		+ '&defCity='+encodeURIComponent(unescape(city)) 
		+ '&defProv='+encodeURIComponent(unescape(province)) 
		+ '&defcc='+encodeURIComponent(unescape(countryCode)) 
		+ '&defLat='+encodeURIComponent(unescape(lat)) 
		+ '&defLong='+encodeURIComponent(unescape(lng))
		+ '&defUnit='+encodeURIComponent(unescape(getCookie('defUnit')));
		
	postAjax('/jsp/equip/getShippingCostEstimate.jsp', args);
	
	document.getElementById('shippingEstimateLoading').style.visibility = 'visible';

	hidePostalCodeEdit();
	
	return false;
}

function calculateShippingWithDefaultLocation() {

	var args = 'eqId=' + equipId 
		+ '&model=' + modelNm 
		+ '&make=' + makeNm 
		+ '&oriPc=' + oriPc 
		+ '&oriCntry=' + oriCntry;

	postAjax('/jsp/equip/getShippingCostEstimate.jsp', args);
	
	document.getElementById('shippingEstimateLoading').style.visibility = 'visible';

	return false;

}

function newShippingEstimate(costEstimate, mileage) {

	showDestination();

	document.getElementById('shippingEstimateValue').innerHTML = costEstimate;
	document.getElementById('shippingEstimateMileageValue').innerHTML = mileage;
	updateDisclaimer('*<a href="#" onclick="return showDisclaimer();">'+JS_shippingEst_importantDisclaimer_7505+'</a>');
	document.getElementById('shippingEstimate').style.display = 'block';
	document.getElementById('shippingEstimateLoading').style.visibility = 'hidden';
	document.getElementById('costEstimate').style.visibility = 'visible';
	var errorDiv = document.getElementById('shippingEstimateError'); 
	errorDiv.style.display = 'none';
	errorDiv.innerHTML = '';
}

function updateDisclaimer(msg) {
	document.getElementById('shippingEstimateDisclaimer').innerHTML = msg;
}

function initShippingEstimate() {
	var estimateErrorElt = document.getElementById('shippingEstimateError');
	if(estimateErrorElt != null) {
		showDestination();
		if(getCookie('defcc') != null && (getCookie('defpc') != null || getCookie('defCity') != null)) {
			estimateErrorElt.innerHTML = JS_shippingEst_getAShipping_7506 + '<div style="margin: 7px 0px 0px 50px;"><a href="#" onclick="return calculateShippingWithDefaultLocation();" class="buttonClass"><span>'+JS_shippingEst_calculate_7507+'</span></a></div>';
		} else {
			estimateErrorElt.innerHTML = JS_shippingEst_enterADest_7508;
		}
	}
	
}

function showDestination() {

	if(document.getElementById('destinationCityPC') != null) {
		var city = getCookie('defCity'); 
		var prov = getCookie('defProv');
		var pc = getCookie('defpc'); 
		var countryName = getCookie('defcc');
		if(prov != null && (pc != null || city != null) && countryName != null) {
			document.getElementById('destinationCityPC').innerHTML = getLocationTextFromCookies(false);
			document.getElementById('destinationCountry').innerHTML = decodeURIComponent(escape(countryName)).replace(/\+/g, ' ');
			document.getElementById('changeDestination').style.display = 'block';
		} else {
			document.getElementById('destinationCityPC').innerHTML = '<a href="#" onclick="showDestinationEdit(event,\''+JS_EnterPostal_1005+'\'); return false;">'+JS_shippingEst_enterDestination_7509+'</a>';
			document.getElementById('changeDestination').style.display = 'none';
		}
		document.getElementById('destinationEdit').style.display = 'none';
		document.getElementById('destinationView').style.display = 'block';
	
		document.getElementById('shippingDestination').style.display = 'block';

	}
}

function showEstimateError(msg) {

	showDestination();
	document.getElementById('costEstimate').style.visibility = 'hidden';
	document.getElementById('shippingEstimateLoading').style.visibility = 'hidden';
	var errorDiv = document.getElementById('shippingEstimateError'); 
	errorDiv.innerHTML = msg;
	errorDiv.style.display = 'block';
}

function showDisclaimer() {
  oDiv = document.getElementById('popunder');
  oDiv.style.display='block';
  return false;
}

function hideDisclaimer() {
  oDiv = document.getElementById('popunder');
  oDiv.style.display='none';
  return false;
}
function hideKBBDisclaimer() {
  oDiv = document.getElementById('popunder');
  oDiv.style.display='none';
  return false;
}

function showKBBDisclaimer() {
  oDiv = document.getElementById('popunder');
  oDiv.style.display='block';
  return false;
}

