if (navigator.userAgent.indexOf("Mozilla/4.0") != -1) {
	version = 4;
} else if (navigator.userAgent.indexOf("Mozilla/3.0") != -1) {
	version = 3;
} else if (navigator.userAgent.indexOf("Mozilla/2.0") != -1) {
	version = 2;
} else if (navigator.userAgent.indexOf("MSIE") != -1) {
	version = 1;
} else {
	version = 0;
}

function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ns6 = (this.b=="ns" && this.v==6)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.min = (this.ns||this.ie)
}
is = new BrowserCheck()

var zoomwindow;

function deplace(window,width,height) {
	var scr_x = screen.width;
	var scr_y = screen.height;
	if (is.v >= 4) {
		if (is.ns) {
			window.moveTo((scr_x/2)-(width/2), (scr_y/2)-(height/2));
		} else {
			window.moveTo(parent.window.screenLeft+300, parent.window.screenTop+50);
		}
	}
}
	
var movePopup = true;
var scrollPopup = 1;

function popup(url, width, height) {
	if (url != "") {
		var features;
		var windowName = "ZOOMWINDOW";
		
		features = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + scrollPopup + ",resizable=0,width=" + width + ",height=" + height + "'";
			
		movePopup = true;
		scrollPopup = 1;
		if (popup.arguments.length >= 4) {
			if (popup.arguments[3]) {
				movePopup = true;
			} else {
				movePopup = false;
			}
		}
		if (popup.arguments.length >= 5) {
			if (popup.arguments[4] == 0 || popup.arguments[4] == 1) {
				scrollPopup = popup.arguments[4];
			}
		}
		if (popup.arguments.length >= 6) {
			zoomwindow = popup.arguments[5];
			windowName = zoomwindow;
		} else {
			if (zoomwindow != null) {
				if (!zoomwindow.closed)
					zoomwindow.close();
			}
		}
		
		zoomwindow = window.open(url,windowName,features);
		
		if (zoomwindow != null) {
			if (version >= 3) {
				zoomwindow.focus();
			}
			if (movePopup) deplace(zoomwindow,width,height);
		}
	}
}

var isPageLoaded = false;

function placeCarto()
{
	isPageLoaded = true;
	
	var oOrigin = document.getElementById("oOrigin");
	var oCartoContainer = document.getElementById("oCartoContainer");
	//alert(oOrigin.offsetLeft);
	/*if (is.ie)
	{
		oCartoContainer.style.width = 823 + "px";
		oCartoContainer.style.left = oOrigin.offsetLeft - 823 + 250 + "px";
		//oCartoContainer.style.left = oOrigin.offsetLeft + "px";
	}
	else
	{*/
		oCartoContainer.style.left = oOrigin.offsetLeft + "px";
	//}
	oCartoContainer.style.top = oOrigin.offsetTop + "px";
	oCartoContainer.style.visibility = "visible";
	
	init();
}

function openSitraObject(id_lang, id_sitra)
{
	popup("/popup_sitra.php?id_lang=" + id_lang + "&id_sitra=" + id_sitra, 617, 700);
}

/* 
Methods for resizing the flash stage at runtime.

setFlashWidth(divid, newW)
divid: id of the div containing the flash movie.
newW: new width for flash movie

setFlashWidth(divid, newH)
divid: id of the div containing the flash movie.
newH: new height for flash movie

setFlashSize(divid, newW, newH)
divid: id of the div containing the flash movie.
newW: new width for flash movie
newH: new height for flash movie

canResizeFlash()
returns true if browser supports resizing flash, false if not. 
*/

function flashDebugMsg(msg)
{
	alert(msg);
}

function setFlashWidth(divid, newW)
{
	//if (!is.ie)
	//{
		var oOrigin = document.getElementById("oOrigin");
		var oCartoContainer = document.getElementById("oCartoContainer");
		if (newW < 823)
		{
			oCartoContainer.style.left = oOrigin.offsetLeft - 12 + "px";
			oCartoContainer.style.width = newW + "px";
		}
		else
		{
			oCartoContainer.style.left = oOrigin.offsetLeft - 823 + 250 + "px";
			oCartoContainer.style.width = newW + "px";			
		}
	//}
	//alert(document.getElementById(divid));
	document.getElementById(divid).style.width = newW + "px";
}

function setFlashHeight(divid, newH)
{
	document.getElementById(divid).style.height = newH + "px";		
}

function setFlashSize(divid, newW, newH)
{
	setFlashWidth(divid, newW);
	setFlashHeight(divid, newH);
}

function canResizeFlash(){
	var ua = navigator.userAgent.toLowerCase();
	var opera = ua.indexOf("opera");
	if (document.getElementById)
	{
		if(opera == -1) return true;
		else if(parseInt(ua.substr(opera+6, 1)) >= 7) return true;
	}
	return false;
}

function showSendtoafriend(divid)
{
	if (isPageLoaded)
	{
		var obj = document.getElementById(divid);
		if (document.getElementById(divid).style.display == "none" || document.getElementById(divid).style.display == "")
		{
			obj.style.display = "block";
		}
		else
		{
			obj.style.display = "none";
		}
	}
}

function showMeteo()
{
	var flashObj = document.getElementById('carto');
	if (flashObj.PercentLoaded() >= 100)
	{
		flashObj.GotoFrame(1);
		flashObj.play();
	}
}

// Get url parameter
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
