 function getElement(obj)
 {
	return document.getElementById(obj);
 }

 function getElementLeft(obj)
 {
	var o=getElement(obj);
	var curentleft = 0;
	if (o.offsetParent)
	{
		while (o.offsetParent)
		{
			curentleft += o.offsetLeft
			o = o.offsetParent;
		}
	}
	else if (o.x)
		curentleft += o.x;
	return curentleft;
 }

 function getElementWidth(obj)
 {
	var o=getElement(obj);
	if (o.offsetWidth)
		return o.offsetWidth;
	else
		return o.width;
 }

 function getElementTop(obj)
 {
	var o=getElement(obj);
	var curenttop = 0;
	if (o.offsetParent)
	{
		while (o.offsetParent)
		{
			curenttop += o.offsetTop;
			o = o.offsetParent;
		}
	}
	else if (o.y)
		curenttop += o.y;
	return curenttop;
 }

 function getElementHeight(obj)
 {
	var o=getElement(obj);
	if (o.offsetHeight)
		return o.offsetHeight;
	else
		return o.height;
 }

 function getScrollX()
 {
	var scrOfX = 0;
  	if(typeof( window.pageYOffset ) == 'number' )
	{
    		//Netscape compliant
		scrOfX = window.pageXOffset;
	}
	else
		if(document.body && ( document.body.scrollLeft || document.body.scrollTop ))
		{
			//DOM compliant
			scrOfX = document.body.scrollLeft;
		}
		else
			if(document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ))
			{
    				//IE6 standards compliant mode
				scrOfX = document.documentElement.scrollLeft;
  			}
	return scrOfX;
 }

 function getScrollY()
 {
	var scrOfY = 0;
  	if(typeof( window.pageYOffset ) == 'number' )
	{
    		//Netscape compliant
		scrOfY = window.pageYOffset;
	}
	else
		if(document.body && ( document.body.scrollLeft || document.body.scrollTop ))
		{
			//DOM compliant
			scrOfY = document.body.scrollTop;
		}
		else
			if(document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ))
			{
    				//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
  			}
	return scrOfY;
 }

 function showElement(obj)
 {
	o=getElement(obj);
	if (o!=null)
		o.style.display='block';
 }

 function hideElement(obj)
 {
	o=getElement(obj);
	if (o!=null)
		o.style.display='none';
 }

 function showHideElement(obj)
 {
	o=getElement(obj);
	if (o!=null)
		o.style.display=o.style.display=='none'?'block':'none';	 
 }
 
 function elementShow(obj)
 {
	var o=getElement(obj);
	if (o!=null)
		o.style.visibility='visible';
 }

 function elementHide(obj)
 {
	var o=getElement(obj);
	if (o!=null)
		o.style.visibility='hidden';
 }

 function markElement(obj)
 {
	o=getElement(obj);
	if (o!=null)
		o.style.color='#FF0000';
 }

 function unMarkElement(obj)
 {
	o=getElement(obj);
	if (o!=null)
		o.style.color='#000000';
 }

 function delconfirm(param)
 {
	if (param)
		return confirm('Czy na pewno chcesz usunąć '+param+'?');
	else
		return confirm('Czy na pewno chcesz usunąć?');
 }

 function preloader(images)
 {
	for (i=0;i<images.length;i++)
	{
		var img=new Image();
		img.src=images[i];
	}
 }
	
 function rolover(object,image)
 {
	getElement(object).src=image;		
 }

 SWFObject= function (id, src, width, height, version, autowrite, idobject)
 {
	this.id      = id;
	this.src     = src;
	this.width   = width;
	this.height  = height;
	this.param   = new Array();
	this.version = (typeof version == 'string') ? version : '7,0,19,0';
	if (autowrite)
	{
		if (idobject != undefined)
			getElement(idobject).innerHTML = this.getHTML();
		else
			document.write(this.getHTML());
	}
 }

SWFObject.prototype = {

	getHTML: function ()
	{
		var str = "";

		str += '<div style="position:relative;width:'+ this.width +'px;height:'+ this.height +'px;z-index:0">';
		str += '<object id="'+ this.id +'" name="'+ this.id +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ this.version +'" width="'+ this.width +'" height="'+ this.height +'">';
		str += '<param name="movie" value="'+ this.src +'" />';		
		str += '<param name="quality" value="high" />';
		str += '<param name="wmode" value="transparent" />';

		for(i=0;i<this.param.length;i++)
			str += '<param name="'+ this.param[i][0] +'" value="'+ this.param[i][1] +'" />';
			
		str += '<embed id="'+ this.id +'" name="'+ this.id +'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="'+ this.src +'" width="'+ this.width +'" height="'+ this.height +'" wmode="transparent" quality="high" ';
		
		for(i=0;i<this.param.length;i++)
			str += this.param[i][0] +'="'+ this.param[i][1] +'" ';
		
		str += '/>';
		str += '</'+'object>';
		str += '</'+'div>';

		return str;
	},
	
	setParam: function(name, value)
	{
		this.param[this.param.length]=new Array(name, value);
	},
	
	write: function ()
	{
		document.write(this.getHTML());	
	}
 }

 function showPopup(src, width, height, x, y)
 {
	var popup = document.getElementById('popup');
	popup.innerHTML  = '<table cellspacing="0" cellpadding="0" width="' + width + '" height="' + height + '" style="border: 1px solid #909090; background-color:#FFFFFF"><tr><td align="center" valign="middle"><img src="'+src+'" width="'+width+'" height="'+height+'" onclick="javascript:hidePopup()" style="cursor:pointer" alt="" /></td></tr></table>';

	var winW   = (window.innerWidth?window.innerWidth:document.documentElement.clientWidth);
	var winH   = (window.innerHeight?window.innerHeight:document.documentElement.clientHeight);
	var bodW   = document.body.clientWidth;
	var bodH   = document.body.clientHeight;

	if (x > 0 && y > 0) 
	{
		popup.style.left    = getScrollX()+(((x + 16 + width) < winW)?(x + 16):(x - 16 - width)) + 'px';
		popup.style.top     = getScrollY()+(((y + height + 2) < winH)? y : (winH - height - 2)) + 'px';
	}
	else
	{

		popup.style.left    = (getScrollX() + Math.floor((winW - width) / 2)) + 'px';
		popup.style.top     = (getScrollY() + Math.floor((winH - height) / 2)) + 'px';
	}
 }

 function showPopupMove(width, height, x, y)
 {

	var popup = document.getElementById('popup');
	
	var winW   = (window.innerWidth?window.innerWidth:document.documentElement.clientWidth);
	var winH   = (window.innerHeight?window.innerHeight:document.documentElement.clientHeight);
	var bodW   = document.body.clientWidth;
	var bodH   = document.body.clientHeight;

	if (x > 0 && y > 0) 
	{
		popup.style.left    = getScrollX()+(((x + 16 + width) < winW)?(x + 16):(x - 16 - width)) + 'px';
		popup.style.top     = getScrollY()+(((y + height + 2) < winH)? y : (winH - height - 2)) + 'px';
	}
	else
	{

		popup.style.left    = (getScrollX() + Math.floor((winW - width) / 2)) + 'px';
		popup.style.top     = (getScrollY() + Math.floor((winH - height) / 2)) + 'px';
	}
 }

 function hidePopup()
 {
	var popup = document.getElementById('popup');
	popup.innerHTML = '';
 }

 document.write('<div id="popup" style="position:absolute; z-index:200; top:0px; left:0px"></div>');

 function copyToClipboard(data)
 {

	if (window.clipboardData && window.clipboardData.setData)
		if (window.clipboardData.setData('Text', data))
			alert('Pełna ścieżka do wybranego pliku została skopiowana do schowka');
		else
			prompt('Pełna ścieżka do wybranego pliku:',data);
	else
		prompt('Pełna ścieżka do wybranego pliku:',data);
 }

 function intFormat(number)
 {
	var tmp = Math.floor(number).toString();
	if (tmp.length > 3 && tmp.length < 7)
		return tmp.substr(0, tmp.length - 3) + ' ' + tmp.substr(tmp.length - 3, 3);
	return tmp;
 }

 function floatFormat(number)
 {
	var dec = Math.round(((number - Math.floor(number)) * 100)).toString().substring(0,2);
	return intFormat(Math.floor(number)) + '.' + (dec.length == 1 ?'0':'') + dec;
 }

 function changeProductPhoto(file)
 {
	var obj = document.getElementById('photoBig');
	if (obj)
	{
		obj.src = file;
	}
 }

 function submitLoginForm(form)
 {
	if (form.login.value.length > 0 && form.password.value.length > 0)
		form.submit();
 }

 function getFeaturePrice(value)
 {
	for (var i = 0; i < featureData.length; i++)
	{
		for (var j=0; j< featureData[i][2].length; j++)
		{
			if (featureData[i][2][j][0] == value)
				return featureData[i][2][j][2];
		}
	}
	return 0.00;
 }

 function setFeatureLabel(id)
 {
	var price = 0;
	var delta;
	var idSelected = 0;

	var arr = document.getElementsByTagName('input');

	for (var i = 0; i < arr.length; i++)
	{ 
		if (arr[i].name  == 'feature_' + id && arr[i].checked)
		{
			price      = getFeaturePrice(arr[i].value);
			idSelected = arr[i].value;
		}
	}

	for (var i = 0; i < featureData.length; i++)
	{
		if (featureData[i][0] == id)
		{
			for (var j=0; j< featureData[i][2].length; j++)
			{
				delta = featureData[i][2][j][2] - price;
				obj = document.getElementById('label_' + featureData[i][0] + '_' + featureData[i][2][j][0]);
				obj.innerHTML = featureData[i][2][j][1] + (delta > 0.00 ?' <span style="color:#606060;font-style:italic">[dodaj ' + intFormat(Math.abs(Math.ceil(delta))) + ' PLN netto]</span>' : (delta < 0.00 ?' <span style="color:#606060;font-style:italic">[odejmij ' + intFormat(Math.abs(Math.ceil(delta))) + ' PLN netto]</span>' : (featureData[i][2][j][0] == idSelected ? ' <span style="color:#606060;font-style:italic">[wliczono w cenę]</span>' : ' <span style="color:#606060;font-style:italic">[dodaj 0 PLN netto]</span>') ));
			}
			return;
		}
	}
 }

 function featureChange()
 {
	var id, price;

	if (typeof(featurePrice) != 'undefined' && featurePrice > 0)
	{
		price = featurePrice;

		var arr  = document.getElementsByTagName('input');
		var last = 0;

		for (var i = 0; i < arr.length; i++)
		{ 
			id    = arr[i].name.substr(8);

			if (arr[i].id.substr(0, 8) == 'feature_' && arr[i].checked == true)
				price += getFeaturePrice(arr[i].value);

			if (last != id)
			{
				setFeatureLabel(id);
				last = id;
			}
		}

		var obj = document.getElementById('productPriceValue');
		if (obj)
		{
			obj.innerHTML = intFormat(Math.ceil(price));
		}

		var obj = document.getElementById('iprice');
		if (obj)
		{
			obj.value = Math.ceil(price);
			if (typeof(obj.onchange) != 'undefined')
				obj.onchange();
		}
	}	
 }

 function handleSetClassification()
 {
 }

 function setClassification(value)
 {
	var arr  = document.getElementsByTagName('div');

	for (var i = 0; i < arr.length; i++)
	{ 
		if (arr[i].id.substr(0, 15) == 'classification_')
		{
			id    = arr[i].id.substr(15);
			if (id == value)
				arr[i].style.display = 'block';
			else
				arr[i].style.display = 'none';
		}
	}

	processHttpRequest('http://www.pckf.pl/system/commit_productclassification_set.php?classification='+value, handleSetClassification);
 }

