var xmlhttp;
function load_biders(url)
{
	xmlhttp=null;
	if (window.XMLHttpRequest)	{
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null)	{
		xmlhttp.onreadystatechange=state_Change;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	else	{
		// alert("Your browser does not support XMLHTTP.");
	}
}

function state_Change()
{
	if (xmlhttp.readyState==4)	{
		if (xmlhttp.status==200)		{
			document.getElementById('ultimii_licitatori').innerHTML=xmlhttp.responseText;
		}
	}
}


//======================================[AJAX]============================
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
function $ajax(ajaxfile,ajaxurl,ajaxaction,otherfunction) {
	if (otherfunction==null) otherfunction=function() {};
	var xmlHttp=GetXmlHttpObject();
	xmlHttp.open("GET",ajaxfile+'?nocache='+Math.random()+'&'+ajaxurl);
	xmlHttp.onreadystatechange=function () {
		if (xmlHttp.readyState==4) {
			if(typeof(ajaxaction)=='function') {
				ajaxaction(xmlHttp.responseText);
			} else if (typeof(ajaxaction)=='string') {
				if(document.getElementById(ajaxaction)) {
					document.getElementById(ajaxaction).innerHTML=xmlHttp.responseText;
				} else {
					alert(xmlHttp.responseText);
				}
				$json(ajaxaction);
				otherfunction(xmlHttp.responseText);
			} else {
				$json(ajaxaction);
				ajaxaction.innerHTML=xmlHttp.responseText;
			}
		}
	}
	xmlHttp.send(null);
}
function load_ajax(ajaxfile,ajaxurl,ajaxaction) {
	var xmlHttp=GetXmlHttpObject();
	xmlHttp.open("GET",ajaxfile+'?nocache='+Math.random()+'&'+ajaxurl);
	xmlHttp.onreadystatechange=function () {
		if (xmlHttp.readyState==4) {
			document.getElementById(ajaxaction).innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.send(null);
}
//===========================================================================
// Eroare daca nu exista elementul
function ErrorNoId(cine) {
	alert(' Reporniti browsetrul \n\r elementul '+cine+' nu exista ! ');
	return false;
}
// Get By Id
function byid(id){
	try{
		return document.getElementById(id);
	}
	catch(e){
		ErrorNoId(id);
	}
}
// Get By Name
function byname(name){
	try{
		return document.getElementsByName(name);
	}
	catch(e){
		ErrorNoId(name);
	}
}
function $v(id,val){
	try{
		document.getElementById(id).value=val;
		return true;
	}
	catch(e){
		ErrorNoId(id);
	}
}
function $val(id){
	try{
		return document.getElementById(id).value;
	}
	catch(e){
		ErrorNoId(id);
	}
}
function $json(id){
	$id('script','type','text/javascript',id).each(function (obj) { eval(obj.innerHTML); } );
}
function $get(campuri) {
	var get='';
	var first='';
	if (typeof(campuri)=='string')  return campuri+'='+$id(campuri).val();
	for (var i=0; i<campuri.length; i++){
		if (i>0) first='&';
		get+=first+campuri[i]+'='+$id(campuri[i]).val();
	}
	return get;
}



function $id(id,atr,valoare,start) {
	// By nostress-solution
	if (id!=null) return new $id().init(id,atr,valoare,start);
	this.init = function (id,atr,valoare,start) {
		this.tags=[];
		this.first_id;
		this.last_id;
		this.id;
		this.no_each=false;
		if (typeof(id)=='string') {
			start=byid(start);
			if (start==null) start=document;
			var tagurile = start.getElementsByTagName(id);
			var j=0;
			for (var i=0; i<tagurile.length; i++){
				var tag = tagurile[i];
				if (atr==null) {
					this.tags[j]=tag;
					this.last_id=tag;
					j++;
				} else {
					if (tag[atr] == valoare){
						this.tags[j]=tag;
						this.last_id=tag;
						j++;
					}
				}
			}
			this.first_id=this.tags[0];
			this.id=this.first_id;
			if (j==0) {
				this.id=byid(id);
				this.no_each=true;
			}
		}
		else {
			this.id=id;
			this.no_each=true;
		}
		return this;
	}
	this.css=function (atribut,valoare) {
		if (valoare==null && typeof(atribut)=='string') {
			return this.id.style[atribut];
		}
		return this.each(function (obj){
			if (valoare==null) {
				for (var key in atribut) {
					obj.style[key]=atribut[key];
				}
			} else {
				obj.style[atribut]=valoare;
			}
		});
	}
	this.replace=function (atribut,inlocuitor) {
		return this.each(function (obj){
			if(typeof(inlocuitor)=='function') {
				obj[atribut]=function () {
					inlocuitor(this);
				};
			}else{
				obj[atribut]=inlocuitor;
			}
		});
	}
	this.html=function (continut) {
		if (continut==null) return this.id.innerHTML;
		return this.each(function (obj){
			obj.innerHTML=continut;
		});
	}
	this.load=function (ajaxfile,otherfunction) {
		if (otherfunction==null) otherfunction=function () {};
		ajax_file_url=ajaxfile.split('?');
		$ajax(ajax_file_url[0],ajax_file_url[1],this.id,otherfunction);
		return this;
	}
	this.val=function (valoare) {
		if (valoare==null) return this.id.value;
		this.id.value=valoare;
		return this;
	}
	this.show=function () {
		return this.each(function (obj){
			obj.style.display='block';
		});
	}
	this.hide=function () {
		return this.each(function (obj){
			obj.style.display='none';
		});
	}
	this.clasa=function (valoare) {
		if (valoare==null) return this.id.className;
		return this.each(function (obj){
			obj.className=valoare;
		});
	}
	this.append=function (code) {
		return this.each(function (obj){
			var div_code = document.createElement("div");
			obj.appendChild(div_code);
			div_code.innerHTML=code;
		});
	}
	this.apptop=function (code) {
		return this.each(function (obj){
			var div_code = document.createElement("div");
			div_code.innerHTML=code;
			obj.insertBefore(div_code, obj.firstChild);
		});
	}
	this.appbefore=function (code) {
		return this.each(function (obj){
			var div_code = document.createElement("div");
			div_code.innerHTML=code;
			obj.parentNode.insertBefore(div_code, obj);
		});
	}
	this.appafeter=function (code) {
		return this.each(function (obj){
			var div_code = document.createElement("div");
			div_code.innerHTML=code;
			obj.parentNode.insertBefore(div_code, obj.nextSibling);
		});
	}
	this.remove = function () {
		return this.each(function (obj){
			obj.parentNode.removeChild(obj);
		});
	}
	this.tag = function (id) {
		if (id==null) id=0;
		this.id=this.tags[id];
		this.no_each=true;
		return this;
	}
	this.first = function (id) {
		this.id=this.first_id;
		this.no_each=true;
		return this;
	}
	this.last = function (id) {
		this.id=this.last_id;
		this.no_each=true;
		return this;
	}
	this.all = function() {
		this.no_each=false;
		return this;
	}
	this.each = function (functie) {
		if (this.no_each==true) {
			if (this.id!=null) functie (this.id,i);
		} else {
			for (var i=0; i<this.tags.length; i++){
				functie (this.tags[i],i);
			}
		}
		return this;
	}
	this.extend=function(nume,functie) {
		this[nume]=functie;
	}
	return this;
}




function $tag(tag,atr,valoare,start) {
	this.tags=[];
	this.first=[];
	this.last=[];
	if (start==null) start=document; else start=byid(start);
	var tagurile = start.getElementsByTagName(tag);
	var j=0;
	for (var i=0; i<tagurile.length; i++){
		var tag = tagurile[i];
		if (atr==null) {
			this.tags[j]=tag;
			this.last=tag;
			j++;
		} else {
			if (tag[atr] == valoare){
				this.tags[j]=tag;
				this.last=tag;
				j++;
			}
		}
	}
	this.first=this.tags[0];
	this.replace=function (atribut,inlocuitor) {
		return this.each(function (obj){
			if(typeof(inlocuitor)=='function') {
				obj[atribut]=function () {
					inlocuitor(this);
				};
			}else{
				obj[atribut]=inlocuitor;
			}
		});
	}
	this.css=function (atribut,valoare) {
		return this.each(function (obj){
			if (valoare==null) {
				for (var key in atribut) {
					obj.style[key]=atribut[key];
				}
			} else {
				obj.style[atribut]=valoare;
			}
		});
	}
	this.each = function (functie) {
		for (var i=0; i<this.tags.length; i++){
			functie (this.tags[i]);
		}
		return this;
	}
	this.id = function() {
		return $id(this.first);
	}
	return this;
}



// NEW ======================

function NSS_getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function NSS_getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
	arrayPageScroll = new Array(xScroll,yScroll)
	return arrayPageScroll;
}

function alerta(mesaj,width,height) {
	if (width==null) width=360;
	if (height==null) height=100;
	var page_size=NSS_getPageSize();
	byid('over_div').style.display='block';
	byid('over_div').style.width=page_size[0]+'px';
	byid('over_div').style.height=page_size[1]+'px';
	byid('over_div').onclick=close_alerta;
	var page_scroll=NSS_getPageScroll();
	byid('alerta_div').style.display='block';
	byid('alerta_div').style.width=width+'px';
	byid('alerta_div').style.left=(page_size[0]-width-20)/2+'px';
	byid('alerta_div').style.top=(page_size[3]-height)/2+page_scroll[1]+'px';
	byid('alerta_div').innerHTML=mesaj;

}
function close_alerta() {
	byid('over_div').style.display='none';
	byid('over_div').style.width='0';
	byid('over_div').style.height='0';
	byid('alerta_div').innerHTML='';
	byid('alerta_div').style.display='none';
	byid('alerta_div').style.left='0';
	byid('alerta_div').style.top='0';
}
function set_image(link) {
	byid('imagine_mare_set').src=link;
}
function lightbox(obj) {
	var mesaj='<img src="'+obj.src+'" width="520" />';
	alerta(mesaj,520,430);
}
function show_hide(id){
	if(byid(id).style.display=='none') {
		byid(id).style.display='block';
	} else {
		byid(id).style.display='none';
	}
}
function schimba_img(imagine,cale,prefix) {
	byid('img_href_mare').href=BASEHREF+cale+'/'+imagine;
	byid('img_prod_mare').src=BASEHREF+cale+'/'+prefix+'-'+imagine;
}
function show_hide_div(div,timp) {
	if (timp==null) timp=1200;
	if (byid(div).style.display=='none') {
		$('#formular_contact_prod').show('clip', {}, timp );
	} else {
		$('#formular_contact_prod').hide('clip', {}, timp );
	}
}