
function printPage()
{
	window.print();
}

function showForm()
{
	document.getElementById('commentButton').style.display='none';
	document.getElementById('commentForm').style.display='block';
}

function isValidEmail(mejl)
{
	var isok = true;
	if (mejl.length<8) isok = false;
	if (mejl.indexOf('@')<=0) isok = false;
	if (mejl.indexOf('.')<=0) isok = false;
	return isok;
}

var xmlhttp;
var fileurl = "";

function loadFile(fileurl, divid)
{
	var divToChange = divid;
	
	if (window.XMLHttpRequest) {
		xmlhttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null) {
		xmlhttp.open("GET", fileurl, true);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState==4) {// 4 = "loaded"
				if (xmlhttp.status==200) {// 200 = "OK"
					document.getElementById(divToChange).innerHTML = xmlhttp.responseText;	
				} else {
					alert("Problem retrieving data from "+fileurl+":\n" + xmlhttp.statusText);
				}
			}
		};
		
		xmlhttp.send(null);
	} else {
		alert("Your browser does not support XMLHTTP!");
	}
}


function loadMenu(path)
{
	var fileurl = "/menu.php?path="+path;
	if (window.XMLHttpRequest) {
		xmlhttp2=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp2!=null) {
		xmlhttp2.open("GET", fileurl, true);
		xmlhttp2.onreadystatechange = function() {
			if (xmlhttp2.readyState==4) {// 4 = "loaded"
				if (xmlhttp2.status==200) {// 200 = "OK"
					document.getElementById("menu_left").innerHTML = xmlhttp2.responseText;	
				}
			}
		}
		xmlhttp2.send(null);
	}
}


// images

function showPics(pid,page)
{
	var turl = "/gallery_album.php?pid="+pid+"&p="+page;
	loadFile(turl,"photos");
}



function setOpacity(opacity, id) 
{ 
  var object = document.getElementById(id).style; 
  object.opacity = (opacity / 100); 
  object.MozOpacity = (opacity / 100); 
  object.KhtmlOpacity = (opacity / 100); 
  object.filter = "alpha(opacity=" + opacity + ")"; 
} 

function showItem(opacity, id) 
{
  if (document.getElementById) 
  {
    if(opacity < 1) 
    {
			document.getElementById(id).style.display='inline';
    }
    if (opacity < 100) 
    {
       setOpacity(opacity,id);
       opacity += 2;
       window.setTimeout("showItem("+opacity+","+id+")", 50);
    }
  }
}

function findPosY(ajdi) 
{
	var curtop = 0;
	var obj = document.getElementById(ajdi);
	if (obj.offsetParent) 
	{
		do 
		{
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}	
	return curtop;
}

function showImage(url,id, pid)
{
		document.getElementById('bigpic').innerHTML = "<img src='/src/Gallery/"+pid+"/"+url+"' alt='"+id+"' title=''>"; 
		window.open('gallery_image.php?imgid='+id,'dummy');
		var distance = findPosY('bigpic');
		setTimeout("window.scroll(0,"+distance+")", 300);
}



// video player

function showVideo(divid, video, video_image, autostart)
{
		var s1 = new SWFObject("/swf/mediaplayer.swf","mediaplayer","640","480","8");
		s1.addParam('allowscriptaccess','always');
		s1.addParam("allowfullscreen","true");
		s1.addVariable("width","640");
		s1.addVariable("height","480");
		s1.addVariable('backcolor','0x000000');
		s1.addVariable('frontcolor','0xffd700');
		s1.addVariable('lightcolor','0xffffff');
		s1.addVariable('screencolor','0x000000');
		s1.addVariable('searchbar','false');
		s1.addVariable('autostart',autostart);
		s1.addVariable('enablejs','true');
		s1.addVariable("file",video);
		if(video_image!="") {
			s1.addVariable("image",video_image);
		}
		s1.write(divid);
	
}


function orderSubmit()
{
	var frm = document.frmOrder;
	var errmsg = "";
	if(frm.name.value.length<5 || frm.name.value.indexOf(" ")<=0) errmsg += "\n- Ime in priimek";
	if(frm.address.value.length<4|| frm.address.value.indexOf(" ")<=0) errmsg += "\n- Naslov (ulica in številka)";
	if(frm.town.value.length<2 || frm.post.value.length<4) errmsg += "\n- Poštno številko in kraj";
	if(!isValidEmail(frm.email.value))	errmsg += "\n- Pravilen email naslov";
	if(frm.phone.value.length<8) errmsg += "\n- Telefonsko številko";
	if(errmsg!="") {
		alert("Vnesti morate še:"+errmsg);
	} else {
		frm.method = "POST";
		frm.action = "/order.php?w=sub";
		frm.submit();
	}
}

function contactSubmit()
{
	var frm = document.frmKontakt;
	var errmsg = "";
	if(frm.name.value.length<5 || frm.name.value.indexOf(" ")<=0) errmsg += "\n- Ime in priimek";
	if(!isValidEmail(frm.email.value))	errmsg += "\n- Pravilen email naslov";
	if(errmsg!="") {
		alert("Vnesti morate še:"+errmsg);
	} else {
		frm.method = "POST";
		frm.action = "/contact.php?w=sub";
		frm.submit();
	}
}