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 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 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 changeLang() {
	var frm = document.frmLang;
	if(frm.lang[frm.lang.selectedIndex].value != '') {
		frm.action = '/lang/'+(frm.lang[frm.lang.selectedIndex].value) + fileExt;
		frm.submit();
	}
}

// user
function registerSubmit() {
	var frm = document.getElementById('frmRegister');
	frm.com_check.value='1';
	frm.action = '/user/register'+fileExt;
	frm.method = 'post';
	frm.submit();
}

function profileSubmit() {
	var frm = document.getElementById('frmProfile');
	frm.com_check.value='1';
	frm.action = '/profile'+fileext;
	frm.method = 'post';
	frm.submit();
}



function sortEvents(kaj) {
	var frm = document.frmEvents;
	var cy = frm.selYear[frm.selYear.selectedIndex].value;
	var cm = frm.selMonth[frm.selMonth.selectedIndex].value;
	var cc = escape(frm.selCountry[frm.selCountry.selectedIndex].value);
	frm.action = '/events'+fileExt+'?cy='+cy+'&cm='+cm+'&cc='+cc;
	frm.submit();
}

function login() {
	var frm = document.frmLogin;
	frm.action = '/index.php?w=li';
	frm.submit();
}


function loadContentList(contentType,page) {
	if(page=="") {
		page=1;
	}
	var fileurl = "/dummy_content.php?ct="+contentType+"&p="+page;
	if(contentType=="events") fileurl = "/dummy_events.php?p="+page;
	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("content_list").innerHTML = xmlhttp2.responseText;	
				}
			}
		}
		xmlhttp2.send(null);
	}
}

// comments

function loadCommentList(contentId, contentTypeId, page) {
	if(page=="") {
		page=1;
	}
	var fileurl = "/dummy_comments.php?ct="+contentTypeId+"&cid="+contentId+"&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"
					parent.document.getElementById("comment_list").innerHTML = xmlhttp3.responseText;	
				}
			}
		}
		xmlhttp3.send(null);
	}
}

function showCommentForm() {
	document.getElementById('comment_add_link').style.display='none';
	document.getElementById('comment_form').style.display='block';
}

function loadUserVotes(userId,rank) {
	var fileurl = "/dummy_user_votes.php?userid="+userId+"&rank="+rank;
	if (window.XMLHttpRequest) {
		xmlhttp4=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xmlhttp4=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp4!=null) {
		xmlhttp4.open("GET", fileurl, true);
		xmlhttp4.onreadystatechange = function() {
			if (xmlhttp4.readyState==4) {// 4 = "loaded"
				if (xmlhttp4.status==200) {// 200 = "OK"
					parent.document.getElementById("user_votes").innerHTML = xmlhttp4.responseText;
				}
			}
		}
		xmlhttp4.send(null);
	}
}

function voteForUser(userid, rank) {
	
	loadUserVotes("'"+userid+"'","'"+rank+"'");
}

// infobox (errmsg)

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




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


// catcha
function captchaReload() {
	//document.getElementById('captcha').innerHTML = '<img src="/captcha.php?'+(Math.floor(Math.random()*111111111111))+'" alt="Slika" width="200" height="50" />';
	document.getElementById('captcha').innerHTML = '<img src="/captcha.php?r='+(Math.floor(Math.random()*111111111111))+'" alt="Slika" width="200" height="50" alt="Osveži" title="Osveži" onclick="captchaReload()" onmouseover="this.style.cursor=\'pointer\'" />';
}


// calendar
function showCalendar(fid, link) {
	window.open('/dummy_calendar.php?fid='+fid+'&'+link,'dummy');
}
function fillDate(fid, day) {
	document.getElementById(fid).value=day;
	document.getElementById('pop_calendar').style.display='none';
}
function hideCalendar() {
	document.getElementById('pop_calendar').style.display='none';
}

// events
function eventAttend(eventid) {
	window.open('/dummy_event_attend.php?id='+eventid,'dummy');
}
function eventAttendIcon(eventid, i) {
	window.open('/dummy_event_attend.php?justicon=1&id='+eventid,'dummy');
}

// messages
function msgMarkRead() {
	var frm = document.frmMsg;
	frm.action += "&w=read";
	frm.submit();
}
function msgDelete() {
	var frm = document.frmMsg;
	frm.action += "&w=del";
	frm.submit();
}


// banners
function setClick(banid) {
	window.open('/dummy_banner_click.php?id='+banid,'dummy');
}





/* jQuery related */
$(document).ready(function() {

	//colorbox 
	$("a[rel='gallery']").colorbox({slideshow:false, slideshowAuto:false});
	$("a[rel='frame_wide']").colorbox({iframe:true, innerWidth:900, innerHeight:550, rel:'nofollow'});
	$("a[rel='frame_normal']").colorbox({iframe:true, innerWidth:670, innerHeight:550, rel:'nofollow'});
	$("a[rel='frame_small']").colorbox({iframe:true, innerWidth:470, innerHeight:300, rel:'nofollow'});
	
	

	
	
});









