﻿jQuery.fn.extend({
check: function()
{
return this.each(function() { this.checked = true; });
},
uncheck: function()
{
return this.each(function() { this.checked = false; });
}
});
function pause(millis)
{
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while (curDate - date < millis);
}
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
}
return [curleft, curtop];
}
function Lookup(key)
{
return (this[key]);
}
function Delete()
{
for (c = 0; c < Delete.arguments.length; c++)
{
this[Delete.arguments[c]] = null;
}
var keys = new Array();
for (var i = 0; i < this.Keys.length; i++)
{
if (this[this.Keys[i]] != null)
keys[keys.length] = this.Keys[i];
}
this.Keys = keys;
}
function Add()
{
for (c = 0; c < Add.arguments.length; c += 2)
{
this[Add.arguments[c]] = Add.arguments[c + 1];
this.Keys[this.Keys.length] = Add.arguments[c];
}
}
function Dictionary()
{
this.Add = Add;
this.Lookup = Lookup;
this.Delete = Delete;
this.Keys = new Array();
}
this.imagePreview = function()
{
xOffset = 10;
yOffset = 30;
$("a.imgpreview").hover(function(e){	this.t = this.title;
this.title = "";
var c = (this.t != "") ? "<br/>" + this.t : "";
var imgSize = getImgSize(this.href, 350);
$("body").append("<p id='preview'><img src='" + this.href + "' alt='' style='width:" + imgSize[0] + ";height:" + imgSize[1] + "px;' />" + c + "</p>");
$("#preview")
.css("top", (e.pageY - xOffset) + "px")
.css("left", (e.pageX + yOffset) + "px")
.css("width", imgSize[0] + "px")
.css("height", imgSize[1]+ "px")
.fadeIn("fast");
},
function()
{
this.title = this.t;
$("#preview").remove();
});
$("a.imgpreview").mousemove(function(e)
{
$("#preview")
.css("top", (e.pageY - xOffset) + "px")
.css("left", (e.pageX + yOffset) + "px");
});
};
function getImgSize(imgSrc, max)
{
var newImg = new Image();
newImg.src = imgSrc;	var width = newImg.width;
var height = newImg.height;
if (width > max || height > max)
{
var skala = Math.min(max / width, max / height);
width *= skala;
height *= skala;
}
return [width, height];
}
jQuery.fn.GetPrice = function() {
var val = $(this).val();
val = val.replace(/ /g, '').replace(',', '.');
var valF = parseFloat(val);
if (isNaN(valF) == true) return parseFloat('0');
return TruncateToPrice(valF);
};
function FormatPrice(value) {
return CommaFormatted(TruncateToPrice(value).toFixed(2), ' ', ',');
}
function TruncateToPrice(value) {
if (isNaN(value)) { value = 0.00; }
var minus = '';
if (value < 0) { minus = '-'; }
value = Math.abs(value);
value = parseInt((value * 100) + 0.001);
value = value / 100;
s = new String(value);
if (s.indexOf('.') < 0) { s += '.00'; }
if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
return parseFloat(s);
}
function CommaFormatted(amount, delimiter, coma) {
var minus = '';
if (amount < 0) { minus = '-'; }
var a = amount.split('.', 2)
var d = a[1];
var i = parseInt(a[0]);
if (isNaN(i)) { return ''; }
i = Math.abs(i);
var n = new String(i);
var a = [];
while (n.length > 3) {
var nn = n.substr(n.length - 3);
a.unshift(nn);
n = n.substr(0, n.length - 3);
}
if (n.length > 0) { a.unshift(n); }
n = a.join(delimiter);
if (d.length < 1) { amount = n; }
else { amount = n + coma + d; }
amount = minus + amount;
return amount;
}
function format(str) {
for (i = 1; i < arguments.length; i++) {
str = str.replace('{' + (i - 1) + '}', arguments[i]);
}
return str;
}
function gup(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
