// --- galerijas apskates funkcija
function prewview(url,dir){
	var url;
	var dir;
	var td_hei = document.body.scrollTop + 75;
	var content = "<table border='0' cellpadding='0' cellspacing='0' style='height: 100%; width: 100%'>";
	    content += "<tr><td height='"+td_hei+"' colspan='3' class='opac70'>&nbsp;</td></tr>";
	    content += "<tr><td width='50%' class='opac70'>&nbsp;</td>";
	    content += "<td bgcolor='#FFFFFF' onclick='hide()' style='cursor: pointer'><img src='"+dir+"/"+url+"' hspace='2' vspace='2'></td>";
	    content += "<td width='50%' class='opac70'>&nbsp;</td></tr>";
	    content += "<tr><td height='100%' colspan='3' class='opac70'>&nbsp;</td></tr>";
	    content += "</table>";
	document.all.img_box.innerHTML=content;
	document.getElementById('img_box').style.top = 0;
	if(document.body.scrollHeight > document.body.clientHeight){document.getElementById('img_box').style.height = document.body.scrollHeight;}
	else{document.getElementById('img_box').style.height = document.body.clientHeight;}
}

// --- vidus ieguushanas funkcija
function getScrollXY(tp) {
    var x = 0, y = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        // Netscape
        x = window.pageXOffset;
        y = window.pageYOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        // DOM
        x = document.body.scrollLeft;
        y = document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        // IE6 standards compliant mode
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
    }
  if(tp=='x') return x;
  if(tp=='y') return y;
}

// --- nosleepjam elementu
function hide(){
	document.getElementById('img_box').style.top = -1 * document.body.scrollHeight; ;
}

// --- elementa ieguushanas funkcija
function el(el){
	return document.getElementById(el);
}

// --- jauna loga func
function open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable){
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';
  nw=window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
  nw.focus();
}

// --- jauna info loga func
function open_info_window(name, curl, cwidth, cheight){
	top = 50;
	left = document.body.clientWidth / 2 - cwidth / 2;
  nw = window.open(curl, name, 'left='+left+',top='+top+',width='+cwidth+',height='+cheight+',toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no');
  nw.focus();
}

// --- galerijas apskates funkcija(jauns logs, viena bilde)
function view_img(url,dir){
	var url;
	var dir;
	nw=window.open('php/show_img.php?src='+url+'&dir='+dir,"img","width=590,height=500");
	nw.focus();
}
// --- galerijas apskates funkcija no admin(jauns logs, viena bilde)
function view_img_adm(url,dir){
	var url;
	var dir;
	nw=window.open('../php/show_img.php?src='+url+'&dir='+dir,"img","width=590,height=500");
	nw.focus();
}

// --- linka apstiprinaajuma funkcija
function confirm_link(link) {
	msg = "Are you shore whant to continue?";
	c_link = window.confirm(msg);
	if (c_link) {document.location = link;}
}

// --- formas apstiprinaajuma funkcija
function confirm_form(){
       msg = "Are you shore whant to continue?";
       return confirm(msg);
}

// --- formas paarbaudes funkcija
function check_emty_fields2(mas){
  for(var i=0; i < mas.length; i++) {
		if($("#" + mas[i]).val()=="" || $("#" + mas[i]).val()===undefined) {alert("Aizpildiet nepieciešamos laukus!"); $("#" + mas[i]).focus(); return false; break;}
  }
}

// --- formas paarbaudes funkcija bez jquery
function check_emty_fields(mas){
  for(var i=0; i < mas.length; i++) {
		if(el(mas[i]).value=="" || el(mas[i]).value===undefined) {alert("Aizpildiet nepieciešamos laukus!"); el(mas[i]).focus(); return false; break;}
  }
}

// --- lapas elementa paraadiishana vai nosleepshana
function chb(id) {
	if (document.getElementById(id).style.display=='none') {
		document.getElementById(id).style.display='inline';
	} else {
		if (document.getElementById(id).style.display=='inline') {
			document.getElementById(id).style.display='none';
		}
	}
}

// --- progresa bildes paraadiishana
function progr_go(){
	document.getElementById('prog_box').style.display = "inline";
}

// --- bannera aktiv
function void_act(g_arg1,g_arg2){
	$.get("/ajax/void_act.php", { rnd:Math.random(),arg1: g_arg1,arg2: g_arg2});
}	
	
// --- iet uz adresi
function go_url(curl){
	document.location.href=curl;
}

// --- elementa redzamiibas mainja
function chdisp(el){
	// --- veertiibas ieguushana
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle['display'];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue('display');
	// --- stila mainja
	if(y=="block" || y=="table-row" || y=="table") x.style.display="none";
	else x.style.display="";	
}

// --- ieguustam visas lapas augstumu
function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}
// --- paraadam popup
function pops(c_src,c_w,c_h){
	// --- peleekais
	el('w_over').style.height = getDocHeight() + 'px';
	el('w_over').style.width = document.body.clientWidth + 'px';
	el('w_over').style.display = '';	
	// --- iframe
	var ww = document.body.clientWidth;
	var wh = document.body.clientHeight;
	el("pop_d").style.top = getScrollXY('y') + 100 + 'px';
	el("pop_d").style.left = ((ww - c_w)/2) + 'px';
	el("pop_d").style.display = '';
	el("pop_d").innerHTML = '<div style="width:'+c_w+'px; height: 25px; line-height: 25px; background-image: url(\'/img/popup-top-bg.jpg\'); text-align: right"><a href="javascript: void(0)" onclick="poph(); return false" style="color: white; margin-right: 3px; text-decoration: none">aizvērt</a></div><iframe src="' + c_src + '" width="' + c_w + '" height="' + c_h + '" scrolling="no" frameborder="0"></iframe>';

}
// --- paraadam audio popup
function pops_a(a_src,a_txt){
	var c_w = 350;
	var c_h = 80;
	// --- peleekais
	el('w_over').style.height = getDocHeight() + 'px';
	el('w_over').style.width = document.body.clientWidth + 'px';
	el('w_over').style.display = '';	
	// --- iframe
	var ww = document.body.clientWidth;
	var wh = document.body.clientHeight;
	el("pop_d").style.top = getScrollXY('y') + 100 + 'px';
	el("pop_d").style.left = ((ww - c_w)/2) + 'px';
	el("pop_d").style.display = '';
	el("pop_d").innerHTML = '<div style="width: '+c_w+'px; height: 25px; line-height: 25px; background-image: url(\'/img/popup-top-bg.jpg\'); text-align: right"><a href="javascript: void(0)" onclick="poph(); return false" style="color: white; margin-right: 3px; text-decoration: none">aizvērt</a></div><iframe src="/flv_player/?tp=audio&asrc=' + a_src + '&txt='+a_txt+'" width="' + c_w + '" height="' + c_h + '" scrolling="no" frameborder="0"></iframe>';
}
// --- paraadam video popup
function pops_v(a_src,a_txt,c_w,c_h){
	// --- peleekais
	el('w_over').style.height = getDocHeight() + 'px';
	el('w_over').style.width = document.body.clientWidth + 'px';
	el('w_over').style.display = '';	
	// --- iframe
	var ww = document.body.clientWidth;
	var wh = document.body.clientHeight;
	el("pop_d").style.top = getScrollXY('y') + 100 + 'px';
	el("pop_d").style.left = ((ww - c_w)/2) + 'px';
	el("pop_d").style.display = '';
	el("pop_d").innerHTML = '<div style="width: '+c_w+'px; height: 25px; line-height: 25px; background-image: url(\'/img/popup-top-bg.jpg\'); text-align: right"><a href="javascript: void(0)" onclick="poph(); return false" style="color: white; margin-right: 3px; text-decoration: none">aizvērt</a></div><iframe src="/flv_player/?tp=video&vsrc=' + a_src + '&txt='+a_txt+'&cw='+c_w+'&ch='+c_h+'" width="' + c_w + '" height="' + c_h + '" scrolling="no" frameborder="0"></iframe>';
}

// --- nosleepjam popup
function poph(){
	el("w_over").style.display = 'none';
	el("pop_d").style.display = 'none';
	el("pop_d").innerHTML = '';
}

// --- kalendaara pieprasiishanas funkcija
function show_cal(){
	$.get("/cal.php", { date: "" },
		function(data){
			el("cal_div").innerHTML = data;
	});
}
// --- dat mainjaas funkcija
function ch_dat(time){
	$.get("/cal.php", { date: time },
		function(data){
			el("cal_div").innerHTML = data;
	});
}
