
var Request = new Object();

var exp=new Date();
exp.setTime(exp.getTime()+86400);
var exp2=new Date();
exp2.setTime(exp2.getTime()-3423);

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);
}

//help top
function show_help_h(site,wtd,prodid,tip) {
    if (prodid!="") prodtxt = "&idhc="+prodid;
    else prodtxt = "";
    var options = "toolbar=1,status=0,menubar=0,scrollbars=1," + "resizable=0,width=660,height=500";
    var theUrl = 'http://help.neogen.ro/help.php?wtd='+wtd+prodtxt+'&tip='+tip+'&site=';
    window.open(theUrl+site,"",options);
}

// pozitia relativa a unui element relativ la document
function getPos(theObj) {
	x = y = 0;
	h = theObj.offsetHeight;
	w = theObj.offsetWidth;
	while(theObj) {
		x += theObj.offsetLeft;
		y += theObj.offsetTop;
		theObj = theObj.offsetParent;
	}
	return {x:x, y:y, height:h, width:w}
}

var show_img = "http://img.neogen.ro/common/header/show.gif";
var hide_img = "http://img.neogen.ro/common/header/hide.gif";

function swapImg() {
	document.getElementById("show_hide_img").src = (document.getElementById("show_hide_img").src == show_img) ? hide_img : show_img;
}

function showHide(defX) {
	// Show or hide floating div
	var div1 = document.getElementById("lang_selector_1");
	pos1 = getPos(div1);
	pos2 = getPos(div1.parentNode);
	var div2 = document.getElementById("lang_selector_2");
	div2.style.width = pos1.width + 'px';
	div2.style.left = defX + pos1.x + 'px';	
	div2.style.top = (pos2.y + pos2.height + 1) + 'px';
	div2.style.display = (div2.style.display=='none') ? 'block' : 'none';
}

function changeLocation(un_lang, loc, nurl) {
	window.location = loc + un_lang + '&next_url=' + nurl;
}

function getMouseXY(e) {
	if (!e) e = window.event;
    if (e.clientX || e.clientY) {
	    tempX = e.clientX;
	    tempY = e.clientY;
    }
    else {
	    tempX = e.pageX;
	    tempY = e.pageY;
    }
}

function elementsShowHide(mode) {
	var newmode=(mode==true) ? "hidden" : "visible"; 
	for(var i=0;i<3;i++) {
		var o = document.getElementById("motor_"+i);
		if (o) o.style.visibility=newmode;
	}
}
function popupopen() {
	 elementsShowHide(true);//resolve floating div problem
	x = tempX-135;
	if(x+435>document.body.clientWidth)x=document.body.clientWidth-435;
	document.getElementById('popup').style.left = x + 'px';
	document.getElementById('popup').style.display = 'block';
	document.getElementById('popup').style.zIndex = 255;
}

function popupclose() {
 	elementsShowHide(false);
	document.getElementById('popup').style.display = 'none';
	document.getElementById('popup').style.zIndex = 0;
}

function chgBK(id,nr,action)
{
	for(i=1;i<=nr;i++)
	{
		elem = document.getElementById('stop'+i);
		elem.className = 'nb';
		elem = document.getElementById('stopa'+i);
		elem.className = 'div_srch_link';
		if(1)
			elem.style.textDecoration='underline';
		else
			elem.style.textDecoration='none';
	}

	elem.className = 'div_srch_link nb';
	elem = document.getElementById('stop'+id);
	elem.className = 'av';	
	elem = document.getElementById('stopa'+id);
	elem.className = 'div_srch_link ava';
	elem.style.textDecoration='none';
	if(id>1)
	{
		elem = document.getElementById('stopa'+(id-1));
		elem.className = 'div_srch_link nb';	
	}
	frm = document.getElementById('topft2')
	frm.action = unescape(action);
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) curtop += obj.y;
	return curtop;
}
function open_remember(obj) {
	var dv=document.createElement("div");
	dv.id="rem_details";
	dv.className="remdiv";
	dv.innerHTML="Salveaza timp si nu-ti mai bate capul cu datele de logare! Apropo: nu-l folosi cand esti in i-cafe:-)";
	dv.style.position="absolute";
	dv.style.paddingLeft="2px";
	dv.style.paddingRight="2px";
	dv.style.paddingTop="2px";
	dv.style.paddingBottom="2px";
	dv.style.left=parseInt(findPosX(obj)+0)+"px";
	dv.style.top=parseInt(findPosY(obj)+30)+"px";
	dv.style.borderStyle="solid";
	dv.style.borderWidth="1px";
	dv.style.borderColor="#819DD7";
	dv.style.width="200px";
	dv.style.backgroundColor="#EBF1FA";
	document.body.appendChild(dv);
}
function real_collapse() {
	document.body.removeChild($("rem_details"));
}
function collapse_remember() {
	setTimeout("real_collapse()",500);
}

function searchbox_onfocus(orig_text) {
	var oSearchBox = document.getElementById("tags");

	if (oSearchBox.value==orig_text) {
		oSearchBox.value = "";
		oSearchBox.style.color = "#000000";
	}
}

function searchbox_onblur(orig_text) {
	var oSearchBox = document.getElementById("tags");

	if (oSearchBox.value=="") {
		oSearchBox.value = orig_text;
		oSearchBox.style.color = "#626562";
	}
}

function searchKeyboardEnter(oSearchText, e, thisLink) {
	if (!e) e = window.event;

	if (e.keyCode==13) {
		if (!oSearchText.value.length) return false;
	var searchtextPattern = new RegExp("[^"+all_chars+"0-9_\-]", "g");
	var searchtextVal = oSearchText.value.replace(searchtextPattern, "+");
	
		window.location = thisLink+searchtextVal;
	}
	return 1;
}

function prepareSearch(srchdText)
{
	var srchdTextPattern = new RegExp("[^"+all_chars+"0-9_\-]", "g");
	var srchdTextVal = srchdText.replace(srchdTextPattern, "+");
	return srchdTextVal;
}

function checkDefaultValue(srchdText, origText)
{
	if(srchdText == origText || srchdText == '')
		return false;
	else
		return true;		
}


function searchBoxOnBlur(element, text)
{
	if(element.value == '')
		element.value = text;
}

function searchBoxOnFocus(element, text)
{
	if(element.value == text)
		element.value = '';
}


function open_collapse(whatString) {
	var oObj = document.getElementById(whatString);

	if (oObj.style.display=="") {
		oObj.style.display = "none";
	} else {
		oObj.style.display = "";
	}
}


/*  this.getScrTop = function() {
    var scrTop = 0;
    if(document.documentElement && document.documentElement.scrollTop)
      scrTop = document.documentElement.scrollTop;
    else if(document.body && document.body.scrollTop)
      scrTop = document.body.scrollTop;
    else if(window.pageYOffset) scrTop = window.pageYOffset;
    return scrTop;
  } */


function getAbsoluteLeft(o) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	// var o = document.getElementById('box_more_arrow');
	var oLeft = o.offsetLeft;            // Get left position from the parent object
	var oParent;
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent;    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft;
}

function getAbsoluteTop(o) {
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	// var o = document.getElementById('box_more_arrow');
	var oTop = o.offsetTop;            // Get top position from the parent object
	var oParent;
	while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent  // Get parent object reference
		oTop += oParent.offsetTop // Add parent top position
		o = oParent
	}
	// Return top position
	return oTop
}



function show_box_more(wichObj,imagePath)
{
	var bm=document.getElementById('box_more');
	var bma=document.getElementById('box_more_arrow');
	var leftVal=getAbsoluteLeft(wichObj);
	var topVal=getAbsoluteTop(wichObj);
	leftVal=leftVal-16;
	bm.style.left=leftVal+'px';
	//alert('Left: '+leftVal+' Top: '+topVal+' Real left: '+bm.style.left);
	if(bm.style.visibility!='visible')
	{
		bm.style.visibility='visible';
		bma.src=imagePath+'/header/hide.gif';
	}
	else
	{
		bm.style.visibility='hidden';
		bma.src=imagePath+'/header/show.gif';
	}
	return true;
}

document.onmousemove = getMouseXY;