//Profis added begin
var IE  = (document.all) ? true : false;                      // ie4+
//Profis added end


function langas (p, w, h){
 var url = "index.php"+p+"&langas=true";
    if (w == ""){
        w = 660;
    }
    else{
        if((parseInt(w) < 300)||(parseInt(w) > 600))
            w = 300;
        w =parseInt(w) + 260;
    }
    if (h == ""){
        h = 600;
    }
    else {
        if (parseInt(h) <= 600)
            h = 600;
    }


 a = window.open(url,"Įsiskolinimai","status=no,toolbar=no,scrollbars=yes,titlebar=no,resizable=no,width="+w+",height="+h+",top=100,left=200");
 a.focus();
}
function langas1(p) {
 var kl = document.prekes.lygp.value;
 var url = "index.php"+p;

    url = url + "&lpid="+kl+"&kur=1";
 a = window.open(url,"Įsiskolinimai","status=yes,toolbar=no,scrollbars=yes,titlebar=no,resizable=no,width=800,height=500,top=100,left=200");
 a.focus();
}
function show_debts (p) {
 var url = "Kreditas/debt_table.php?what="+p;
 a = window.open(url,"Įsiskolinimai","status=no,toolbar=no,scrollbars=yes,titlebar=no,resizable=no,width=655,height=200,top=100,left=200");
 a.focus();
}
function show_ataskaita (p) {
 var url = "Ataskaitos/ataskaitos.php?"+p;
 a = window.open(url,"ataskaita","status=no,toolbar=no,scrollbars=yes,titlebar=no,resizable=no,width=655,height=600,top=100,left=200");
 a.focus();
}

//--- Nustato focusas ant login lauko
function init(){
    if(document.login){
        if(document.login.login_name){
            document.login.login_name.focus();
        }
    }
}
function print_page(){
    x=document.getElementById("butns");
    x.style.visibility = "hidden";
    print();
    x.style.visibility = "visible";
}
function cl(){
    close();
}

var WindowObjectReference = null; // global variable

//parodo paveiksleli
function show_pict(id){	
    if(WindowObjectReference == null || WindowObjectReference.closed)
  	{
  		WindowObjectReference = window.open("../_include/img.php?img="+id,
           "PromoteFirefoxWindowName", "status=no,toolbar=no,scrollbars=no,titlebar=no,resizable=no,width=200, height=200");
  	}
  	else
  	{
		WindowObjectReference = window.open ("../_inlcude/img.php?img="+id,
		"PromoteFirefoxWindowName", "status=no,toolbar=no,scrollbars=no,titlebar=no,resizable=no,width=200, height=200");
		WindowObjectReference.focus();
		
		
  	};
}

//rodomas duoto URL paveikslelis
function show_pict2 (source){	
    if(WindowObjectReference == null || WindowObjectReference.closed)
  	{
  		WindowObjectReference = window.open(source,
           "PromoteFirefoxWindowName", "status=no,toolbar=no,scrollbars=no,titlebar=no,resizable=no,width=400, height=400");
  	}
  	else
  	{
		WindowObjectReference = window.open ("../_include/img.php?src="+source,
		"PromoteFirefoxWindowName", "status=no,toolbar=no,scrollbars=no,titlebar=no,resizable=no,width=400, height=400");
		WindowObjectReference.focus();
		
  	};
}




//padeda i krepselis preke
function put_to_cart(url, name){
    var elements = document.forms["prekes"].elements;
    var pk ="";
    if(elements){   
	    for (i=0;i<elements.length;i=i+1){
	        if(elements[i].name == name)
	            pk = elements[i].value;
	    }
    }    
    document.location.href= url + "&pk="+pk;
}

//padeda i krepselis preke si kompletuojamu prekiu
function put_to_cart_kompl(url, name,id){
    //var selectas = document.f[name];
    var pk ="";
    pik = id;
    pk = document.f[name+"_kiekis"].value;
  
    document.location.href= url + "&pik="+pik+"&pk="+pk

}
//padeda i krepselis preke si kompletuojamu prekiu
function put_to_cart_kompl1(url, name){
    var selectas = document.f[name];
    var pk ="";
    pik = selectas.options[selectas.selectedIndex].value;
    pk = document.f[name+"_kiekis"].value;
    document.location.href= url + "&pik="+pik+"&pk="+pk;

}



//leidzia ivesti tik skaicius
function numbers(e, link){
        var key;

         if (document.all) {
                key = window.event.keyCode;
        }
        else{
                key = e.which;
        }
        
        if(key == 13){
            cart_walk(link);
            if (document.all)
                        e.returnValue = false
                else
                        return false;
        }
        else if(!((key == 0)||(key == 8)||((key >= 48)&&(key <= 57))))
                if (document.all)
                        e.returnValue = false
                else
                        return false;
}
//vaiksciojimas krepselyje
function cart_walk(param){
    var str = "";
    if(document.kreps){
        for(i = 0;  i < document.kreps.elements.length; i = i +2){
            if(str == ""){
                str = document.kreps.elements[i+1].value + "-"+ document.kreps.elements[i].value;
            }
            else{
                str += "-" + document.kreps.elements[i+1].value + "-"+  document.kreps.elements[i].value;
            }
        }
        if(param != ""){
            if(document.comment.pag_pastaba.value != "")
                document.location.href="index.php?" + param + "&prekes="+ str + "&comment="+document.comment.pag_pastaba.value ;
            else
                document.location.href="index.php?" + param + "&prekes="+ str;
        }
    }
    else{
        if(param != ""){
            document.location.href="index.php?" + param
        }
    }
}

//uzsako tiesiai is krepselio
function uzsakyti(){
    document.uzsk.pag_pastaba.value = document.comment.pag_pastaba.value;
    document.uzsk.submit();
}
function uzsakymas(link){
    document.uzsk.pag_pastaba.value = document.comment.pag_pastaba.value;
    document.uzsk.action = link; 
    document.uzsk.submit();
}

//saugo sablonini krepseli
var click = 1;
function save_sh(ths, uzrasas,uzrasas1){
    ths.value=uzrasas;
     if(click == 2){
        var lyer = document.getElementById('zz');
        lyer.style.visibility = "hidden";
        var inpt =document.getElementById('shpavadinimas');
        var pavad = inpt.value
        if(pavad != ""){
            cart_walk("mid=2&shkp=" + pavad);
        }
        else{
            ths.value=uzrasas1;
        }
     }
     if(click == 1){
        var lyer = document.getElementById('zz');
        lyer.style.visibility = "visible";
           click++;
     }
     else{
       click = 1;
     }
    //var pavad = window.open("Krepselis/shpavad.html","","status=no,toolbar=no,scrollbars=yes,titlebar=no,resizable=no,width=300,height=130,top=100,left=200");
    //var pavad = showModalDialog("Krepselis/shpavad.html","","dialogWidth:300px; dialogHeight:120px" )
    //alert(pavad.returnValue);
    //cart_walk("mid=2&shkp=" + pavad);
}
//parodo prekes info is ijuostos
function ijuosta(link, val){
    document.location.href= link + val;
}

//nepraleidzia blogu simboliu
var z = new Array();
z[0] = "*";
z[1] = '"';
z[2] = "|";
z[3] = ":";
z[4] = ">";
z[5] = "<";
z[6] = "=";
z[7] = "+";
z[8] = ";";
z[9] = '\\';
z[10] = "(";
z[11] = ")";
z[12] = "#";
z[13] = "[";
z[14] = "]";
z[15] = "&";
z[16] = "/";
z[17] = "^";
z[18] = "";
z[19] = "®";
z[20] = "^";
z[21] = "";
z[22] = "";


function blogu_nepraleidzia_ivesti(e, ths){
    var str = ths.value.toString();

    for (i = 0; i < z.length ; i++)
    {
        if(str.indexOf(z[i]) >=0){
            ths.value="";
        }
    }
    return true;
}

function put_to_lyg(id){
    var line = document.prekes.lygp.value;
    var arr= line.split("-");
    var found = false;
    var foundi;



    for(var i = 0; i <= arr.length; i++){
        if(arr[i] == id){
            arr[i] = "";
            found = true;
            foundi = i;
        }
    }
    line = "";
    for(var i = 0; i <= arr.length; i++){
        if((arr[i] != "")&&(arr[i] != undefined)){
            if(i == foundi) continue;
            if(line == "")
                line += arr[i];
            else
                line += "-"+arr[i];
        }
    }

    if(!found){
        if( line == "")
            line  += id;
        else
            line  += "-"+id;
    }
   
   document.prekes.lygp.value = line;

   line = document.prekes.lygp.value;
   arr= line.split("-");
   var lpk = document.getElementById('lpk');
   var lpk1 = document.getElementById('lpk1');
   if(line == ""){
    lpk.innerHTML = "0";
    lpk1.innerHTML = "0";
   }
   else{
    lpk.innerHTML =arr.length;
    lpk1.innerHTML =arr.length;
   }
}

function DoDiv(id, ths) {
	
    var item = null;
        if (document.getElementById) {
        item = document.getElementById(id);
        }
    else if (document.all){
            item = document.all[id];
        } else if (document.layers){
            item = document.layers[id];
        }
        if (!item) {
        }
        else if (item.style) {
        	if (item.style.display == "none"){
        		item.style.display = ""; 
        		//ths.style.color = "#ff0000";
        	}
        	else {
        		item.style.display = "none"; 
        		ths.style.color = "";
        	}
        }
        else{
        	item.visibility = "show"; 
        }
}

function open_sh_view(url){
	var width = 600;
	var height = 600;
	var param_line  = "status=no,toolbar=no,scrollbars=yes,titlebar=no,resizable=no,width=";
        param_line += width;
        param_line += ",height=";
        param_line += height;
        param_line += ",top=100,left=200";
    var wind = window.open(url, 'wwwSkaitaWindow1',param_line);
    wind.focus();
}

function change_to_input(url, kiekis, id, ths){
	var val = ths.innerHTML;
	var str_tmp = "'"+url+"',"+id;
	var str = '<input type="text" size="5" value="'+kiekis+'" name="pr_'+id+'" >';
	str +=    '<input type="button" value="Keisti" onclick="change_kiekis('+str_tmp+')">';	
	
	ths.innerHTML = str;
	ths.onclick = "";
}

function change_kiekis(url, id){
	var kiekis = document.kreps['pr_'+id].value;	
	document.location.href= url+"&nkiekis="+id+"-"+kiekis;
}

function ask(question){
    if(confirm(question))
        return true;
    else
        return false;
}

var tolaiau_ar_ne = 0;

function confirm_window(msg, f){	
	var myWin= open("", "displayWindow","width=300,height=100,status=no,toolbar=no,menubar=no");
  	myWin.document.open();
    myWin.document.write('<html><head><title>Dėmesio</title>\n');
    myWin.document.write('<style>\n');
    myWin.document.write('body{text-align: center;font-size: 11px;margin: 0px 0px 0px 0px; background-color: #DCDCDC;}\n');
    myWin.document.write('input{border-right: #808080 1px solid;border-top: #808080 1px solid;');
    myWin.document.write('border-bottom: #808080 1px solid;border-left: #808080 1px solid;color: #000000;');
	myWin.document.write('font-size: 13px;font-family: Verdana; background-color: #ffffff;}\n');
    myWin.document.write('</style>\n');
    myWin.document.write('</head>\n<body style="padding: 0px;">\n');
    myWin.document.write("<h3 style=+\" font-family: Verdana; font-size: 13px;text-align: center;\">"+msg+"</h3>");
    myWin.document.write("<input type=\"button\" value=\"Toliau\" style=\"color: green;\" onclick=\"JavaScript: window.opener."+f+"; window.close();\">&nbsp;");    
    myWin.document.write("<input type=\"button\" value=\"Atšaukti\" style=\"color: red;\" onclick=\"JavaScript: window.close();\">");    
    myWin.document.write("</body>\n</html>");    
    myWin.document.close();
    myWin.focus();
}
function sudeti_prekes_is_istorijos(url){
	document.location.href=url;
}


/*** STATISTIKA ***/

function st_add_part() {
  var s = document.f;
  var S2len=s['all_part[]'].length;
  for(i=0; i<s.tmp_part.length; i++) {
    if(s.tmp_part[i].selected) {
       s['all_part[]'].options[S2len++]=new Option(s.tmp_part[i].text, s.tmp_part[i].value, true, true);
      // s['all_part[]'][S2len].selected=false;
       s.tmp_part.options[i]=null;
    }
 }
}

function st_remove_part() {
  var s = document.f;
  var S2len=s.tmp_part.length;
  for(i=0; i<s['all_part[]'].length; i++) {
    if(s['all_part[]'][i].selected) {
       s.tmp_part.options[S2len++]=new Option(s['all_part[]'][i].text, s['all_part[]'][i].value, true, true);
       s['all_part[]'].options[i]=null;
    }
  }
}

function st_add_igr() {
  var s = document.f;
  var S2len=s['igrupe[]'].length;
  for(i=0; i<s.igrupe_tmp.length; i++) {
    if(s.igrupe_tmp[i].selected) {
       s['igrupe[]'].options[S2len++]=new Option(s.igrupe_tmp[i].text, s.igrupe_tmp[i].value, true, true);
      // s['all_part[]'][S2len].selected=false;
       s.igrupe_tmp.options[i]=null;
    }
 }
}

function st_remove_igr() {
  var s = document.f;
  var S2len=s.igrupe_tmp.length;
  for(i=0; i<s['igrupe[]'].length; i++) {
    if(s['igrupe[]'][i].selected) {
       s.igrupe_tmp.options[S2len++]=new Option(s['igrupe[]'][i].text, s['igrupe[]'][i].value, true, true);
       s['igrupe[]'].options[i]=null;
    }
  }
}

function do_select() {
/*  var s = document.f;

  for(i=0; i<s['igrupe[]'].length; i++)
    s['igrupe[]'][i].selected=true;

  for(i=0; i<s['all_part[]'].length; i++)
    s['all_part[]'][i].selected=true;
    */
    
}

var kkiekis = "";
function delete_kiekis(ths){
        kkiekis = ths.value;
        ths.value = '';
}
function change_kiekis(ths){
        if(ths.value == ""){
                ths.value = kkiekis;
        }
        kkiekis = '';
}

//datos pasirinkimas
function prDate(form, element ) {
    var form;
    var element;
    var posX = 300;
    var posY = 200;

    if (!window.focus) return true;

    window.open("../_include/date.php?form="+form+"&element="+element, "data",
                "directories=0,status=0,menubar=no,resizable=no,width=300,height=205,toolbar=no," +
                "screenX="+posX+",screenY="+posY+",left="+posX+",top="+posY );
  return false;
}
/*** STATISTIKA ***/

