// gomarket_js.js
function linkuj(url)
{
	window.location.href=url;
}
var confirmMsg  = 'Prosimy o potwierdzenie decyzji:';
function confirmLink(theLink, theSqlQuery)
{
    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
        return true;
    }
    var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
    if (is_confirmed) {
        theLink.href += '';
    }
    return is_confirmed;
}

function WarstwaZawartosci(url,id_warstwy)
{
	advAJAX.get({
		url : url,
		onInitialization : function(obj) {
		document.getElementById(id_warstwy).innerHTML = '<div style="margin: 10px;border: 0px solid #A40000;padding:5px"><img src="images/loadingff.gif" width="64" height="74" border="0" alt="proces..." /></div>';
			},
		onSuccess : function(obj) {document.getElementById(id_warstwy).innerHTML = obj.responseText;},
		onError : function(obj) { alert("Error: " + obj.status); }
	});
}

function PokazSklad(prefix,zawartosc)
{
	//var zawartosc = document.getElementById('zawartosc').value;
	document.getElementById('grafikowa').style.display='block';
	WarstwaZawartosci("grafiki.php?prefix="+prefix+"&jakie="+zawartosc,"grafikowa")
}

function Zamknij()
{
	document.getElementById('grafikowa').style.display='none';
}

function Pokaz()
{
	document.getElementById('topPan').style.display='block';
	document.getElementById('pokaz_showaj').style.top='-93px';
}
function Schowaj()
{
	document.getElementById('topPan').style.display='none';
	document.getElementById('pokaz_showaj').style.top='0px';
}
function SkoczDalej()
{
	document.forms[0].submit();
}

function DodajTowar(id_warstwy) {

	advAJAX.submit(document.getElementById("xmyform"), {
		headers : {"Content-type" : "application/x-www-form-urlencoded"},
		onInitialization : function(obj) {document.getElementById("submitBtn").value = "Czekaj...";},
		onComplete : function() {document.getElementById("submitBtn").value = "Sprawdź";},
		onSuccess : function(obj) {
		//document.getElementById(id_warstwy).innerHTML = obj.responseText;;
		alert(obj.responseText);
		document.getElementById("sybmol_towaru").value="";
		
		},
		onError : function(obj) {alert("Nie można nawiązać połączenia z serwerem, spróbuj później.");}
	});
}


function DodajDoKoszyka(id_warstwy)
{
	document.getElementById(id_warstwy).style.display='block';
	
	advAJAX.submit(document.getElementById("koszykowy"), {
		headers : {"Content-type" : "application/x-www-form-urlencoded"},
		onInitialization : function(obj) {
			document.getElementById(id_warstwy).innerHTML = '<div style="margin: 10px;border: 0px solid #A40000;padding:5px"><img src="images/loadingff.gif" width="64" height="74" border="0" alt="proces..." /></div>';
		},
		onSuccess : function(obj) {
		document.getElementById(id_warstwy).innerHTML = obj.responseText;
		},
		onError : function(obj) {alert("Nie można nawiązać połączenia z serwerem, spróbuj później.");}
	});
}

function Kupujemy()
{
	document.getElementById('zakupowa').style.display='block';
}
function ZamknijKupujemy(jaka)
{
	document.getElementById(jaka).style.display='none';
}

function zaokraglenie(liczba)
{
	liczba = liczba * 100;
	var wynik = Math.round(liczba)/100;
	return wynik;
}

function grajCene(cena_za_sztuke)
{
	//var cena_za_sztuke = document.getElementById('cena_za_sztuke').value;	
	var ile_sztuk = document.getElementById('ile_sztuk').value;	
	var placi = 0;
	
	if(ile_sztuk > 1)
	{
		placi = ile_sztuk *cena_za_sztuke;
		document.getElementById('sztukowa2').innerHTML= zaokraglenie(placi)+' PNL';
		document.getElementById('sztukowa2').style.display='block';
		document.getElementById('sztukowa').style.display='none';
	}
	else
	{
		document.getElementById('sztukowa2').style.display='none';
		document.getElementById('sztukowa').style.display='block';
	}

}

function testOdbierz(url,id_warstwy)
{
	var idk = document.getElementById("idk").value ;
	var id_firmy = document.getElementById("id_firmy").value ;
	var session_id = document.getElementById("session_id").value ;
	var sybmol_towaru = document.getElementById("sybmol_towaru").value ;
	document.getElementById(id_warstwy).style.display='block';
	
advAJAX.get({
		timeout : 1000,
		retryCount: 5,
		retryDelay: 500,
		onTimeout : function() { },
		url : url+'?akcja=get_do_sprawdzenia&sybmol_towaru='+sybmol_towaru+'&idk='+idk+'&id_firmy='+id_firmy+'&session_id='+session_id,
		onInitialization : function(obj) {
		document.getElementById("submitBtn").value = "Czekaj...";
		document.getElementById("submitBtn").disabled=true;

		document.getElementById(id_warstwy).innerHTML = '<div style="margin: 10px;border: 0px solid #A40000;padding:5px"><img src="images/loadingff.gif" width="64" height="74" border="0" alt="proces..." /></div>';	},
		onComplete : function() {document.getElementById("submitBtn").value = "Sprawdź";
		document.getElementById("submitBtn").disabled=false;
		},
		onSuccess : function(obj) {document.getElementById(id_warstwy).innerHTML = obj.responseText;},
		onError : function(obj) { alert("Error: " + obj.status); }
	});

}


function NewZakupuTowaru(id_warstwy) {

	document.getElementById(id_warstwy).style.display='block';
	
	advAJAX.assign(document.getElementById("koszykowy"), {
		headers : {"Content-type" : "application/x-www-form-urlencoded"},
		onInitialization : function(obj) {
			document.getElementById(id_warstwy).innerHTML = '<div style="margin: 10px;border: 0px solid #A40000;padding:5px"><img src="images/loadingff.gif" width="64" height="74" border="0" alt="proces..." /></div>';
		},
		onSuccess : function(obj) {
		document.getElementById(id_warstwy).innerHTML = obj.responseText;
		},
		onError : function(obj) {alert("Nie można nawiązać połączenia z serwerem, spróbuj później.");}
	});


}


//////////////////////////////

function getSprawdzSymbol(url,id_warstwy)
{
	var idk = document.getElementById("idk").value ;
	var id_firmy = document.getElementById("id_firmy").value ;
	var session_id = document.getElementById("session_id").value ;
	var sybmol_towaru = document.getElementById("sybmol_towaru").value ;
	var adres_strony_wywolujacej = document.getElementById("adres_strony_wywolujacej").value;
	document.getElementById(id_warstwy).style.display='block';
	
	advAJAX.get({
		url : url+'?akcja=get_do_sprawdzenia&sybmol_towaru='+sybmol_towaru+'&idk='+idk+'&id_firmy='+id_firmy+'&session_id='+session_id+'&adres_strony_wywolujacej='+adres_strony_wywolujacej,
		timeout : 2000,
		retryCount: 5,
		retryDelay: 500,

		onTimeout : function(obj) {
			//alert('Przekroczono czas żądania');
		},
		
		onRetry : function(obj) {
			//alert('Ządanie zostalo powtórzone...');
		},

		
		onInitialization : function(obj) {
			document.getElementById("submitBtn").disabled=true;
			document.getElementById(id_warstwy).innerHTML = 'Pobieram dane...';
			//document.getElementById(id_warstwy).innerHTML = '<div style="margin: 10px;border: 0px solid #A40000;padding:5px"><img src="images/loadingff.gif" width="64" height="74" border="0" alt="proces..." /></div>';
		},

		onSuccess : function(obj) {
			document.getElementById(id_warstwy).innerHTML = obj.responseText;
			document.getElementById("submitBtn").disabled=false;
		}
	})
}


function getNewDodajDoKoszyka(url,id_warstwy)
{
	document.getElementById(id_warstwy).style.display='block';
	var ile_sztuk = document.getElementById("ile_sztuk").value;
	
	advAJAX.get({
		url : url+'&ile_sztuk='+ile_sztuk,
		timeout : 2000,
		retryCount: 5,
		retryDelay: 500,

		onTimeout : function(obj) {
			//alert('Przekroczono czas żądania');
		},		
		onRetry : function(obj) {
			//alert('Ządanie zostalo powtórzone...');
		},
		
		onInitialization : function(obj) {
			document.getElementById("butDodaKoszyka").disabled=true;
			//document.getElementById(id_warstwy).innerHTML = '<div style="margin: 10px;border: 0px solid #A40000;padding:5px"><img src="images/loadingff.gif" width="64" height="74" border="0" alt="proces..." /></div>';
			document.getElementById(id_warstwy).innerHTML = 'Pobieram dane...';
		},

		onSuccess : function(obj) {
			document.getElementById(id_warstwy).innerHTML = obj.responseText;
		}
	});
}
function SchowajDiv(jaki)
{
	document.getElementById(jaki).innerHTML ='';
	document.getElementById(jaki).style.display='none';
}
//////////////

function OknoInfo(pageUrl,pageTitle,pageWidth,pageHeight) 
{
	if(screen){ 
	var page_width = pageWidth; 
	var page_height = pageHeight; 
	var page_set = 'no'; 
	var page_top = (screen.height-page_height)/2; 
	var page_left = (screen.width-page_width)/2; 
	openPage=window.open(''+ pageUrl + '',''+ pageTitle + '','width=' + page_width + ',height=' + page_height + ',top=' + page_top + ',left=' + page_left + ',pageSet=' + page_set + ''); 
	openPage.focus(); 
	} else { 
	openPage=window.open(''+ pageUrl + '',''+ pageTitle + ''); 
	openPage.focus(); 
	}
}

function SprawdzLoginAjax(id_warstwy)
{
	var login = document.getElementById("login").value ;
	if(login.length >5)
	{
		advAJAX.get({
			url : 'get_do_koszyka.php?akcja=sprawdz_login&szabon=nie&&login='+login,
			timeout : 1000,
			retryCount: 5,
			retryDelay: 100,
			onTimeout : function(obj) {
				//alert('Przekroczono czas żądania');
			},
			
			onRetry : function(obj) {
				//alert('Ządanie zostalo powtórzone...');
			},
			onInitialization : function(obj) {

				document.getElementById(id_warstwy).innerHTML = ' sprawdzam...';
			},

			onSuccess : function(obj) {
				document.getElementById(id_warstwy).innerHTML = obj.responseText;
			},

			onError : function(obj) { alert("Error: " + obj.status); }
		});

	}
}

function SymbolSprawdz(url,id_warstwy,sybmol_towaru,session_id)
{
	//var sybmol_towaru = document.getElementById("sybmol_towaru").value ;
	document.getElementById(id_warstwy).style.display='block';
	
	advAJAX.get({
		url : url+'?akcja=get_do_sprawdzenia&sybmol_towaru='+sybmol_towaru+'&dodatkowo=tak&session_id='+session_id,
		timeout : 2000,
		retryCount: 5,
		retryDelay: 500,

		onTimeout : function(obj) {
			//alert('Przekroczono czas żądania');
		},
		
		onRetry : function(obj) {
			//alert('Ządanie zostalo powtórzone...');
		},

		
		onInitialization : function(obj) {
			//document.getElementById("submitBtn").disabled=true;
			document.getElementById(id_warstwy).innerHTML = 'Pobieram dane...';
			//document.getElementById(id_warstwy).innerHTML = '<div style="margin: 10px;border: 0px solid #A40000;padding:5px"><img src="images/loadingff.gif" width="64" height="74" border="0" alt="proces..." /></div>';
		},

		onSuccess : function(obj) {
			document.getElementById(id_warstwy).innerHTML = obj.responseText;
			//document.getElementById("submitBtn").disabled=false;
		}
	})
}

function getOkno(pageUrl,pageTitle,pageWidth,pageHeight,pageSet) 
{
	if(screen)
	{ 
		var page_width = pageWidth; 
		var page_height = pageHeight; 
		var page_set = pageSet; 
		var page_top = (screen.height-page_height)/2; 
		var page_left = (screen.width-page_width)/2; 
		openPage=window.open(''+ pageUrl + '',''+ pageTitle + '','width=' + page_width + ',height=' + page_height + ',top=' + page_top + ',left=' + page_left + ',scrollbars=yes'); 
		openPage.focus(); 
	}
	else
	{ 
		openPage=window.open(''+ pageUrl + '',''+ pageTitle + ''); 
		openPage.focus(); 
	}
}