var ADVERT_ADDLAYOUT = 2;
var ADVERT_ADDSHOWEMPLOYERLINK = 4;

function eventAdd(el, evname, func) {
	nav = new navi();
	if (nav.ie4) {
		return el.attachEvent("on" + evname, func);
	} else {
		return el.addEventListener(evname, func, true);
	}
}

function checkEmptySearch(frm, defkey) {
	var err = (
		(frm['key'] && (frm['key'].value == '' || frm['key'].value == defkey))
		&&
		(frm['brn[]'] && frm['brn[]'].selectedIndex < 0)
		&&
		(frm['jct[]'] && frm['jct[]'].selectedIndex < 0)
		&&
		(frm['lrg[]'] && frm['lrg[]'].selectedIndex < 0)
	);
	if (!err && frm['key'].value == defkey)
		frm['key'].value = '';
	return !err;
}

function createEmployerAdsLink() {
	obj = this.document.getElementById('showemployerads');
	
	if (!obj) {
		obj = this.document.createElement('div');
		obj.id = 'showemployerads';
		obj.style.position = 'absolute';
		obj.style.top = this.innerHeight;
		obj.style.left = 0;
		obj.style.width = '100%';
		obj.style.height = 40;
		obj.style.border = "1px solid red";
		if (!this.oldHeight) {
			this.oldHeight = this.innerHeight;
			this.innerHeight += 40;
		}
		this.document.body.appendChild(obj);
	}
	obj.innerHTML = '<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td>ddSDFSDFS</td></tr></table>';
}

function showAdvert(id) {
	var wnd = window.open('ofertypracy,pl,' + id + '.html', 'ad_' + id, 'width=780,height=' + (screen.height - 120) + ',screenX=' + ((screen.width - 780) / 2) + ',screenY=10,left=' + ((screen.width - 780) / 2) + ',top=10,location=1,resizable=1,scrollbars=0');
	wnd.focus();
}

function showEmployer(id) {
	if (top.opener)
		wnd = top.opener;
	else
		wnd = top;
	if (wnd)
		wnd = wnd.open('praca,pl,' + id + '.html');
}

function toBriefcase(id) {
	if (top.opener)
		wnd = top.opener;
	else
		wnd = top;
	if (wnd)
		wnd = wnd.open('mojaaktowka,pl,' + id + '.html');
}

function sendApplication(id) {
	if (top.opener)
		wnd = top.opener;
	else
		wnd = top;
	if (wnd)
		wnd = wnd.open('aplikuj,pl,' + id + '.html');
}

function changeResCount(num) {
	if (document.forms.results && document.forms.results.cnt) {
		document.forms.results.cnt.value = parseInt(num);
		document.forms.results.submit();
	}
}

function changePage(num) {
	if (document.forms.results && document.forms.results.ofs) {
		document.forms.results.ofs.value = parseInt(num);
		document.forms.results.submit();
	}
}

function validatePage(num) {
	num = parseInt(num);
	num = Math.max(1, num);
	num = Math.min(pageMax, num);
	return num;
}

function validateAndChangePage(evt, obj) {
	if (window.event)
		evt = window.event;
	if (typeof(evt) == 'undefined')
		return false;
	var key;
	if (evt.keyCode) {
		key = evt.keyCode;
	} else if(evt.which) {
		key = evt.which;
	} else if(evt.charCode) {
		key = evt.charCode;
	} else {
		return false;
	}
	if (key == 13) {
		changePage((validatePage(obj.value) - 1) * pageCnt + 1);
		return false;		
	} else {
		return true;
	}
}

function initWindow() {
	top.document.title = window.document.title;
	if (typeof(localInitWindow) == 'function')
		localInitWindow();
}
