function addNewsLetter(){
	if(document.getElementById('newsInput')){
		aInp = document.getElementById('newsInput').value;
		if(aInp.length > 6){
			new Ajax.Updater('newsletter','/connectors/newsletter/addNewsletter.php',{parameters:{inp: aInp}});
		}else{
			alert('Napačni elektronski naslov.');
		}
	}
}
function addJoke(){
	if(document.getElementById('jokeInput')){
		if(document.getElementById('jokeInput').innerHTML.length > 10){
			new Ajax.Updater('joker','/connectors/jokes/saveJoke.php', {parameters: {inp:document.getElementById('jokeInput').innerHTML}});
		}else{
			alert('Vnos je prekratek.');
		}
	}else{
		new Ajax.Updater('joker','/connectors/jokes/addJoke.php');
	}
}
function mainJokes(){
	new Ajax.Updater('joker','/connectors/jokes/viewJoke.php');
}
function onl(){
	if( document.getElementById('chatter')){
		chat = document.getElementById('chatter');
		chat.scrollTop = 750
	}
}
function submitTest(){
	a = document.getElementById('radio_1');
	b = document.getElementById('radio_2');
	c = document.getElementById('radio_3');
	if(a.checked || b.checked || c.checked){
		document.testForm.submit()
	}else{
		alert('Prosim izberi eno od treh možnosti.');
	}
}
function sendMsg(){
	new Ajax.Updater('msgform','/connectors/email/sendMsg.php',
		{
			parameters:{
				f:document.getElementById('from').value,
				t:document.getElementById('to').value,
				m:document.getElementById('msg').innerHTML
			}
		}
	);
}
var tChatter;
function scrollChatter(where){
	chat = document.getElementById('chatter');
	if(where == 'up'){
		chat.scrollTop = chat.scrollTop - 20;
	}
	if(where == 'down'){
		chat.scrollTop = chat.scrollTop + 20;
	}
	tekst="scrollChatter('" + where + "')";
	tChatter = setTimeout(tekst, 50);
}
function scrollChatterStop(){
    clearTimeout(tChatter);
}
var tChatterN;
function scrollContent(where){

	chat2 = document.getElementById('printMe');
	if(where == 'up'){
		chat2.scrollTop = chat2.scrollTop - 20;
	}
	if(where == 'down'){
		chat2.scrollTop = chat2.scrollTop + 20;
	}
	tekstNew="scrollContent('" + where + "')";
	tChatterN = setTimeout(tekstNew, 50);
}
function scrollContentStop(){
	clearTimeout(tChatterN)
}
var tChatterNN;
function scrollMenu(where){

	chat2 = document.getElementById('menuScroll');
	if(where == 'up'){
		chat2.scrollTop = chat2.scrollTop - 20;
	}
	if(where == 'down'){
		chat2.scrollTop = chat2.scrollTop + 20;
	}
	tekstNew="scrollMenu('" + where + "')";
	tChatterNN = setTimeout(tekstNew, 50);
}
function scrollMenuStop(){
	clearTimeout(tChatterNN);
}
function hideKricac(){
	a = document.getElementById('kriHolder');
	if(a){
		if(a.style.display == ''){
			a.style.display = 'none';
			b = 1;
		}else{
			a.style.display = '';
			b = 0;
		}
		new Ajax.Request('/connectors/chatter/openChat.php', {parameters: {kriDi:b}});
	}
}
function hideAnketa(){
	a = document.getElementById('anketa');
	if(a){
		if(a.style.display == ''){
			a.style.display = 'none';
			b = 0;
		}else{
			a.style.display = '';
			b = 1;
		}
		new Ajax.Request('/connectors/chatter/openAnketa.php', {parameters: {ankDi:b}});
	}
}
/* TO BE MOVED TO SITE */
function sendChatter(event, a){
	event = event || window.event;
	keyID = event.keyCode;
	if(keyID == 13 || a == 1){
		inp = document.getElementById('chatterInput').value;
		if(inp != ''){
			//sendData
			new Ajax.Updater('chatter','/connectors/chatter/addChat.php',{parameters:{inp:inp}});
			document.getElementById('chatterInput').value = '';
			document.getElementById('chatterInput').focus();
		}
	}
}
function sendChatterButton(){
	inp = document.getElementById('chatterInput').value;
	if(inp != ''){
		//sendData
		new Ajax.Updater('chatter','/connectors/chatter/addChat.php',{parameters:{inp:inp}});
		document.getElementById('chatterInput').value = '';
		document.getElementById('chatterInput').focus();
	}
}

function chatterLoader(){

	new Ajax.PeriodicalUpdater('chatter', '/connectors/chatter/listChat.php', {frequency: 15,decay: 1,
			onSuccess: function(){
				if(document.getElementById('chatterScroll').checked){
					t = document.getElementById('chatter');
					t.scrollTop = 750;
				}
			}
		});

}
function printPage(juhu, juhu2){
	popupwin('/popup/print.php?id=' + juhu + '&cat=' + juhu2, 'printMe', 500, 575, 1);
}
function printPageThink(){
	dat = document.getElementById('printMe').innerHTML;
	var printWin = window.open("","printSpecial", 'width=632px,height=445px,scrollbars=no,status=no,left=150px,top=0px');
    	html_st = '<html><head><title>Vesela Šola</title><link rel="stylesheet" type="text/css" href="/layout/main.css" /><body onload="this.print()"><div class="otxt" style="background-color:#F28316;text-align:left;">';
	html_en = "</div></body></html>";
	printWin.document.open();
	printWin.document.write(html_st + dat + html_en);
	setTimeout("printWin.print();", 500);
}
function popupwin( page, popupname, popwidth, popheight, popscroll ){
	var top         = ( window.screen.height - popheight ) / 2 ;
	var left        = ( window.screen.width - popwidth ) / 2;
	var windowprops = "width=" + popwidth + ",height=" + popheight + ",left=" + left + ",top=" + top + ",location=no,menubar=no,status=no,toolbar=no,scrollbars=" + popscroll + ",resizable=yes";
	newWindow = window.open( page, popupname, windowprops );
}
function timePrint(){
	printWin.print();
}
/*
function PrintIt(whicElement, OptionPR){
    try {
    	var content_vlue = document.getElementById(whicElement).innerHTML;
    	var printWin = window.open("","printSpecial", 'width=500px,height=500px,scrollbars=yes,status=no,left=150px,top=150px');
    	html_st = '<html><head><title>OpenAd</title><link rel="stylesheet" type="text/css" href="/css/dyna_layout.css" /><style>.dashed_line{width:100%; height: 1px; border-bottom: 1px dashed #000000;}.gray_line2{width:100%; height: 1px; border-bottom: 1px dashed #c6c6c6; padding: 0px;}.gray_line{width:100%; height: 1px; border-bottom: 1px solid #c6c6c6;}.gray_dashed{width:100%; height: 1px; border-bottom: 1px solid #c6c6c6; padding: 0px;margin:0px;}</style></head><body><div style="padding:5px;height:6em;font-size:9px;">';
    	html_en = "</div></body></html>";
    	printWin.document.open();
    	printWin.document.write(html_st + content_vlue + html_en);
    	if(OptionPR == true)printWin.print();
    	printWin.document.close();
    } catch(E) {}
}

*/

function addPollVote(ank){
	var vote = document.getElementById('anketarezult').value;
	createCookie('anketa', ank, 30);
	new Ajax.Updater('anketa','/connectors/poll/addPollVote.php', {parameters: {ank:ank, vot:vote}});
}
function createCookie(name, value, days){
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function voteclick(vote){
	document.getElementById('anketarezult').value = vote;
}
function saveComments(cid){
	var im = document.getElementById('ime').value;
	var st = document.getElementById('starost').value;
	var kr = document.getElementById('kraj').value;
	var ko = document.getElementById('komentar').value;
	if(im){
		new Ajax.Request('/connectors/comments/save.php', {
				parameters: {cid:cid, im:im, st:st, kr:kr, ko:ko},
				onSuccess:function(transport){
					document.getElementById('ime').value = '';
					document.getElementById('starost').value = '';
					document.getElementById('kraj').value = '';
					document.getElementById('komentar').value = '';
				}
			}
		);
	}else
		alert('Brez imena ne bo nič!');
}
function showPageComments(cid, page){
	new Ajax.Updater('commentslist','/connectors/comments/list.php', {
			parameters: {par:'list',cid:cid, page:page},
			onSuccess:function(transport){
				new Ajax.Updater('commentspages','/connectors/comments/list.php', {parameters: {par:'page',cid:cid, page:page}});
			}
		}
	);
}
function displayPopup(setX,setY,setURL,setWinName){
	SetTop = ( window.screen.height - setX) / 2;
	SetLeft = ( window.screen.width - setY) / 2;
	setWin = "width="+setX+",height="+setY+",left=" + SetLeft + ",top=" + SetTop + ",location=no,menubar=no,status=no,toolbar=no,scrollbars=0,resizable=no";
	setWinName = window.open(setURL, setWinName, setWin);
	try{
		setWinName.focus();
	}catch(E){

	}
}
function showAndHideBar(a){
	if(document.getElementById(a)){
		if(document.getElementById(a).style.display == 'none'){
			document.getElementById(a).style.display = '';
		}else{
			document.getElementById(a).style.display = 'none';
		}
	}
}

function saveTheme(){
	val = document.getElementById('tema').value;
	if(val.length < 5){
		alert('Ime naslova je prekratko');
	}else{
		new Ajax.Request('/connectors/forum/addThread.php', {
				parameters: {
					val:val
				},
				onSuccess:function(transport){
					location=self.location;
				}
			}
		);
	}
}
function saveChangedTheme(k){
	val = document.getElementById('chg_n_' + k).value;
	if(val.length < 5){
		alert('Ime naslova je prekratko');
	}else{
		new Ajax.Request('/connectors/forum/editThread.php', {
				parameters: {
					val:val,
					k:k
				},
				onSuccess:function(transport){
					location=self.location;
				}
			}
		);
	}
}
function deleteThread(a){
	k = confirm('Ali ste prepričani?');
	if(k){
		new Ajax.Request('/connectors/forum/deleteThread.php', {
				parameters: {
					k:a
				},
				onSuccess:function(transport){
					location=self.location;
					//alert(transport.responseText);
				}
			}
		);
	}
}
function addSubThread(cat){
	val = document.getElementById('subName').value;
	val2 = document.getElementById('subText').innerHTML;
	if(val.length < 3){
		alert('Ime naslova je prekratko');
	}else{
		new Ajax.Request('/connectors/forum/addSubThread.php', {
				parameters: {
					cat:cat,
					name:val,
					msg: val2
				},
				onSuccess:function(transport){
					location=self.location;
					//alert(transport.responseText);
				}
			}
		);
	}
}
function saveMsg(cat){
	val2 = document.getElementById('subText').innerHTML;
	if(val2.length < 3){
		alert('Ime naslova je prekratko');
	}else{
		new Ajax.Request('/connectors/forum/addMsg.php', {
				parameters: {
					thr:cat,
					name:'<none>',
					msg: val2
				},
				onSuccess:function(transport){
					location=self.location;
					//alert(transport.responseText);
				}
			}
		);
	}
}
function confMe(a,b){
	c = confirm(a);
	if(c){
		location = b;
	}
}
function oltestfwd(tree, test){
	var page = document.getElementById('onlinetest_page').value;
	var opage = page;
	var pageNo = document.getElementById('onlinetest_pageNo').value;
	page++;
	if(page > pageNo) return;

	document.getElementById('onlinetest_page').value = page;
	new Ajax.Updater('onlinetest_que','/connectors/test/connector.php',{parameters:{act:'pf',page:page,test:test,tree:tree}});
}
function oltestbck(tree, test){
	var page = document.getElementById('onlinetest_page').value;
	page--;
	if(page < 0) return;
	document.getElementById('onlinetest_page').value = page;
	new Ajax.Updater('onlinetest_que','/connectors/test/connector.php',{parameters:{act:'pf',page:page,test:test,tree:tree}});
}

function selectSchool(sch, naz){
	document.getElementById('MSola').value = sch;
	document.getElementById('MSolaNaz').value = sch+" - "+naz;
}

function addSchool(sch){
	var tree = document.getElementById('storetree').value;
	new Ajax.Updater('mentortree','/connectors/mentor/connector.php',{parameters:{act:'mads',sch:sch, tree:tree}});
	new Ajax.Updater('mentorseznam','/connectors/mentor/connector.php',{parameters:{act:'msel', par:'', tree:tree}});
}
function showSchoolTable(){
	var tree = document.getElementById('storetree').value;
	var sch = document.getElementById('mentor_sola_naziv').value;
	var pla = document.getElementById('mentor_sola_kraj').value;
	new Ajax.Updater('taglist','/connectors/mentor/connector.php',{parameters:{act:'msst',sch:sch,pla:pla, tree:tree}});
}

function supermentor(par){
	var tree = document.getElementById('storetree').value;
	var filter = document.getElementById('admfilter').value;
	new Ajax.Updater('mentorseznam','/connectors/mentor/connector.php',{parameters:{act:'asel', par:par, tree:tree, filter:filter}});
}
function izpisovanje(par){
	var tree = document.getElementById('storetree').value;
	var filter = document.getElementById('admfilter').value;
	new Ajax.Updater('mentorseznam','/connectors/mentor/connector.php',{parameters:{act:'izpis', par:par, tree:tree, filter:filter}});
}
function menAdmCheckSchool(sch){
	var tree = document.getElementById('storetree').value;
	var filter = document.getElementById('admfilter').value;
	var tog = document.getElementById('checkbox_'+sch).checked;
	//alert("check:"+tog);
	var cc = 'conf_'+sch;
	//alert(cc);
	//new Ajax.Updater(cc,'');
	new Ajax.Updater('conf_'+sch,'/connectors/mentor/connector.php',{parameters:{act:'achs', par:sch, tog:tog, tree:tree, filter:filter}});
}
function menAdmCheckSchoolStudent(sch, stu, chk){
	var tree = document.getElementById('storetree').value;
	var filter = document.getElementById('admfilter').value;
	//alert(chk);
	new Ajax.Updater('conf_'+sch,'/connectors/mentor/connector.php',{parameters:{act:'achst', par:sch, stu:stu, chk:chk, tree:tree, filter:filter}});
}
function menAdmCheckMentor(men){
	var tree = document.getElementById('storetree').value;
	var filter = document.getElementById('admfilter').value;
	var tog = document.getElementById('checkbox_'+men).checked;
	//alert("check:"+tog);
	new Ajax.Updater('conf_'+men,'/connectors/mentor/connector.php',{parameters:{act:'achm', par:men, tog:tog, tree:tree, filter:filter}});
}
function menAdmCheckMentorStudent(men, stu, chk){
	var tree = document.getElementById('storetree').value;
	var filter = document.getElementById('admfilter').value;
	//alert(chk);
	new Ajax.Updater('conf_'+men,'/connectors/mentor/connector.php',{parameters:{act:'achmt', par:men, stu:stu, chk:chk, tree:tree, filter:filter}});
}
function saveStudent(par, sch, clas, ctype){
	var tree = document.getElementById('storetree').value;
	//save student

	ident = document.getElementById('studentId').value;
	name2 = document.getElementById('name').value;
	lastname = document.getElementById('lastname').value;
	birthdate = document.getElementById('birthdate').value;
	address = document.getElementById('address').value;
	address_no = document.getElementById('address_no').value;
	email = document.getElementById('email').value;
	sex = document.getElementById('sex').value;
	postal = document.getElementById('postal').value;
	city = document.getElementById('city').value;

	new Ajax.Request('/connectors/mentor/updateStudent.php',{parameters:
			{
			id:ident,
			name:name2,
			lastname:lastname,
			birthdate:birthdate,
			address:address,
			address_no:address_no,
			email:email,
			sex:sex,
			postal:postal,
			city:city,
			clas:clas,
			classtype:ctype,
			school:sch
		},
		onSuccess:function (transport){
			//alert(transport.responseText);
			new Ajax.Updater('mentorseznam','/connectors/mentor/connector.php',{parameters:{act:'msel', par:par, sch:sch, clas:clas, tree:tree}});
		}


		});

}

function showNew(){
	if(document.getElementById('row1')){
		if(document.getElementById('row1').style.display == ''){
			document.getElementById('row1').style.display = 'none';
			document.getElementById('row2').style.display = 'none';
		}else{
			document.getElementById('row1').style.display = '';
			document.getElementById('row2').style.display = '';
		}
	}
}
function addMentorClass(sch){
	var kls = ' ';
	var tree = document.getElementById('storetree').value;
	var dd;
	for(c=4; c<10;c++){
		dd = document.getElementById('kls'+c);
		if(dd.checked) kls += 'kls['+c+']=true&';
	}
	dd = document.getElementById('kls58');
	if(dd.checked) kls += 'kls[58]=true&';
	kls = kls + 'act=madc&';
	kls = kls + 'sch=' + sch + '&';
	kls = kls + 'tree=' + tree + '&';

	new Ajax.Updater('mentortree','/connectors/mentor/connector.php',{postBody:(kls)});
	new Ajax.Updater('mentorseznam','/connectors/mentor/connector.php',{parameters:{act:'msel', par:''}});
}
function mentorShowList(sch, kls, typ){
	var tree = document.getElementById('storetree').value;
	new Ajax.Updater('mentorseznam','/connectors/mentor/connector.php',{parameters:{act:'msel', par:'showlist', sch:sch, kls:kls, typ:typ, tree:tree}});
}
function Popup_EditScool(returnurl) {
  window.open('./popup/newschoolform.php', 'editWindow', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=360,height=233,left = 490,top = 462');
}
function Popup_EditMentor(returnurl) {
  window.open('./popup/newmentorform.php', 'editWindow', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=700,left = 100,top = 100');
}
function searchText(){
	/*par = document.getElementById('search').value;
	if(par == '') return;

	self.location.href = '/search.php?search='; //+par;*/
	document.thaIberSearch.submit();

}

function CheckSubmit_searchText() {
	//IE, netscape


		if (navigator.appName=="Microsoft Internet Explorer"){
	     if (window.event && window.event.keyCode == 13){
	  			searchText(); }}

		//if (navigator.appName=="Netscape"){
	    // if (event && event.which == 13){
	  		//	searchText(); }}

}
function mentorContent(par, sch, clas){
	var tree = document.getElementById('storetree').value;
	var filter = '';
	try{
		filter = document.getElementById('admfilters').value;
    } catch(E) {}
	if((par == 'remschool') && (sch)){
		ans = confirm('Izbrisal boš šolo in vse povezane podatke!\n Ali si prepričan?');
		if(ans){
			new Ajax.Updater('mentorseznam','/connectors/mentor/connector.php',{
					parameters:{act:'rmsc', par:par, sch:sch, clas:clas, tree:tree},
					onSuccess:function (transport){
						par = '';
						sch = null;
						new Ajax.Updater('mentorseznam','/connectors/mentor/connector.php',{parameters:{act:'msel', par:par, sch:sch, clas:clas, tree:tree}});
						new Ajax.Updater('mentortree','/connectors/mentor/connector.php',{parameters:{act:'mslt', par:par, sch:sch, clas:clas, tree:tree}});
					}
				});
		}
		return;
	}else if((par == 'remclass') && (sch) && (clas)){
		ans = confirm('Izbrisal boš razred in vse povezane podatke!\n Ali si prepričan?');
		if(ans){
			new Ajax.Updater('mentorseznam','/connectors/mentor/connector.php',{
					parameters:{act:'rmcl', par:par, sch:sch, clas:clas, tree:tree},
					onSuccess:function (transport){
						par = '';
						sch = null;
						clas = null;
						new Ajax.Updater('mentorseznam','/connectors/mentor/connector.php',{parameters:{act:'msel', par:par, sch:sch, clas:clas, tree:tree}});
						new Ajax.Updater('mentortree','/connectors/mentor/connector.php',{parameters:{act:'mslt', par:par, sch:sch, clas:clas, tree:tree}});
					}
				});
		}
		return;
	}else if((par == 'remstudent') && (sch)){
		ans = confirm('Izbrisal boš tekmovalca!\n Ali si prepričan?');
		if(ans){
			new Ajax.Updater('mentorseznam','/connectors/mentor/connector.php',{
					parameters:{act:'rmst', par:par, sch:sch, tree:tree},
					onSuccess:function (transport){
						par = '';
						sch = null;
						new Ajax.Updater('mentorseznam','/connectors/mentor/connector.php',{parameters:{act:'msel', par:par, sch:sch, clas:clas, tree:tree}});
						new Ajax.Updater('mentortree','/connectors/mentor/connector.php',{parameters:{act:'mslt', par:par, sch:sch, clas:clas, tree:tree}});
					}
				});
		}
		return;
	}
	new Ajax.Updater('mentortree','/connectors/mentor/connector.php',{parameters:{act:'mslt', par:par, sch:sch, clas:clas, tree:tree, filter:filter}});
	new Ajax.Updater('mentorseznam','/connectors/mentor/connector.php',{parameters:{act:'msel', par:par, sch:sch, clas:clas, tree:tree}});
}

function showhelp(){
	new Ajax.Request('/connectors/mentor/connector.php',{
					parameters:{act:'shhlp'},
					onSuccess:function (transport){
						location=self.location;
					}
		 });
}