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

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;
}

function getStyle(el, cssprop){
 if (el.currentStyle) //IE
  return el.currentStyle[cssprop]
 else if (document.defaultView && document.defaultView.getComputedStyle) //Firefox
  return document.defaultView.getComputedStyle(el, "")[cssprop]
 else //try and get inline style
  return el.style[cssprop]
}

var xmlhttp;
var fileurl = "";

function loadFileToDiv(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"
					window.parent.document.getElementById(divToChange).innerHTML = xmlhttp.responseText;	
				} else {
					window.status = "Problem retrieving data from "+fileurl+": " + xmlhttp.statusText;
				}
			}
		};
		
		xmlhttp.send(null);
	} else {
		alert("Vaš brskalnik ne podpira XMLHTTP!");
	}
}

function loadCommentList(cid, ctid, page) {
	if(page=="") {
		page=1;
	}
	var fileurl = "/dummy_comment_list.php?cid="+cid+"&ctid="+ctid+"&p="+page;
	if (window.XMLHttpRequest) {
		xmlhttp3=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xmlhttp3=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp3!=null) {
		xmlhttp3.open("GET", fileurl, true);
		xmlhttp3.onreadystatechange = function() {
			if (xmlhttp3.readyState==4) {// 4 = "loaded"
				if (xmlhttp3.status==200) {// 200 = "OK"
					window.parent.document.getElementById("comment_list").innerHTML = xmlhttp3.responseText;	
				}
			}
		}
		xmlhttp3.send(null);
	}
}


function show_info(kaj) {
	var infobox = document.getElementById("info_box");
	infobox.innerHTML = kaj;
	showItem(0,"info_box");
}


// images

function show_image(pic, path, orig) {
	var div = document.getElementById('content_big_image');
	if(div) {
		div.innerHTML = '<img src="/src/'+path+'/0'+pic+'" alt="'+orig+'" />';
	}
}

function show_big_pic(picdivid, picpath, picurl)
{
	var picdiv = document.getElementById(picdivid);
	var output = '';
	picdiv.className = 'imgbox pad2 sel';
	picdiv.style.background = 'none';
	output =  '<h5>CLICK ON THE IMAGE TO CLOSE IT</h5>';
	output += '<img src="'+picpath+"/"+picurl+'" alt="image" onclick="close_big_pic(\''+picdivid+'\',\''+picpath+'\',\''+picurl+'\')" ';
	//output += 'onmouseover="document.getElementById(\'image_close\').style.display=\'block\'" ';
	//output += 'onmouseout="document.getElementById(\'image_close\').style.display=\'none\'" ';
	output += ' />';
	output +=  '<h5>&nbsp;</h5>';
	picdiv.innerHTML = output;
}

function close_big_pic(picdivid, picpath, picurl) {
	var picdiv = document.getElementById(picdivid);
	var output = '';
	picdiv.className = 'thumb_preview m2';
	picdiv.style.background = 'url('+picpath+"/thumb."+picurl+')';
	output = '<img onclick="show_big_pic(\''+picdivid+'\',\''+picpath+'\',\''+picurl+'\')\" src="/images/spacer.gif" ';
	output += 'width="76" height="76" alt="Image" title="Image" class="imglink" />';
	picdiv.innerHTML = output;
}



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='block';
    }
    if (opacity < 100) {
       setOpacity(opacity,id);
       opacity += 2;
       window.setTimeout("showItem("+opacity+",'"+id+"')", 5);
    }
    if(opacity>98) {
			window.setTimeout("hideItem(100,'info_box')", 3000);
		}
  }
}

function hideItem(opacity, id) 
{
  if (document.getElementById) {
    if(opacity < 2) {
			document.getElementById(id).style.display='none';
    }
    if (opacity > 0) {
       setOpacity(opacity,id);
       opacity -= 2;
       window.setTimeout("hideItem("+opacity+",'"+id+"')", 5);
    }
  }
}

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 findPosX(ajdi) {
	var curleft = 0;
	var obj = document.getElementById(ajdi);
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
		} while (obj = obj.offsetParent);
	}
	return curleft;
}

function showImage(url,id, pid)
{
		document.getElementById('bigpic').innerHTML = "<img src='/src/Gallery/"+pid+"/"+url+"' alt='' 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);
	
}

// comments

function commentAddShow(cid,ctid)
{
	document.getElementById('comment_show').style.display='none';
	document.getElementById('comment_add').style.display='block';
	//loadFileToDiv('/dummy_comment_add_form.php?cid='+cid+'&ctid='+ctid,'comment_add');
}

function commentSubmit(cid, ctid) {
	var frm = document.getElementById('frmComment');
	frm.action = '/dummy_comment_add.php?cid='+cid+'&ctid='+ctid;
	frm.target = 'dummy';
	frm.method = 'post';
	frm.submit();
}

function captchaReload() {
	window.parent.document.getElementById('captcha').innerHTML = '<img src="/captcha.php?'+(Math.floor(Math.random()*111111111111))+'" alt="Slika" width="200" height="50" />';
}

function faqSubmit() {
	var frm = document.getElementById('frmFaq');
	frm.action = '/dummy_faq_add.php';
	frm.target = 'dummy';
	frm.method = 'post';
	frm.submit();
}



// jQuery

$(document).ready(function() {
	
	var e = $("#navigation .nivo-1 ul li");
	e.each(function() {
		if($(this).is('.active')){
			var catid = $(this).attr("id").replace("cat-","");
			var menu = "#menu-"+catid;
			$('#navigation .nivo-2').show();
			$(menu).show();
		}
	});
	
   $('#navigation .nivo-1 ul li').click(function(e) { 
	   var catid = $(this).attr("id").replace("cat-","");
	   var menu = "#menu-"+catid;
	   
	   if($(menu).children().size() > 0) {
		   $('#navigation .nivo-2').show();
		   e.preventDefault();
	   
		   $('.nivo-1 ul li').removeClass('active');
		   $(this).addClass('active');
		   

		   
		   $('.nivo-2 ul').hide();
		   
		   $(menu).show();
		   $(this).addClass('active');
	   }
   });
  
   //colorbox 
   $("a[rel='colorbox-product']").colorbox();
   $("a[rel='colorbox-pdf']").colorbox({iframe:true, innerWidth:950, innerHeight:550});
   $("a[rel='colorbox-catalog']").colorbox({iframe:true, innerWidth:640, innerHeight:550});
   
   $('.ordering.block.closed').click(function(e) {
	   $(this).children('.block-content').slideDown();
	   $(this).removeClass('closed');
   });
   
});
