
function removephoto(id){

	var photo = $('photo_'+id);

	//Listing
	new Ajax.Request('/content/ajax/removephoto.php',
	{
		parameters: {id: id},
		onSuccess: function(transport)
		{
			if(transport.responseText){
				photo.remove();
				alert("Photo successfully removed.");
			}else{
				alert("Hmm i have some problems. Please contact administrator");
			}
		},
		on800: function(transport)
		{
			alert("Hmm i have some problems. Please contact administrator");
		}
	});
}


function LightCandle(id){

	var candle = $('candle');

	//Listing
	new Ajax.Request('/content/ajax/candle.php',
	{
		parameters: {id: id},
		onSuccess: function(transport)
		{
			if(transport.responseText){
				//photo.remove();
//				alert(transport.responseText);

				if(transport.responseText == "OK"){
					candle.addClassName('disabled');
					window.location.reload();
				}else{

				}
			}else{
				alert("Hmm i have some problems. Please contact administrator");
			}
		},
		on800: function(transport)
		{
			alert("Hmm i have some problems. Please contact administrator");
		}
	});
}

function Report(id,type){
	if (confirm("Are you sure you want to report this content?")){
	new Ajax.Request('/content/ajax/report.php',
	{
		parameters: {id: id,type: type},
		onSuccess: function(transport)
		{
			if(transport.responseText){
				//photo.remove();
//				alert(transport.responseText);

				if(transport.responseText == "OK"){
					alert("Admin and user were informed. Thank you.");
					changeClass(commentDiv, 'comment unapproved', 'comment');
				}else{

				}
			}else{
				alert("Hmm i have some problems. Please contact administrator");
			}
		},
		on800: function(transport)
		{
			alert("Hmm i have some problems. Please contact administrator");
		}
	});
	}
}

function OpenMoreCandles(){
	var boxek = $('more_candles');
	var link = $('less_candles');

	boxek.style.display = "block";
	link.remove();
}


/* Credits */
function alertSize(){
	var ovca = 0;
	if( typeof( window.innerHeight ) == 'number' ) {
    	//Non-IE
	    ovca = window.innerHeight;
	}else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    	//IE 6+ in 'standards compliant mode'
		ovca = document.documentElement.clientHeight;
	}else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		ovca = document.body.clientHeight;
	}
	return ovca;
}

function ozadje(){
	var size = alertSize()+'px';
//	$('ozadje').style.height = document.body.getHeight()+'px';
	//$('ozadje').style.height = size;
	$('ozadje').style.visibility = 'visible';
}

function pogoji(){

	var data = $('nakupni_pogoji');

	if(data.style.display == "block"){
		data.style.display = "none";
		data.style.visibility = "hidden";
	}else{
		data.style.display = "block";
		data.style.visibility = "visible";
	}

}

function prijava_submit(){
	var d = document.prijava;

	/*radio check */
	var radioSelected = false;
	for (i = 0;  i < d.zakonski_stan.length;  i++)
	{
		if (d.zakonski_stan[i].checked)
		radioSelected = true;
	}

    if ( d.imepriimek.value == '' || d.naslov.value == '' || d.datum_rojstva.value == '' || d.telefon.value == '' || !radioSelected || d.izkusnje.value == '' || d.pricakovanja.value == '')
    {
        alert('Prosimo izpolnite vsa obvezna polja!');
        return false;
    }else if (!d.strinjamse.checked){
        alert('Strinjati se morate s pogoji!');
        return false;
	}else{
		document.prijava.submit();
		return false;
	}
}

/* ROlli */
function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

	function MM_findObj(n, d) { //v4.0
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && document.getElementById) x=document.getElementById(n); return x;
	}

	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

	function ClearOptions(OptionList) {

		//Always clear an option list from the last entry to the first
		for (x = OptionList.length; x >= 0; x = x - 1) {
			OptionList[x] = null;
		}

	}

/* funkcija zamenja star class z novim */
function changeClass(id, oldclass, newclass){
	if($(id))
	{
		$(id).removeClassName(oldclass);
		$(id).addClassName(newclass);
	}
}


function selectCountry(state, country){

	if ($(state).value != "99")  {
  	$(country)[226].selected = true;
	} else {
  	$(country)[226].selected = false;
    $(country)[0].selected = true;
	}
}

function resetCountry(){
  	$('country')[0].selected = true;
}

function selectState(state, country){

	if ($(country).value != "US")  {
  	$(state)[0].selected = true;
	}
}

function resetState(){
  	$('country')[0].selected = true;
}


function switchContent(contentID, tabID){
	var contentID = contentID;
	var tabID = tabID;
    	$('col1').style.display='none';
	new Ajax.Request('/content/ajax/ajax.php',
	{
		parameters: {action: 'switchcontent', contentID : contentID},
		onSuccess: function(transport)
		{
				if(transport.responseText != false){
					var jSon = transport.responseText.evalJSON();
					var vsebina = jSon.vsebina;
					$('col1').update(vsebina);
     				setTimeout("$('col1').appear()", 300);


	    			for (var n=1; n<7; n++) {
		    		    if (n != tabID) {
		    		    	changeClass('list'+n, 'active', '');
		    		    }
		    		    else {
		    		    	changeClass('list'+tabID, '', 'active');
		    		    }
	    		    }
	    		    } else {
	    		    	alert('problems...');
	    			}



		},
		on800: function(transport)
		{
			alert("Hmm i have some problems. Please contact administrator");
		}
	});
}

function isAlphaKey(evt)
{
   var charCode = (evt.which) ? evt.which : event.keyCode
   if ((charCode > 47 && charCode < 58) || ( charCode < 31 ) ||  ( charCode > 97 && charCode < 123 ) )
      return true;

   return false;
}

//zamenja sliko
function changeImg(source, id, all) {
   var source=source;
   var id=id;
   var all=all;
   $('prikazna_slika').style.display='none';
   $('prikazna_slika').src = '/files/profileimg/small/'+source;
   $('img_loading_msg').update('Loading...');

	if ( navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
    	setTimeout("$('img_loading_msg').innerHTML=''", 1000);
 		setTimeout("$('prikazna_slika').appear()", 1000);

 	} else {
    $('prikazna_slika').observe("load", function() {
    	$('img_loading_msg').innerHTML='';
 		$('prikazna_slika').appear();
	});
 	}
 	$('img_comment').update($('thumb'+id).readAttribute('alt'));
   	for (var n=1; n<=all; n++) {
	    if (n != id) {
	    changeClass($('thumb'+n), 'imgselected', '');
	    }
	    else {
	    changeClass($('thumb'+n), '', 'imgselected');
	    }
   }

}

function RemoveElement(id){
var id = id;
var element = $('kosarica_element_'+id);
if(id){
	new Ajax.Request('/content/ajax/remphoto.php',
	{
		parameters: {action: 'remove_element', id: id},
		onSuccess: function(transport)
		{
			if(transport.responseText == true){
				Effect.Fade('kosarica_element_'+id);
			}else{
				alert("Hmm i have some problems. Please contact administrator");
			}
		},
		on800: function(transport)
		{
			alert("Hmm i have some problems. Please contact administrator");
		}
		});
}
}
function UpdateIt(what, content) {
	$(what).update(content);
}

function DeleteComment(commentID){
var commentID = commentID;

if (confirm("Are you sure you want to delete comment?")){
	new Ajax.Request('/content/ajax/ajax.php',
	{
		parameters: {action: 'delete_comment', commentID: commentID},
		onSuccess: function(transport)
		{
				var commentDiv = $('comment'+commentID);
				Effect.Fade('comment_'+commentID);
               	var jSon = transport.responseText.evalJSON();
				var novo = jSon.novo;
				UpdateIt('numcomments', novo);

		},
		on800: function(transport)
		{
			alert("Hmm i have some problems. Please contact administrator");
		}
		});
}
}

function ApproveComment(commentID){
var commentID = commentID;

if (confirm("Are you sure you want to approve comment?")){
	new Ajax.Request('/content/ajax/ajax.php',
	{
		parameters: {action: 'approve_comment', commentID: commentID},
		onSuccess: function(transport)
		{
				var commentDiv = $('comment_'+commentID);
				changeClass(commentDiv, 'comment unapproved', 'comment');
               	var jSon = transport.responseText.evalJSON();
				var novo = jSon.novo;
             	Effect.Fade('approve_'+commentID);
             	Effect.Fade('unapproved_msg_'+commentID);

		},
		on800: function(transport)
		{
			alert("Hmm i have some problems. Please contact administrator");
		}
		});
}
}




//pošiljanje komentarjev
function PostComment() {
	var comment_txt = $('comment_txt').value;
	var profile_id = $('profile_id').value;

	if (comment_txt) {
		window.location.hash= "#comments";
		new Ajax.Request('/content/ajax/ajax.php',
		{
			parameters: {action: 'add_comment', comment_txt:comment_txt, profile_id:profile_id},
			onSuccess: function(transport)
			{
           		var jSon = transport.responseText.evalJSON();
				var newcomment = jSon.newcomment;
				var num_comments = jSon.num_comments;
            //    var commentID = jSon.commentID;
                var comm_msg = jSon.comm_msg;

                $('comment_msg').update(comm_msg);
                $('numcomments').update('Comments ('+num_comments+')');
            	$('list_comments').insert({top : newcomment });

			},

			on800: function(transport)
			{
				alert("Hmm i have some problems. Please contact administrator");
			}
		});
		$('comment_txt').value='';
	}
}


function OdpriPopup(id){
	if (id=="terms")
	{		$('pop_title').update('Terms and conditions');
		$('terms').src= "/templates/terms.html";

	} else {		$('pop_title').update('Authors');
		$('terms').src= "/templates/authors.html";
	}

	$('popup_avtorji').style.display="none";

	var flash = document.getElementById('flash_naslovka');
	var flash2 =document.getElementById('flash_profile');
	if (flash)     {
		flash.style.visibility = 'hidden';
    }
    if (flash2)     {
		flash2.style.visibility = 'hidden';
    }
	if (window.innerHeight && window.scrollMaxY) {// Firefox
	yWithScroll = window.innerHeight + window.scrollMaxY;
	xWithScroll = window.innerWidth + window.scrollMaxX;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
	yWithScroll = document.body.scrollHeight;
	xWithScroll = document.body.scrollWidth;
} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
	yWithScroll = document.body.offsetHeight;
	xWithScroll = document.body.offsetWidth;
 	}
	el = $('PopUpCont');
	bg = document.getElementById('ozadje');

	bg.style.display="block";
	var wSize = (yWithScroll);
	bg.style.height=wSize+"px";
 	$('PopUpCont').style.display="block";
  	$('popup_avtorji').appear({duration: 0.5});
}


function ZapriPopup(id) {
	el = $('PopUpCont');
	var flash = document.getElementById('flash_naslovka');
	var flash2 =document.getElementById('flash_profile');
	if (flash) {
		flash.style.visibility = 'visible';
    }
    if (flash2){
		flash2.style.visibility = 'visible';
    }
	bg = document.getElementById('ozadje');
	$(el).fade({ duration: 0.5 });
	setTimeout('bg.style.display="none"', 400);
}

function AddFavourite(id){

	var favourite = $('favourite');

	//Listing
	new Ajax.Request('/content/ajax/favourite.php',
	{
		parameters: {id: id},
		onSuccess: function(transport)
		{
			if(transport.responseText){
				if(transport.responseText == "OK"){
					favourite.addClassName('disabled');
					window.location.reload();
				}else{

				}
			}else{
				alert("Hmm i have some problems. Please contact administrator");
			}
		},
		on800: function(transport)
		{
			alert("Hmm i have some problems. Please contact administrator");
		}
	});
}

function RemoveFavourite(favID){
var favID = favID;

if (confirm("Are you sure you want to remove favourite?")){
	new Ajax.Request('/content/ajax/removefav.php',
	{
		parameters: {favID: favID},
		onSuccess: function(transport)
		{
				Effect.Fade('fav_'+favID);
		},
		on800: function(transport)
		{
			alert("Hmm i have some problems. Please contact administrator");
		}
		});
}
}


function SaveMemorial(publish,pid,scene_id,gravestone_id,items){
	new Ajax.Request('/content/ajax/publish.php',
	{
		parameters: {items: items, pid: pid, scene_id: scene_id, gravestone_id: gravestone_id},
		onSuccess: function(transport)
		{

			if(publish < 1){
				window.parent.location.href = "/edpm/" + pid + "/5";
			}else{
				window.reload();
			}


		},
		on800: function(transport)
		{
			alert("Hmm i have some problems. Please contact administrator");
		}
	});
}

function Examples(id){
	var data = $(id);

	if(data.style.display == "block"){
		data.style.display = "none";
		data.style.visibility = "hidden";
	}else{
		data.style.display = "block";
		data.style.visibility = "visible";
	}
}


