var timeoutId;
var TimeoutID;
var mode = 1;

function getAbsoluteLeft(objectId)
{

	// Get an object left position from the upper left viewport corner

	// Tested with relative and nested objects

	if ( document.getElementById(objectId) == null ) {
		
		alert(document.getElementById(objectId));
		
	}
	
	o = document.getElementById(objectId)

	oLeft = o.offsetLeft            // Get left position from the parent object

	while(o.offsetParent != null) {    // Parse the parent hierarchy up to the document element

		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent

	}

	// Return left postion

	return oLeft

}

/*
 * funkcja przelicza:
 *  - pole netto na brutto jezeli mode = 1
 *  - pole brutto na netto jezeli mode = 2
 * Argumentami funkcji jest pole z cena netto i pole z cena brutto. 
 * 'mode' jest zmienna globalna wiec nie musi byc przekazywane po prostu jezeli:
 *  - netto onfocus mode trzeba ustawic = 1
 *  - brutto onfocus mode trzeba ustawic = 2
 */
function translate_netto_to_brutto(nettoField, bruttoField, vatField, formName, precision)
{

	
	if ( document.getElementById(nettoField) == null ) {
		
		alert('Unable to locate ID: ' + nettoField);
		
	}
	
	if ( document.getElementById(bruttoField) == null ) {
		
		alert('Unable to locate ID: ' + bruttoField);
		
	}
	
	if ( document.getElementById(vatField) == null ) {
		
		alert('Unable to locate ID: ' + vatField);
		
	}
	
	netto 	= eval(document.getElementById(nettoField).value);
	brutto 	= eval(document.getElementById(bruttoField).value);
	vat 	= eval(document.getElementById(vatField).options[document.forms[formName].elements[vatField].selectedIndex].text);

	if ( mode == 1 ) {
		
		if ( isNaN(netto) ) {
			
			brutto = 0;
			
		} else {
		
			brutto = roundResult(netto * (1 + vat/100), 4);
				
		}
		
		document.getElementById(bruttoField).value = brutto;
		
	} else {
		
		if ( isNaN(brutto) ) {
			
			netto = 0;
			
		} else {
		
			netto = roundResult(brutto / (1 + vat/100), 4);
				
		}
		
		document.getElementById(nettoField).value = netto;
		
	}
	
}

function getAbsoluteTop(objectId)
{

	if ( document.getElementById(objectId) == null ) {
		
		alert(document.getElementById(objectId));
		
	}
	
	// Get an object top position from the upper left viewport corner

	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object

	while( o.offsetParent != null )  { // Parse the parent hierarchy up to the document element

		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent

	}

	// Return top position

	return oTop
	
}

/*
 * funkcja zaokragla wartosc, za argumentu przyjmuje:
 *  - elementValue -> wartosc do zaokraglenia
 *  - precission -> dokladnosc
 *  - keepSign -> czy moze byc ujemne (1 -> tak)
 */
function roundResult(elementValue, precission, keepSign)
{
	
	var x;
	var qty = 1;
	var sign = 0;
	var keep_dot_at_front = 0;
	
	if ( isNaN(elementValue) ) {
		
		return elementValue;
		
	}
	
	if ( keepSign == null ) {
		
		keepSign = 0;
		
	}
	
	if ( elementValue[0] == "-" ) {
		
		sign = 1;
		
	}
	
	if ( elementValue[0] == '.' ) {
		
		keep_dot_at_front = 1;
		
	}
	
	if ( precission == null ) {
		
		precision = 2;
		
	}
	
	for ( x = 0 ; x < precission ; x++ ) {
		
		qty *= 10;
		
	}
	
	// zaokraglamy 
	
	elementValue = Math.round(elementValue*qty)/qty;
	
	elementValue = '' + elementValue;
	
	if ( keep_dot_at_front && elementValue[0] == '0' ) {
		
		elementValue = elementValue.substring(1, elementValue.length);
		
	}
	
	if ( elementValue.indexOf('.') == -1 ) {
		
		elementValue += '.';
		
		var i;	
	
		for ( i = 0 ; i < precission ; i++ ) {
			
			elementValue += '0';	
			
		}
		
	}
	
	return elementValue;
	
}

/*
 * funkcja sprawdza czy pole o zadanym id jest puste, czy tez nie
 */
function is_empty(fieldId)
{
	
	if ( document.getElementById(fieldId) == null ) {
		
		return true;
		
	}
	
	if ( document.getElementById(fieldId).value.length < 1 ) {
		
		return true;
		
	}
	
}

function is_numeric(fieldId)
{
	
	if ( document.getElementById(fieldId) == null ) {
		
		return false;
		
	}
	
	var number_to_go;
	
	number_to_go = parseInt(document.getElementById(fieldId).value);
	
	if ( isNaN(number_to_go) ) {
		
		return false;
		
	}
	
	return true;
	
}
	

// funkcja usuwa wszystkie nie numeryczne wartosci w tym przecinki i kropki 

function remove_non_numeric_values(elementValue, keepSign)
{

	// ponizsza klauzula wyrzuca ze stringa wszystko co nie jest cyfra lub kropka/przecinkiem

	convString = elementValue.replace(/[^0-9-]*/g, '');
	
	return convString;

}


function keep_it_int(elementValue, keepSign)
{
	
	var sign = 0;
	
	if ( keepSign == null ) {
		
		keepSign = 0;
		
	}
	
	if ( elementValue[0] == "-" ) {
		
		sign = 1;
		
	}

	// ponizsza klauzula wyrzuca ze stringa wszystko co nie jest cyfra
	convString = elementValue.replace(/[^0-9]*/g, '');
	
	// na koniec wyciac wszystkie zera z poczatku stringi jezeli tylko nie jest to zero
	// poprzedzajace kropke
	while ( convString[0] == '0' ) {

		convString = convString.substring(1, convString.length);

	}
	
	if ( keepSign == 1 && sign == 1 ) {
		
		convString = '-' + convString; 
		
	}
	
	return convString;
	
}

// funkcja usuwa wszystkie nie numeryczne wartosci, zmienia przecinki w kropki, 
// usuwa wszystkie kropki oprocz pierwsze, usuwa wszystkie zera z poczatku cyfry
function keep_it_float(elementValue, keepSign, precission)
{

	var sign = 0;
	
	if ( keepSign == null ) {
		
		keepSign = 0;
		
	}
	
	if ( elementValue[0] == "-" ) {
		
		sign = 1;
		
	}
	
	if ( precission == null ) {
		
		precission = 4;
		
	}

	// ponizsza klauzula wyrzuca ze stringa wszystko co nie jest cyfra lub kropka/przecinkiem

	convString = elementValue.replace(/[^0-9.,]*/g, '');
	
	// wszystkie przecinki zmieniaja sie w kropki

	convString = convString.replace(',', '.');

	// a nastepnie ucinamy wszystkie kropki oprocz pierwszej

	// nie da sie ukryc ze ponizsza kombinacja replace'ow wynika z faktu,
	// iz autor zna regexp na slowo honoru
	// w tym celu pierwsza kropke zmieniamy w literke 'u'

	convString = convString.replace(/[\.]/, 'u');

	// nastepnie wszystie inne kropki usuwamy

	convString = convString.replace('.', '');

	// na koniec literke u przywracamy do bazowej postaci

	convString = convString.replace('u', '.');

	// na koniec wyciac wszystkie zera z poczatku stringi jezeli tylko nie jest to zero
	// poprzedzajace kropke
	
	while ( ((convString[0] == '0') && (convString[1] != '.')) && ((convString[0] == '0') && (convString[1] != null)) ) {

		convString = convString.substring(1, convString.length);

	}
	
	if ( convString[0] == '.' && ( convString[1] == '' || convString[1] == null ) ) {
		
		convString = '0' + convString;
		
	}
		
	if ( keepSign == 1 && sign == 1 ) {
		
		convString = '-' + convString; 
		
	}
	
	var x = convString.indexOf('.');
	
	if ( x != -1 && ( (convString[x+1] != null && convString[x+1] != '0') || (convString[x+precission+1] == '0') )  ) {
		
		convString = roundResult(convString, precission, keepSign);
		
	}
	
	return convString;

}

function ask( text,  onYes ) {
	
	var showWindow, hideWindow,onYesF;
	//wiem kim jestem wiec sie zapamietuje
	var that = this;

	that.showWindow = function() {
		$('#window').css('overflow', 'hidden').css('top', '100px');
	
		if ( $(window).width() > 880 ) {
		
			var differ = $(window).width() - 880;
			$("div#window").css('left', differ/2);
			
		}
//		$('#window').css("top","35%");
//		$('#window').css("left","33%");
		$('#window').css("width",600);
		$('#overLay').show();
		$('#window').show();
		
	};
	 that.hideWindow = function() {
		
		$('#overLay').hide();
		$('#window').hide();
	};
	
	that.onYesF =  onYes;

	if( typeof that.onYesF  != 'undefined') {
		
		var btnYes = $('<input type = "button" class="button_yes" value="Tak">');
		btnYes.click( function(){ that.onYesF(); that.hideWindow();});
	} else {
		var btnYes = '';
	}

	
	var btnNo = $('<input type = "button" class="button_no" value="Nie">');
	btnNo.click(that.hideWindow);
	
	if( $(text).size() ) {
		
		var cont = $(text);
		$('#windowBody').html(cont);
		if( cont.find('.button_yes_cont').size() ){
			$('.button_yes_cont',cont).append(btnYes);
		} else {
			cont.each(function(){
				if( $(this).hasClass('button_yes_cont') ){
					
					$(this).append(btnYes);
					return;
				}
			});
		}
		
		if( cont.find('.button_no_cont').size() ){
			$('.button_no_cont',cont).append(btnNo);
		} else {
			cont.each(function(){
				if( $(this).hasClass('button_no_cont') ){
					
					$(this).append(btnNo);
					return;
				}
			});
		}
		
//		$('.button_no_cont',cont).html(btnNo);
		
		
	} else {
		
		var cont = $('<p>'+text+'</p>');
		var f = $('<fieldset class="form_set"></fieldset>');
		f.append(btnYes);
		f.append(btnNo);
		$('#windowBody').html(cont);
		cont.after(f);
	}
	
	
	
	//form_set
	
	that.showWindow();
}

function checkRecl()
{
	
	if ( document.forms['Main'].elements['nazwa_sprzetu'].value.length < 3 ) {
	
		alert('Musisz podac nazwe reklamowanego towaru.');
		
		document.forms['Main'].elements['nazwa_sprzetu'].focus();
		
		return false;
		
	}
	
	if ( document.forms['Main'].elements['numer_seryjny'].value.length < 2 ) {
		
		alert('Musisz podac numer seryjny reklamowanego towaru.');
		
		document.forms['Main'].elements['numer_seryjny'].focus();
	
		return false;
		
	}
	
	return true;
	
}

function show_me_warning(objectId)
{
	
	if ( timeoutId != null ) {
		
		clearTimeout(timeoutId);
		
	}
	
	if ( document.getElementById(objectId) == null ) {
		
		alert('Obiekt nie istnieje: ' + objectId);
		
		return false; 
		
	}
	
	left = getAbsoluteLeft(objectId);
	top = getAbsoluteTop(objectId);
	
	document.getElementById('warning').style.left = (left - 62) + 'px';
	document.getElementById('warning').style.top = (top - 52) + 'px';
	
	document.getElementById('warning').style.display = '';
	
}

function close_my_warning()
{
	
	document.getElementById('warning').style.display = 'none';
	
}

function reset(variable_field, variant) 
{

	document.forms[''+variant+''].elements[''+variable_field+''].checked = 0;

}

function mark(variable_field, marker)
{
	
	if ( document.getElementById(variable_field) == null ) {
		
		alert('Unable to find ID: ' + variable_field);
		
		return false;
		
	}
	
	if ( document.getElementById(variable_field).type == 'checkbox' ) {

		document.getElementById(variable_field).checked = marker;

	}
		
}

function touch(variable_field) 
{

	if ( document.getElementById(variable_field) == null ) {
		
		//alert('Unable to find ID: ' + variable_field);
		
		return false;
		
	}
	
	if ( document.getElementById(variable_field).checked == 1 ) {

		document.getElementById(variable_field).checked = 0;

	} else {

		document.getElementById(variable_field).checked = 1;

	}

}

function touch_radio(variable_field, field, formName) 
{
	
	if ( document.getElementById(variable_field) == null ) {
		
		alert('Unable to find ID: ' + variable_field);
		
		return false;
		
	}
	
	var length = document.forms[formName].elements[variable_field].length;
	
	var i;
	
	for ( i = 0 ; i < length ; i++ ) {
		
		if ( document.forms[formName].elements[variable_field][i].value == field ) {
			
			document.forms[formName].elements[variable_field][i].checked = 1;
			
		}
		
	}
	
}

////////////////////////////
//Menu kategorii
///////////////////////////

var persisteduls=new Object()
var ddtreemenu=new Object()

//////////No need to edit beyond here///////////////////////////

ddtreemenu.createTree=function(treeid, enablepersist, persistdays){
var ultags=document.getElementById(treeid).getElementsByTagName("ul")
if (typeof persisteduls[treeid]=="undefined")
persisteduls[treeid]=(enablepersist==true && ddtreemenu.getCookie(treeid)!="")? ddtreemenu.getCookie(treeid).split(",") : ""
for (var i=0; i<ultags.length; i++)
ddtreemenu.buildSubTree(treeid, ultags[i], i)
if (enablepersist==true){ //if enable persist feature
var durationdays=(typeof persistdays=="undefined")? 1 : parseInt(persistdays)
ddtreemenu.dotask(window, function(){ddtreemenu.rememberstate(treeid, durationdays)}, "unload") //save opened UL indexes on body unload
}
}

ddtreemenu.buildSubTree=function(treeid, ulelement, index){
ulelement.parentNode.className="submenu"
if (typeof persisteduls[treeid]=="object"){ //if cookie exists (persisteduls[treeid] is an array versus "" string)
if (ddtreemenu.searcharray(persisteduls[treeid], index)){
ulelement.setAttribute("rel", "open")
ulelement.style.display="block"
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
}
else
ulelement.setAttribute("rel", "closed")
} //end cookie persist code
else if (ulelement.getAttribute("rel")==null || ulelement.getAttribute("rel")==false) //if no cookie and UL has NO rel attribute explicted added by user
ulelement.setAttribute("rel", "closed")
else if (ulelement.getAttribute("rel")=="open") //else if no cookie and this UL has an explicit rel value of "open"
ddtreemenu.expandSubTree(treeid, ulelement) //expand this UL plus all parent ULs (so the most inner UL is revealed!)
ulelement.parentNode.onclick=function(e){
var submenu=this.getElementsByTagName("ul")[0]
if (submenu.getAttribute("rel")=="closed"){
submenu.style.display="block"
submenu.setAttribute("rel", "open")
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
}
else if (submenu.getAttribute("rel")=="open"){
submenu.style.display="none"
submenu.setAttribute("rel", "closed")
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.closefolder+")"
}
ddtreemenu.preventpropagate(e)
}
ulelement.onclick=function(e){
ddtreemenu.preventpropagate(e)
}
}

ddtreemenu.expandSubTree=function(treeid, ulelement){ //expand a UL element and any of its parent ULs
var rootnode=document.getElementById(treeid)
var currentnode=ulelement
currentnode.style.display="block"
currentnode.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
while (currentnode!=rootnode){
if (currentnode.tagName=="UL"){ //if parent node is a UL, expand it too
currentnode.style.display="block"
currentnode.setAttribute("rel", "open") //indicate it's open
currentnode.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
}
currentnode=currentnode.parentNode
}
}

ddtreemenu.flatten=function(treeid, action){ //expand or contract all UL elements
var ultags=document.getElementById(treeid).getElementsByTagName("ul")
for (var i=0; i<ultags.length; i++){
ultags[i].style.display=(action=="expand")? "block" : "none"
var relvalue=(action=="expand")? "open" : "closed"
ultags[i].setAttribute("rel", relvalue)
ultags[i].parentNode.style.backgroundImage=(action=="expand")? "url("+ddtreemenu.openfolder+")" : "url("+ddtreemenu.closefolder+")"
}
}

ddtreemenu.rememberstate=function(treeid, durationdays){ //store index of opened ULs relative to other ULs in Tree into cookie
var ultags=document.getElementById(treeid).getElementsByTagName("ul")
var openuls=new Array()
for (var i=0; i<ultags.length; i++){
if (ultags[i].getAttribute("rel")=="open")
openuls[openuls.length]=i //save the index of the opened UL (relative to the entire list of ULs) as an array element
}
if (openuls.length==0) //if there are no opened ULs to save/persist
openuls[0]="none open" //set array value to string to simply indicate all ULs should persist with state being closed
ddtreemenu.setCookie(treeid, openuls.join(","), durationdays) //populate cookie with value treeid=1,2,3 etc (where 1,2... are the indexes of the opened ULs)
}

////A few utility functions below//////////////////////

ddtreemenu.getCookie=function(Name){ //get cookie value
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

ddtreemenu.setCookie=function(name, value, days){ //set cookei value
var expireDate = new Date()
//set "expstring" to either future or past date, to set or delete cookie, respectively
var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

ddtreemenu.searcharray=function(thearray, value){ //searches an array for the entered value. If found, delete value from array
var isfound=false
for (var i=0; i<thearray.length; i++){
if (thearray[i]==value){
isfound=true
thearray.shift() //delete this element from array for efficiency sake
break
}
}
return isfound
}

ddtreemenu.preventpropagate=function(e){ //prevent action from bubbling upwards
if (typeof e!="undefined")
e.stopPropagation()
else
event.cancelBubble=true
}

ddtreemenu.dotask=function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent(tasktype, functionref)
}


//tooltip

function hide_layer()
{

	if ( TimeoutID != null ) {
		
		clearTimeout(TimeoutID);
		setTimeout('go_and_hide()', 200);	
		
	} else {
	
		setTimeout('go_and_hide()', 200);
	
	}

}

function toggle_visibility(elementId, clean)
{
	
	if ( clean == '' ) {
		
		clean = 0;
		
	}
	
	if ( document.getElementById(elementId).style.display == 'none' ) {
		
		unhide(elementId);
		
	} else {
		
		hide(elementId, clean);
		
	}
	
}

function go_and_hide()
{

	var pre = document.getElementById('loading');

	pre.style.display='none';
	pre.innerHTML = "&nbsp;";
	
}

function check_if_good_to_go(formName)
{

	if ( document.forms[formName].elements['block'].value == 0 ) {
		
		return true;
	
	} else {
		
		document.forms[formName].elements['block'].value = 0;

		return false;
		
	}
	
}


function hide(elementId, clean)
{
	
	if ( clean == null ) {
		
		clean = 0;
		
	}
	
	document.getElementById(elementId).style.display = 'none';
	
	if ( clean ) {

		document.getElementById(elementId).innerHTML = '';
		
	}
	
}

function unhide(elementId)
{
	
	if ( TimeoutID != null ) {
		
		clearTimeout(TimeoutID);
		
	}
	
	document.getElementById(elementId).style.display = '';
	
}

function hide_autofield_sec(variant, fieldName, clean)
{
	
	if ( clean == 'null' ) {
		
		clean = 0;
		
	}
	
	if (variant == 1) {
	
		hide(fieldName, clean);
		
	} else {
	
		TimeoutID = setTimeout('hide_autofield_sec(1, \''+fieldName+'\', '+clean+')', 250);
		
	}
	
}

function detectBrowser()
{
	
	if ( !document.all ) {
		
		return 1; // mozilla type
		
	} else {
		
		var version = /MSIE \d+.\d+/
		
		return 0; // ie type
	
	}

}


/*
 * ustawiamy polozenie tooltipa, jezeli 'parentId' jest rozny od -1 to ustawiamy tooltipa
 * wzgledem elementu 'parentId', w przeciwnym przypadku centrum ekranu skorygowane
 * o korekte top i left
 */
function set_tooltip_position(tooltipNameId, parentId, korektaTop, korektaLeft, toolTipWidth)
{
		
	var x, y;
	
	if ( parentId != -1 ) {

		x = getAbsoluteLeft(parentId);
		y = getAbsoluteTop(parentId);
		
	} else {
		
		if ( detectBrowser() ) {

			y = window.pageYOffset;
			x = window.pageXOffset;
			
		} else {
			
			y = document['documentElement'].scrollTop;
			x = document['documentElement'].scrollLeft;

		}
		
	}
	
	document.getElementById(tooltipNameId).style.left = x + korektaLeft + 'px';
	document.getElementById(tooltipNameId).style.top = y + korektaTop + 'px';
	
	document.getElementById(tooltipNameId).style.width = toolTipWidth + 'px';
		
}

/*
 * publiczna funkcja, ktora wyswietla komunikat o tresci 'message' przez 'time' sekund,
 * tooltip jest pozycjonowany wzgledem 'parentId', pozycja jest przesunieta wzgledem 
 * osi x oraz osi y gdzie lewy gorny rog to wspolrzedna 0,0 a dolny prawy rog to np. 100, 100
 *
 */
function show_tooltip(parentId, message, time, x_axis, y_axis, width)
{

	if ( parentId == null ) {
		
		return false;
		
	}
	
	if ( time == null ) {
		
		time = 1;
		
	}
	
	if ( width == null ) {
		
		width = 300;
		
	}
	
	if ( x_axis == null ) {
		
		x_axis = 0;
		
	}
	
	if ( y_axis == null ) {
		
		y_axis = 0;
		
	}
	
	set_tooltip_position('tooltip', parentId, y_axis, x_axis, width); 
	document.getElementById('tooltip').innerHTML = '' + message + '';
	unhide('tooltip');
	TimeoutID = setTimeout('hide(\'tooltip\')', time * 1000);
	
}

/*
 * funkcja odpala ajaxowe wyslanie danego forma (celem jest standardowe action="")
 * efekt pracy tej funkcji ustawia sie wzgledem wlasnie ogladanego ekranu (nie ma ryzyka,
 * ze uzytkownik jest przeskrolowany na dol i go nie zobaczy)
 */
function sendFormToScript(formName, width, axis_x, axis_y, divName)
{
	
	if ( width == null ) {
		
		width = 860;
		
	}
	
	if ( axis_y == null ) {
		
		axis_y = 0;
		
	}
	
	if ( axis_x == null ) {
		
		axis_x = 0;
		
	}
	
	if ( divName == null ) {
		
		divName = 'window';
		
	}
	
	set_tooltip_position(divName, -1, axis_y, axis_x, width);
	
	var content = document.getElementById(divName+'Body');
	var pre 	= document.getElementById(divName);
	
	advAJAX.submit(document.getElementById(formName), {

		onError: function(obj) { 
			
			pre.style.display = '';			
			content.innerHTML = '<font color="red"><strong><center>' +  obj.status + '</center></strong></font>';

		},

		onFinalization: function(obj) {

			content.innerHTML = obj.responseText;
			
		},
		
		onLoading: function() {
			
			pre.style.display = '';			
			content.innerHTML = '<font color="red"><strong><center>Loading</center></strong></font>';
			
		}
		
	});
	
}

function show_me_standard_window(scriptName, top, left, divName, width, parentId, variables)
{

	if ( top == null ) {
		
		top = 0;
		
	}
	
	if ( left == null ) {
		
		left = 0;
		
	}
	
	if ( width == null ) {
		
		width = 650;
		
	}
	
	if ( divName == null ) {
		
		divName = 'window';
		
	} 
	
	if ( parentId == null) {
		
		parentId = -1;
		
	}
	
	var content = document.getElementById(divName+'Body');
	var pre = document.getElementById(divName);
	
	set_tooltip_position(divName, parentId, 80 + top, 30 + left, width);
	
	advAJAX.post({ url: '' + scriptName + '',
	
		parameters : {
			"variables" : variables
		},
	
		onError : function(obj) { 
			
			pre.style.display = '';			
			content.innerHTML = '<font color="red"><strong><center>' +  obj.status + '</center></strong></font>';

		},
		
		onLoading : function(obj) {

			pre.style.display = '';			
			content.innerHTML = '<font color="red"><strong><center>Loading</center></strong></font>';
			
		},
		
		onFinalization: function(obj) {
			
			content.innerHTML = obj.responseText;
			
		}
		
	});
	
}

function disabled_readonly(box, date, descr)
{
	if ( document.getElementById(box).checked == true ) {
		
		document.getElementById(date).disabled=false; 
		document.getElementById(descr).disabled=false;
		
	} else {
		
		document.getElementById(date).disabled=true; 
		document.getElementById(descr).disabled=true;
	}
}

function show_me_inner_content( divName, idForm)
{

	if ( divName == null ) {
		
		divName = 'window';
		
	}
	

	
	var content = document.getElementById(divName);
	
	advAJAX.submit(document.getElementById(idForm), {
		
		
		
		onError: function(obj) { 
			
					
			content.innerHTML = '<font color="red"><strong><center>' +  obj.status + '</center></strong></font>';

		},
		
		onLoading: function() {

			
			content.innerHTML = '<center><img src="graph/Layout/icons/LayoutPreloader.gif" title="Ładuję" alt="Ładuję" style="border-style: none; margin-top: 30px;" /></center>';
			
		},

		onFinalization: function(obj) {
//			content.innerHTML = obj.responseText;
			$(content).html( obj.responseText );
			
		}
		
	});
	
}

/**
*Funkcja startuje modul asynchroniczny
* @params divname - nazwa diva do ktorego zostanie wrzucona zwrocona przez ajax tresc
* @params scriptName - nazwa skryptu php ktory zostanie wywolany przez ajaxa,
* @params id - identyfikator obiektu
* @params params - tablica js wlasciwosci
*
*
*/
function start_window( divName, scriptName, id, params )
{
	//sample of assign default value in js unused in this case
	if(typeof id == 'undefined' || id== null)
	var id='';
	
	
	//set params as array when empty string
	if(params == "" )
	{		
		var params = new Array();
	}
	
	var dataObject 		= new Object();
	
	if ( params.constructor == Object ) {
		
		params.divName		= divName;
		params.id			= id;
		
		dataObject			= params;
		
	} else {
	
		dataObject.divName 	= divName;
		dataObject.id		= id;
		
		for(a in params) {
			
			eval( 'dataObject.'+a+' = '+params[a] );
			
		};
	}
	
	var content = document.getElementById(divName);
	
	$(content).html( '<center><img src="graph/Layout/icons/LayoutPreloader.gif" title="Ładuję" alt="Ładuję" style="border-style: none; margin-top: 30px;" /></center>' );
	
	$.ajax({
	  type: "POST",
	  url: ''+scriptName+'',
	  dataType: "html",
	  data: dataObject,
	  error: function( obj ) {
	  			$(content).html( '<font color="red"><strong><center>' +  obj.status + '</center></strong></font>' );
	  		},
	  success: function( obj ) {
	  			$("#"+divName).html(obj);	
	  		}
	  
	});

	
//	advAJAX.post({ url: '' + scriptName + '',
//		
//		parameters: {
//			
//			"divName"   : divName,
//			"id": id
//		},
//		onInitialization: function(obj){
//			
//			for(a in params)
//				obj.addParameter(a,params[a]);
//		
//		},
//		onError: function(obj) { 
//			
//					
//			content.innerHTML = '<font color="red"><strong><center>' +  obj.status + '</center></strong></font>';
//
//		},
//		
//		onLoading: function() {
//
//			
//			content.innerHTML = '<center><img src="graph/Layout/icons/LayoutPreloader.gif" title="Ładuję" alt="Ładuję" style="border-style: none; margin-top: 30px;" /></center>';
//			
//		},
//
//		onFinalization: function(obj) {
//					
//			jQuery("#"+divName).html(obj.responseText);
//
//		}
//		
//	});
	
	
}

function reloadImageCode(idImg)
{
	$('img#'+idImg).attr('src',$('img#'+idImg).attr('src')+'b');
	return false;
}

function clearDefValue(obj,defValue)
{
	if( obj.value==defValue ) {
		
		obj.value='';
		obj.style.color = 'black';
	
	} else if( obj.value=='' ) {
		
		obj.value=defValue;
		obj.style.color = 'gray';
	
}


}


function countCharacters(id,message)
{
	if(typeof massage == 'undefined')
		var massage = false;
	
	if($("#"+id).val().length > $("#"+id).attr("maxlength")){
		
		if (message)
			alert('Za długi tekst');
			
			$("#"+id).val($("#"+id).val().substring(0,$("#"+id).attr("maxlength")));
		
	}
	
	return false;

}

function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

function handleWindow( width, top , left) {
	
	if( typeof width == 'undefined' || width == null )
		width = '50%';
		
//	if ( typeof top == 'undefined' || top == null )
//		top = "35%";
	
	
//	if ( typeof left == 'undefined' || left == null )
//		left = "33%";
	
	$('#window').css('overflow', 'hidden').css('top', '100px');
	
	if ( $(window).width() > 880 ) {
	
		var differ = $(window).width() - 880;
		$("div#window").css('left', differ/2);
		
	}

	$('#overLay').show();
//	$('#window').css("top",top);
//	$('#window').css("left",left);
	$('#window').css('width',width);
	 
	$('#window').show();
	
	
}
function hideWindow() 
{
	$('#overLay').hide();
	$('#window').hide();
}

