var $selected=new Boolean();
var $przerwa=new Number();
var $clockcounter=new Number();
var $imgnumber=new Number();
var $event=new Object();

function getEventSrc() {
	if ($event==null) {
		//ms
		alert("im here");
		$event=window.event;
		alert($event.srcElement);
		return(event.srcElement);
		} else {
		//other
		return($event.target);
		}
	}

function change($stropis) {
$dst=document.getElementById("bigpic");
$dstpodpis=document.getElementById("galtitle");
$src=getEventSrc();
if (!$src) {
	$src=event.srcElement;
	}
$tmpimg=document.createElement("IMG");
if ($dstpodpis!==null && $dst!==null) {
	$oldpic=$dst.firstChild;
	while($oldpic!=null && $oldpic.tagName!="IMG") {
		$oldpic=$oldpic.nextSibling;
		}
	$ow=$oldpic.clientWidth;
	$oh=$oldpic.clientHeight;
	$prop=$ow/$oh;
	if ($prop>=1) {
		$newprop=120/$ow;
		} else {
		$newprop=120/$oh;
		}
	if ($oldpic!=null) {
		$oldpic.onclick=function() {change(this.alt);};
		$oldpic.width=$ow*$newprop;
		$oldpic.height=$oh*$newprop;
		}
	}
if($src!=null) {
	$sw=$src.clientWidth;
	$sh=$src.clientHeight;
	$prop=$sw/$sh;
	$dstpodpis.innerHTML="<b>"+$stropis+"</b>";
	if ($prop>=1) {
		$newprop=240/$sw;
		} else {
		$newprop=240/$sh;
		}
	$src.width=$sw*$newprop;
	$src.height=$sh*$newprop;
	$srcd=$src.parentNode;
	$src.onclick=function() {showsrc();};
	while($srcd!=null && $srcd.tagName!="DIV") {
		$srcd=$srcd.parentNode;
		}
	}
if ($srcd!=null) {
	$tmpimg=$oldpic;
	$dst.replaceChild($src,$oldpic);
	$srcd.appendChild($tmpimg);
	}
}


function changeclock() {
window.clearInterval($przerwa);
$tmpStr=new String();
$dt=new Date();
$t=document.getElementById("timer");
if ($t!=null) {
	$h=$dt.getHours();
	if ($h<10) {
		$tmpStr="0"+$h;
		} else {
		$tmpStr=$h;
		}
	$h=$dt.getMinutes();
	if ($h<10) {
		$tmpStr+=":0"+$h;
		} else {
		$tmpStr+=":"+$h;
		}
	$h=$dt.getSeconds();
	if ($h<10) {
		$tmpStr+=":0"+$h;
		} else {
		$tmpStr+=":"+$h;
		}
	$t.innerText=$tmpStr;
	$clockcounter++;
/*	if ($clockcounter==5) {
		changeimage();
		$clockcounter=0;
		}
*/
	$przerwa=window.setInterval("changeclock()",1000);
	}
}

function checkenter() {
$src=getEventSrc();
if (!$src) {
	$src=event.srcElement;
	}
if ($src!=null) {
	if (event.keyCode==13) {
		$strTmp=cleartext($src.value);
		if ($strTmp.length==0) {
			event.returnValue=false;
			}
		}
	}
}

function checkforum() {
$bAnswer=new Boolean(false);
$strAnswer=new String("");
$strTmp=new String("");
$l=new Number(0);
$f=document.getElementById("forumform");
if ($f!=null) {
	$strTmp=cleartext($f.podpis.value);
	if ($strTmp.length>0) {
		$bAnswer=true;
		} else {
		$bAnswer=false;
		alert("nie uwzgl&#x119;dniamy wpis&#x00F3;w anonimowych");
		return(false);
		}
	$strTmp=cleartext($f.temat.value);
	if ($strTmp.length>0) {
		$bAnswer=true;
		} else {
		$bAnswer=false;
		alert("temat forum powinien zaistnie&#x107");
		return(false);
		}
	$strTmp=cleartext($f.tresc.value);
	if ($strTmp.length>0) {
		$bAnswer=true;
		} else {
		$bAnswer=false;
  		alert("jaka&#x15B; tre&#x15B;&#x107; nie by&#x142;aby wskazana?");
		return(false);
		}
	if ($f.priv.value=="true") {
		//forum prywatne
		$bAnswer=false;
		$strTmp=cleartext($f.alias.value);
		if ($strTmp.length>0) {
			$bAnswer=true;
			} else {
			$bAnswer=false;
  			alert("je&#x17C;eli chcesz za&#x142;o&#x17C;y&#x107; prywatne forum podaj u&#x17C;ytkownika");
			return(false);
			}
		$strTmp=cleartext($f.pwd[0].value);
		if ($strTmp.length>0) {
			if ($f.newuser.checked==true) {
				if ($strTmp!=$f.pwd[1].value) {
					$bAnswer=false;
	  				alert("b&#x142;&#x119;dnie potwierdzi&#x142;e&#x15B; has&#x142;o");
					return(false);
					} else {
					//hasla ok
					$strTmp=cleartext($f.imie.value);
					if ($strTmp.length>0) {
						$strTmp=cleartext($f.nazwisko.value);
						if ($strTmp.length>0) {
							$strTmp=cleartext($f.email.value);
							if ($strTmp.length>0) {
								if ($strTmp.indexOf("@")<=0) {
									$bAnswer=false;
					  				alert("fa&#x142;szywy email?");
									return(false);
									} else {
									if ($strTmp.indexOf(",")>=0) {
										$bAnswer=false;
						  				alert("fa&#x142;szywy email?");
										return(false);
										} else {
										$bAnswer=true;
										}
									}
								} else {
								$bAnswer=false;
				  				alert("podaj email do kontaktu z Tob&#x105;");
								return(false);								
								}
							} else {
							$bAnswer=false;
			  				alert("podaj nazwisko je&#x15B;li chcesz si&#x119; zarejestrowa&#x107");
							return(false);
							}
						} else {
						$bAnswer=false;
		  				alert("podaj imie je&#x15B;li chcesz si&#x119; zarejestrowa&#x107");
						return(false);
						}
					}
				} else {
				$bAnswer=true;
				}
			} else {
			$bAnswer=false;
  			alert("podaj has&#x142;o istniej&#x105;cego u&#x17C;ytkownika");
			return(false);
			}
		$strTmp=cleartext($f.pwdprotect[0].value);
		if ($strTmp.length>0) {
			if ($strTmp==$f.pwdprotect[1].value) {
				$bAnswer=true;
				} else {
				$bAnswer=false;
  				alert("has&#x142;o dost&#x119;pu b&#x142;&#x119;dnie potwierdzone");
				return(false);
				}
			} else {
			$bAnswer=false;
  			alert("je&#x17C;eli chcesz za&#x142;o&#x17C;y&#x107 prywatne forum has&#x142;o dost&#x119;pu do niego");
			return(false);
			}
		
		}
	if ($bAnswer==true) {
		$f.submit();
		}
	} else {
	$strAnswer="wyst&#x105;pi&#x142; nieprzewidziany b&#x142;&#x105;d - od&#x15B;wie&#x17C; stron&#x119;";
	alert($strAnswer);
	return(false);
	}
}

function cleartext($strInput) {
var $strAnswer=new String("");
$strTmp=$strInput;
$l=0;
do {
   $strTmp=$strTmp.replace(" ","");
   if ($l==$strTmp.length) {
   	break;
   	}
   $l=$strTmp.length;
   } while ($l>0);
$strAnswer=$strTmp;   
return($strAnswer);
}

function login() {
$lb=document.getElementById("lblbtn");
if (document.forms[document.forms.length-1].alias.value.length>0) {
	$d=document.getElementById('username');
/*	alert("key="+event.keyCode);
	alert("litera="+String.fromCharCode(event.keyCode));*/
	$letter=String.fromCharCode(event.keyCode);
	if ($d!=null) {
		if (event.keyCode==13) {
			$strText=cleartext(document.forms[document.forms.length-1].pwd.value);
			if ($strText.length>0) {
				document.forms[document.forms.length-1].pwd.value=$strText;
				document.forms[document.forms.length-1].submit();
				} else {
				document.forms[document.forms.length-1].reset();
				$lb.innerText="podaj nazw&#x119; u&#x17C;ytkownika";
				$d.value="";
				}
			} else {
			document.forms[document.forms.length-1].pwd.value=document.forms[document.forms.length-1].pwd.value+$letter;
			$d.style.color=$d.style.backgroudColor;
			event.cancelBubble=true;
			event.keyCode=42;
/*
			$d.value="";
			for ($i=0;$i<document.forms[document.forms.length-1].pwd.value.length;$i++) {
				$d.value=$d.value+"*";
				}
*/				
			}
		}
	} else {
	$d=document.getElementById('username');
	if ($d!=null) {
		if (event.keyCode==13) {
			$strText=cleartext($d.value);
			if ($strText.length>0) {
				document.forms[document.forms.length-1].alias.value=$strText;
				$lb.innerText="podaj has&#x142;o";
				$d.value="";
				}
			}
		}
	}
}

function showsrc() {
$src=getEventSrc();
if (!$src) {
	$src=event.srcElement;
	}
if ($src!==null) {
	if ($src.tagName=="DIV") {
		$im=$src.firstChild;
		while($im!==null && $im.tagName!="IMG") {
			$im=$im.nextSibling;
			}
		} else {
		$im=$src;
		}
	if ($im!=null && $im.tagName=="IMG") {
		$nameArr=$im.src.split("/");
		viewIt("img/"+$nameArr[$nameArr.length-1],1,0);
		}
	}
}

function viewIt($filename,$poziomo,$max) {
	$o=null;
	if ($filename.length>0) {
		if ($poziomo==1) {
			$t=document.images[0].offsetTop+50;
			$l=((window.document.body.offsetWidth-640)/2)-50;
			$o=window.open("srcs/picViewer.php?pic="+$filename+"","imgviewer","statusbar=no,toolbar=no,menubar=no,personalbar=no,scrollbars=yes,left="+$l+",top="+$t+",width=750,height=600");
			} else {
			if ($max==1) {
				$t=0;
				$l=0;
				$o=window.open("srcs/picViewer.php?pic="+$filename+"","imgviewer","statusbar=no,toolbar=no,menubar=no,personalbar=no,scrollbars=yes,left="+$l+",top="+$t+",width="+screen.availWidth+",height="+screen.availHeight+"");
				} else {
				$t=document.images[0].offsetTop+75;
				$l=((window.document.body.offsetWidth-420)/2)-75;
				$o=window.open("srcs/picViewer.php?pic="+$filename+"","imgviewer","statusbar=no,toolbar=no,menubar=no,personalbar=no,scrollbars=yes,left="+$l+",top="+$t+",width=640,height=600");
				}
			}
		if ($o!=null) {
			$o.focus();
			}
		}
	event.cancelBubble=true;
	}


