/**************************************************
 * Funkcje JavaScrip - walidacja pol.			     *
 **************************************************
 */

/***********************************************************/
/* Funkcja sprawdza czy dany string jest emailem           */
/***********************************************************/
function CheckEmail(x) { return /^[a-z][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/i.test(x) }

/***********************************************************/
/* Funkcja sprawdza czy dany string nie jest pusty         */
/* lub nie zawiera samych pustych znakow                   */
/***********************************************************/
function CheckString(s) { return !(/^\s*$/i.test(s)) }

/***********************************************************/
/* Funkcja sprawdza czy dany string jest numerem           */
/* telefonu lub fax'u                                      */
/***********************************************************/
function CheckNumberPF(y) { return /^[.w0-9)(\-+\/]+$/i.test(s) }

/***********************************************************/
/* Funkcja sprawdza czy dany string jest liczba calkownita */
/***********************************************************/
//function CheckInteger(y) { return /^\d*$/i.test(y); }
function CheckInteger(x){return~~x==x}

/***********************************************************/
/* Funkcja sprawdza czy dany string jest liczba rzeczywista*/
/***********************************************************/
function CheckFloat(y) { return /^\d+(\.|,)?\d*$/i.test(s); }

/***********************************************************/
/* Funkcja sprawdza czy dany string jest nazwa pliku       */
/* moze zawierac tylko znaki 0-9a-zA-Z.-_
/***********************************************************/
function CheckFileName(y) { return /^[A-Za-z0-9_\-.]+$/i.test(s); }

/***********************************************************/
/* Funkcja sprawdza czy podane parametry tworza            */
/* poprawna date                                           */
/***********************************************************/

function isDateCorrect(iYear, iMonth, iDay)
{
	var isLeapYear = false;
	var iDays;
	// rok, miesiac i dzien musza byc liczbami calkowitymi
	if (!CheckInteger(iYear) || !CheckInteger(iMonth) || !CheckInteger(iDay)) return false;
	// miesiac tylko z przedzialu <1, 12>
	if (iMonth < 1 || iMonth > 12) return false;
	// dzien tylko z przedzialu <1, 31>
	if (iDay < 1 || iDay > 31) return false;
	// cz rok przestepny
	if (CheckInteger(iYear/4) || CheckInteger(iYear/100) || CheckInteger(iYear/400)) isLeapYear = true;

	switch (iMonth) {
		case 1: case 3: case 5: case 7: case 8: case 10: case 12:
			iDays = 31;
		break;
		case 4: case 6: case 9: case 11:
			iDays = 30;
		break;
		case 2:
			if (isLeapYear) iDays = 29; else iDays = 28;
		break;
	}
	return (iDay >= 1 && iDay <= iDays)
}

/* Funkcja sprwdza poprawnosci numeru NIP */
function CheckNip(x)
{
	sNip = new String(x);
	// sprawdzenie czy format NIP-u to 123-123-12-12
	if (!(/^[0-9]{3}-[0-9]{3}-[0-9]{2}-[0-9]{2}$/.text(x))) return false;
	// pozostawienie tylko cyferek (usuniecie minusow)
	sNip = sNip.replace(/-/g, '');
	// tablica wag dla NIP-u
	steps = new Array(6, 5, 7, 2, 3, 4, 5, 6, 7);
	// liczenie sumu kontrolnej
	suma = 0;
	for (i = 0; i < 9; i++) suma += steps[i] * sNip.charAt(i);
	last = suma % 11;
	return (last == sNip.charAt(9));
}

/* Funkcja sprwdza poprawnosci numeru REGON */
function CheckRegon(x)
{
	sREGON = new String(x);
	// sprawdzenie czy format REGON-u to 123-123-12-12
	if (!(/^[0-9]{3}-[0-9]{3}-[0-9]{3}$/.text(x))) return false;
	steps = new Array(8, 9, 2, 3, 4, 5, 6, 7);
	sNip.value.replace(/[^0-9]/, '');
	if (sREGON.length != 9) return false;
	suma = 0;
	for (i = 0; i < 8; i++) suma+= steps[i] * sREGON.charAt(i);
	last = suma % 11;
	if (last == 10) last = 0;
	return (last==sREGON.charAt(8));
}

function isRadioChecked(obj)
{
	// set var radio_choice to false
	var radio_choice = false;
	// Loop from zero to the one minus the number of radio button selections
	if (obj.length)
	{
		for (i = 0; i < obj.length; i++) { if (obj[i].checked) return true; }
	} else { return obj.checked; }
	return false;
}

function resize() 
{
	/*if($('menu1').clientHeight < 418) {
		//$('menu1').style.height = $('menuses3').clientHeight - 264 +'px';
	}*/
	//alert($('content').clientHeight);
	var sumaC = $('content1').clientHeight + $('content2').clientHeight + $('content3').clientHeight;

	var sumaM = $('menuses2').clientHeight + $('menuses3').clientHeight + $('menuses5').clientHeight;	

	var boxy = $('boxy').clientHeight;

	

	if ($('content').clientHeight < sumaM) {
		$('content2').style.height = $('content2').clientHeight + $('menu1').clientHeight - $('content').clientHeight + 'px';
	} else {
		$('menuses3').style.height = $('content').clientHeight - $('menuses2').clientHeight - $('menuses5').clientHeight + 'px';
	}


	if($('aktualnosci1')) {
		if (sumaC < boxy - $('aktualnosci1').clientHeight)
		{
			$('content2').style.height = boxy - $('aktualnosci1').clientHeight - $('aktualnosci22').clientHeight + $('content2').clientHeight  + 'px';
			
			$('menuses3').style.height = $('content').clientHeight - $('menuses2').clientHeight - $('menuses5').clientHeight + 'px';
		}
	}

}

function resizeR() {
	setTimeout('resize()',3000);
}

function resizeCala() {
	if($('menu1').clientHeight < 418) {
		$('menu1').style.height = 418+'px';
		//alert("menu1 = 418");
	}
	
	var sumaC = $('content1').clientHeight + $('content2').clientHeight + $('content3').clientHeight;

	var sumaM = $('menuses2').clientHeight + $('menuses3').clientHeight + $('menuses5').clientHeight;	

	
	if (sumaC < sumaM) {
		$('content2').style.height = $('menu1').clientHeight - $('content1').clientHeight - $('content3').clientHeight + 'px';
	} else {
		$('menuses3').style.height = $('content').clientHeight - $('menuses2').clientHeight - $('menuses5').clientHeight + 'px';
	}
}


