var isDOM = (document.getElementById  ? true : false); 
var isIE4 = (document.all ? true : false);
var isIE6 = ((document.all && isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
var isNS6 = document.getElementById && !document.all;
var isDyn = (isDOM || isIE4 || isNS4);


offsetX = 50;
offsetY = 0;
var toolTipSTYLE="";

//----------------- 
/*functions preloadImages, initToolTips, moveToMouseLoc and ToolTip originally by Macromedia */

function initToolTips()
{
  if(isNS4||isNS6||isIE4)
  {
    if(isNS4) toolTipSTYLE = document.toolTipLayer;
    else if(isNS6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
    else if(isIE4) toolTipSTYLE = document.all.toolTipLayer.style;
    if(isNS4) document.captureEvents(Event.MOUSEMOVE);
    else
    {
      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";
    }
    document.onmousemove = moveToMouseLoc;
  }
}

//-----------------

function moveToMouseLoc(e)
{
	
  if(isNS4||isNS6)
  {
    x = e.pageX;
    y = e.pageY;
  }
   else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
  {
    //IE6 standards compliant mode, another few hours lost for me... :)
    y =event.y + document.documentElement.scrollTop;
    x =event.x + document.documentElement.scrollLeft;
  }
  else
  {
    x = event.x + document.body.scrollLeft;
    y = event.y + document.body.scrollTop;
	//window.alert( document.body.scrollLeft +' - '+document.body.scrollTop); -this will show '0 - 0' in IE6
  }
 

  
  toolTipSTYLE.left = x + offsetX +'px';  //this lacks "px" in the original MM version. Took me a few hours to figure it out...
  toolTipSTYLE.top = y + offsetY +'px';
  return true;
}

//-----------------



//-----------------

function tipGrad(grad)
{
  if(tipGrad.arguments.length < 1) // hide
  {
    if(isNS4) toolTipSTYLE.visibility = "hidden";
    else toolTipSTYLE.display = "none";
  }
  else // show
  {
	//moveToMouseLoc(this); 
	
	
		
    var content =
    '<img src="/grim/gr/'+grad+'" style="border: 1px solid #666; border-width: 1px 2px 2px 1px;" />';
    if(isNS4)
    {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }
    if(isDOM)
    {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block';
    }
    if(isIE4)
    {
		// window.alert(toolTipSTYLE.left +' '+toolTipSTYLE.top);
      document.all("toolTipLayer").innerHTML=content;
      toolTipSTYLE.display='block';
    }
  }
}

//------------------------------

function validateEmail(email)
{
var regx=new RegExp("\\w+[.-]?\\w+\\@\\w+\\.(\\w*\\.)*\\w{2,4}"); 
if(email.match(regx))
	{
	var niz=email.match(regx);
	var provjera=new String(niz[0]);
	if(email.length==provjera.length)
		return true;
	}
window.alert('Morate unijeti validnu e-mail adresu! \nYou must enter a valid e-mail address!');
return false;
}
	
//-----------------

function validateNumeric(broj, naziv_polja)
{
if(isNaN(broj))
	{
		window.alert(naziv_polja+" moze sadrzati samo numericke znake, ne i slova ili znake interpunkcije.");
		return false;
	}
return true;
}

//-----------------

function validateAlpha(polje, naziv_polja)
{		
var nedozvoljeni= new RegExp("\\W+\\d+");
if(polje.match(nedozvoljeni))
	{
		window.alert("Nedozvoljeni karakteri u imenu ili prezimenu (brojevi ili znaci interpunkcije)."); 
		return false;
	}
return true;
}

//-----------------------------
function uzbuna()
{
window.alert("Morate unijeti sva obavezna polja (oznacena zvjezdicom)! \nYou must enter the all required fields (marked with asterisk)!");
}

//-----------------------------

function validateForm(formName)  //svaka mi cast! :)
{
for(i=0; i<document.forms[formName].elements.length; i++)
	{
	document.forms[formName].elements[i].style.border="1px solid #909D73"; //resetovanje okvira (ako f-ja prolazi po drugi put)
	
	if(document.forms[formName].elements[i].name=="email")
		if(!validateEmail(document.forms[formName].elements[i].value))
			{
			document.forms[formName].elements[i].style.border="2px solid red";
			document.forms[formName].elements[i].focus();
			return false;
			}
			
			
	if(document.forms[formName].elements[i].value=="" && document.forms[formName].elements[i].id=="asterisk")
		{
		uzbuna();
		document.forms[formName].elements[i].style.border="2px solid red";
		document.forms[formName].elements[i].focus();
		return false;
		}
		
	}
return true;
}

//--------------------------------

function preloadImages()
{
  if(document.images)
  {
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    
    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}

//-----------------

function getLayerStyle(id)
{
	var layerStyle;
	if (isDOM) layerStyle = document.getElementById(id).style;
	if (isIE4 && !isDOM) layerStyle = document.all[id].style;
	if (isNS4) layerStyle = document.layers[id];
	return layerStyle;
}
	
//-----------------

function showHide(id)
{
	var layerStyle=getLayerStyle(id);
	if(layerStyle.display !="block")
		{
		layerStyle.display = "block";
		document.images["plus"+id].src = "img/minus.gif";
		setCookie("visible"+id, 1);
		}
	else
		{
		layerStyle.display = "none";
		document.images["plus"+id].src = "img/plus.gif";
		setCookie("visible"+id, 0);
		}

}
//-----------------

function setCookie(name, value, expires) //set 'expires' in seconds or don't set it at all ;)
{
	if(expires)
		{
		var ispar=new Date();
		var tv=ispar.getTime()+(1000*expires); //needs miliseconds!?
		ispar.setTime(tv);
		document.cookie=name+"="+value+"; expires="+ispar.toGMTString();
		}
	else
		document.cookie=name+"="+value+";";
}

//-----------------

function maliProzor(adresa)
{
window.open(adresa, "", "menubar=no,titlebar=no,scrollbars=yes,left=50,top=50,width=690,height=500, allwaysRaised=yes");
}

//-----------------

function snow()
{
	var snijeg = getLayerStyle('spisak_snijeg');
	if(snijeg.height!="auto")
		{
		snijeg.height = "auto";
		document.images["slika_spisak"].src = "img/sn_minus.gif";
		}
	else
		{
		snijeg.height = "16px";
		document.images["slika_spisak"].src = "img/sn_plus.gif";
		}

}

//--------------------------------------------------------
function showHideSimple(id)
{
	var layerStyle=getLayerStyle(id);
	if(layerStyle.display !="block")
		{
		layerStyle.display = "block";
		}
	else
		{
		layerStyle.display = "none";
		}

}
