﻿// JScript File

function sendcomment(txt,id,target){
    
    ajaxpack.getAjaxRequest('/xmag/nightlife/controls/fotokomentar_insert.aspx','id=' + id + '&tekst=' + txt,processSendComment,"txt",target)
}
function processSendComment(sender,target,filetype){
    var myreq = sender;
        if (myreq.readyState == 4){ //if request of file completed
            if (myreq.status==200 || window.location.href.indexOf("http://")!=0){ //if request was successful or running script locally
                if (filetype=="txt"){
                    alert("Komentar je poslan. Nakon autorizacije bit će dodan.")
                    target.value='';
                }
            }
            else
            {
                alert("Greška")
            }
        }
}

function sendforumpost(idgalerija,naziv,txtel,target){
   //alert('id=' + idgalerija + '&tekst=' + escape(txtel.value) + '&naziv=' + naziv)
    ajaxpack.getAjaxRequest('/xmag/nightlife/controls/postfromgallery.aspx','idgalerija=' + idgalerija + '&tekst=' + escape(txtel.value) + '&naziv=' + naziv + '&post=true',processSendPost ,"txt",target)
    txtel.value="";
}

function processSendPost(sender,target,filetype){
    var myreq = sender;
        if (myreq.readyState == 4){ //if request of file completed
            if (myreq.status==200 || window.location.href.indexOf("http://")!=0){ //if request was successful or running script locally
                if (filetype=="txt"){
                    target.innerHTML=myreq.responseText;
                }
            }
            else
            {
                alert("Html nije dozvoljen.")
            }
        }
}


function changeclub(id){
    document.location.href='/xmag/nightlife/klub/' + id + '/show.aspx';
}


function reloadPanel(url,params,identifier){   
    ajaxpack.getAjaxRequest(url,params,processreloadPanel,"txt",identifier)
}
function reloadEvents(url,params,identifier){   
    ajaxpack.getAjaxRequest(url,params,processreloadEvents,"txt",identifier)
}

function processreloadPanel(sender,target,filetype){
        if (sender.readyState == 4){ //if request of file completed
            if (sender.status==200 || window.location.href.indexOf("http://")!=0){ //if request was successful or running script locally
                if (filetype=="txt"){
                    if (target) {                      
                        document.getElementById(target).innerHTML = sender.responseText;  
                    }
                    else
                        alert('ERROR: no target');
                }
            }
        }       
}


function processreloadEvents(sender,target,filetype){
 
        if (sender.readyState == 4){ //if request of file completed
            if (sender.status==200 || window.location.href.indexOf("http://")!=0){ //if request was successful or running script locally
                if (filetype=="txt"){
                    if (target) {
                        
                        document.getElementById(target).innerHTML = sender.responseText;
                        scr0=new hscroll('hscrollviewport0','hscroll0','hscroll0inner',176,0,4,document.getElementById('eventitems').innerHTML,2);
                    }
                    else
                        alert('ERROR: no target');
                }
            }
            else
            {
            alert(sender.status);
            }
        }
        
}


var lastselected=null;
var lastselectedclassname='';
function change(el,year,month,day,idklub){
        if (lastselected!=null){lastselected.parentNode.className=lastselectedclassname};
        lastselected=el;
        lastselectedclassname=el.parentNode.className;
        el.parentNode.className='today';
        
        reloadEvents("/xmag/nightlife/controls/events.aspx","idklub=" + idklub +"&datum=" + day + "." + month + "." + year,'hscroll0inner')
        
}


function sendshout(txtid,elMessages,elLastMessage){
    var el=document.getElementById(txtid);
    ajaxpack.postAjaxRequest("/xmag/nightlife/controls/shoutbox.ashx","last=" + document.getElementById(elLastMessage).value + "&post=true&tekst=" + escape(el.value),processAppendShoutboxpannel,"xml",elMessages,elLastMessage,el) 
    el.value='';
}

function appendshoutboxpannel(url,elMessages,elLastMessage,txtid){
    var el=document.getElementById(txtid);
    ajaxpack.postAjaxRequest(url,"last=" + document.getElementById(elLastMessage).value,processAppendShoutboxpannel,"xml",elMessages,elLastMessage,el)  
}

function processAppendShoutboxpannel(sender,target,filetype,elLastMessage,el){       
						
							if (sender.readyState == 4){ 
							
							if (sender.status==200 || window.location.href.indexOf("http")==-1){
								if (filetype=="xml"){																
										
										var xmlDoc;
										xmlDoc=sender.responseXML;
										nl=xmlDoc.getElementsByTagName("poruke");
										var scrollerel=document.getElementById('shoutboxholder');
										var scrolling=false;
										if (scrollerel.scrollTop + scrollerel.clientHeight==scrollerel.scrollHeight || document.getElementById(elLastMessage).value==0){scrolling=true}
										
										
										
										for (var i=0;i<nl.length;i++)
										{		
												var newel=document.createElement("li");
												try{
													newel.innerHTML='<a target="_blank" href="/indexklub/profili/?' + nl[i].getElementsByTagName("post_username")[0].firstChild.nodeValue + '"><img class="main" src="http://www.index.hr/indexklub/' + nl[i].getElementsByTagName("fotografija")[0].firstChild.nodeValue + '" /></a>';
												}
												catch (e)
												{
													newel.innerHTML='<a target="_blank" href="/indexklub/profili/?' + nl[i].getElementsByTagName("post_username")[0].firstChild.nodeValue + '"><img class="main" src="http://www.index.hr/indexklub/slike/Ostalo/Razno/204.jpg" /></a>'
												}
												newel.innerHTML+=nl[i].getElementsByTagName("post_text")[0].firstChild.nodeValue;
												newel.innerHTML+='<em><a target="_blank" href="/indexklub/profili/?' + nl[i].getElementsByTagName("post_username")[0].firstChild.nodeValue + '">' + nl[i].getElementsByTagName("post_username")[0].firstChild.nodeValue + '</a> &bull; ' + nl[i].getElementsByTagName("post_time")[0].firstChild.nodeValue.substring(11,16) + '</em>'
												var parent=document.getElementById(target);
												if (parent.childNodes.length>20){parent.removeChild(parent.childNodes[0])}
												parent.appendChild(newel);
												
												if (i==nl.length-1){
												document.getElementById(elLastMessage).value=nl[i].getElementsByTagName("post_id")[0].firstChild.nodeValue
										        }
										}
										
										
										if (scrolling==true){
										scrollerel.scrollTop=32767;
										}
										if (el!=null){
										setTimeout("appendshoutboxpannel('/xmag/nightlife/controls/shoutbox.ashx','shoutboxmessages','lastmessageid','" + el.id + "')",10000);
										}
								       
								}
							}
							else
							{
							    
							}
							}
}
