var Request = new Object();

Request.send = function(url, method, callback, data) {
	var req;
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	 else
	 {
			return;
	}
	req.onreadystatechange = function() {
		if (req.readyState == 4) {// only if req shows "loaded"
			if (req.status < 400) {// only if "OK"
				(method=="POST") ? callback(req) : callback(req,data);
			} else {
				//alert("There was a problem saving your changes :\n" + req.status+ "/" + req.statusText);
			}
		}
	}
	if (method=="POST") {
		req.open("POST", url, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(data);
	} else {
		req.open("GET", url, true);
		req.send(null);
	}
	return req;
}

Request.sendGET = function(url, callback, args) {
	return Request.send(url, "GET", callback, args);
}

Request.sendPOST = function(url, data, callback) {
	Request.send(url, "POST", callback, data);
}

function showSuggestionDiv()
{
	var left, top, suggestionCont, obj, suggestionText;
	
	obj = document.getElementById('suggestionLink');
	
	top = getAbsoluteOffsetTop(obj);
	left = getAbsoluteOffsetLeft(obj);
	
	suggestionText = document.getElementById ('suggestionText');
	suggestionCont = document.getElementById("sendSuggestionCont");
	
	suggestionText.value = "";
	suggestionCont.style.left = (left-350)+"px";
	suggestionCont.style.top = (top+30)+"px";
	suggestionCont.style.display = "";
}

function saveSuggestion() 
{
	var suggestionText = document.getElementById ('suggestionText');
	var post_vars = "";
	
	post_vars += "&txt="+suggestionText.value;

	Request.sendPOST("http://www.neogen.rs/reklama/index/savesuggestion/", post_vars, saveSuggestionCallback);

	return false;
}

function saveSuggestionCallback(response)
{
	var left, top, suggestionCont, obj, thxSuggestionCont;
	
	obj = document.getElementById('suggestionLink');
	
	top = getAbsoluteOffsetTop(obj);
	left = getAbsoluteOffsetLeft(obj);
	
	suggestionCont = document.getElementById("sendSuggestionCont");
	thxSuggestionCont = document.getElementById("thx4SuggestionCont");
	
	suggestionCont.style.display = "none";
	
	thxSuggestionCont.style.left = (left-350)+"px";
	thxSuggestionCont.style.top = (top+30)+"px";
	thxSuggestionCont.style.display = "";
	
}

function getAbsoluteOffsetTop(obj)
{
	var top = obj.offsetTop;
    var parent = obj.offsetParent;
    while (parent != document.body)
    {
    	top += parent.offsetTop;
     	parent = parent.offsetParent;
    }

    return top;
}

function getAbsoluteOffsetLeft(obj)
{
	var left = obj.offsetLeft;
    var parent = obj.offsetParent;
    while (parent != document.body)
    {
		left += parent.offsetLeft;
     	parent = parent.offsetParent;
    }

    return left;
}

function ifr_add (ifr_src, obj) {
	var urlstat_ifr = document.createElement ("iframe");
	urlstat_ifr.style.width = "0px";
	urlstat_ifr.style.height = "0px";
	urlstat_ifr.style.margin = "0px";
	urlstat_ifr.style.display = "none";
	urlstat_ifr.src = ifr_src;
	obj.parentNode.appendChild (urlstat_ifr);
	return;
}

function trackThis (idurl, obj) {
	if (arguments[2]) {//poate sa fie un al treilea parametru,care restrictioneaza trackerul pentru o singura tara
		if (parseInt (arguments[2])==parseInt(10)) {
			ifr_add ("http://url.neogen.ro/index/increment/"+idurl+"/"+escape(uip)+"/"+escape(urf),obj);
		}
	} else {
		ifr_add ("http://url.neogen.ro/index/increment/"+idurl+"/"+escape(uip)+"/"+escape(urf),obj);
	}
}

var disp = 0;

function toggleDisplayLng()
{
	var display;

	if(disp == 0)
	{
		display = "";
		disp = 1;
	}
	else
	{
		display = "none";
		disp = 0;
	}

	document.getElementById("alng").style.display = display;
}

function setLng(id)
{
	var postVars = "";
	postVars += "&languageId="+id;
	
	Request.sendPOST("http://www.neogen.rs/ajax/set-language", postVars, setLngCallback);
}

function setLngCallback(response)
{
	eval(response.responseText);
}