var WindowObjectReference = null; // global variable

function otworz_okno(strUrl, strWindowName, width, height)
{
var strWindowName = 'Zdjecie';
  if(WindowObjectReference == null || WindowObjectReference.closed)
  {
    WindowObjectReference = window.open(strUrl, strWindowName,
           "resizable=yes,scrollbars=yes,status=yes,width="+width+",height="+height);
  }
  else
  {
    WindowObjectReference.focus();
  };
}
	
	function clickclear(thisfield, defaulttext) {
		if (thisfield.value == defaulttext) {
			thisfield.value = "";
		}
	}
	
	function clickrecall(thisfield, defaulttext) {
		if (thisfield.value == "") {
			thisfield.value = defaulttext;
		}
	}
	
	var faktura_imie = "";
	var faktura_nazwisko = "";
	var faktura_ulica = "";
	var faktura_mieszkanie = "";
	var faktura_dom = "";
	var faktura_kod = "";
	var faktura_miejscowosc = "";
	
	function InitSaveVariables(form) {
	faktura_imie = form.faktura_imie.value;
	faktura_nazwisko = form.faktura_nazwisko.value;
	faktura_ulica = form.faktura_ulica.value;
	faktura_mieszkanie = form.faktura_mieszkanie.value;
	faktura_dom = form.faktura_dom.value;
	faktura_kod = form.faktura_kod.value;
	faktura_miejscowosc = form.miejscowosc.value;
	}
	
	function ShipToBillPerson(form) {
	if (form.copy.checked) {
	InitSaveVariables(form);
	form.faktura_imie.value = form.imie.value;
	form.faktura_nazwisko.value = form.nazwisko.value;
	form.faktura_ulica.value = form.ulica.value;
	form.faktura_mieszkanie.value = form.mieszkanie.value;
	form.faktura_dom.value = form.dom.value;
	form.faktura_kod.value = form.kod.value;
	form.faktura_miejscowosc.value = form.miejscowosc.value;
	
	} else {
	form.faktura_imie.value = faktura_imie;
	form.faktura_nazwisko.value = faktura_nazwisko;
	form.faktura_ulica.value = faktura_ulica;
	form.faktura_mieszkanie.value = faktura_mieszkanie;
	form.faktura_dom.value = faktura_dom;
	form.faktura_kod.value = faktura_kod;
	form.faktura_miejscowosc.value = faktura_miejscowosc;
	}
	}
	//  End -->
	
	/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

/* Function called to get the product categories list */
function getProducts(rozmiar, prod, targetDiv, szczegoly){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/

	
	
	http.open('get', '/parametry/?rozmiar=' 
			+rozmiar+'&prod='+prod+'&targetDiv='+targetDiv+'&szczegoly='+szczegoly);

	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
		var obj = document.getElementById(targetDiv);
	http.onreadystatechange = function() {
		if(http.readyState == 4){ //Finished loading the response
			/* We have got the response from the server-side script,
				let's see just what it was. using the responseText property of 
				the XMLHttpRequest object. */
			var response = http.responseText;
			/* And now we want to change the product_categories <div> content.
				we do this using an ability to get/change the content of a page element 
				that we can find: innerHTML. */
			obj.innerHTML = response;
		}
	}
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

function spraw() {
	if (document.f1.s1.value==0) {
		alert("Wybierz sposób platnosci");
		return false;
	} else {
		return true;
	}
}

	

function openRequestedPopup3()
{
 WindowObjectReference = window.open("przypominacz.php",
       "DescriptiveWindowName",
       "resizable=yes,scrollbars=yes,status=yes,width=400,height=300");
}

function ajax_pobierz_kolory(id, miejsce) {
	var rozmiar = document.getElementById('rozmiary_id_'+id).value;
	if (rozmiar == 0) {
		document.getElementById('kolory_div_id_'+id).innerHTML = '';
		document.getElementById('submit_button_id_'+id).onclick = kolorICena;
		return;
	}
	//var id = document.getElementById('produkty_id').value;

	var strURL = '/ext/rozmiary_kolory/kolory/'+id+'/'+rozmiar+'/'+miejsce;

	http.open('POST', strURL);

	http.setRequestHeader("Method", "POST " + strURL + " HTTP/1.1");
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

	http.onreadystatechange = function() {
		if(http.readyState == 4){ //Finished loading the response
			var response = http.responseText;
			document.getElementById('kolory_div_id_'+id).innerHTML = response;
			document.getElementById('submit_button_id_'+id).onclick = function () {
				document.getElementById('koszyk_id_'+id).submit();
			}
		}
	}
	
	http.send(null);
}

function kolorICena() {
	alert("Najpierw wybierz rozmiar i kolor");
}
