var copyspeed= 1;
var actualwidth = 0;
var cross_slide, ns_slide;
var is_ie = (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent));
var is_opera = ((navigator.userAgent.toUpperCase().indexOf("OPERA") != -1));

function getTargetElement(ev){
	var f = is_ie ? window.event.srcElement : ev.target;
	while(f.nodeType != 1) f = f.parentNode;
	return f;
}

function getAbsolutePos(el){
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(el.tagName);
	if(is_div && el.scrollLeft) SL = el.scrollLeft;
	if(is_div && el.scrollTop)  ST = el.scrollTop;
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if(el.offsetParent){
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

function addEvent(el, evname, func){
	if(el.attachEvent){
		el.attachEvent("on" + evname, func);
	}else if(el.addEventListener){
		el.addEventListener(evname, func, true);
	}else{
		el["on" + evname] = func;
	}
}

function h6_over(ev){
	var oH6 = getTargetElement(ev);
	var vizibil = oH6.getAttribute("vizibil");
	if(vizibil == 1){
		oH6.style.borderColor = "blue";
		oH6.style.borderWidth = "2px";
		oH6.style.cursor = "hand";
		oH6.style.cursor = "pointer";
	}else{
		oH6.style.borderColor = "red";
		oH6.style.borderWidth = "2px";
		oH6.style.cursor = "hand";
		oH6.style.cursor = "pointer";
	}
}

function h6_out(ev){
	var oH6 = getTargetElement(ev);
	oH6.style.borderColor = "transparent";
	oH6.style.borderWidth = "0px";
}

function h6_click(ev){
	var oH6 = getTargetElement(ev);
	var vizibil = oH6.getAttribute("vizibil");
	location.href = ATLAS_HTTP + "/_mapclick.php?" + oH6.id;
}

function disableEvent(ev){
	return false;
}

function InitJS(){
	// Load image gallery
	fillup();

	// Get map click position
	var mc = document.getElementById("mapclick");
	if(mc){
		// Get position
		var mc_pos = getAbsolutePos(mc);

		// Set maps event listeners
		var h6s = document.getElementsByTagName("h6");
		for(kk=0; kk<h6s.length; kk++){
			var h6 = h6s[kk];
			if(h6.className != "m") continue;
			addEvent(h6, "mouseover", h6_over);
			addEvent(h6, "mouseout", h6_out);
			addEvent(h6, "click", h6_click);

			// Set position
			var pos = h6.getAttribute("pos").split(":");
			var ll = parseInt(pos[0]);
			var tt = parseInt(pos[1]);
			var ww = pos[2];
			var hh = pos[3];
			h6.style.left   = (mc_pos.x + ll - 1) + "px";
			h6.style.top    = (mc_pos.y + tt - 2) + "px";
			h6.style.width  = ww + "px";
			h6.style.height = hh + "px";
		}
	}

	// Protect images
	var imgs = document.getElementsByTagName("img");
	for(kk=0; kk<imgs.length; kk++){
		addEvent(imgs[kk], "contextmenu", disableEvent);
	}
}

function fillup(){
	cross_slide  = document.getElementById("test2");
	cross_slide2 = document.getElementById("test3");
	cross_slide.innerHTML  = lrs;
	cross_slide2.innerHTML = lrs;
	actualwidth = document.all ? cross_slide.offsetWidth : document.getElementById("temp").offsetWidth;
	cross_slide.style.left = "0px";
	cross_slide2.style.left = actualwidth + "px";
	lefttime = setInterval("slideleft()", 30);
}

function slideleft(){
	if(parseInt(cross_slide.style.left)  > (actualwidth*(-1) + 8)) cross_slide.style.left  = (parseInt(cross_slide.style.left)  - copyspeed) + "px";
	else cross_slide.style.left = (parseInt(cross_slide2.style.left) + actualwidth) + "px";
	if(parseInt(cross_slide2.style.left) > (actualwidth*(-1) + 8)) cross_slide2.style.left = (parseInt(cross_slide2.style.left) - copyspeed) + "px";
	else cross_slide2.style.left = (parseInt(cross_slide.style.left) + actualwidth) + "px";
}

function checkEnter(ev){
	if(event.keyCode == 13) doSearch();
}

function doSearch(){
	var oQ = document.getElementById("qstr");
	var vQ = oQ.value;
	oQ.focus();
	if(vQ == ""){
		oQ.style.backgroundColor = "#FFD7D7";
		return;
	}
	oQ.value = " Asteptati...";
	oQ.disabled  = true;
	location.href = "/?/cautare/qstr" + escape(vQ) + "/";
}

function popme(url, width, height){
	if(typeof width == "undefined") var width = Math.floor(window.screen.availWidth/1.7);
	if(typeof height == "undefined") var height = Math.floor(window.screen.availHeight/1.7);

	var left = Math.floor((window.screen.availWidth-width)/2);
	var top  = Math.floor((window.screen.availHeight-height)/2);
	if(top > 20) top -= 20;
	
	var winObj = null;
	winObj = window.open(url, "_blank", "resizable=yes,status=yes,toolbar=no,location=no,menubar=no,width="+width+",height="+height+",top="+top+",left="+left);

	// Check window opened
	if(winObj == null){
		alert("Please configure your popup blocker to allow popup from this site!");
	}
}

function zoom(img_name){
	popme(ATLAS_HTTP + "/lib/zoom.php?" + escape(img_name), 300, 110);
}

function efcm(id_com, id_fcm){
	
}

var xmlHttp = false;
function ajxObj(){
	if(xmlHttp)	return;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	try{
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xmlHttp = false;
		}
	}
@end @*/
	if(!xmlHttp && typeof XMLHttpRequest!="undefined"){
		try{
			xmlHttp = new XMLHttpRequest();
		}catch(e){
			xmlHttp = false;
		}
	}
	if(!xmlHttp && window.createRequest){
		try{
			xmlHttp = window.createRequest();
		}catch(e){
			xmlHttp = false;
		}
	}
}

var ajxUrl = "";
var ajxCallback = "";
var ajxCache = new Array();
function ajxGet(urlStr, funcName){
	// Check cache
	var cachedStr = ajxCache[urlStr];
	if(cachedStr!=undefined && cachedStr!="undefined" && cachedStr!=""){
		eval(funcName + "('" + cachedStr.substring(1) + "');");
		// alert("cache hit");
		return;
	}

	// Init Ajx
	ajxObj();

	// Check Ajx
	if(!xmlHttp){
		alert("ERROR: Cannot create the Ajx XML transporter.\nSome features on this page might not work as expected.       \n\nClick OK to continue.");
		return;
	}

	// Make request
	ajxUrl = urlStr;
	ajxCallback = funcName;
	xmlHttp.open("GET", ajxUrl, true);
	xmlHttp.onreadystatechange = ajxGet_DONE;
	xmlHttp.send(null);
}

function ajxGet_DONE(){
	if(xmlHttp.readyState != 4) return;
	if(ajxCallback != ""){
		eval(ajxCallback + "('" + xmlHttp.responseText + "');");
		ajxCallback = "";

		// Save to cache
		ajxCache[ajxUrl] = "." + xmlHttp.responseText;
	}
}

function ajxErr(str){
	return (str.substring(0, 5) == "ERROR");
}

function checkLgn(){
	var form = document.forms["lgnForm"];
	var username = form.username.value;
	var password = form.password.value;
	var canContinue = true;

	if(username == ""){
		form.username.style.backgroundColor = "#FFDCDC";
		canContinue = false;
	}else form.username.style.backgroundColor = "white";

	if(password == ""){
		form.password.style.backgroundColor = "#FFDCDC";
		canContinue = false;
	}else form.password.style.backgroundColor = "white";

	return canContinue;
}