
function parseqs () {
	var t, t2, r, key, val, qs, a, i;
	qs = String(document.location.search).substring(1);
	a = new Array();
	r = /[&;]/;
	t = qs.split(r);
	for (i = 0; i < t.length; i++) {
		t2 = t[i].split('=');
		key = String(unescape(t2[0]));
		val = String(unescape(t2[1]));
		a[key] = val;
	};
	return (a);
};

function reloadOpener () {
	window.opener.history.go(0);
};

function submitForm (formName) {
	formName.submit();
	return true;
};

function setReferrer(form, urlname) {
	var qs = parseqs();
	var url = String(qs['url']);
	if (url == 'undefined') {
		url = String(document.referrer);
	};
	if (url != 'undefined' && url.length > 1) {
		var i = eval('form.'+ urlname);
		i.value = url;
	};
	return true;
};

function redirectOpener (newaction, newurl) {
	var w = window.opener.document.forms['redirect'];
	w.action = newaction;
	w.url.value = unescape(newurl);
	w.submit();
	return true;
};

function openWindow (wid, hei, url, window_name) {
	var newurl = '/h/pl/redir.html?url='+ escape(url);
    if ( ! window_name ) {
        window_name = "smallwindow";
    }
	window.open(newurl, "smallwindow", "toolbar=no,directories=no,width="+ wid +",height="+ hei +",status=no,scrollbars=yes,resizable=yes,menubar=no,dependent=yes,hotkeys=no");
};

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie (name) {
	var cs = document.cookie.indexOf(name + "=");
	if (cs == -1) return null;
	cs = document.cookie.indexOf("=", cs) + 1;
	var ce = document.cookie.indexOf(";", cs);
	if (ce == -1) ce = document.cookie.length;
	return unescape(document.cookie.substring(cs, ce));
};

function findInCookie (name, needle, search) {
	var inCookie = -1;
	var cookie = name;
	if (search) cookie = getCookie(name);
	if (cookie) {
		inCookie = cookie.indexOf(needle);
	};
	return ((inCookie >= 0) ? true : false);
};

function sonda (set) {
	if (findInCookie('oVoVote', set, 1)) {
		writeResults();
	} else {
		writeSonda(set);
	};
	return true;
};

function poll (id, resultshtml, formhtml) {
	if (findInCookie('oVoPoll', id, 1)) {
		writeEscStr(resultshtml);
	} else {
		writeEscStr(formhtml);
	};
	return true;
};

function writeEscStr (t) {
	var to = '';
	for (var i = 0; i < t.length; i++) {
		if (t.charAt(i) == '%') { to += unescape(t.substr(i,3)); i += 2;
		} else { to += t.charAt(i); };
	};
	document.write(to);
	return true;
};

function picUploadWin (img) {
	return '<html><head><script>function onClose() { setTimeout("winClose()", 3000); }; function winClose() { window.close(); };</script></head><body onLoad="onClose(); style="background-color: #FFF;""><div style="width:100%;height:100%;background-image:url(' + img +') no-repeat;"><div style="position: absolute; top: 40%; left: 0%; height: 25%; width: 100%; text-align: center; line-height: 0;"><img src="/images/loading.gif"></div></div></body></html>';
};

function voteOnPoll (id, wid, hei) {
	var oVoPoll = getCookie('oVoPoll');
	if (findInCookie(oVoPoll, id)) {
		voteWindow(350,280,'/errors/voteagain.html');
	} else {
		voteWindow(wid, hei);
		return true;
	};
	return false;
};

function hashform() {
	var fi,fo,f,args = hashform.arguments;
	f = args[0];
	for (var i = 1; i < args.length; i+=2) {
		fi = eval("f."+ args[i]);
		fo = eval("f."+ args[i+1]);
		fo.value = hex_md5(hex_md5(fi.value));
		fi.disabled = 1;
	};
	f.ismd5.value = 1;
};

function validateForm() { //v3.0
	var d,f,i,fN='',fT='',fV='',errors=0,args=validateForm.arguments;
	errors = (args.length - 1) / 2;
	d = eval("document.forms['"+ args[0] +"']");
	for (i = 1; i < args.length; i += 2) {
		fN = args[i];
		fT = args[i+1];
		f = eval ('d.'+ fN);
		switch (fT) {
			case 'radio':
			case 'check':
				fN = f.length;
				if (!fN || fN == 'undefined') {
					if (f.checked == true) errors--;
				} else {
					for (j = 0; j < fN; j++) {
						if (f[j].checked == true) errors--;
					};
				};
				break;
			case 'select':
			case 'multi':
				if (f.selectedIndex >= 0) errors--;
				break;
			case 'text':
			case 'area':
				fV = String(f.value);
				if (fV != '' && fV != 'undefined') errors--;
				break;
		};
	};
	if (errors) {
		alert('Prosimy o wypełnienie wymaganych pól formularza.\nDziękujemy!');
		return false;
	};
	return true;
};

function voteOnSet (set) {
	var oVoVote = getCookie('oVoVote');
	if (findInCookie(oVoVote, set)) {
		voteWindow(350,280,'/errors/voteagain.html');
	} else {
		if (votePoints()) {
//			voteWindow('about:blank');
			voteWindow(350,280);
			return true;
		} else {
			alert("Głosowanie:\nMusisz wybrać ocenę!\n\nDziękujemy\noVo.pl\n");
			return false;
		};
	};
	return false;
};

function voteWindow (wid, hei, url) {
	var newurl = '/h/pl/wait.html';
	if (url) newurl = url;
	window.open(newurl, "results", "toolbar=no,directories=no,width="+ wid +",height="+ hei +",status=no,scrollbars=yes,resizable=yes,menubar=no");
	return true;
};

function shrink (w, h) {
	window.resizeTo(w, h);
	if (window.toolbar) { // NN
		window.toolbar.visible=false;
		window.statusbar.visible=false;
		window.menubar.visible=false;
		window.locationbar.visible=false;
		window.personalbar.visible=false;
	};
};

function votePoints () {
	var d = document.forms['vote'].points;
	return ((d.options[d.selectedIndex].value != '0') ? 1 : 0);
};


function writeResults () {
	var t = '%3Cform onSubmit="return showVotesAV(this)" action="../../../../k/index.html" name="vres" %3E%3Cselect name="z"%3E%3Coption value="1" selected%3E... wyniki ...%3C/option%3E%3Coption value="2" selected%3E... głosy ...%3C/option%3E%3C/select%3E %3Cinput type="Submit" name="Submit" value="zobacz wyniki"%3E%3C/form%3E';
	writeEscStr(t);
	return true;
};

function showVotesAV (f) {
	if (f.z.options[f.z.selectedIndex].value == '2') {
		openWindow(350,180,document.URL.substring(0,document.URL.lastIndexOf('/')) +'/votesrange.html');
		return false;
	};
	return true;
};


function writeSonda (set) {
	var t = '%3Cform action="/i/vote.pl" name="vote" method="post" target="results"  onsubmit="return voteOnSet(%27'+ set +'%27);"%3E%3Cselect name="points"%3E%3Coption value="a"%3Etakie sobie%3C/option%3E%3Coption value="b"%3Emoże być%3C/option%3E%3Coption value="c"%3Edobre%3C/option%3E%3Coption value="d" selected%3Eb. dobre%3C/option%3E%3Coption value="e"%3Eperfekcyjne%3C/option%3E%3C/select%3E%3Cinput type="hidden" name="lang" value="pl"%3E%3Cinput type="hidden" name="set" value="'+ set +'"%3E%3Cinput type="hidden" name="action" value="vote"%3E%3Cinput type="hidden" name="sw" value="1"%3E%26nbsp%3B%3Cinput type="Submit" name="Submit" value="głosuj"%3E%3C/form%3E';
	writeEscStr(t);
	return true;
};

function setElemProperty(f, ename, prop, val) {
	var fl = f.length;
	for (var i = 0; i < fl; i++) {
		if (f.elements[i].name == ename) {
			eval("f.elements["+ i +"]."+ prop +" = "+ val);
		};
	};
	return true;
};

function simGalEdit(f) {
	var fl = f.length;
	var cc = 0;
	for (var i = 0; i < fl; i++) {
		if (f.elements[i].name == 'pics' && f.elements[i].checked == true) {
			if (cc & 1) {
				cc |= 2;
			} else {
				cc |= 1;
			};
		};
		if (f.elements[i].name == 'pgac' && f.elements[i].type == 'radio' && f.elements[i].checked == true) {
			 if (f.elements[i].value == 'seticon') {
				cc |= 4;
			} else {
				cc |= 8;
			};
		};
	};
	if (cc == 5 || cc == 9 || cc == 11) {
		voteWindow(350,280);
		return true;
	} else {
		var msg = "Galeria:\n";
		if (cc == 7) {
			msg += " - możesz wybrać dokładnie jedno zdjęcie jako ikonę!\n";
		} else if (!(cc & 1)) {
			msg += " - musisz wybrać zdjęcie!\n";
		};
		if (!(cc & 4) && !(cc & 8)) {
			msg += " - musisz wybrać akcję!\n";
		};
		msg += "\nDziękujemy\noVo.pl\n";
		alert(msg);
		return false;
	};
};

function simPMEdit(f) {
	var fl = f.length;
	var cc = 0;
	for (var i = 0; i < fl; i++) {
		if (f.elements[i].name == 'msgs' && f.elements[i].checked == true) {
			cc |= 1;
		};
	};
	if (cc == 1) {
		return true;
	} else {
		var msg = "Prywatne Wiadomości:\n";
		if (!(cc & 1)) {
			msg += " - musisz wybrać wiadomość!\n";
		};
		msg += "\nDziękujemy\noVo.pl\n";
		alert(msg);
		return false;
	};
};

function setquickcomment(f) {
	if (f.make.options[f.make.selectedIndex].value == 'setqsetwrite') {
		f.target = 'results';
		f.sw.value = 1;
		voteWindow(400,350);
	} else {
		f.target = '_self';
		f.sw.value = 0;
	};
	return true;
};

function pfpichtml (imgsrc, imgw, imgh) {
	return '<html><head><title>oVoCE - Photoforum</title></head><body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" height="16" bgcolor="#666666" style="font-family: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 10px; color: #CCC;">uwaga: zdjęcie podpisane cyfrowo</td></tr><tr><td style="background: url(http://st.ovoce.pl'+imgsrc+') top center no-repeat #666666;" width="'+imgw+'"><img src="http://st.ovoce.pl/_g/zakaz_rozpowszechniania.gif" height="'+imgh+'" width="'+imgw+'"></td></tr></table></body></html>';
};

function pfpic (imgsrc, imgw, imgh) {
	var w = imgw > (screen.width - 40) ? (screen.width - 40) : imgw;
	var h = imgh > (screen.height - 140) ? (screen.height - 140) : imgh;
	var cw = h != imgh ? 20 : 0;
	var ch = w != imgw ? 20 : 0;
	w += cw; h += ch;
	var scroll = cw || ch ? 'yes' : 'no';
	var picWin = window.open('', '', 'height='+h+',width='+w+',toolbar=no,status=no,location=no,directories=no,menubar=no,scrollbars='+scroll+',resizable=no,dependent=yes,hotkeys=no');
	picWin.document.writeln(pfpichtml(imgsrc, imgw, imgh));
	picWin.document.close();
	picWin.focus();
};

function pichtml (imgsrc, imgw, imgh) {
	return '<html><head><title>oVo/oVoCE.pl</title></head><body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><img src="'+imgsrc+'" height="'+imgh+'" width="'+imgw+'"></body></html>';
};

function pic (imgsrc, imgw, imgh) {
	var w = imgw > (screen.width - 40) ? (screen.width - 40) : imgw;
	var h = imgh > (screen.height - 140) ? (screen.height - 140) : imgh;
	var cw = h != imgh ? 50 : 0;
	var ch = w != imgw ? 50 : 0;
	w += cw; h += ch;
	var scroll = cw || ch ? 'yes' : 'no';
	var picWin = window.open('', '', 'height='+h+',width='+w+',toolbar=no,status=no,location=no,directories=no,menubar=no,scrollbars='+scroll+',resizable=yes,dependent=yes,hotkeys=no');
	picWin.document.writeln(pichtml(imgsrc, imgw, imgh));
	picWin.document.close();
	picWin.focus();
};




