function toggle(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'block') e.style.display = 'none';
	else e.style.display = 'block';
}
function hide(obj)  {
	obj1 = document.getElementById(obj);
	obj1.style.display = 'none';
}
function show(obj)  {
	obj1 = document.getElementById(obj);
	obj1.style.display = 'block';
}
function showin(obj)  {
	obj1 = document.getElementById(obj);
	obj1.style.display = 'inline';
}
function show_other(optionValue){
	if(optionValue=='autoturisme'){show('anfab'); show('kmpar'); show('cutv'); show('comb'); show('tipan'); hide('tiploc'); hide('chir')} 
	if(optionValue=='locuinte'){show('tiploc'); showin('chir'); show('tipan'); hide('anfab'); hide('kmpar'); hide('cutv'); hide('comb')} 
	if(optionValue=='birouri' || optionValue=='spatii-comerciale'){showin('chir'); show('tipan'); hide('anfab'); hide('kmpar'); hide('cutv'); hide('comb')} 
	if(optionValue=='meditatii' || optionValue=='oferte munca (angajari)'){hide('tipan')}
	if((optionValue!='autoturisme') && (optionValue!='locuinte') && (optionValue!='meditatii')&& (optionValue!='oferte munca (angajari)') && (optionValue!='birouri') && (optionValue!='spatii-comerciale')) {hide('anfab'); hide('kmpar'); hide('tiploc');  hide('cutv');  hide('comb'); hide('chir'); show('tipan')} 
}
function showautodet(){
	if(document.getElementsByName('categorie').value=='autoturisme')
	{
		document.getElementById('anfab').style.display='block'; 
		document.getElementById('kmpar').style.display='block'; 
		document.getElementById('cutv').style.display='block'; 
		document.getElementById('comb').style.display='block';
	}				
}
function hideautodet(){
	hide('anfab');
	hide('kmpar');
	hide('cutv'); 
	hide('comb');
}
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
function hov(jud, ax, ay){
	document.getElementById(jud).style.textDecoration='underline';
	document.getElementById('hovmap').style.backgroundImage='url(images/harta/'+jud+'.gif)';
	document.getElementById('hovmap').style.backgroundPosition=ax+'px '+ay+'px';
}

function unhov(jud){
	document.getElementById(jud).style.textDecoration='none';
	document.getElementById('hovmap').style.backgroundImage='none';
}
$(document).ready(function() {

	image_url = [];
	image_url[0] = "images/harta/Alba.gif";
	image_url[1] = "images/harta/Arad.gif";
	image_url[2] = "images/harta/Arges.gif";
	image_url[3] = "images/harta/Bacau.gif";
	image_url[4] = "images/harta/Bihor.gif";
	image_url[5] = "images/harta/Bistrita-Nasaud.gif";
	image_url[6] = "images/harta/Botosani.gif";
	image_url[7] = "images/harta/Brasov.gif";
	image_url[8] = "images/harta/Braila.gif";
	image_url[9] = "images/harta/Bucuresti.gif";
	image_url[10] = "images/harta/Buzau.gif";
	image_url[11] = "images/harta/Caras-Severin.gif";
	image_url[12] = "images/harta/Calarasi.gif";
	image_url[13] = "images/harta/Cluj.gif";
	image_url[14] = "images/harta/Constanta.gif";
	image_url[15] = "images/harta/Covasna.gif";
	image_url[16] = "images/harta/Dambovita.gif";
	image_url[17] = "images/harta/Dolj.gif";
	image_url[18] = "images/harta/Galati.gif";
	image_url[19] = "images/harta/Giurgiu.gif";
	image_url[20] = "images/harta/Gorj.gif";
	image_url[21] = "images/harta/Harghita.gif";
	image_url[22] = "images/harta/Hunedoara.gif";
	image_url[23] = "images/harta/Ialomita.gif";
	image_url[24] = "images/harta/Iasi.gif";
	image_url[25] = "images/harta/Maramures.gif";
	image_url[26] = "images/harta/Mehedinti.gif";
	image_url[27] = "images/harta/Mures.gif";
	image_url[28] = "images/harta/Neamt.gif";
	image_url[29] = "images/harta/Olt.gif";
	image_url[30] = "images/harta/Prahova.gif";
	image_url[31] = "images/harta/Satu Mare.gif";
	image_url[32] = "images/harta/Salaj.gif";
	image_url[33] = "images/harta/Sibiu.gif";
	image_url[34] = "images/harta/Suceava.gif";
	image_url[35] = "images/harta/Teleorman.gif";
	image_url[36] = "images/harta/Timis.gif";
	image_url[37] = "images/harta/Tulcea.gif";
	image_url[38] = "images/harta/Valcea.gif";
	image_url[39] = "images/harta/Vaslui.gif";
	image_url[40] = "images/harta/Vrancea.gif";

	preload_image = [];
	for(i=0; i<=image_url.length; i++)
	{
		preload_image[i] = new Image();
		preload_image[i].src = image_url[i];
	}

});

$(document).ready(function() {

	// Launch fancybox
	
	$("a.iframe").fancybox({
		'width':502, 
		'height':246,
		'scrolling':'no'
	});

	// Custom input file

	var W3CDOM = (document.createElement && document.getElementsByTagName);

	function init() {
		if (!W3CDOM) return;
		var fakeFileUpload = document.createElement('div');
		fakeFileUpload.className = 'fakefile';
		fakeFileUpload.appendChild(document.createElement('input'));
		var image = document.createElement('img');
		image.src='images/browse.png';
		fakeFileUpload.appendChild(image);
		var x = document.getElementsByTagName('input');
		for (var i=0;i<x.length;i++) {
			if (x[i].type != 'file') continue;
			if (x[i].getAttribute('noscript')) continue;
			if (x[i].parentNode.className != 'fileinputs') continue;
			x[i].className = 'file hidden';
			var clone = fakeFileUpload.cloneNode(true);
			x[i].parentNode.appendChild(clone);
			x[i].relatedElement = clone.getElementsByTagName('input')[0];
			//if (x[i].value) x[i].onchange();
			x[i].onchange = x[i].onmouseout = function () {
				this.relatedElement.value = this.value;
			}
		}
	}
	
	init();
	
	// Search changer
	
	$('#autoturisme, #locuinte, #birouri, #spatii-comerciale').hide();
	if (eval("typeof showsearch== 'function'")) {
		showsearch();
	} 
	$('#switcher').bind('change',function(e){
		$('#autoturisme, #locuinte, #birouri, #spatii-comerciale').slideUp(200);
		$('#'+$(this).val()).slideDown(500);
	})
	
	// Add changer
	
	$('#anfab, #kmpar, #cutv, #comb, #tiploc, #chir').hide();
	$('#switcher2').bind('change',function(e){
		$('#anfab, #kmpar, #cutv, #comb, #tiploc, #chir').slideUp(200);
		if($(this).val() == 'autoturisme'){
			$('#anfab, #kmpar, #cutv, #comb').slideDown(800);
		}
		if($(this).val() == 'locuinte'){
			$('#tiploc, #chir').slideDown(600);
		}
	})
	
	// Toggle add more images
	
	$('.adauga-imagini').bind('click',function(){
		$('#poze').slideToggle('slow');
		return false;
	})
	
	$('#termcond').hide();
	$('#termeni').bind('click',function(){
		$('#termcond').slideToggle('slow');
		return false;
	})
	
	$('#titlu').bind('keyup',function(){
		$('#countdown').val(50 - $('#titlu').val().length);
	})
	
	// fade on pics
	
	$(".picdet").bind("click",function(){
		var newpic = $(this).attr("href");
		$(".imgbig").fadeTo(700,0,"linear",function(){
			$(".imgbig").attr("src",newpic).fadeTo(700,1,"linear");
		});
		return false;
	});

});
