// ----------------------------------------------------------------------
// Javascript form validation routines.
// Author: Stephen Poley
// Modified: Rafał Turowicz (Sep 2006)
//
// Simple routines to quickly pick up obvious typos.
// All validation routines return true if executed by an older browser:
// in this case validation must be left to the server.
//
// Update Jun 2005: discovered that reason IE wasn't setting focus was
// due to an IE timing bug. Added 0.1 sec delay to fix.
//
// Update Oct 2005: minor tidy-up: unused parameter removed
//
// Update Jun 2006: minor improvements to variable names and layout
// ----------------------------------------------------------------------

var nbsp = 160;		// non-breaking space char
var node_text = 3;	// DOM text node-type
var emptyString = /^\s*$/ ;
var global_valfield;	// retain valfield for timer thread

function trim(str) {
  return str.replace(/^\s+|\s+$/g, '');
}

function setFocusDelayed() {
  global_valfield.focus();
}

function setfocus(valfield) {
  global_valfield = valfield;
  setTimeout( 'setFocusDelayed()', 100 );
}

function commonCheck(valfield, required) {
  if (!document.getElementById) 
	  return true;
  
  if (emptyString.test(valfield.value)) {
	  if (required) {
		  setfocus(valfield);
		  return false;
	  }
	  else {
		  return true;  
	  }
  }
  
  return true;
}

function toggleLayer(whichLayer, info) {
	if (document.getElementById) {  // this is the way the standards work
		var style2 = document.getElementById(whichLayer);
		style2.innerHTML = info;
	}
	else if (document.all) {  // this is the way old msie versions work
		var style2 = document.all[whichLayer];
		style2.innerHTML = info;
	}
	else if (document.layers) {  // this is the way nn4 works
		var style2 = document.layers[whichLayer];
		style2.innerHTML = info;
	}
}


//
// valfield - pole do sprawdzenia
//
function validatePresent(valfield) {
	return commonCheck(valfield, true);
}

function wybierz(formularz, valfield, idM) {
	formularz.frm_miasto_gdzie.value = valfield.options[valfield.selectedIndex].value;
	formularz.frm_miasto_id.value = idM;
	toggleLayer('miastoPanel', formularz.frm_miasto_gdzie.value);	
}

function sprawdzMiasta(valfield) {
	if (valfield.frm_miasto_gdzie.value != "" && valfield.frm_miasto_gdzie.value != "-") {
		return true;
	}
	else {
		alert('Proszę wybrać sklep!!');
		return false;
	}
}


$(document).ready(function() {
	$('a.media').media({ width: 468, height: 62, autoplay: true });
});

