var lang_msg = new Array();
lang_msg['sended_msg'] = 'Mesajul a fost trimis\r\nVa multumim';
lang_msg['no_nume'] = 'Nu ati completat numele';
lang_msg['no_email'] = 'Nu ati completat adresa de email';
lang_msg['invalid_email'] = 'Adresa de email nu este valida';
lang_msg['no_telefon'] = 'Nu ati completat numarul de telefon';
lang_msg['invalid_telefon'] = 'Numarul de telefon nu este valabil';
lang_msg['no_mesaj'] = 'Nu ati scris mesajul';
lang_msg['message_send'] = 'Mesajul a fost trimis cu succes';
lang_msg['message_not_send'] = 'Mesajul nu a fost trimis\r\nMai incercati o data';
lang_msg['server_error'] = 'Eroare de server';
lang_msg['no_transaction_type'] = 'Nu ati completat tipul tranzactiei';
lang_msg['no_imobil_type'] = 'Nu ati completat tipul imobilului';
lang_msg['no_oras'] = 'Nu ati completat localitatea';
lang_msg['no_zona'] = 'Nu ati completat zona';
lang_msg['no_pret'] = 'Nu ati completat pretul';

// echivalentul functiei implode din PHP
function implode(chunk, array)
{
	var maxim = array.length;
	var response = '';
	for (I=0; I<maxim; I++)
	{
		response += array[I];
		if (I < (maxim-1))
		{
			response += chunk;
		}
	}
	return response;
}

function validation(arr,form,vFld)
{	
	if(form===undefined){ form = "my_form"; }
	if(vFld===undefined){ vFld = "checkSend"; }
	var err = new Array();
	
	var I = 0;
	
	for(var i=0;i<arr.length;i++){
		if(arr[i].value.length < 1){
			err[I] = ' '+lang_msg['no_'+arr[i].name];
			I++;
		} else 
		if(arr[i].name=='email' && !validate(arr[i].value)){
			err[I] = ' '+lang_msg['invalid_email'];
			I++;
		}
	}
	
	if (err.length > 0)
	{
		alert(implode("\r\n", err));
		return false;
	}
	else
	{
		$("checkSend").value=")(*&^%";
		$(form).submit();
		
		return false;
	}
	return false;
}

function validate(email)
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	if(reg.test(email) == false)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function stop_scroll_pics()
{
	clearTimeout(sto);
}

var sto;
function scroll_pics(a,no)
{
	div_pics = $('scroll_box_'+no);
	if(a==0) return;
	else if(a<0)
	{
		if(div_pics.scrollLeft<=0) return;
	}
	else if(a>0)
	{
		if(div_pics.scrollLeft>=div_pics.scrollWidth) return;
	}
	div_pics.scrollLeft = div_pics.scrollLeft+a;
	sto=setTimeout('scroll_pics('+a+','+no+')',30);
}

function show_popup(nume,phone,email){
	new Ajax.Updater('popup_container','/?section=ajax&screen=popup',{evalScripts:true, method:'post', parameters: {nume_agent: nume,tel_agent:phone, email_agent:email}});
}
function show_popup_oferte(nume,email,phone,id_oferta){
	new Ajax.Updater('popup_container','/?section=ajax&screen=popup_oferte',{evalScripts:true, method:'post', parameters: {nume_agent: nume, email_agent:email,phone_agent:phone, offer_id:id_oferta}});	
}
function changePic(k){
	$('main_poza').src = "/usr/thumbs/thumb_598_x_338/"+pics[k]['filename'];
	if(pics[k]['author'].length>0){
		$('sursa_poza').innerHTML = "Sursa foto: "+pics[k]['author'];}
	else 
		$('sursa_poza').innerHTML='Sursa foto: www.PremierService.ro';
	$('descriere_poza').innerHTML = pics[k]['text'];
	$('lightbox_poza').href = pics[k]['filename_big'];
}


//cautare js
	function addOption(selectbox,text,value )
	{
		var optn = document.createElement("OPTION");
		optn.text = text;
		optn.value = value;
		selectbox.options.add(optn);
	}
	
	
	function setSelectedIndexByValue(selectbox,value){
		var i=0;
		numar_optiuni = selectbox.length;
		for(i=0;i<numar_optiuni;i++){
			option = selectbox.options[i];
			if(option.value==value){
				selectbox.selectedIndex=i;
				return;
			}
		}
		//selectbox.selectedIndex=0;
	}
	function setIndexesFromValues(selectbox,values){
		var i=0;
		numar_optiuni = selectbox.length;
		numar_valori = values.length;
		for(i=0;i<numar_optiuni;i++){
			for(j=0;j<numar_valori;j++){
				option = selectbox.options[i];
				value = values[j];
				if(option.value==value){
					selectbox.options[i].selected = true;
				}
			}
		}
	}
	
	function updateJudete(tipImobil,tipTranzactie,judet_default)
	{
		tipImobil = (typeof tipImobil  == 'undefined') ? $('filterCLS[TIP_IMOBIL]').value : tipImobil ;
		tipTranzactie = (typeof tipTranzactie  == 'undefined') ? $('filterCLS[TIP_TRANZ]').value : tipTranzactie ;
		domain_base = (typeof domain_base  == 'undefined') ? '/' : domain_base;


		judet_selectat  = (typeof judet_default == 'undefined') ? $F("filterEQ[ORAS]"): judet_default;

		//resetam orase
		$("filterEQ[ORAS]").options.length = 0;
		addOption($("filterEQ[ORAS]"),"Alege","");
		
		//resetam zone
		$("filterEQ[ZONA]").options.length = 0;
		$("filterEQ[ZONA]").innerHTML='';
		addOption($("filterEQ[ZONA]"),"Alege","");
		
		
		new Ajax.Request('/?section=ajax&ajax=1&screen=search_box&cmd=judete&tip_imobil=' + tipImobil + '&tip_tranz=' + tipTranzactie, 	
		{
			method:'get',
			onSuccess: function(transport)
			{
		  
					var d = transport.responseText;
					if(d !='[]')  
					{
						var json = d.evalJSON();
					}
					else
					{
						//resetam orase
						$("filterEQ[ORAS]").options.length = 0;
						addOption($("filterEQ[ORAS]"),"Nu exista oferte","");
						
						//resetam zone
						$("filterEQ[ZONA]").options.length = 0;
						$("filterEQ[ZONA]").innerHTML='';
						addOption($("filterEQ[ZONA]"),"Nu exista oferte","");	
					}
		
					for ( keyVar in json )
					{
						v = json[keyVar];
						addOption($("filterEQ[ORAS]"),v, v); 
					}
					setSelectedIndexByValue($("filterEQ[ORAS]"),judet_selectat);
	
			}.bind(judet_selectat)
		});
	
		
	}
	
	
	function updateZone(tipImobil, tipTranzactie, oras,zone_default)
	{	
		tipImobil = (typeof tipImobil  == 'undefined') ? $('filterCLS[TIP_IMOBIL]').value : tipImobil ;
		tipTranzactie = (typeof tipTranzactie  == 'undefined') ? $('filterCLS[TIP_TRANZ]').value : tipTranzactie ;
		oras = (typeof oras  == 'undefined') ? $('filterEQ[ORAS]').value : oras ;
		
		if(typeof zone_default != 'undefined'){
			if(zone_default.localeCompare("null")!=0)
				zone_selectate = zone_default.evalJSON();
			else 
				zone_selectate = {};
		} else {
			zone_selectate = {};
		}

		$("filterEQ[ZONA]").options.length = 0;
		$("filterEQ[ZONA]").innerHTML='';
		
		//alert(tipImobil);
		
		new Ajax.Request('index.php?section=ajax&ajax=1&screen=search_box&cmd=zone&tip_imobil=' + tipImobil + '&tip_tranz=' + tipTranzactie, 
		{
				method:'get',
				onSuccess: function(transport)
				{
					
						var d = transport.responseText;
						var json = d.evalJSON();
						if(d !='[]');
						/*{
							addOption($("filterEQ[ZONA]"),"Alege zona","");
						}*/
						else 
						{
							addOption($("filterEQ[ZONA]"),"Nu exista oferte","");	
						}
			
						var nume_zona='';
						for ( keyVar in json ) 
						{
							
							if(nume_zona != keyVar)
							{
								nume_zona = keyVar;
							
								objSelect=$("filterEQ[ZONA]");
								optGroup = document.createElement('optgroup');
								optGroup.label = nume_zona;
								
							}
							for ( indx in  json[keyVar])
							{
								v = json[keyVar][indx];
								if(json[keyVar].hasOwnProperty(indx))
								{
									objOption=document.createElement("option");
									objOption.innerHTML = v;
									objOption.value = v;
									optGroup.appendChild(objOption)
								}
							}
							
							objSelect.appendChild(optGroup);

//							optGroup.appendChild(objOption);
												
						}
						
						//alert(zone_selectate);
						setIndexesFromValues($("filterEQ[ZONA]"),zone_selectate);
							
						try{
							selcb.redraw();
						} catch(e){ alert(e); }
		
				}.bind(zone_selectate)
		});
	
	}
	
	
	
	//select checkbox js //by ady
	
	
	// JavaScript Document

var SelectCheckbox = Class.create();
SelectCheckbox.prototype = {
	initialize: function(myselect,options)
	{
		this.myselect = myselect;
		this.total_options = myselect.length;
		this.width_1 = (options.width_1 || 0);
		this.width_2 = (options.width_2 || 0);
		this.height_lines = (options.height_lines || 0);
		this.line_height = (options.line_height || 16);
		this.type = (options.type || "hover");
		this.options_height = this.height_lines*this.line_height;
		this.optgruoup = '';
		this.blur_it = 1;
		this.bodyblur=0;
		this.draw();
	},
	draw: function()
	{
		this.parent_all = this.myselect.parentNode;

		//creeaza combobox-ul hiddenul care va tine valorile trimise
		this.myselect.setAttribute("style","display:none");
		
		//creeaza div-ul vizual cu optiunea aleasa: e nevoie de 3 divuri pentru a afisa backgroundul
		this.div_actual_1 = document.createElement("DIV");
		this.div_actual_1.className = "select_div_actual_1";
		this.parent_all.appendChild(this.div_actual_1);
		this.div_actual_2 = document.createElement("DIV");
		this.div_actual_2.className = "select_div_actual_2";
		this.div_actual_1.appendChild(this.div_actual_2);
		this.div_actual = document.createElement("DIV");
		this.div_actual.setAttribute("id",this.myselect.name+"_div_actual");
		this.div_actual.className = "select_div_actual";
		this.div_actual_2.appendChild(this.div_actual);
		this.div_actual_text = document.createElement("DIV");
		this.div_actual_text.className = "text_select";
		this.div_actual_text.setAttribute("id",this.myselect.name+"_div_actual_text");
		this.div_actual.appendChild(this.div_actual_text);
		
		this.div_actual_text.appendChild(document.createTextNode("Alege zona"));
		
		//creeaza catcherul de evenimente
		this.eventcatcher = document.createElement("INPUT");
		this.eventcatcher.setAttribute("type","text");
		this.eventcatcher.className = "select_eventcatcher";
		this.parent_all.appendChild(this.eventcatcher);
		
		
		if(this.type=="hover"){
			Event.observe(this.div_actual,"mouseover",function(){
				this.open_options();
				this.eventcatcher.focus();
			}.bind(this));
			Event.observe(this.div_actual,"mouseout",function(evt){
				this.close_options();
			}.bind(this));
		} else if(this.type=="click"){
			Event.observe(this.div_actual,"click",function(){
				this.bodyblur=0;
				this.open_options();
				this.eventcatcher.focus();
				setTimeout("selcb.bodyblur=1;",10);			
			}.bind(this));
			Event.observe(this.eventcatcher,"blur",function(evt){
				if(this.blur_it==1)
					this.close_options();					
			}.bind(this));
			Event.observe(document.body,"click",function(evt){
				if(this.bodyblur==1){
					this.bodyblur=0;
					this.close_options();					
				}
			}.bind(this));
		}
		Event.observe(this.div_actual,"keyup",function(evt){
			this.navigate(evt);
		}.bind(this));
		
		//insereaza un clear:both inainte de optiuni
		this.my_clear = document.createElement("DIV");
		this.my_clear.className = "clear";
		this.parent_all.appendChild(this.my_clear);
		
		
		//creeaza div-ul cu optiunile selectului
		this.options = document.createElement("DIV");
		this.options.setAttribute("id",this.myselect.name+"_options");
		this.options.className = "select_options selectcb_options";
		this.options.style.display = "none";
		this.div_actual.appendChild(this.options);
		
		//elimina bugul de blur() de pe eventcatcher
		Event.observe(this.options,"mousedown",function(){
			this.blur_it=0;
			this.bodyblur=0;
		}.bind(this));
		Event.observe(this.options,"mouseup",function(){
			setTimeout("selcb.bodyblur=1;",0);
			this.blur_it=1;
		}.bind(this));
		Event.observe(this.options,"scroll",function(){
			this.blur_it=1;
			this.eventcatcher.focus();			
		}.bind(this));
		
		//adaugarea dimensiunii pe orizontala daca are si selectul
		if(this.width_1!=0)
		{
			this.div_actual.style.width = this.width_1;
			this.div_actual_text.style.width = this.width_1;
		}
		if(this.width_2!=0)
		{
			this.options.style.width = this.width_2;
		}
		//adaugare scroll pe verticala
		if(this.height_lines!=0 && this.myselect.length>this.height_lines)
		{
			this.options.style.height = this.options_height+"px";
			this.options.style.overflow = "auto";
			this.options.style.width = parseInt(this.width_2)+20+"px";
		}
		
		//afisam opgroupurile
		for(i=0;i<this.myselect.length;i++)
		{
			if(this.myselect[i].parentNode.tagName=="OPTGROUP" && this.optgroup!=this.myselect[i].parentNode.label)
			{
				this.optgroup=this.myselect[i].parentNode.label;
				this.option_label = document.createElement("DIV");
				this.option_label.className = "select_option_label";
				this.option_label.appendChild(document.createTextNode(this.myselect[i].parentNode.label));
				this.options.appendChild(this.option_label);				
			}
			new SelectCheckboxOption(this.myselect[i],this.myselect,i,this);
		}
		//cautam elementul selectat si il afisam
		//if(this.myselect.options[i].selected == true)
		//{
		//	this.act_option(this.myselect.options[i],1);
		//}
		
		//this.myselect.options[0].selected = false;
		//eliminam vechiul element <select>
		//this.parent_all.removeChild(this.myselect);
	},
	navigate:function(evt)
	{
		if(evt.keyCode=="38" || evt.keyCode=="40" || evt.keyCode=="13" || evt.keyCode=="27")
		{
			maxim = this.total_options;
			curent = -1;
			for(i=0;i<this.total_options;i++)
			{
				if($(this.myselect.name+"_my_option_"+i).className=="select_my_option hover" && curent==-1)
				{
					curent = i;
					$(this.myselect.name+"_my_option_"+i).className="select_my_option";
					break;
				}
			}
			if(curent == -1)
			{
				for(i=0;i<this.total_options;i++)
				{
					if($(this.myselect.name+"_my_option_"+i).className=="select_my_option act")
					{
						curent = i;
						break;
					}
				}
			}
			if(maxim==0) return;
			if(evt.keyCode=="40")
			{
				prev_i = curent+1;
				if(prev_i==maxim) prev_i = 0;
				my_i = prev_i;
			}
			else if(evt.keyCode=="38")
			{
				next_i = curent-1;
				if(next_i<0) next_i = maxim-1;
				my_i = next_i;
			}
			else if(evt.keyCode=="13")
			{
				my_i = curent;
				this.act_option(my_i,0);
				return;
			}
			else if(evt.keyCode=="27")
			{
				this.close_options();
				return;
			}
			if($(this.myselect.name+"_my_option_"+my_i).className!="select_my_option act")
			{
				$(this.myselect.name+"_my_option_"+my_i).className="select_my_option hover";
				poz_option = $(this.myselect.name+"_my_option_"+my_i).offsetTop;
				///*console.log*/alert(parseInt(poz_option)+"-"+(parseInt(this.options.scrollTop)+this.options_height)+' => '+(parseInt(poz_option)+this.line_height)+"px");
				if(parseInt(poz_option)>(parseInt(this.options.scrollTop)+this.options_height-this.line_height))
					this.options.scrollTop = (parseInt(poz_option)+this.line_height-this.options_height);
				else if(parseInt(poz_option)<parseInt(this.options.scrollTop))
					this.options.scrollTop = parseInt(poz_option);
			}
			return;
		}
	},
	open_options:function()
	{
		this.options.style.display = "";
	},
	close_options:function()
	{
		for(i=0;i<this.total_options;i++)
		{
			if($(this.myselect.name+"_my_option_"+i).className=="select_my_option hover")
			{
				$(this.myselect.name+"_my_option_"+i).className="select_my_option";
				break;
			}
		}
		this.options.style.display = "none";
	},
	act_option:function(my_i,ondefault)
	{	
		if($(this.myselect.name+"_my_option_"+my_i).className=="select_my_option act"){
			$(this.myselect.name+"_my_option_"+my_i).className="select_my_option";
			$(this.myselect.name+"_my_option_"+my_i).getElementsByTagName('input')[0].checked=false;
			$(this.myselect).options[my_i].selected = false;
		} else {
			$(this.myselect.name+"_my_option_"+my_i).className="select_my_option act";
			$(this.myselect.name+"_my_option_"+my_i).getElementsByTagName('input')[0].checked=true;
			$(this.myselect).options[my_i].selected = true;
		}
		
		this.setActualText();
		
		if(this.myselect.onchange!=undefined && this.myselect.onchange!="" && ondefault==0)
		{
			this.myselect.onchange.call();
		}
	},
	get_value:function(){
		return $(this.myselect.name+"_hidden_input").value;
	},
	setActualText:function(){
		var tot=0;
		var str="";
		$(this.myselect.name+"_div_actual_text").innerHTML = "";
		for(var i=0;i<this.myselect.length;i++){
			if($(this.myselect).options[i].selected){
				tot++;
				str += $(this.myselect).options[i].value+', ';
			}
		}
		str = str.substr(0,str.length-2);
		if(tot==0)
			if(this.myselect.length>1)
				$(this.myselect.name+"_div_actual_text").innerHTML = "Alege zona";
			else
				$(this.myselect.name+"_div_actual_text").innerHTML = "Nu exista oferte";
		else if(tot>2)
			$(this.myselect.name+"_div_actual_text").innerHTML = tot + " Zone selectate"; 
		else 
			$(this.myselect.name+"_div_actual_text").innerHTML = str;
	},
	redraw:function(){
		this.options.innerHTML = '';
			
		//adaugarea dimensiunii pe orizontala daca are si selectul
		if(this.width_1!=0)
		{
			this.div_actual.style.width = this.width_1;
			this.div_actual_text.style.width = this.width_1;
		}
		if(this.width_2!=0)
		{
			this.options.style.width = this.width_2;
		}
		
		//afisam opgroupurile
		var u = 0;
		for(i=0;i<this.myselect.length;i++)
		{
			if(this.myselect[i].parentNode.tagName=="OPTGROUP" && this.optgroup!=this.myselect[i].parentNode.label)
			{
				this.optgroup=this.myselect[i].parentNode.label;
				this.option_label = document.createElement("DIV");
				this.option_label.className = "select_option_label";
				this.option_label.appendChild(document.createTextNode(this.myselect[i].parentNode.label));
				this.options.appendChild(this.option_label);			
				u++;
			}
			new SelectCheckboxOption(this.myselect[i],this.myselect,i,this);
		}
		
		//adaugare scroll pe verticala
		if(this.height_lines!=0 && this.myselect.length>this.height_lines)
		{
			this.options.style.height = this.options_height+"px";
			this.options.style.overflow = "auto";
			this.options.style.width = parseInt(this.width_2)+"px";
		} else {
			this.options.style.height = (this.myselect.length+u+1)*this.line_height+"px";
		}
		
		this.setActualText();
	}
}

var SelectCheckboxOption = Class.create();
SelectCheckboxOption.prototype = {
	initialize: function(myoption,myselect,current,master_reference)
	{
		this.myselect = myselect;
		this.current = current;
		this.text = myoption.text;
		this.value = myoption.value;
		this.master_reference = master_reference;
		this.draw();
	},
	draw: function()
	{
		this.my_option = document.createElement("DIV");
		this.checkb = document.createElement("INPUT");
		this.val = document.createElement("SPAN");
		this.checkb.setAttribute("type","checkbox");
		this.checkb.className = "checkbox_opt";
		this.checkb.setAttribute("id",this.myselect.name+"_cb_"+this.current);
		this.my_option.appendChild(this.checkb);
		this.val.setAttribute("id",this.myselect.name+"_val_"+this.current);
		this.val.appendChild(document.createTextNode(this.text));
		this.my_option.appendChild(this.val);
		this.my_option.className = "select_my_option";
		this.my_option.setAttribute("value",this.value);
		this.my_option.setAttribute("id",this.myselect.name+"_my_option_"+this.current);
		$(this.myselect.name+"_options").appendChild(this.my_option);
		if(this.myselect.options[i].selected==true){
			this.checkb.checked = true;
			this.my_option.className = "select_my_option act";
		}
		Event.observe(this.my_option,"click",function(){
			this.master_reference.act_option(this.current,0);
		}.bind(this));
		Event.observe(this.my_option,"mouseover",function(){
			if(this.my_option.className!="select_my_option act")
				this.my_option.className="select_my_option hover";
		}.bind(this));
		Event.observe(this.my_option,"mouseout",function(){
			if(this.my_option.className!="select_my_option act")
				this.my_option.className="select_my_option";
		}.bind(this));
	}
}



//input files js //by ady

var InputFile = Class.create();
InputFile.prototype = {
	initialize: function(input_file)
	{
		this.input_file = input_file;
		this.draw();
	},
	draw: function()
	{
		this.parent_all = this.input_file.parentNode

		this.my_form = document.createElement("FORM");
		this.my_form.setAttribute("method","post");
		this.my_form.setAttribute("action",upload_callback);
		this.my_form.encoding = "multipart/form-data";
		this.parent_all.appendChild(this.my_form);

		this.max_size = document.createElement("INPUT");
		this.max_size.setAttribute("type","hidden");
		this.max_size.setAttribute("name","MAX_FILE_SIZE");
		this.max_size.setAttribute("value","2097152");
		this.my_form.appendChild(this.max_size);
		
		this.my_form.appendChild(this.input_file);
	
		this.fake_div = document.createElement("DIV");
		this.fake_div.className="fake_div";
		
		this.my_form.appendChild(this.fake_div);

		Event.observe(this.input_file, 'change', function(){
			if(this.fake_div.lastChild) this.fake_div.removeChild(this.fake_div.lastChild);
			this.my_text = document.createTextNode(this.input_file.value.substr(this.input_file.value.lastIndexOf("\\")+1));
			this.fake_div.appendChild(this.my_text);
			this.input_file.style.display="none";
			this.send_file();
			activ_inputs--;
			if(activ_inputs=="0" && no_more_inputs!=1)
			{
				this.add_input;
				activ_inputs++;
				total_inputs++;
				this.add_new_file();
			}
		}.bind(this), false);
	},
	send_file: function()
	{
		AIM.submit(this.my_form, {
			'onStart': function() {
				this.se_incarca = document.createElement("SPAN");
				this.se_incarca.style.color = "red";
				this.se_incarca.appendChild(document.createTextNode(" - se incarca"));
				this.fake_div.style.background = "none";
				this.fake_div.style.margin = "0";
				this.fake_div.appendChild(this.se_incarca);
				status_incarcare = 1;
			}.bind(this),
			'onComplete': function(response) {
				json_response=response.evalJSON();
				while(this.parent_all.lastChild)
				{
					this.parent_all.removeChild(this.parent_all.lastChild);
				}
				this.resp_div = document.createElement("DIV");
				this.resp_div.className="resp";
				this.parent_all.appendChild(this.resp_div);
				if(json_response.error=="0")
				{
					this.fl_name=document.createElement("SPAN");
					this.fl_name.className="fl_name";
					this.fl_name.appendChild(document.createTextNode(json_response.name+" ("+json_response.size+")"));
					this.resp_div.appendChild(this.fl_name);
					//this.resp_div.appendChild(document.createTextNode(json_response.name+" ("+json_response.size+")"));
					this.del_link = document.createElement("SPAN");
					this.del_link.className = "del_link left";
					this.del_link.appendChild(document.createTextNode("Sterge"));
					this.resp_div.appendChild(this.del_link);
					
					this.inp_hidden = document.createElement("INPUT");
					this.inp_hidden.setAttribute("type","hidden");
					this.inp_hidden.setAttribute("name","ul_file[]");
					this.inp_hidden.setAttribute("value",json_response.file);					
					$("my_form").appendChild(this.inp_hidden);
					
					Event.observe(this.del_link, 'click', function(){
						$("my_form").removeChild(this.inp_hidden);
						this.resp_div.removeChild(this.del_link);
						this.resp_div.className="resp strike";
					}.bind(this), false);

				}
				else this.resp_div.appendChild(document.createTextNode(json_response.error));
				status_incarcare = 0;
			}.bind(this)
		})
		this.my_form.submit();
	},
	add_new_file: function()
	{
		input_item = document.createElement("DIV");
		input_item.className="file_item";
		
		$("files").appendChild(input_item);
		
		label_part = document.createElement("DIV");
		label_part.className = "label_part padded";
		label_part.appendChild(document.createTextNode("Poza "+total_inputs));
		input_item.appendChild(label_part);
		
		input_part = document.createElement("DIV");
		input_part.className = "input_part";
		input_item.appendChild(input_part);
		
		input = document.createElement("INPUT");
		input.className = "type_file";
		input.setAttribute("type","file");
		input.setAttribute("name","poza[]");
		input_part.appendChild(input);
		
		new InputFile(input);
	}
}
var SearchInputFiles = Class.create();
SearchInputFiles.prototype = {
	initialize: function()
	{
		inputs = new Array();
		inputs = $$(".type_file");
		this.input_files = new Array();
		for(i=0;i<inputs.length;i++)
		{
			this.input_files[i] = new InputFile(inputs[i]);
		}
	}
}
AIM = {

    frame : function(c) {

        var n = 'f' + Math.floor(Math.random() * 99999);
        var d = document.createElement('DIV');
        d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
        document.body.appendChild(d);

        var i = document.getElementById(n);
        if (c && typeof(c.onComplete) == 'function') {
            i.onComplete = c.onComplete;
        }

        return n;
    },

    form : function(f, name) {
        f.setAttribute('target', name);
    },

    submit : function(f, c) {
        AIM.form(f, AIM.frame(c));
        if (c && typeof(c.onStart) == 'function') {
            return c.onStart();
        } else {
            return true;
        }
    },

    loaded : function(id) {
        var i = document.getElementById(id);
        if (i.contentDocument) {
            var d = i.contentDocument;
        } else if (i.contentWindow) {
            var d = i.contentWindow.document;
        } else {
            var d = window.frames[id].document;
        }
        if (d.location.href == "about:blank") {
            return;
        }

        if (typeof(i.onComplete) == 'function') {
            i.onComplete(d.body.innerHTML);
        }
    }
}

//lightbox js // de la romanialibera //by ady

// -----------------------------------------------------------------------------------
//
//	Lightbox v2.03.2
//	by Lokesh Dhakar - http://www.huddletogether.com
//	4/30/06
//
//	For more information on this script, visit:
//	http://huddletogether.com/projects/lightbox2/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//	
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.org), Thomas Fuchs(mir.aculo.us), and others.
//
//
// -----------------------------------------------------------------------------------
/*

	Table of Contents
	-----------------
	Configuration
	Global Variables

	Extending Built-in Objects	
	- Object.extend(Element)
	- Array.prototype.removeDuplicates()
	- Array.prototype.empty()

	Lightbox Class Declaration
	- initialize()
	- start()
	- changeImage()
	- resizeImageContainer()
	- showImage()
	- updateDetails()
	- updateNav()
	- enableKeyboardNav()
	- disableKeyboardNav()
	- keyboardAction()
	- preloadNeighborImages()
	- end()
	
	Miscellaneous Functions
	- getPageScroll()
	- getPageSize()
	- getKey()
	- listenKey()
	- showSelectBoxes()
	- hideSelectBoxes()
	- showFlash()
	- hideFlash()
	- pause()
	- initLightbox()
	
	Function Calls
	- addLoadEvent(initLightbox)
	
*/
// -----------------------------------------------------------------------------------

//
//	Configuration
//
var fileLoadingImage = "/plugins/lgt/images/loading.gif";		
var fileBottomNavCloseImage = "/plugins/lgt/images/closelabel.gif";
var fileBottomSigla = "/plugins/lgt/images/sigla.jpg";

var overlayOpacity = 0.6;	// controls transparency of shadow overlay

var animate = true;			// toggles resizing animations
var resizeSpeed = 7;		// controls the speed of the image resizing animations (1=slowest and 10=fastest)

var borderSize = 10;		//if you adjust the padding in the CSS, you will need to update this variable

// -----------------------------------------------------------------------------------

//
//	Global Variables
//
var imageArray = new Array;
var activeImage;

var track_open=0;

if(animate == true){
	overlayDuration = 0.2;	// shadow fade in/out duration
	if(resizeSpeed > 10){ resizeSpeed = 10;}
	if(resizeSpeed < 1){ resizeSpeed = 1;}
	resizeDuration = (11 - resizeSpeed) * 0.15;
} else { 
	overlayDuration = 0;
	resizeDuration = 0;
}

// -----------------------------------------------------------------------------------

//
//	Additional methods for Element added by SU, Couloir
//	- further additions by Lokesh Dhakar (huddletogether.com)
//
Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

// -----------------------------------------------------------------------------------

//
//	Extending built-in Array object
//	- array.removeDuplicates()
//	- array.empty()
//
Array.prototype.removeDuplicates = function () {
    for(i = 0; i < this.length; i++){
        for(j = this.length-1; j>i; j--){        
            if(this[i][0] == this[j][0]){
                this.splice(j,1);
            }
        }
    }
}

// -----------------------------------------------------------------------------------

Array.prototype.empty = function () {
	for(i = 0; i <= this.length; i++){
		this.shift();
	}
}

// -----------------------------------------------------------------------------------

//
//	Lightbox Class Declaration
//	- initialize()
//	- start()
//	- changeImage()
//	- resizeImageContainer()
//	- showImage()
//	- updateDetails()
//	- updateNav()
//	- enableKeyboardNav()
//	- disableKeyboardNav()
//	- keyboardNavAction()
//	- preloadNeighborImages()
//	- end()
//
//	Structuring of code inspired by Scott Upton (http://www.uptonic.com/)
//
var Lightbox = Class.create();

Lightbox.prototype = {
	
	// initialize()
	// Constructor runs on completion of the DOM loading. Loops through anchor tags looking for 
	// 'lightbox' references and applies onclick events to appropriate links. The 2nd section of
	// the function inserts html at the bottom of the page which is used to display the shadow 
	// overlay and the image container.
	//
	initialize: function() {	
		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');
		var areas = document.getElementsByTagName('area');
		this.relAttribute = '';
		// loop through all anchor tags
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			
			var relAttribute = String(anchor.getAttribute('rel'));
			this.relAttribute = relAttribute;
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('lightbox'))){
				anchor.onclick = function () {myLightbox.start(this); return false;}
			}
		}

		// loop through all area tags
		// todo: combine anchor & area tag loops
		for (var i=0; i< areas.length; i++){
			var area = areas[i];
			
			var relAttribute = String(area.getAttribute('rel'));
			this.relAttribute = relAttribute;
			
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (area.getAttribute('href') && (relAttribute.toLowerCase().match('lightbox'))){
				area.onclick = function () {myLightbox.start(this); return false;}
			}
		}

		// The rest of this code inserts html at the bottom of the page that looks similar to this:
		//
		//	<div id="overlay"></div>
		//	<div id="lightbox">
		//		<div id="outerImageContainer">
		//			<div id="imageContainer">
		//				<img id="lightboxImage">
		//				<div style="" id="hoverNav">
		//					<a href="#" id="prevLink"></a>
		//					<a href="#" id="nextLink"></a>
		//				</div>
		//				<div id="loading">
		//					<a href="#" id="loadingLink">
		//						<img src="/plugins/lgt/images/loading.gif">
		//					</a>
		//				</div>
		//			</div>
		//		</div>
		//		<div id="imageDataContainer">
		//			<div id="imageData">
		//				<div id="imageDetails">
		//					<span id="caption"></span>
		//					<span id="numberDisplay"></span>
		//				</div>
		//				<div id="bottomNav">
		//					<a href="#" id="bottomNavClose">
		//						<img src="/plugins/lgt/images/close.gif">
		//					</a>
		//				</div>
		//			</div>
		//		</div>
		//	</div>


		var objBody = document.getElementsByTagName("body").item(0);
		
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		objOverlay.style.display = 'none';
		objOverlay.onclick = function() { myLightbox.end(); }
		objBody.appendChild(objOverlay);
		
		var objLightbox = document.createElement("div");
		objLightbox.setAttribute('id','lightbox');
		objLightbox.style.display = 'none';
		objLightbox.onclick = function(e) {	// close Lightbox is user clicks shadow overlay
			if (!e) var e = window.event;
			var clickObj = Event.element(e).id;
			if ( clickObj == 'lightbox') {
				myLightbox.end();
			}
		};
		objBody.appendChild(objLightbox);
			
		var objOuterImageContainer = document.createElement("div");
		objOuterImageContainer.setAttribute('id','outerImageContainer');
		objLightbox.appendChild(objOuterImageContainer);

		// When Lightbox starts it will resize itself from 250 by 250 to the current image dimension.
		// If animations are turned off, it will be hidden as to prevent a flicker of a
		// white 250 by 250 box.
		if(animate){
			Element.setWidth('outerImageContainer', 250);
			Element.setHeight('outerImageContainer', 250);			
		} else {
			Element.setWidth('outerImageContainer', 1);
			Element.setHeight('outerImageContainer', 1);			
		}

		var objImageContainer = document.createElement("div");
		objImageContainer.setAttribute('id','imageContainer');
		objOuterImageContainer.appendChild(objImageContainer);
	
		var objLightboxImage = document.createElement("img");
		objLightboxImage.setAttribute('id','lightboxImage');
		objImageContainer.appendChild(objLightboxImage);
	
		var objHoverNav = document.createElement("div");
		objHoverNav.setAttribute('id','hoverNav');
		objImageContainer.appendChild(objHoverNav);
	
		var objPrevLink = document.createElement("a");
		objPrevLink.setAttribute('id','prevLink');
		objPrevLink.setAttribute('href','#');
		objHoverNav.appendChild(objPrevLink);
		
		var objNextLink = document.createElement("a");
		objNextLink.setAttribute('id','nextLink');
		objNextLink.setAttribute('href','#');
		objHoverNav.appendChild(objNextLink);
	
		var objLoading = document.createElement("div");
		objLoading.setAttribute('id','loading');
		objImageContainer.appendChild(objLoading);
	
		var objLoadingLink = document.createElement("a");
		objLoadingLink.setAttribute('id','loadingLink');
		objLoadingLink.setAttribute('href','#');
		objLoadingLink.onclick = function() { myLightbox.end(); return false; }
		objLoading.appendChild(objLoadingLink);
	
		var objLoadingImage = document.createElement("img");
		objLoadingImage.setAttribute('src', fileLoadingImage);
		objLoadingLink.appendChild(objLoadingImage);

		var objImageDataContainer = document.createElement("div");
		objImageDataContainer.setAttribute('id','imageDataContainer');
		objLightbox.appendChild(objImageDataContainer);

		var objImageData = document.createElement("div");
		objImageData.setAttribute('id','imageData');
		objImageDataContainer.appendChild(objImageData);
	
		var objImageDetails = document.createElement("div");
		objImageDetails.setAttribute('id','imageDetails');
		objImageData.appendChild(objImageDetails);
	
		var objCaption = document.createElement("span");
		objCaption.setAttribute('id','caption');
		objImageDetails.appendChild(objCaption);
	
		var objDescription = document.createElement("span");
		objDescription.setAttribute('id','lbDescription');
		objImageDetails.appendChild(objDescription);

		var objnumberLink = document.createElement("span");
		objnumberLink.setAttribute('id','numberLink');
		objImageDetails.appendChild(objnumberLink);

		var objNumberDisplay = document.createElement("span");
		objNumberDisplay.setAttribute('id','numberDisplay');
		objnumberLink.appendChild(objNumberDisplay);

		var objlinkArticol = document.createElement("span");
		objlinkArticol.setAttribute('id','linkArticol');
		objnumberLink.appendChild(objlinkArticol);		

		var objBottomNav = document.createElement("div");
		objBottomNav.setAttribute('id','bottomNav');
		objImageData.appendChild(objBottomNav);
	
		var objBottomNavCloseLink = document.createElement("a");
		objBottomNavCloseLink.setAttribute('id','bottomNavClose');
		objBottomNavCloseLink.setAttribute('href','#');
		objBottomNavCloseLink.onclick = function() { myLightbox.end(); return false; }
		objBottomNav.appendChild(objBottomNavCloseLink);

		var objBottomNavCloseImage = document.createElement("img");
		objBottomNavCloseImage.setAttribute('src', fileBottomNavCloseImage);
		objBottomNavCloseLink.appendChild(objBottomNavCloseImage);

/*		var objBottomNavCloseLink = document.createElement("img");
		objBottomNavCloseLink.setAttribute('id','fileBottomSigla');
		objBottomNavCloseLink.setAttribute('src', fileBottomSigla);*/
		
		objBottomNav.appendChild(objBottomNavCloseLink);	
	},
	
	//
	//	start()
	//	Display overlay and lightbox. If image is part of a set, add siblings to imageArray.
	//
	start: function(imageLink) {	

		hideSelectBoxes();
		hideFlash();

		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		Element.setHeight('overlay', arrayPageSize[1]);

		new Effect.Appear('overlay', { duration: overlayDuration, from: 0.0, to: overlayOpacity });

		imageArray = [];
		imageNum = 0;		

		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName( imageLink.tagName);


		// if image is NOT part of a set..
		if((imageLink.getAttribute('rel') == 'lightbox')){
			// add single image to imageArray
			imageArray.push(new Array(imageLink.getAttribute('href'), imageLink.getAttribute('title'), imageLink.getAttribute('id'), 'lightbox'));			
		} else {
		// if image is part of a set..

			// loop through anchors, find other images in set, and add them to imageArray
			for (var i=0; i<anchors.length; i++){
				var anchor = anchors[i];
				if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == imageLink.getAttribute('rel'))){
					rel = anchor.getAttribute('rel').substring(anchor.getAttribute('rel').indexOf('[')+1, anchor.getAttribute('rel').lastIndexOf(']'));
					imageArray.push(new Array(anchor.getAttribute('href'), anchor.getAttribute('title'), anchor.getAttribute('id'), rel));
				}
			}
			imageArray.removeDuplicates();
			while(imageArray[imageNum][0] != imageLink.getAttribute('href')) { imageNum++;}
		}

		// calculate top offset for the lightbox and display 
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);

		Element.setTop('lightbox', lightboxTop);
		Element.show('lightbox');
		
		this.changeImage(imageNum);
	},

	//
	//	changeImage()
	//	Hide most elements and preload image in preparation for resizing image container.
	//
	changeImage: function(imageNum) {	
		
		activeImage = imageNum;	// update global var

		// hide elements during transition
		if(animate){ Element.show('loading');}
		Element.hide('lightboxImage');
		Element.hide('hoverNav');
		Element.hide('prevLink');
		Element.hide('nextLink');
		Element.hide('imageDataContainer');
		Element.hide('numberLink');
	
		imgPreloader = new Image();
		
		// once image is preloaded, resize image container
		imgPreloader.onload=function(){
			Element.setSrc('lightboxImage', imageArray[activeImage][0]);
			//Element.setWidth('lightboxImage', imageArray[activeImage][0]);
			myLightbox.resizeImageContainer(imgPreloader.width, imgPreloader.height);
//			alert('a');
//			alert(imgPreloader.width + " " +  imgPreloader.height);
			imgPreloader.onload=function(){};	//	clear onLoad, IE behaves irratically with animated gifs otherwise 
		}
		imgPreloader.src = imageArray[activeImage][0];
	},

	//
	//	resizeImageContainer()
	//
	resizeImageContainer: function( imgWidth, imgHeight) {

		// get curren width and height
		this.widthCurrent = Element.getWidth('outerImageContainer');
		this.heightCurrent = Element.getHeight('outerImageContainer');

		// get new width and height
		var widthNew = (imgWidth  + (borderSize * 2));
		var heightNew = (imgHeight  + (borderSize * 2));

		// scalars based on change from old to new
		this.xScale = ( widthNew / this.widthCurrent) * 100;
		this.yScale = ( heightNew / this.heightCurrent) * 100;

		// calculate size difference between new and old image, and resize if necessary
		wDiff = this.widthCurrent - widthNew;
		hDiff = this.heightCurrent - heightNew;

		if(!( hDiff == 0)){ new Effect.Scale('outerImageContainer', this.yScale, {scaleX: false, duration: resizeDuration, queue: 'front'}); }
		if(!( wDiff == 0)){ new Effect.Scale('outerImageContainer', this.xScale, {scaleY: false, delay: resizeDuration, duration: resizeDuration}); }

		// if new and old image are same size and no scaling transition is necessary, 
		// do a quick pause to prevent image flicker.
		if((hDiff == 0) && (wDiff == 0)){
			if (navigator.appVersion.indexOf("MSIE")!=-1){ pause(250); } else { pause(100);} 
		}

		Element.setHeight('prevLink', imgHeight);
		Element.setHeight('nextLink', imgHeight);
		Element.setWidth( 'imageDataContainer', widthNew);
		
		Element.setWidth( 'lightboxImage',imgWidth);
		Element.setHeight( 'lightboxImage',imgHeight);

		this.showImage();
	},
	
	//
	//	showImage()
	//	Display image and begin preloading neighbors.
	//
	showImage: function(){
		Element.hide('loading');
		new Effect.Appear('lightboxImage', { duration: resizeDuration, queue: 'end', afterFinish: function(){	myLightbox.updateDetails(); } });
		this.preloadNeighborImages();
		if(track_open==0 && $('for_ganal')){
			pageTracker._trackEvent('lightbox', 'open', $('for_ganal').innerHTML);
			track_open = 1;
		}
	},

	//
	//	updateDetails()
	//	Display caption, image number, and bottom nav.
	//
	updateDetails: function() {
	
		Element.show('caption');
		Element.setInnerHTML( 'caption', imageArray[activeImage][1]);

		if(imageArray[activeImage][2] && $("description_"+imageArray[activeImage][2]))
		{
			Element.show('lbDescription');
			Element.setInnerHTML( 'lbDescription', $("description_"+imageArray[activeImage][2]).innerHTML);
		}
		else
		{
			Element.setInnerHTML( 'lbDescription', '');
		}
		
		if(imageArray[activeImage][2] && $(imageArray[activeImage][3]+"_description_"+imageArray[activeImage][2]))
		{
			Element.show('lbDescription');
			Element.setInnerHTML( 'lbDescription', $(imageArray[activeImage][3]+"_description_"+imageArray[activeImage][2]).innerHTML);
		}
		else
		{
			Element.setInnerHTML( 'lbDescription', '');
		}		

		if(imageArray[activeImage][2] && $(imageArray[activeImage][3]+"_link_"+imageArray[activeImage][2]))
		{
			Element.show('linkArticol');
			Element.setInnerHTML( 'linkArticol', $(imageArray[activeImage][3]+"_link_"+imageArray[activeImage][2]).innerHTML);
		}
		else
		{
			Element.setInnerHTML( 'linkArticol', '');
		}

		// if image is part of set display 'Image x of x' 
		if(imageArray.length > 1){
			Element.show('numberLink');
			Element.setInnerHTML( 'numberDisplay', "Imaginea " + eval(activeImage + 1) + "/" + imageArray.length);
		}

		new Effect.Parallel(
			[ new Effect.SlideDown( 'imageDataContainer', { sync: true, duration: resizeDuration, from: 0.0, to: 1.0 }), 
			  new Effect.Appear('imageDataContainer', { sync: true, duration: resizeDuration }) ], 
			{ duration: resizeDuration, afterFinish: function() {
				// update overlay size and update nav
				var arrayPageSize = getPageSize();
				Element.setHeight('overlay', arrayPageSize[1]);
				myLightbox.updateNav();
				}
			} 
		);
	},

	//
	//	updateNav()
	//	Display appropriate previous and next hover navigation.
	//
	updateNav: function() {

		Element.show('hoverNav');				

		// if not first image in set, display prev image button
		if(activeImage != 0){
			Element.show('prevLink');
			document.getElementById('prevLink').onclick = function() {
				//if($('for_ganal')) pageTracker._trackEvent('lightbox', 'prev', $('for_ganal').innerHTML);
				myLightbox.changeImage(activeImage - 1); return false;
			}
		}

		// if not last image in set, display next image button
		if(activeImage != (imageArray.length - 1)){
			Element.show('nextLink');
			document.getElementById('nextLink').onclick = function() {
				//if($('for_ganal')) pageTracker._trackEvent('lightbox', 'next', $('for_ganal').innerHTML);
				myLightbox.changeImage(activeImage + 1); return false;
			}
		}
		
		this.enableKeyboardNav();
	},

	//
	//	enableKeyboardNav()
	//
	enableKeyboardNav: function() {
		document.onkeydown = this.keyboardAction; 
	},

	//
	//	disableKeyboardNav()
	//
	disableKeyboardNav: function() {
		document.onkeydown = '';
	},

	//
	//	keyboardAction()
	//
	keyboardAction: function(e) {
		if (e == null) { // ie
			keycode = event.keyCode;
			escapeKey = 27;
		} else { // mozilla
			keycode = e.keyCode;
			escapeKey = e.DOM_VK_ESCAPE;
		}

		key = String.fromCharCode(keycode).toLowerCase();
		
		if((key == 'x') || (key == 'o') || (key == 'c') || (keycode == escapeKey)){	// close lightbox
			myLightbox.end();
		} else if((key == 'p') || (keycode == 37)){	// display previous image
			if(activeImage != 0){
				myLightbox.disableKeyboardNav();
				myLightbox.changeImage(activeImage - 1);
			}
		} else if((key == 'n') || (keycode == 39)){	// display next image
			if(activeImage != (imageArray.length - 1)){
				myLightbox.disableKeyboardNav();
				myLightbox.changeImage(activeImage + 1);
			}
		}

	},

	//
	//	preloadNeighborImages()
	//	Preload previous and next images.
	//
	preloadNeighborImages: function(){

		if((imageArray.length - 1) > activeImage){
			preloadNextImage = new Image();
			preloadNextImage.src = imageArray[activeImage + 1][0];
		}
		if(activeImage > 0){
			preloadPrevImage = new Image();
			preloadPrevImage.src = imageArray[activeImage - 1][0];
		}
	
	},

	//
	//	end()
	//
	end: function() {
		this.disableKeyboardNav();
		Element.hide('lightbox');
		new Effect.Fade('overlay', { duration: overlayDuration});
		showSelectBoxes();
		showFlash();
	}
}

// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){
	}
}

// -----------------------------------------------------------------------------------

//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }
	
// ---------------------------------------------------


function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

// ---------------------------------------------------

function showFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}

}


// ---------------------------------------------------

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Help from Ran Bar-On [ran2103@gmail.com]
//

function pause(ms){
	var date = new Date();
	curDate = null;
	do{var curDate = new Date();}
	while( curDate - date < ms);
}
/*
function pause(numberMillis) {
	var curently = new Date().getTime() + sender;
	while (new Date().getTime();	
}
*/
// ---------------------------------------------------



function initLightbox() { myLightbox = new Lightbox(); }
Event.observe(window, 'load', initLightbox, false);

