var scroll_size = 20;
var top = 0;

function news_bg(that, mod) {		
	if (mod=="on") {
		//that.style.background='#FFF';
		that.style.backgroundImage="url(imgs/glass.png)";
		that.style.backgroundRepeat="no-repeat";
		//that.style.backgroundImage="url(someimage.gif)";
			//background-image: url(imgs/link_bg.png);
			//background-repeat: repeat-x;

	}
	else that.style.background='';
}

function news_bg2(that, mod) {		
	if (mod=="on") {
		that.style.backgroundImage="url(imgs/glassBig.png)";
		that.style.backgroundRepeat="no-repeat";
	}
	else that.style.background='';
}

function msg_obicna() {
	//document.form.naslov.style.visibility="visible";
	document.form.tip_poruke[0].checked=true;;
	document.getElementById("tr5").style.display="";
	document.getElementById("tr6").style.display="none";
	document.getElementById("tr7").style.display="none";
	document.getElementById("tr8").style.display="none";
	document.getElementById("tr9").style.display="none";
	document.getElementById("tr10").style.display="none";
	document.getElementById("tr11").style.display="none";
	document.getElementById("tr12").style.display="none";	
}

function msg_rezervacija() {
	//document.form.naslov.style.visibility="hidden";
	document.getElementById("tr5").style.display="none";
	document.getElementById("tr6").style.display="";
	document.getElementById("tr7").style.display="";
	document.getElementById("tr8").style.display="";
	document.getElementById("tr9").style.display="";
	document.getElementById("tr10").style.display="";
	document.getElementById("tr11").style.display="";
	document.getElementById("tr12").style.display="";	
}


function scrollDown(){
	obj = window.frames['frame'].document.getElementById('scroler');
	duzina=obj.offsetHeight;
	
	if (top==0) obj.style.top = "0px";	
	if (parseInt(obj.style.top)>duzina*(-1)) {  top-=scroll_size; obj.style.top=top+"px"; }
}

function scrollUp() {
	obj = window.frames['frame'].document.getElementById('scroler');
	duzina=obj.offsetHeight;
	
	if (parseInt(obj.style.top)<0) { top+=scroll_size; obj.style.top=top+"px";}
}

function keypress_number(e, that, size) {	
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ //backspace		
		if (that.value.length>size) return false;
		else if (unicode<48||unicode>57) return false; // blokira ukoliko nije broj
	}
}

function check_formular_prijava() {
	var ime = document.getElementById("ime").value;
	var prezime = document.getElementById("prezime").value;
	var roditelj = document.getElementById("roditelj").value;
	var pol = document.getElementById("pol").options[document.getElementById("pol").selectedIndex].innerHTML;
	
	var dd = document.getElementById("dd").value;
	var mm = document.getElementById("mm").value;
	var gg = document.getElementById("gg").value;
	
	var jmbg = document.getElementById("jmbg").value;
	var adresa = document.getElementById("adresa").value;
	var mesto = document.getElementById("mesto").value;
	var nazivskole = document.getElementById("nazivskole").value;
	var telefon = document.getElementById("telefon").value;
	var email = document.getElementById("email").value;
	var vrstaplesa = document.getElementById("vrstaplesa").options[document.getElementById("vrstaplesa").selectedIndex].innerHTML;		

	//jmbg=="" || adresa=="" || mesto=="" || nazivskole=="" || 
	if (ime=="" || prezime=="" || pol=="") alert("Sva polja oznacena * moraju biti popunjena !");
	else if (dd=="" || mm=="" || gg=="") alert("Sva oznacena * polja moraju biti popunjena !");
	else if (telefon=="" || email=="" || vrstaplesa=="") alert("Sva polja oznacena * moraju biti popunjena !");	
	else if (checkEmail(email)==false) alert("Nevalidna e-mail adresa !");	
	else {  document.getElementById("singUP").action="index.php?p=singup&mod=save"; document.getElementById("singUP").submit(); }

}


function checkEmail(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID 1")
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID 2")
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID 3")
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID 4")
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID 5")
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID 6")
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID 7")
		    return false;
		 }

 		 return true;					
}
