﻿
$(document).ready(function() {
	OnLoad();
	$(document).pngFix();
});

var runOnLoad = new Array();
function OnLoad() {
	var func;
	for (var i=0; i < runOnLoad.length; i++) {
		func = runOnLoad[i];
		func();
	}
	return true;
}

function OpenWin(windowURL, windowWidth, windowHeight, windowName, windowFeatures, noPopup) {

	// Add popup flag to querystring
	if (typeof(noPopup) == "undefined") {
		if (windowURL.lastIndexOf("?") >= 0)
			windowURL = windowURL + "&popup=true";
		else if (windowURL.substr(windowURL.length-1, 1) != "/")
			windowURL = windowURL + "/?popup=true";
		else
			windowURL = windowURL + "?popup=true";
	}

	// Default window sizes
	if (typeof(windowWidth) == "undefined" || windowWidth == "default")
		windowWidth = "550";
	if (typeof(windowHeight) == "undefined" || windowHeight == "default")
		windowHeight = "400";

	// Default window name
	if (typeof(windowName) == "undefined" || windowName == "default")
		windowName = "popup";

	// Default window features
	if (typeof(windowFeatures) == "undefined" || windowFeatures == 'default')
		windowFeatures = "top=50,left=50,toolbar=no,location=no,menubar=no,scrollbars=yes,status=no,resizable=yes";

	// Open and focus
	popupWindow = window.open(windowURL, windowName, windowFeatures + ',width=' + windowWidth + ',height=' + windowHeight);
	popupWindow.focus();

	return false;
}

function Support(url) {

	OpenWin(url, 800, 600, 'support', 'top=100,left=100,toolbar=yes,location=no,menubar=no,scrollbars=yes,status=no,resizable=yes', true);

	return false;
}

function PopImage(url) {

	if ($('#image_nr').length)
		url += '#' + $('#image_nr').val();

	OpenWin(url, 790, 620, 'itempics2', 'top=100,left=100,toolbar=no,location=no,menubar=no,scrollbars=yes,status=no,resizable=yes', true);

	return false;
}

function ShowImage(src, nr) {

	$('#image_big').attr('src', src);
	$('#image_nr').val(nr);

	return false;
}

function MapLinks(obj) {
	$(obj + ' a').attr('target','_blank');
}

function toggle_featured(element, label, txt_closed, txt_open) {

	$(element).toggle();

	if ($(element).is(":visible"))
		$(label).val(txt_open);
	else
		$(label).val(txt_closed);

	return;
}

function toggleSearchResults(element, elem_open, elem_closed, opt) {

	if ($(element).is(":visible")) {

		$(element).css('display', 'none');
		$(elem_open).css('display', '');
		$(elem_closed).css('display', 'none');

		if (opt == true) {

			$(".showmore").css('display', '');
			$(".showless").css('display', 'none');
			$(".extended").css('display', 'none');
		}

	} else {

		$(element).css('display', '');
		$(elem_open).css('display', 'none');
		$(elem_closed).css('display', '');

		if (opt == true) {

			$(".showmore").css('display', 'none');
			$(".showless").css('display', 'none');
			$(".extended").css('display', '');
		}
	}

	return false;
}

function confirmAndDisable(txt, element1, element2) {

	var conf = confirm(txt);

	if (conf) {
		$(element1).attr('disabled', true);
		$(element2).attr('value', '1');
	}

	return conf;
}

function calcPrice() {

	val = parseFloat($('#price').val());
	if (isNaN(val))
		val = 0;

	if (val >= 1 && val < 1500)
		before = val * 0.10;
	else if (val >= 1500 && val < 5000)
		before = val * 0.09;
	else if (val >= 5000 && val < 20000)
		before = val * 0.07;
	else if (val >= 20000 && val < 100000)
		before = val * 0.05;
	else if (val >= 100000 && val < 1000000)
		before = val * 0.03;
	else if (val >= 1000000)
		before = val * 0.01;
	else
		before = 0;

	if (val <= 2000)
		after = val * 0.09;
	else if (val <= 10000)
		after = 2000 * 0.09 + (val - 2000) * 0.05;
	else
		after = 2000 * 0.09 + 8000 * 0.05 + (val - 10000) * 0.02;

	$('#before').html(before.toFixed(2));
	$('#after').html(after.toFixed(2));
}

checkSet = true;
function CheckAll(oForm) {
	for (i=0; i < oForm.elements.length; i++) {
		if (oForm.elements[i].type == "checkbox" && !oForm.elements[i].disabled)
			oForm.elements[i].checked = checkSet;
	}
	checkSet = !checkSet;
}

function CheckAll2(oForm, oChecked, oElem) {

	for (i=0; i < oForm.elements.length; i++) {
		if (oForm.elements[i].type == "checkbox" && oForm.elements[i].name == oElem && !oForm.elements[i].disabled)
			oForm.elements[i].checked = oChecked;
	}
}

function ConfirmMsg(msg) {

	if (confirm(msg)) {
		return true;
	} else {
		return false;
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*
 * qTip tooltips
 */
// Array to hold all tooltips
var tooltips = new Array();

function populateTooltips() {

	$.fn.qtip.styles.qtipstyle = {
		width: 250,
		padding: 5,
		background: '#F6F6F6',
		color: 'black',
		border: {
			width: 0,
			radius: 5,
			color: '#FF9900'
		},
		tip: 'bottomLeft'
	}

	for (i=0; i<tooltips.length; i++) {

		$(tooltips[i][0]).qtip({
			content: tooltips[i][1],
			show: 'mouseover',
			hide: {
				delay: 250,
				fixed: true,
				effect: {
					length: 250
				}
			},
			position: {
				corner: {
					target: 'topRight',
					tooltip: 'bottomLeft'
				}
			},
			style: 'qtipstyle'
		});
	}
};