function start() {
	//start	
	if(typeof uploadOn=='function'&&$('main_photo_uploaded')) uploadOn();
	if($('aparat')) {
		$('counterAparat').innerHTML = (25 - $('aparat').value.length);
		$('aparat').onkeyup = aparatMaxLength;
	}
	if($('opis')) {
		$('counterOpis').innerHTML = (45 - $('opis').value.length);
		$('opis').onkeyup = opisMaxLength;
	}
	if($('komentarz_text')) {
		$('counterKomentarz').innerHTML = (400 - $('komentarz_text').value.length);
		$('komentarz_text').onkeyup = komentarzMaxLength;
	}
	if($('topmenu_expanded_new')) {
		
		$('wep_button1').observe('mouseover',topmenuOver);
		$('wep_button1').observe('mouseout',topmenuOut);

		$('topmenu_expanded_new').observe('mouseover',topmenuOver);
		$('topmenu_expanded_new').observe('mouseout',topmenuOut);
		//$('topmenu_expanded')
	}
}
window.onload = start;

function test(text) {
	window.console.log(text);
}

//top menu - pokazywanie 
var peTM = new PeriodicalExecuter(hideSubMenu, 2);
peTM.stop();
function topmenuOver() {
	peTM.stop();
	showSubMenu();
}
function topmenuOut() {
	peTM = new PeriodicalExecuter(hideSubMenu, 2);
}
function hideSubMenu() {
	$('topmenu_expanded_new').hide();	
}
function showSubMenu() {
	$('topmenu_expanded_new').show();	
}
//top menu - koniec
window.onload = start;


//top menu - pokazywanie 
var peTM = new PeriodicalExecuter(hideSubMenu, 2.5);
peTM.stop();
function topmenuOver() {
	peTM.stop();
	showSubMenu();
}
function topmenuOut() {
	peTM = new PeriodicalExecuter(hideSubMenu, 2.5);
}
function hideSubMenu() {
	$('topmenu_expanded_new').hide();	
}
function showSubMenu() {
	$('topmenu_expanded_new').show();	
}
//top menu - koniec



function setText(x,myText) {
	if(document.getElementById(x).value=="") document.getElementById(x).value=myText;
	}
function czyscText(x,myText) {
	if(document.getElementById(x).value==document.getElementById(x).defaultValue) document.getElementById(x).value="";
	}

function formSetText(oTextInput) {
	if(oTextInput.value=='') oTextInput.value = oTextInput.defaultValue;
}
function formDelText(oTextInput) {
	if(oTextInput.value==oTextInput.defaultValue) oTextInput.value = '';
}

function aparatMaxLength() {
	maxLength($('aparat'),25,$('counterAparat'));
}
function opisMaxLength() {
	maxLength($('opis'),45,$('counterOpis'));
}
function komentarzMaxLength() {
	maxLength($('komentarz_text'),400,$('counterKomentarz'));
}

function maxLength(oInput,limit,oCounter) {
	//usuwamy znaki, których nie chcemy oraz zmniejszamy 
	if (oInput.value.length>limit) {
		oInput.value = oInput.value.substring(0,limit);
	}
	else oCounter.innerHTML = (limit - oInput.value.length);
}

function pokaz_chmurke(ch_id) {
	$('status_chmurka_'+ch_id).show();
}

function schowaj_chmurke(ch_id) {
	$('status_chmurka_'+ch_id).hide();
}

function checkFormKomentarz(oMyForm) {
	if(oMyForm.komentarz_text.value==''||oMyForm.komentarz_text.value=='wpisz swój komentarz...') {
		alert('Komentarz nie zawiera tekstu, wpisz tekst.');
		return false;
	}
	return true;
}

var okno = null;
function window_open(page,PosX,PosY,width,height)
{
  borderless = false;
  
  if(okno != null && !document.layers)
  {
    okno.close();
  }
  if(borderless && !document.layers)
  {
	okno = window.open(page, "", "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=0");
	okno.resizeTo(w, s);
	okno.moveTo(PosX, PosY);
  }
  else
  {
	okno = window.open(page, "", "menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=" + width + ", height=" + height + ", left=" + PosX + ", top=" + PosY);
  }
  okno.focus();
  okno = null;
}
function window_open_scroll(page,PosX,PosY,width,height)
{
  borderless = false;
  
  if(okno != null && !document.layers)
  {
    okno.close();
  }
  if(borderless && !document.layers)
  {
	okno = window.open(page, "", "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=0");
	okno.resizeTo(w, s);
	okno.moveTo(PosX, PosY);
  }
  else
  {
	okno = window.open(page, "", "menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=" + width + ", height=" + height + ", left=" + PosX + ", top=" + PosY);
  }
  okno.focus()
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function selectedRadioValue(oForm, sRadioName) {
	var retval = '';
	for(var i=0;i<oForm.elements.length;i++) {
		if(oForm.elements[i].type!='radio'||oForm.elements[i].name!=sRadioName) continue;
		if(oForm.elements[i].checked) retval = oForm.elements[i].value;
	}
	return retval;
}

function isEmail(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return(reg.test(address));
}
function chImg(id,fn) {
	$(id).src=fn;
}
