//kreiranje postavki za dialogbox kod greski
// global variables //
var TIMER = 10;
var SPEED = 100;
var WRAPPER = 'content';

// calculate the current window width //
function pageWidth() {
  return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// calculate the current window height //
function pageHeight() {
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// calculate the current window vertical offset //
function topPosition() {
  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// calculate the position starting at the left of the window //
function leftPosition() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

// build/show the dialog box, populate the data and call the fadeDialog function //
function showDialog(message)
{	var dialog;
	var dialogOK;
	var dialogcontent;
	var dialogmask;
	if(!document.getElementById('dialog')) 
	{dialog = document.createElement('div');
    dialog.id = 'dialog';
    dialogcontent = document.createElement('div');
    dialogcontent.id = 'dialog-content';
    dialogOK = document.createElement('div');
    dialogOK.id = 'dialog-OK'
    dialogmask = document.createElement('div');
    dialogmask.id = 'dialog-mask';
    document.body.appendChild(dialogmask);
	document.body.appendChild(dialog);
    dialog.appendChild(dialogcontent);
	dialog.appendChild(dialogOK);
    dialogOK.setAttribute('onclick','hideDialog()');
    dialogOK.onclick = hideDialog;
	} else {
    dialog = document.getElementById('dialog');
    dialogcontent = document.getElementById('dialog-content');
    dialogOK = document.getElementById('dialog-OK');
    dialogmask = document.getElementById('dialog-mask');
    dialogmask.style.visibility = "visible";
	dialog.style.visibility = "visible";
	}
	var width = pageWidth();
	var height = pageHeight();
	var left = leftPosition();
	var top = topPosition();
	var dialogwidth = dialog.offsetWidth;
	var dialogheight = dialog.offsetHeight;
	var topposition = top + (height / 2) - (dialogheight / 2);
	var leftposition = left + (width / 2) - (dialogwidth / 2);
	dialog.style.top = topposition + "px";
	dialog.style.left = leftposition + "px";
	dialogcontent.innerHTML = message;
	dialogOK.innerHTML = 'OK';
}

// hide the dialog box //
function hideDialog() 
{
  var dialog = document.getElementById('dialog');
  dialog.style.visibility = "hidden";
  var dialog = document.getElementById('dialog-mask');
  dialog.style.visibility = "hidden";
	if (setfocus==1)
  {document.getElementById('name').focus()}
	  else if (setfocus==2)
  {document.getElementById('email').focus()}
}


// provjera da li su ispunjeni podaci za Ime i e-mail i ako nisu prikazivanje dialoga i postavljanje fokusa na polje koje je potrebno ispuniti//
function validate_name(namefield,namealert)
    {
    with (namefield)
      {
      if (value==null||value=="")
        {setfocus=1;showDialog(namealert);return false;}
      else
        {return true;}
      }
    }
    
function validate_email(emailfield,emailalert)
    {
    with (emailfield)
      {
      apos=value.indexOf("@");
      dotpos=value.lastIndexOf(".");
      if (apos<1||dotpos-apos<2)
        {setfocus=2;showDialog(emailalert);return false;}
      else {return true;}
      }
    }
    
    
function validate_form(thisform)
    {
	var setfocus;
	setfocus = 0;
    with (thisform)
      {
      if (validate_name(Name,"Molimo upi&scaron;ite Va&scaron;e ime.")==false)
      {return false;}
      else if (validate_email(Email,"Niste unijeli e-mail adresu ili je neispravna. Molimo upi&scaron;ite ispravnu e-mail adresu.")==false)
      	{return false;}
      }
	}

