  function ds_getel(id) {
	return document.getElementById(id);
}

// Get the left and the top of the element.
function ds_getleft(el) {

	var tmp = el.offsetLeft;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetLeft;
		el = el.offsetParent;
	}
	return tmp;
}
function ds_gettop(el) {
	var tmp = el.offsetTop;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetTop;
		el = el.offsetParent;
	}
	return tmp;
}
function hides(div)
{
document.getElementById(div).style.display="none";
}
function info(t)
{
the_left = ds_getleft(t);
	the_top = ds_gettop(t) + t.offsetHeight;
	document.getElementById("info").style.display="block";
document.getElementById("info").style.top=the_top-270+'px';
document.getElementById("info").style.left=the_left-700+'px';
}
////////korpa/////////
var nek;
var path1
function displaySubs(id,vr,path,t){

if(vr=='yes' && id>0)
{
info(t);
}

nek=vr;
path1=path

    var url=path+"/korpa_add.php?id="+id+"&vr="+vr+"&tabela=proizvodi_new&random=" + Math.random();
   
    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();// Mozilla/Safari
    }else if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");// IE
    }

    xmlHttp.onreadystatechange=AJAXresponse;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null)
}

function AJAXresponse(){
 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
  
   document.getElementById("result").innerHTML=xmlHttp.responseText;
// ddrivetip(xmlHttp.responseText);
}
    else{
  
        document.getElementById("result").innerHTML = '<img src="'+path1+'/images/16.gif" style="position:absolute;right:80px;top:10px;">';
    }
}



///////end korpa//////
///go session//
function gosession(){

    var url="sess.php";
   
    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();// Mozilla/Safari
    }else if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");// IE
    }

    xmlHttp.onreadystatechange=AJAXresponseS;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null)
}

function AJAXresponseS(){
 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
 ddrivetip(xmlHttp.responseText,200)
   
}
   
}
////////////////
/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

//document.write('<div id="dhtmltooltip" style="height:15px;"></div>') //write out tooltip DIV
//document.write('<img id="dhtmlpointer" src="pixel.jpg">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip



function lol(id,path)
{
var path;

var xPos;
var yPos;
width="700";
height="700";
xPos = (window.screen.width/2) - (width/2 + 10);
yPos = (window.screen.height/2) - (height/2 + 50);
var win2 = window.open(path+"/panel/print_narocil.php?id="+id,"Window2","status=no,height="+height+",width="+width+",resizable=yes,left=" + xPos + ",top=" + yPos + ",screenX=" + xPos + ",screenY=" + yPos + ",toolbar=no,menubar=no,scrollbars=yes,location=no,directories=no");
win2.focus();
}


function aktiviraj(odpr,sid){

 document.getElementById("link").style.display="block";
    var url="glas.php?id="+odpr+"&sid="+sid;
   
    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();// Mozilla/Safari
    }else if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");// IE
    }

    xmlHttp.onreadystatechange=AJAXresponseS;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null)
//}

}
function AJAXresponseS(){

    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
   document.getElementById("results").innerHTML=xmlHttp.responseText;
}  else{
        document.getElementById("results").innerHTML = '<span style="font-weight:bold;">Glasam...</span>';
    }
}


//////// check reg form
var form = "";
var submitted = false;
var error = false;
var error_message = "";

function check_input(field_name, field_size, message) {
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (field_value == '' || field_value.length < field_size) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_radio(field_name, message) {
  var isChecked = false;

  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var radio = form.elements[field_name];

    for (var i=0; i<radio.length; i++) {
      if (radio[i].checked == true) {
        isChecked = true;
        break;
      }
    }

    if (isChecked == false) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_select(field_name, field_default, message) {
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (field_value == field_default) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_password(field_name_1, field_name_2, field_size, message_1, message_2) {
  if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) {
    var password = form.elements[field_name_1].value;
    var confirmation = form.elements[field_name_2].value;

    if (password == '' || password.length < field_size) {
      error_message = error_message + "* " + message_1 + "\n";
      error = true;
    } else if (password != confirmation) {
      error_message = error_message + "* " + message_2 + "\n";
      error = true;
    }
  }
}

function check_password_new(field_name_1, field_name_2, field_name_3, field_size, message_1, message_2, message_3) {
  if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) {
    var password_current = form.elements[field_name_1].value;
    var password_new = form.elements[field_name_2].value;
    var password_confirmation = form.elements[field_name_3].value;

    if (password_current == '' || password_current.length < field_size) {
      error_message = error_message + "* " + message_1 + "\n";
      error = true;
    } else if (password_new == '' || password_new.length < field_size) {
      error_message = error_message + "* " + message_2 + "\n";
      error = true;
    } else if (password_new != password_confirmation) {
      error_message = error_message + "* " + message_3 + "\n";
      error = true;
    }
  }
}

function check_form(form_name) {
  if (submitted == true) {
    alert("Ovaj formular je već primljen. Kliknite na Ok i sačekajte da se proces završi.");
    return false;
  }

  error = false;
  form = form_name;
  error_message = "Greške su nastale prilikom slanja vašeg formulara!\nMolimo napravite sledece ispravke:\n\n";


  check_input("firstname", 2, "Vaše ime se mora sadržati od najmanje 2 znakova.");
  check_input("lastname", 2, "Vaše prezime se mora sastojati od najmanje 2 znakova.");


  check_input("email_address", 6, "Vaša E-Mail mora sadržati najmanje 6 znakova.");
  check_input("street_address", 5, "Naziv Vaše ulice mora sadržati najmanje 5 znakova.");
  check_input("postcode", 4, "Vaš poštanski broj mora se sastojati od najmanje 4 znakova.");
  check_input("city", 3, "Vaš grad mora se sastojati od najmanje 3 znakova.");


  check_select("country", "", "Morate izabrati državu sa spiska.");

  check_input("telephone", 3, "Vaš telefon se mora sastojati od najmanje 3 brojeva.");

  check_password("password", "confirmation", 5, "Vaša šifra se mora sastojati od najmanje 5 znakova.", "Potvrdena šifra mora biti identicna sa šifrom.");
  check_password_new("password_current", "password_new", "password_confirmation", 5, "Vaša šifra se mora sastojati od najmanje 5 znakova.", "Vaša nova šifra se mora sastojati od najmanje 5 znakova.", "Potvrdena šifra mora biti identicna šifri.");

  if (error == true) {
    alert(error_message);
    return false;
  } else {
    submitted = true;
    return true;
  }
}
//////// end chec reg  form//
