function StartCountDown(countDownControlId, secondsRemaining, finishedMessage) {
	var countDownControl = document.getElementById(countDownControlId);

	var tmpCalc, days, hours, minutes, seconds;

	if (!secondsRemaining) {
		if (document.all) {
			secondsRemaining = countDownControl.innerText;
		}
		else {
			secondsRemaining = countDownControl.textContent;
		}
	}
	secondsRemaining--;
	tmpCalc = secondsRemaining;

	days = Math.floor(tmpCalc / 86400);
	tmpCalc -= days * 86400;

	hours = Math.floor(tmpCalc / 3600);
	tmpCalc -= hours * 3600;

	minutes = Math.floor(tmpCalc / 60);
	tmpCalc -= minutes * 60;

	seconds = tmpCalc;

	var message = '';

	if (secondsRemaining > 0) {
		if (days > 0) { message = message + days + 'd '; }
		if (hours > 0) { message = message + hours + 't '; }
		if (minutes > 0) { message = message + minutes + 'm '; }
		message = message + seconds + 's';
	}
	else {
		document.location.replace(String(document.location));
	}

	if (countDownControl != null) {
		document.getElementById(countDownControlId).innerHTML = message;
	}

	if (secondsRemaining > 0) {
		setTimeout("StartCountDown('" + countDownControlId + "'," + secondsRemaining + ",'" + finishedMessage + "')", 1000);
	}
}


function getBrowserDimensions() {
	var browserWidth = 0;
	var browserHeight = 0;
	if (window.innerWidth) { //if browser supports window.innerWidth
		browserWidth = window.innerWidth;
		browserHeight = window.innerHeight;
	}
	else if (document.all) { //else if browser supports document.all (IE 4+)
		browserWidth = document.body.clientWidth;
		browserHeight = document.body.clientHeight;
	}
	return [browserWidth, browserHeight];
}

function getDocumentScrollOffsetCoordinates() {
	var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body

	var dsocleft = document.all ? iebody.scrollLeft : pageXOffset
	var dsoctop = document.all ? iebody.scrollTop : pageYOffset
	return [dsocleft, dsoctop];
}

function showImage(source, offsetX, offsetY, imageDivName, imageDivImgName, imageUrl) {
	var imageDiv = document.getElementById(imageDivName);
	var coors = findPos(source);

	var coordsBrowser = getBrowserDimensions();
	var coordsDsoc = getDocumentScrollOffsetCoordinates();

	var midBrowserWidth = coordsBrowser[0] / 2;
	var midBrowserHeight = coordsBrowser[1] / 2;
	var sourceVisibleLeft = coors[0] - coordsDsoc[0];
	var sourceVisibleTop = coors[1] - coordsDsoc[1];

	//imageDiv.style.left = (sourceVisibleLeft <= midBrowserWidth ? (coors[0] - offsetX) : (coors[0] + offsetX)) + 'px';
	imageDiv.style.left = (sourceVisibleLeft <= midBrowserWidth ? (coors[0] + offsetX) : (coors[0] + offsetX)) + 'px';
	imageDiv.style.top = (sourceVisibleTop <= midBrowserHeight ? (coors[1] + offsetY) : (coors[1] - offsetY - 300)) + 'px';

	//    imageDiv.style.top = (coors[1] + offsetY) + 'px';
	//    imageDiv.style.left = (coors[0] + offsetX) + 'px';                

	var imageDivImg = document.getElementById(imageDivImgName);

	imageDivImg.src = imageUrl;
	imageDivImg.style.visibility = "visible";

	imageDiv.style.visibility = "visible";
}


function zImg(imageDivImgName, imageDivName, it) {
	var imageDiv = document.getElementById(imageDivName);
	var imageDivImg = document.getElementById(imageDivImgName);
	imageDivImg.src = "i.ashx?w=400&it=" + it;
	imageDivImg.style.visibility = "visible";
	imageDiv.style.visibility = "visible";
}

function setImageSrc(imageID, it) {
	var image = document.getElementById(imageID);
	image.src = "i.ashx?w=400&it=" + it;
}

function hideImage(source, imageDivName, imageDivImgName) {
	var imageDiv = document.getElementById(imageDivName);
	imageDiv.style.visibility = "hidden";

	var imageDivImg = document.getElementById(imageDivImgName);

	imageDivImg.src = "space.gif";
	imageDivImg.style.visibility = "hidden";
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft, curtop];
}

// getPageScroll() by quirksmode.org
// Finds the scroll position of a page
function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
	return [xScroll, yScroll]
}

// Finds the position of an element relative to the viewport.
function findPosRelativeToViewport(obj) {
	var objPos = this.findPos(obj)
	var scroll = this.getPageScroll()
	return [objPos[0] - scroll[0], objPos[1] - scroll[1]]
}


function WgrEvt(obj) {
	/*
	id   : WGR.DOCID
	h    : WGR.HASCHILDREN
	a    : WGR.APPLICATION
	t    : WGR.TARGET
	u    : WGR.URL
	i    : WGR.ITLIST
	ac   : WGR.TCLLIST
	s    : WGR.SEARCHSTRING
	f    : WGR.FILTER
	*/


	var id = obj.getAttribute("id");

	var application = obj.getAttribute("a");
	var url = "";
	var query = "";
	var target = obj.getAttribute("t");
	var navigateUrl = obj.getAttribute("u");
	var itList = obj.getAttribute("i");
	var tclList = obj.getAttribute("ac");
	var searchString = obj.getAttribute("s");
	var filter = obj.getAttribute("f");

	var sibling = obj.nextSibling;
	var hasSibling = false;
	var hasChildren = false;


	if (sibling && sibling.getAttribute("id") == "") hasSibling = true;
	if (sibling && sibling.getAttribute("id") == null) hasSibling = true;
	if (obj.getAttribute("h") == "1") hasChildren = true;

	if (hasSibling) {
		// Hide or show node.
		if (sibling.style.visibility == "hidden") {
			sibling.style.display = "block";
			sibling.style.visibility = "visible";
		}
		else {
			sibling.style.display = "none";
			sibling.style.visibility = "hidden";
		}
	}
	else if (!application && hasChildren) {
		// Do postback to get children nodes
		var postBackUrl = "WgrNode.ashx?n=" + id;
		var http = XmlHttp();

		try {
			http.open("GET", postBackUrl, true);
			http.setRequestHeader('content-type', 'text/plain');
		}
		catch (e) {
			alert("PostBack from node failed: " + id + "\n" + postBackUrl);
		}
		http.send(null);

		http.onreadystatechange = function () {
			if (http.readyState == 4) {
				if (http.status == 200) {
					// Alt OK i fra server
					var newDiv = document.createElement("div");
					newDiv.innerHTML = http.responseText;
					obj.parentNode.insertBefore(newDiv, obj.nextSibling);
				} else {
					// Fikk en feil i fra server, f.eks. statuskode 404 eller liknende
					alert("Fikk feilkode i fra server: " + http.status + ", " + http.statusText);
				}
			}
		}
	}

	if (application) {
		switch (application.toUpperCase()) {
			case "ARTDETAIL":
				url = "ArtDtl.aspx";
				break;
			case "ARTLIST":
				url = "ArtLst.aspx";
				break;
			case "ARTPROFILE":
				url = "ArtPrf.aspx";
				break;
			case "AUCDETAIL":
				url = "AucDtl.aspx";
				break;
			case "AUCLIST":
				url = "AucLst.aspx";
				break;
			case "SPOTS":
				url = "Spots.aspx";
				break;
		}
		query = "?";
		if (itList) {
			//query = ReplaceQuery("i",escape(itList),query,"replace");
		}
		if (id) {
			query = ReplaceQuery("n", id, query, "replace");
		}
		if (tclList) {
			query = ReplaceQuery("ac", tclList, query, "replace");
		}
		if (searchString) {
			query = ReplaceQuery("s", searchString, query, "replace");
		}
		if (filter) {
			query = ReplaceQuery("f", filter, query, "replace");
		}
		url += query;
		if (!navigateUrl) document.location.href = url;
	}

	if (navigateUrl) {
		var s = navigateUrl.split("?");
		if (s.length > 2) {
			navigateUrl = s[0] + "?" + s[1];
		}
		document.location.href = navigateUrl;
	}
}

function leseFraTxtFil() {
	http.open("get", "test.txt"); // Opner en kobling med filen test.txt med metoden "get"
	http.onreadystatechange = lagAlertBoks; // Når hele filen er lastet kjør funksjon
	http.send(null); // Sender ingen ting, etter som vi brukte metoden "get"
}

function lagAlertBoks() {
	if (http.readyState == 4) { // Hvis xmlHttpRequest-objektet er helt klart
		alert(http.responseText); // Lag en advarselsboks med test.txt som innhold
	}
}

function WgrTopEvt(obj) {
	/*
	id   : WGR.DOCID
	h    : WGR.HASCHILDREN
	a    : WGR.APPLICATION
	t    : WGR.TARGET
	u    : WGR.URL
	i    : WGR.ITLIST
	ac   : WGR.TCLLIST
	s    : WGR.SEARCHSTRING
	f    : WGR.FILTER
	*/

	var id = obj.getAttribute("id");

	var application = obj.getAttribute("a");
	var url = "";
	var query = "";
	var target = obj.getAttribute("t");
	var navigateUrl = obj.getAttribute("u");
	var itList = obj.getAttribute("i");
	var tclList = obj.getAttribute("ac");
	var searchString = obj.getAttribute("s");
	var filter = obj.getAttribute("f");
	var sibling = obj.nextSibling;
	var hasSibling = false;
	var hasChildren = false;

	if (application) {
		switch (application.toUpperCase()) {
			case "ARTDETAIL":
				url = "ArtDtl.aspx";
				break;
			case "ARTLIST":
				url = "ArtLst.aspx";
				break;
			case "ARTPROFILE":
				url = "ArtPrf.aspx";
				break;
			case "AUCDETAIL":
				url = "AucDtl.aspx";
				break;
			case "AUCLIST":
				url = "AucLst.aspx";
				break;
			case "SPOTS":
				url = "Spots.aspx";
				break;

		}
		query = "?";
		if (itList) {
			//query = ReplaceQuery("i",escape(itList),query,"replace");
		}
		if (id) {
			query = ReplaceQuery("n", id, query, "replace");
		}
		if (tclList) {
			query = ReplaceQuery("ac", tclList, query, "replace");
		}
		if (searchString) {
			query = ReplaceQuery("s", searchString, query, "replace");
		}
		if (filter) {
			query = ReplaceQuery("f", filter, query, "replace");
		}
		url += query;
		//alert("Application to navigate to: " + application + "\n\n" + url);
		if (!navigateUrl) document.location.href = url;
	}

	if (navigateUrl && navigateUrl != "") {
		if (target && target != "") {
			open(navigateUrl, target);
		}
		else {
			document.location.href = navigateUrl;
		}
	}
}

// mouseover mouseout
function hover(obj) {
	//obj.style.background = "#dcdcdc";
}
function hoverOut(obj) {
	/*
	if(obj.tagName == "DIV"){
	obj.style.background = "transparent";
	}
	else{
	obj.style.background = "transparent";
	obj.style.backgroundImage = "url('App_Themes/default/images/background_gray.gif')";
	}
	*/
}

function XmlHttp() {
	var xmlhttp = false;
	/*@cc_on@*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	@end@*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function ReplaceQuery(name, value, loc, mode) { // mode : replace(insert) or delete
	var queryString = String(loc);
	var n = (queryString.indexOf("?") + 1);
	if (queryString != "") {
		var data, aData, aOut
		var insert = false
		var outValue = "?";
		data = queryString.slice(n, queryString.length);
		aData = data.split("&");
		for (i = 0; i < aData.length; i++) {
			aOut = aData[i].split("=");
			if (aOut[0].toUpperCase() == name.toUpperCase()) {
				if (mode != "delete") {
					if (outValue != "?") outValue += "&";
					outValue += name + "=" + value;
				}
				insert = true;
			}
			else {
				if (outValue != "?") outValue += "&";
				outValue += aData[i];
			}
		}
		if (insert != true && mode != "delete") {
			if (outValue != "?") outValue += "&";
			outValue += name + "=" + value;
		}
		return outValue;
	}
	else {
		return null;
	}
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		// if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	}
	else {
		// otherwise, update 'characters left' counter
		countfield.value = maxlimit - field.value.length;
	}
}

function popitup(url) {
	newwindow = window.open(url, 'GECalculator', 'height=420,width=400');
	if (window.focus) {
		newwindow.focus()
	}
	return false;
}

function CalculateAndDisplayMinimumPayment(LoanAmount) {
	//document.writeln("");
	//return;
	var period = "";
	var CreditLimitPercentage = 0.03;
	var MimimumLoanAmountAllowed = 1999;
	var MaximumLoanAmountAllowed = 75000;
	var MimimumMonthlyPaymentAllowed = 199;


	var FinancedAmount = LoanAmount;
	var DownPaymentPeriod = 12;
	var MonthlyPaymentRef = new Array(0);
	var TotalFinancingCostRef = new Array(0);
	var EffectiveInterestRateRef = new Array(0);
	var TotalFinancingCostAfterTaxRef = new Array(0);



	if ((LoanAmount >= MimimumLoanAmountAllowed) && (LoanAmount <= MaximumLoanAmountAllowed)) {
		if (LoanAmount >= 1999 && LoanAmount <= 3200) period = 12;
		if (LoanAmount >= 3200 && LoanAmount <= 4300) period = 24;
		if (LoanAmount >= 4300 && LoanAmount <= 50000) period = 36;
		DownPaymentPeriod = period;
		if (period == "") return;

		GECalculator_GetMonthlyPayment(FinancedAmount, DownPaymentPeriod, MonthlyPaymentRef, TotalFinancingCostRef, EffectiveInterestRateRef, TotalFinancingCostAfterTaxRef);


		var MonthlyPayment = CreditLimitPercentage * LoanAmount;
		var CreditAmount = GECalculator_FormatToCurrency((period * MimimumMonthlyPaymentAllowed));

		if (MonthlyPayment < MimimumMonthlyPaymentAllowed) {
			document.writeln("<b style='text-decoration:none'>Kun " + MonthlyPaymentRef[0] + " pr mnd</b><br/>");
			document.writeln("<span style='text-decoration:none;color:silver'>Kredittkj&oslash;pspris " + TotalFinancingCostRef[0] + "&nbsp;</span><span style='text-decoration:underline;color:silver'>Effektiv rente</span>");
			return;
		}
		else {
			document.writeln("<b style='text-decoration:none'>Kun " + MonthlyPaymentRef[0] + " pr mnd</b><br/>");
			document.writeln("<span style='text-decoration:none;color:silver'>Kredittkj&oslash;pspris " + TotalFinancingCostRef[0] + "&nbsp;</span><span style='text-decoration:underline;color:silver'>Effektiv rente</span>");
			document.writeln("<br/>");
			return;
		}
	}
	document.writeln("");
	return;
}

function CalculateMinimumPayment(LoanAmount) {
	LoanAmount = Math.ceil(LoanAmount);
	var CreditLimitPercentage = 0.03;
	var MimimumLoanAmountAllowed = 1999;
	var MaximumLoanAmountAllowed = 75000;
	var MimimumMonthlyPaymentAllowed = 199;
	var result = "";

	var FinancedAmount = LoanAmount;
	var DownPaymentPeriod = 12;
	var MonthlyPaymentRef = new Array(0);
	var TotalFinancingCostRef = new Array(0);
	var EffectiveInterestRateRef = new Array(0);
	var TotalFinancingCostAfterTaxRef = new Array(0);

	if ((LoanAmount >= MimimumLoanAmountAllowed) && (LoanAmount <= MaximumLoanAmountAllowed)) {
		if (LoanAmount >= 1999 && LoanAmount <= 3200) period = 12;
		if (LoanAmount >= 3200 && LoanAmount <= 4300) period = 24;
		if (LoanAmount >= 4300 && LoanAmount <= 50000) period = 36;
		DownPaymentPeriod = period;


		GECalculator_GetMonthlyPayment(FinancedAmount, DownPaymentPeriod, MonthlyPaymentRef, TotalFinancingCostRef, EffectiveInterestRateRef, TotalFinancingCostAfterTaxRef);


		var MonthlyPayment = CreditLimitPercentage * LoanAmount;
		var CreditAmount = GECalculator_FormatToCurrency((period * MimimumMonthlyPaymentAllowed));

		if (MonthlyPayment < MimimumMonthlyPaymentAllowed) {
			result += "Kun " + MonthlyPaymentRef[0] + " pr mnd!";
			result += "Kredittkjøpspris " + TotalFinancingCostRef[0] + " Effektiv rente";
		}
		else {
			result += "Kun " + MonthlyPaymentRef[0] + " pr mnd!";
			result += "Kredittkjøpspris " + TotalFinancingCostRef[0] + "Effektiv rente";
		}
	}
	return result;
}




// BuyBid start

function OpenProductBidList(ev, obj) {
	try {
		var parentClassString = obj.parentNode.className;
		var objPopupId = parentClassString.split(",")[0].split(":")[1];
		var objPopupPositionStorage = parentClassString.split(",")[1].split(":")[1];
		var objLabelVerboseId = parentClassString.split(",")[2].split(":")[1];
		var objPanelBidId = parentClassString.split(",")[3].split(":")[1];
		var _lblProductListBidVerbose = document.getElementById(objLabelVerboseId);
		if ((typeof (_lblProductListBidVerbose) != "undefined") && (_lblProductListBidVerbose != null)) {
			_lblProductListBidVerbose.style.display = "block";
		}
		var _pnlBidList = document.getElementById(objPanelBidId);
		if ((typeof (_pnlBidList) != "undefined") && (_pnlBidList != null)) {
			_pnlBidList.style.display = "none";
		}
		var _pnlProductBidListPopup = document.getElementById(objPopupId);
		if ((typeof (_pnlProductBidListPopup) != "undefined") && (_pnlProductBidListPopup != null)) {
			var coords = findPos(obj);
			var offsetX = 320;
			var offsetY = 50;

			_pnlProductBidListPopup.style.display = 'block';
			_pnlProductBidListPopup.style.visibility = 'visible';
			_pnlProductBidListPopup.style.zIndex = 1;
			var posLeft = (coords[0] - offsetX - _pnlProductBidListPopup.offsetParent.offsetLeft);
			var posTop = (coords[1] + offsetY - _pnlProductBidListPopup.offsetParent.offsetTop);
			_pnlProductBidListPopup.style.left = posLeft + 'px';
			_pnlProductBidListPopup.style.top = posTop + 'px';

			var coordsBrowser = getBrowserDimensions();
			var coordsScroll = getDocumentScrollOffsetCoordinates();
			var totalBrowserHeightScroll = coordsBrowser[1] + coordsScroll[1];
			if ((posTop + 200) > totalBrowserHeightScroll) {
				window.scrollBy(0, (posTop + 200) - totalBrowserHeightScroll);
			}

			var _hdnProductBidListPopupPosition = document.getElementById(objPopupPositionStorage);
			if ((typeof (_hdnProductBidListPopupPosition) != "undefined") && (_hdnProductBidListPopupPosition != null)) {
				_hdnProductBidListPopupPosition.value = posLeft + "px," + posTop + "px,open";
			}

		}
		return true;
	} catch (e) {
		alert("error: at \"" + this.location.pathname + "\": name: \"" + e.name + "\": message: \"" + e.message + "\"");
	}
}

function CloseProductBidList(ev, obj) {
	var parentClassString = obj.parentNode.className;
	var objPopupId = parentClassString.split(",")[0].split(":")[1];
	var objPopupPositionStorage = parentClassString.split(",")[1].split(":")[1];
	var objLabelVerboseId = parentClassString.split(",")[2].split(":")[1];
	var objPanelBidId = parentClassString.split(",")[3].split(":")[1];
	var _lblProductListBidVerbose = document.getElementById(objLabelVerboseId);
	if ((typeof (_lblProductListBidVerbose) != "undefined") && (_lblProductListBidVerbose != null)) {
		_lblProductListBidVerbose.style.display = "block";
	}
	var _pnlBidList = document.getElementById(objPanelBidId);
	if ((typeof (_pnlBidList) != "undefined") && (_pnlBidList != null)) {
		_pnlBidList.style.display = "none";
	}
	var _pnlProductBidListPopup = document.getElementById(objPopupId);
	if ((typeof (_pnlProductBidListPopup) != "undefined") && (_pnlProductBidListPopup != null)) {
		_pnlProductBidListPopup.style.display = "none";
		_pnlProductBidListPopup.style.visibility = "hidden";
	}
	var _hdnProductBidListPopupPosition = document.getElementById(objPopupPositionStorage);
	if ((typeof (_hdnProductBidListPopupPosition) != "undefined") && (_hdnProductBidListPopupPosition != null)) {
		_hdnProductBidListPopupPosition.value = ",,closed";
	}
	return true;
}

function closeProductBidCompany(objId) {
	var _pnlBidCompanyPopup = document.getElementById(objId);
	if ((typeof (_pnlBidCompanyPopup) != "undefined") && (_pnlBidCompanyPopup != null)) {
		_pnlBidCompanyPopup.style.display = 'none';
		_pnlBidCompanyPopup.style.visibility = 'hidden';
	}
}

function closeProductBidCompanyFromOutside(e) {
	try {
		var target = (e && e.target) || (event && event.srcElement);
		var allDivs = document.getElementsByTagName('DIV');
		if ((typeof (allDivs) != "undefined") && (allDivs != null)) {
			for (var i = 0; i < allDivs.length; i++) {
				var divObj = allDivs[i];
				if (divObj.className == 'product_bid_company_div') {
					var _pnlBidCompanyPopup = divObj;
					if ((target != _pnlBidCompanyPopup) && (!isDescendentOfProductBidCompany(target, _pnlBidCompanyPopup))) {
						if (_pnlBidCompanyPopup.style.display == 'block') {
							var theDiv = null;
							var innerDivs = _pnlBidCompanyPopup.getElementsByTagName('DIV');
							if ((typeof (innerDivs) != "undefined") && (innerDivs != null)) {
								for (var j = 0; j < innerDivs.length; j++) {
									var innerDiv = innerDivs[j];
									if ((innerDiv.className.length > 0) && (innerDiv.className.substring(0, 12) == "popupTextId:")) {
										theDiv = innerDiv;
										j = innerDivs.length;
									}
								}
							}
							if ((typeof (theDiv) != "undefined") && (theDiv != null)) {
								var objPopupTextId = theDiv.className.split(",")[0].split(":")[1];
								var objPopupLabelVerboseId = theDiv.className.split(",")[1].split(":")[1];
								var _txtBidCompany = document.getElementById(objPopupTextId);
								if ((typeof (_txtBidCompany) != "undefined") && (_txtBidCompany != null)) {
									if (_txtBidCompany.disabled == false) {
										_txtBidCompany.disabled = true;
										var _lblBidCompanyVerbose = document.getElementById(objPopupLabelVerboseId);
										if ((typeof (_lblBidCompanyVerbose) != "undefined") && (_lblBidCompanyVerbose != null)) {
											_lblBidCompanyVerbose.innerHTML = "cancelling...";
										}
									}
								}
							}
							setTimeout("closeProductBidCompany('" + _pnlBidCompanyPopup.id + "')", 1000);
						}
					}
				}
			}
		}
	} catch (e) {
		alert("error: at \"" + this.location.pathname + "\": name: \"" + e.name + "\": message: \"" + e.message + "\"");
	}
}

function isDescendentOfProductBidCompany(t, _pnlBidCompanyPopup) {
	while (t.parentNode) {
		if (t == _pnlBidCompanyPopup) {
			return true
		}
		t = t.parentNode
	}
	return false
}

//    function txtBuyBidOnChange(txtObj, btnObj) {
//        if (txtObj.value.length > 0) {
//            btnObj.disabled = false;
//        } else {
//            btnObj.disabled = true;
//        }
//    }

function txtBuyBidOnKeyPress(e, btnObj, lblObj) {
	try {
		var target = (e && e.target) || (event && event.srcElement);
		e = window.event || e;
		e = e.charCode || e.keyCode;
		if (target.value.length > 0) {
			btnObj.disabled = false;
			if (e == 13) {
				target.disabled = true;
				lblObj.innerHTML = "buying, please wait...";
				btnObj.click();
			}
		} else {
			btnObj.disabled = true;
		}
	} catch (e) {
		alert("error: at \"" + this.location.pathname + "\": name: \"" + e.name + "\": message: \"" + e.message + "\"");
	}
}

function OpenBidCompany(ev, obj) {
	try {
		var parentClassString = obj.parentNode.className;
		var objPopupId = parentClassString.split(",")[0].split(":")[1];
		var objPopupPositionStorage = parentClassString.split(",")[1].split(":")[1];
		var objPopupTextId = parentClassString.split(",")[2].split(":")[1];
		var objPopupButtonId = parentClassString.split(",")[3].split(":")[1];
		var objPopupLabelVerboseId = parentClassString.split(",")[4].split(":")[1];
		var _txtBidCompany = document.getElementById(objPopupTextId);
		if ((typeof (_txtBidCompany) != "undefined") && (_txtBidCompany != null)) {
			_txtBidCompany.disabled = false;
			_txtBidCompany.value = "";
			var _lblBidCompanyVerbose = document.getElementById(objPopupLabelVerboseId);
			if ((typeof (_lblBidCompanyVerbose) != "undefined") && (_lblBidCompanyVerbose != null)) {
				_lblBidCompanyVerbose.innerHTML = "";
				var _btnBidBuy = document.getElementById(objPopupButtonId);
				if ((typeof (_btnBidBuy) != "undefined") && (_btnBidBuy != null)) {
					_btnBidBuy.disabled = true;
					if (_txtBidCompany.addEventListener) {
						// _txtBidCompany.addEventListener('change', function() { txtBuyBidOnChange(_txtBidCompany, _btnBidBuy); }, false);
						_txtBidCompany.addEventListener('keyup', function (event) { txtBuyBidOnKeyPress(event, _btnBidBuy, _lblBidCompanyVerbose); }, false);
					} else if (_txtBidCompany.attachEvent) {
						// _txtBidCompany.attachEvent('onchange', function() { txtBuyBidOnChange(_txtBidCompany, _btnBidBuy); });
						_txtBidCompany.attachEvent('onkeyup', function () { txtBuyBidOnKeyPress(event, _btnBidBuy, _lblBidCompanyVerbose); });
					}
				}
			}
		}
		var _pnlBidCompanyPopup = document.getElementById(objPopupId);
		if ((typeof (_pnlBidCompanyPopup) != "undefined") && (_pnlBidCompanyPopup != null)) {
			var coords = findPos(obj);
			var offsetX = 250;
			var offsetY = -30;

			_pnlBidCompanyPopup.style.display = 'block';
			_pnlBidCompanyPopup.style.visibility = 'visible';
			_pnlBidCompanyPopup.style.zIndex = 2;
			var posLeft = (coords[0] - offsetX - _pnlBidCompanyPopup.offsetParent.offsetLeft) + 'px';
			var posTop = (coords[1] + offsetY - _pnlBidCompanyPopup.offsetParent.offsetTop) + 'px';
			_pnlBidCompanyPopup.style.left = posLeft;
			_pnlBidCompanyPopup.style.top = posTop;

			var _hdnBidCompanyPopupPosition = document.getElementById(objPopupPositionStorage);
			if ((typeof (_hdnBidCompanyPopupPosition) != "undefined") && (_hdnBidCompanyPopupPosition != null)) {
				_hdnBidCompanyPopupPosition.value = posLeft + "," + posTop + ",open";
				//alert(_hdnProductBidListPopupPosition.value);
			}
			ev.returnValue = false;
			ev.cancelBubble = true;
			if (typeof (ev.preventDefault) == "function") {
				ev.preventDefault();
			}
		}
	} catch (e) {
		alert("error: at \"" + this.location.pathname + "\": name: \"" + e.name + "\": message: \"" + e.message + "\"");
	}
}

function BuyBid(ev, obj) {
	try {
		var parentClassString = obj.parentNode.className;
		var objPopupTextId = parentClassString.split(",")[0].split(":")[1];
		var objPopupLabelVerboseId = parentClassString.split(",")[1].split(":")[1];
		var _txtBidCompany = document.getElementById(objPopupTextId);
		if ((typeof (_txtBidCompany) != "undefined") && (_txtBidCompany != null)) {
			if (_txtBidCompany.disabled == false) {
				_txtBidCompany.disabled = true;
				var _lblBidCompanyVerbose = document.getElementById(objPopupLabelVerboseId);
				if ((typeof (_lblBidCompanyVerbose) != "undefined") && (_lblBidCompanyVerbose != null)) {
					_lblBidCompanyVerbose.innerHTML = "buying, please wait...";
				}
			}
		}
	} catch (e) {
		alert("error: at \"" + this.location.pathname + "\": name: \"" + e.name + "\": message: \"" + e.message + "\"");
	}
}

this.imagePreview = function () {
	/* CONFIG */

	xOffset = 10;
	yOffset = 30;

	// these 2 variable determine popup's distance from the cursor
	// you might want to adjust to get the right result

	/* END CONFIG */
	$("a.preview").hover(function (e) {
		this.t = this.title;
		this.title = "";
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='" + this.href + "' alt='Image preview' />" + c + "</p>");
		$("#preview")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px")
			.fadeIn("fast");
	},
	function () {
		this.title = this.t;
		$("#preview").remove();
	});
	$("a.preview").mousemove(function (e) {
		$("#preview")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px");
	});
	$("a.preview").unbind('click');

};


function stopDefault(e) {
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}


// BuyBid end

