// JavaScript Document

// Function that shows "not supported" alert
function unsupported(){
	alert("Opcija jo\u0161 nije podr\u017Eana!");
}

// Function that popups window with given URL and dimensions
function popUp(URL, sWinName, wWidth, wHeight) {
		newWindow = window.open(URL,new Date().getTime(),"toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+wWidth+",height="+wHeight+"");
		newWindow.focus();
	//newWindow = window.open(URL, 'PRoba naslova', "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+wWidth+",height="+wHeight+"");
	//newWindow.focus( );
}

// =======================================================================================================
// Group of functions that work with group of elements, tables that should be displayed or hidden on click
// =======================================================================================================
// Note: idList is array of elements id's that need to be displayed or hidden

// Function that display element with ID id
function switchid(idList,id){	
	hideallids(idList);
	showelement(id);
}

// Function that hides all elements from array idList
function hideallids(idList){
	//loop through the array and hide each element by id
	for (var i=0;i<idList.length;i++){
		hideelement(idList[i]);
	}
}

function setSelected(linksArray, link_ID){
	//Use linksArray to reset each element's CSS class
	for ( var i=0; i < linksArray.length; i++ ){
		document.getElementById(linksArray[i]).className = "reasonsSubtitleLeft";
	}
	/*
	alert(document.getElementById(link_ID).className);
	*/
	document.getElementById(link_ID).className = "reasonsSubtitleLeftSelected";
}

// Function that hides element with ID = id
function hideelement(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

// Function that displays element with ID = id
function showelement(id) {
	//safe function to show an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}
// =======================================================================================================

// =======================================================================================================
// Group of functions that works with layers
// =======================================================================================================
// **** findObj ****
// Example: obj = findObj("image1");

function findObj(theObj, theDoc) {

  var p, i, foundObj;

  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length) {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];

  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);

  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

  return foundObj;

}

// **** showHideLayers ****

// Accepts a variable number of arguments, in triplets as follows:
// arg 1: simple name of a layer object, such as "Layer1"
// arg 2: ignored (for backward compatibility)
// arg 3: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'','show',Layer2,'','hide');

function showHideLayers(){ 

  var i, visStr, obj, args = showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) {
    if ((obj = findObj(args[i])) != null) {
      visStr = args[i+2];
      if (obj.style) {
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }
  }
}


// **** moveLayerToMouseLoc ****

function moveLayerToMouseLoc(theLayer, offsetH, offsetV) {

  var obj;

  if ((findObj(theLayer))!=null) {
	
	alert("Nasao sam objekat " + theLayer);
	//NS
    if (document.layers) {
      document.onMouseMove = getMouseLoc;
      obj = document.layers[theLayer];
      obj.left = mLoc.x +offsetH;
      obj.top  = mLoc.y +offsetV;
	  
	  alert("Podesavam za NS");
    }
	//IE
    else if (document.all) {
      getMouseLoc();
      obj = document.all[theLayer].style;
      obj.pixelLeft = mLoc.x +offsetH;
      obj.pixelTop  = mLoc.y +offsetV;
	  
	  alert("Podesavam za IE");
    }

    showHideLayers(theLayer,'','show');

  }

}

// **** get mouse location ****

// **** Point ****
function Point(x,y) {  this.x = x; this.y = y; }

mLoc = new Point(-500,-500);


function getMouseLoc(e) {
	//NS
  if(!document.all) {
    mLoc.x = e.pageX;
    mLoc.y = e.pageY;
  }
	//IE
  else {
    mLoc.x = event.x + document.body.scrollLeft;
    mLoc.y = event.y + document.body.scrollTop;
  }
  return true;
}

//NS init:

if(document.layers){ document.captureEvents(Event.MOUSEMOVE); document.onMouseMove = getMouseLoc; }

//
function test()

{

  if (document.layers) getMouseLoc;     //NS

  else if (document.all) getMouseLoc(); //IE

  alert(mLoc.x+","+mLoc.y);
  
  var b = new BrowserInfo();

  alert(b.name); 

}


// Example:

// var b = new BrowserInfo();

// alert(b.version); 

function BrowserInfo()

{

  this.name = navigator.appName;

  this.codename = navigator.appCodeName;

  this.version = navigator.appVersion.substring(0,4);

  this.platform = navigator.platform;

  this.javaEnabled = navigator.javaEnabled();

  this.screenWidth = screen.width;

  this.screenHeight = screen.height;

}

// Macromedia functions for preloading and swaping images

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Redirect to page on diferent language
function switch_lng(current_page, new_lng){
	// /ru/default.asp
	var new_page="../";
	//alert (new_lng);
	//new_page.concat(new_lng,"/",current_page.substring(4));
	//new_page = current_page.substring(4)
	//alert(new_page.concat(new_lng,"/",current_page.substring(4)));
    window.location = new_page.concat(new_lng,"/",current_page.substring(4));
}
