// Girts Klavins 12.2009

// --- elementa ieguushana	
function el(obj){
	return document.getElementById(obj);
}

// --- iet uz adresi
function go_url(curl){
	document.location.href = curl;
}

// --- formas paarbaudes funkcija
function check_emty_fields_jq(mas,msg){
  for(var i=0; i < mas.length; i++){
		if($("#" + mas[i]).val()=="" || $("#" + mas[i]).val()===undefined) {alert(msg); $("#" + mas[i]).focus(); return false; break;}
  }
}

// --- formas paarbaudes funkcija bez jquery
function check_emty_fields(mas,msg){
  for(var i=0; i < mas.length; i++){
		if(el(mas[i]).value=="" || el(mas[i]).value===undefined) {alert(msg); el(mas[i]).focus(); return false; break;}
  }
}
// --- klases pievienoshana
function addClass(element, strClass){
	element.className += " " + strClass;
}

// --- linka apstiprinaajuma funkcija
function confirm_link(link,msg) {
	c_link = window.confirm(msg);
	if (c_link) {document.location = link;}
}

// --- klases nonjemshana 
function removeClass(element, strClass){
		if(element.className){
  		var arrList = element.className.split(" ");
  		var strClassUpper = strClass.toUpperCase();
 		for(var i=0;i<arrList.length;i++){
			if(arrList[i].toUpperCase() == strClassUpper){
				arrList.splice(i, 1);
				i--;
        	}
		}
		element.className = arrList.join(' ');
	}
}

// --- formas paarbaudes funkcija
function validate_form(form_id,msg){
	if(form_id!=''){
		var v_val = 1;
		var elem = document.getElementById(form_id).elements;
		for (var i=0;i<elem.length;i++){
			removeClass(elem[i],'f_err');
		}
		for(var i=0; i<elem.length; i++){
			if(elem[i].getAttribute("ne")=="ne"){
				if((elem[i].type=="text" || elem[i].type=="textarea" || elem[i].type=="file" || elem[i].type=="password") && elem[i].value==""){ addClass(elem[i],'f_err'); v_val = 0; } 
				if(elem[i].type=="select-one" && elem[i].options[elem[i].selectedIndex].value=="") { addClass(elem[i],'f_err'); v_val = 0; }
				if(elem[i].type=="checkbox" && elem[i].checked!==true) { addClass(elem[i],'f_err'); v_val = 0; }
			}
		}
		if(v_val==1){
			if(msg!=""){
				document.getElementById(form_id).submit();
			}else{
				return true;
			}
		}else{
			if(msg!=""){
				alert(msg);
			}else{
				return false;
			}
		}
	}
}

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

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

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

// --- 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(\'/cms2/img/popup-top-bg.jpg\'); text-align: right"><a href="javascript: void(0)" onclick="poph(); return false" style="color: white; margin-right: 5px; text-decoration: none">aizvērt</a></div><iframe src="' + c_src + '" width="' + c_w + '" height="' + c_h + '" scrolling="no" frameborder="1"></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(\'/cms2/img/popup-top-bg.jpg\'); text-align: right"><a href="javascript: void(0)" onclick="poph(); return false" style="color: white; margin-right: 5px; text-decoration: none">aizvērt</a></div><iframe src="/cms2/js/media.php?tp=a&fl=' + a_src + '&txt='+a_txt+'" width="350" height="30" scrolling="no" frameborder="0"></iframe>';
}
// --- paraadam video popup
function pops_v(a_src,c_w,c_h,a_txt){
	// --- 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(\'/cms2/img/popup-top-bg.jpg\'); text-align: right"><a href="javascript: void(0)" onclick="poph(); return false" style="color: white; margin-right: 5px; text-decoration: none">aizvērt</a></div><iframe src="/cms2/js/media.php?tp=v&fl=' + a_src + '&txt='+a_txt+'&cw='+c_w+'&ch='+c_h+'" width="' + c_w + '" height="' + c_h + '" scrolling="no" frameborder="0"></iframe>';
}
// --- paraadam img popup
function pops_i(a_src,c_w,c_h,a_txt){
	// --- 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(\'/cms2/img/popup-top-bg.jpg\'); text-align: right"><a href="javascript: void(0)" onclick="poph(); return false" style="color: white; margin-right: 5px; text-decoration: none">aizvērt</a></div><iframe src="/cms2/js/media.php?tp=i&fl=' + 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 = '';
}

// --- aktiv
function act(g_arg1,g_arg2){
	$.get("/cms2/ajax/act.php", { rnd:Math.random(),arg1: g_arg1,arg2: g_arg2});
}
