/*
	www.vectorialpx.net/set_js.php
*/
function gol_camp(camp, val, ev) {
	if(ev == 'focus') { if(document.getElementById(camp).value==val) document.getElementById(camp).value = '';
	} else if(ev == 'blur') if(document.getElementById(camp).value=='') document.getElementById(camp).value = val;
}

/* scurte */
function vizionate(adrs) { $('#vizionate').fadeIn(); return false; }
function changeimg(img,imbig) { $('#im_mare').html('<img src="'+img+'" alt="'+img+'" />'); $('#clickptamari').attr({ 'href':imbig }); }
function wo(href, par) { window.open(href, '_blank', par); return false; }
function hide(id) { $('#'+id).hide() }

/* hightlight a word */
function hl(w, where) {
	where = ''+where;
	if(w == '') {
		$(where).removeHighlight();
		$('.seachzona').val('cautare zona aici...');
	} else {
		$(where).removeHighlight();
		$(where).highlight(w);
	}
}

function seefilter(cum, id){
	var id_s = 's_'+id;
	var id_h = 'h_'+id;
	if(cum == 'show') {
		$('#'+id_s).hide(); $('#'+id_h).show();
		$('#'+id).slideDown("slow");
	} else {
		$('#'+id_h).hide();
		$('#'+id_s).show();
		$('#'+id).slideUp("slow");
	}
}


function setOf(cum, TPLADDR) {
	$('.big_cont .tab a').css('background-image', TPLADDR+'images/ca_tab_top_up.jpg');
	$('.big_cont .tab a').removeClass();
	$('.big_cont .tab a').addClass('over');
	$('#but'+cum).css('background-image', TPLADDR+'images/ca_tab_top_over.jpg');
	$('#but'+cum).removeClass();
	$('#tip_oferta').val(cum);
	return false;
}


/* set zonele */
function show_zone() {
	$('#divzoneleafisate').fadeIn();
	$('#divzoneleafisate').fadeTo('slow', 0.98);
	$('#divzoneleafisate').css('height', $('body').height()+'px');
	$('#divzoneleafisate').css('width', $('body').width()+'px');
	scroll_to('inside','no');
	$('select').hide();
	return false;
} function setzone() {
	$('select').show();
	$('#zona').val('');
	var contorizam = 0;
	var getzon = zonele.split(',');
	for(i=0;i<getzon.length;i++) {
		if($('#ck'+getzon[i]+':checked').val() != undefined) {
			$('#zona').val($('#zona').val()+($('#zona').val()==''?'':',')+$('#ck'+getzon[i]+':checked').val());
			contorizam++;
		}
	}
	$('#catzonsel').html(contorizam);
	$('#divzoneleafisate').hide();
	return false;
} function resetzone() {
	if(confirm('Deselectati toate zonele alese pana in acest moment?')) {
		var getzon = zonele.split(',');
		for(i=0;i<getzon.length;i++) {
			$('#ck'+getzon[i]).check('off')
		}
	}
	return false;
}

// setzone2 2
function setzone2() {
	$('select').show();
	$('#zona').val('');
	var contorizam = 0;
	var getzon = zonele.split(',');
	var ales = '';
	for(i=0;i<getzon.length;i++) {
		if($('#ck'+getzon[i]+':checked').val() != undefined) {
			$('#zona').val( $('#zona').val() + ( $('#zona').val()=='' ? '' : ',' ) + $('#ck'+getzon[i]+':checked').val());
			//ales = '<p class="filldiv" title="Stergeti acest filtru"><a class="exista" href="#" title="header=[Stergeti acest filtru] body=[]""><img src="http://www.vindesingur.ro/vs/tpl/images/x.png" class="right" alt="" /> '+ $('#ck'+getzon[i]+':checked').val() + '</a></p>';
			//$('#catzonsel').html( $('#catzonsel').html() + ales);
			contorizam++;
		}
	}
	
	$('#divzoneleafisate').hide();
	return false;
}

/* scroll TO */
function scroll_to(id,addclass) {
	var pos=$('#'+id).offset();
	$.scrollTo(pos.top-20, 500);
	if( addclass == 'yes' ) {
		$('.orangebg').removeClass('orangebg');
		$('#'+id).addClass('orangebg');
		if($('#a_'+id))
			$('#a_'+id).addClass('orangebg');
	}
	return false
}

/* stabileste pachet */
function set_pachet (iduri, preturi, toate_id, pac_id, TPLADDR) {
	var arai_id = iduri.split(',');
	var arai_pret = preturi.split(',');
	var arai_toate = toate_id.split(',');
	for(q=0;q<arai_toate.length;q++) {
		$('#desc_opt_'+arai_toate[q]).hide();
		$('#opt'+arai_toate[q]).hide();
		/*$('#opt'+arai_toate[q]).removeClass();
		$('#opt'+arai_toate[q]).addClass('optiune1');*/
		$('#opt_pret_'+arai_toate[q]).val(0);
		$('#pret_total').html('');
	}
	for(i=0;i<arai_pret.length;i++) {
		var actual = $('#pret_total').html();
		actual = actual-0;
		var setat = arai_pret[i];
		setat = setat-0;
		temp1 = actual+setat;
		temp2 = actual-setat;
		if(!temp1) temp1 = '0';
		if(!temp2) temp2 = '0';
		if($('#opt_pret_'+arai_id[i]).val() == 0) {
			$('#desc_opt_'+arai_id[i]).show();
			$('#opt'+arai_id[i]).show();
			/* $('#opt'+arai_id[i]).removeClass();
			$('#opt'+arai_id[i]).addClass('optiune2'); */
			$('#opt_pret_'+arai_id[i]).val(arai_pret[i]);
			$('#pret_total').html(temp1);
		} else {
			$('#desc_opt_'+arai_id[i]).hide();
			$('#opt'+arai_id[i]).hide();
			/*$('#opt'+arai_id[i]).removeClass();
			$('#opt'+arai_id[i]).addClass('optiune1');*/
			$('#opt_pret_'+arai_id[i]).val(0);
			$('#pret_total').html(temp2);
		}
	}
	var baza = TPLADDR.split('/'); var BASE = '';
	for(ib=0;ib<baza.length-2;ib++) { BASE += baza[ib]+'/' }
	$('#titlu_image').attr('src', TPLADDR+'images/alegere_pachet_'+pac_id+'.jpg');
	/* set the session 4 flash */
	$.ajax({ type: "GET", url: BASE+"ajax/ajax_set_ses4pachet.php", data: "pac="+pac_id });
	$('#entire_page').hide();
	scroll_to('content');
	return false;
}

function set_option (id, pret) {
	$('#desc_opt_'+id).toggle('fast');
	$('#opt'+id).removeClass();
	var actual = $('#pret_total').html();
	actual = actual-0;
	var setat = pret;
	setat = setat-0;
	temp1 = actual+setat;
	temp2 = actual-setat;
	if(!temp1) temp1 = pret_standard;
	if(!temp2) temp2 = pret_standard;
	if($('#opt_pret_'+id).val() == 0) {
		$('#opt'+id).addClass('optiune2');
		$('#opt_pret_'+id).val(pret);
		$('#pret_total').html(temp1);
		$('#pretul_total').val(temp1);
	} else {
		$('#opt'+id).addClass('optiune1');
		$('#opt_pret_'+id).val(0);
		$('#pret_total').html(temp2);
		$('#pretul_total').val(temp2);
	}
}

var img_cur = 11; var tur_cur = 5;
function add_file (baz, c, unde) {
	$('#'+unde+' .'+baz+'_'+c).fadeIn();
}

function set_comp(cum) {
	if(cum == 'show') {
		$('select').hide();
		$('#entire_page').fadeIn();
	} else {
		$('#entire_page').hide('fast');
		$('select').show();
	} return false;
}

function change_tab(but) {
	$('.ct').hide();
	$('#media_'+but).show();
	$('.up').removeClass();
	$('#'+but).addClass('up');
	return false;
}

function show_popup(idu,num) {
	$('#form_contact_firma').show();
	$.get("vs/ajax/get_firma_detalii.php", { id:idu } , function(data) {
		$('#content_form').html(data);
	});
	$('#firma').val(idu);
	$('#nume_f').val(num);
	$('#form_contact_firma').css('height', $('#content').height()-33);
	return false
}

var isopen = 0;
function openvals(care) {
	if(care == 'pret' && $('#tip_oferta').val()=='inchiriere')
		$('#vals').html($('#i_pret1').html());
	else $('#vals').html($('#i_'+care).html());
	var pos = $('#'+care).position();
	$('#vals').css('left', (pos.left-13)+'px');
	$('#vals').show();
	isopen = 1;
	return false;
} function closevals() {
	t = setTimeout ("if(!check_isopen()) { $('#vals').hide(); }", 200);
	isopen = 0;
} function setcont(idu, cont) { $('#'+idu).val(cont); $('#vals').hide(); return false; }
function check_isopen() { if(isopen) return true; else return false; }

var serviciu_curent = null;
var clasa_up = 'serviciu';
var clasa_over = 'serviciu1';
function show_serv(ce) {
	if(serviciu_curent!=ce) {
		$(".form_serviciu").hide();
		$("#"+ce).css('height', $('#content').height()-35);
		$('#'+ce).show();
		$('#'+ce).fadeTo("slow", 0.95);
		$('#but_'+ce).removeClass();
		$('#but_'+ce).addClass(clasa_over);
		$('#but_'+serviciu_curent).removeClass();
		$('#but_'+serviciu_curent).addClass(clasa_up);
		serviciu_curent = ce;
	} else {
		$(".form_serviciu").hide('fast');
		$('#but_'+serviciu_curent).removeClass();
		$('#but_'+serviciu_curent).addClass(clasa_up);
		serviciu_curent = null;
	} return false;
} function hs() {
	$(".form_serviciu").hide('fast');
	$('#but_'+serviciu_curent).removeClass();
	$('#but_'+serviciu_curent).addClass(clasa_up);
	serviciu_curent = null;
	return false;
}

function show_tab(care) {
	$('.tabs').hide();
	$('#'+care).show();
	return false;
}

function afiseaza_optiuni(ce) {
	if(ce == 'toate') {
		$('.col_p').show();
	} else {
		$('.col_p').hide();
		$('.col_p_'+ce).show();
	}
	$('.afisez_'+but_apasat).css('background-color', 'transparent');
	but_apasat = ce;
	$('.afisez_'+but_apasat).css('background-color', '#ffeecc');
	return false
}

/* afiseaza colt grafic dreapta sus - prom smart */
function colt_grafic(cum, TPLADDR) {
	if(cum == 'show') {
		$('#colt_grafic').css('width', '500px');
		$('#colt_grafic').css('height', '100px');
		$('#colt_grafic').css('margin-left', '-500px');
		$('#colt_grafic').css('background', 'url('+TPLADDR+'images/colt_grafic_bg.gif) no-repeat left');
		$('#colt_grafic p').show();
	} else {
		$('#colt_grafic p').hide();
		$('#colt_grafic').css('width', '60px');
		$('#colt_grafic').css('height', '89px');
		$('#colt_grafic').css('margin-left', '-60px');
		$('#colt_grafic').css('background', 'transparent');
	}
}


/* calculator de credite */
function calcul_credit(suma, ani) {
	var an = Number(ani);
	var summ = Number(suma);
	var dobanda_anuala = 0.0075;
	if(suma =='' || ani=='') { alert('Trebuie sa specificati o suma si o perioada de creditare.'); return false; }
	rezultat = summ*dobanda_anuala / ( 12 * ( 1 - Math.pow((1+dobanda_anuala/12), (-an*12)) ) );
	rezultat = Math.round(rezultat*100)/100;
	$('#rez_calcul_credit').html('Rata aproximativa este de <'+'strong>'+Number(rezultat)+'</'+'strong> euro/luna');
	return false;
}

/* printeaza */
function prnt(id) {
	var a = window.open('','prnt');
	a.document.open(); /*"text/html"*/
	a.document.write(document.getElementById(id).innerHTML);
	a.document.close();
	a.print(); a.close();
	return false;
}

var timerSlideshow;
var curenta = 0;
function startSlideshow(cum) {
	
	if(cum == null || cum == undefined) {
		var imag = toate_imag.split(',');
		/* partea grafica */
		$('embed, object, select').css({'visibility':'hidden'});
		var allHTMLimages = '';
		for(mi=0;mi<imag.length;mi++)
			allHTMLimages += '<img style="display:none" src="'+ADR+'img_prop/t700/'+imag[mi]+'">';
		$('body').append('<div id="slideshow_main" onclick="startSlideshow(1)"><p style="margin-top:50px;color:#06c">Imaginile se schimba la un interval de 5 secunde. Click pentru a inchide.</p><img id="theimage" src="'+ADR+'img_prop/t700/'+imag[curenta]+'" style="margin-top:10px;border:3px solid #333">'+allHTMLimages+'</div>');
		$.scrollTo(10, 500);
		$('#slideshow_main').css('position', 'absolute');
		$('#slideshow_main').css('text-align', 'center');
		$('#slideshow_main').css('background-color', '#ffffff');
		$('#slideshow_main').css('top', '0');
		$('#slideshow_main').css('z-index', '205');
		$('#slideshow_main').css('width', $('body').width()+'px');
		$('#slideshow_main').css('height', $('body').height()+'px');
		$('#slideshow_main').fadeTo('slow', 0.95);
		/* --------------------------- */
		timerSlideshow = setInterval('schimba()', 5000);
	} else {
		$('#theimage').remove();
		$('#slideshow_main').fadeOut(function() { $('#slideshow_main').remove(); });
		$('embed, object, select').css({ 'visibility' : 'visible' });
		clearInterval(timerSlideshow);
	}
	return false;
}

function schimba() {
	var imag = toate_imag.split(',');
	if( curenta < imag.length-1 ) {
		curenta++;
		/* $('#theimage').attr('src', ADR+'img_prop/t700/'+imag[curenta]); */
		$('#theimage').fadeOut('fast', function() {$('#theimage').attr('src', ADR+'img_prop/t700/'+imag[curenta]); $('#theimage').fadeIn();} );
	} else {
		curenta = 0;
		/* $('#theimage').attr('src', ADR+'img_prop/t700/'+imag[curenta]); */
		$('#theimage').fadeOut('fast', function() {$('#theimage').attr('src', ADR+'img_prop/t700/'+imag[curenta]); $('#theimage').fadeIn();} );
	}
}

/* modifica X la slider + other 
function changesearch(unde, care, cum){
	$('#slider').animate({ marginLeft: unde+"px" });
	$('#'+care).attr('name',cum);
	return false;
} */

/* proprietati vandute sau toate */
function changeway(care,base) {
	if(care == 1) { /* click = caut1 => incheiate */
		$('#caut').attr('src',base+'but_cauta_up.jpg');
		$('#caut1').attr('src',base+'but_prop_vandute_over.jpg');
	} else {
		$('#caut').attr('src',base+'but_cauta_over.jpg');
		$('#caut1').attr('src',base+'but_prop_vandute_up.jpg');
	}
	$('#incheiat').val(care);
	return false;
}

/* calcul comision, pentru prima pagina */
function calculcom(cat,com) {
	var valo = cat*com/100;
	valo = Math.round(valo*100)/100;
	if(isNaN(valo) || isNaN(com) || cat > 100000000 || com > 100) {
		alert('Suma/Comisionul este prea mare sau nu e numerica!\nSe accepta maxim 100.000.000 EUR si maxim 99%');
		return false;
	} else $('#rezultatcom').html(valo+' EUR');
}


/* refresh IFRAME */
function rfrm(id, cu) { var ifr = document.getElementById(id); ifr.src = cu; return false; }

/* anim imagine de la TUR1 */
function animtur1() {
	$("#tur_virtual1").mousemove(function(e) {
		var pos = $("#tur_virtual1").position();
		$("#tur1image").css({marginTop:(e.pageY-pos.top - 110)+"px"});
	});
}

/* pentru admin, validare form */
function valid_form() {
	var eroareamea = false;
	var trebuie = ['mail_client', 'titlu', 'localitate', 'zona', 'adresa', 'pret', 'det_prop', 'det_cartier'];
	for(i=0;i<trebuie.length;i++) {
		if($('#'+trebuie[i]).val() == '') {
			/* alert('#'+trebuie[i] + ' - ' + $('#'+trebuie[i]).val()); */
			eroareamea = true;
			$('#'+trebuie[i]).css('background-color','#fdc');
		} else {
			$('#'+trebuie[i]).css('background-color','');
			}
	} if(eroareamea) { alert('Nu ai completat campurile obligatorii. Verifica formularul!'); return false;
	} else { $('#jos').hide(); return true; }
}


/* meniu */
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;
var id_dep = 0;
function mopen(id) {
	mcancelclosetime();
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';
	var the_pos = $('.'+id_dep).offset();
	var pozitie_left = the_pos.left;
	$('#'+id).css("position", "absolute");
	$('#'+id).css("left", pozitie_left+9);
} function mclose() {
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
} function mclosetime() {
	closetimer = window.setTimeout(mclose, timeout);
} function mcancelclosetime() {
	if(closetimer) {
		window.clearTimeout(closetimer);
		closetimer = null;
	}
} document.onclick = mclose; 

/* jquery checkbox stuff */
jQuery.fn.check = function(mode) {
	var mode = mode || 'on';
	return this.each(function() {
		switch(mode) {
			case 'on': this.checked = true; break;
			case 'off': this.checked = false; break;
			case 'toggle': this.checked = !this.checked; break;
		}
	});
};

/* pentru filtre */
function setLocation(loc, ADR) {
	if(loc=='') {
		$('#loc_lev1').show();
		$('#loc_lev2').hide();
	} else {
		$('#loc_lev1').hide();
		$('#loc_lev2').show();
		$('#loadlocs').html('&nbsp; Asteptati...');
		$('#jud_filter').val(loc);
		$('#loadlocs').load(ADR+'ajax/filter_get_locations.php?loc='+loc);
	}
	return false;
}

function setJudet(judet, ADR, backlink){
	if(judet != '')
		document.location = ADR + 'act.php?action=filter&amp;back='+backlink+'&amp;f=judet&amp;val='+judet;
}
/* set subLocations*/
function showLocs(care) {
	if($('#'+care).is(':visible')) {
		$('#'+care).slideUp();
	} else {
		$('.loctabs').slideUp();
		$('#'+care).slideDown();
	}
	return false;
}



/* Detection snippet from http://www.dithered.com/javascript/browser_detect/index.html
---------------------------------------------------------------------------------------
http://www.mustardlab.com/developer/flash/jscommunication/ 
var ua = navigator.userAgent.toLowerCase(); 
var is_pc_ie = ( (ua.indexOf('msie') != -1 ) && ( ua.indexOf('win') != -1 ) && ( ua.indexOf('opera') == -1 ) && ( ua.indexOf('webtv') == -1 ) );
*/
function callExternalInterface(valoare) {
    thisMovie("externalInterfaceExample").goHome(valoare);
} function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	}
	else {
		return document[movieName]
	}
}

function openZonele() {
	$('#zone4flash').show();
	$('#zone4flash').fadeTo('fast',0.9);
	return false;
} function closeZonele() {
	$('#zone4flash').hide();
	return false;
}

function setzoneAlerte() {
	var getzon = zoneleHarta.split(',');
	var zonaalerte = '';
	for(i=0;i<getzon.length;i++) {
		if($('#hck'+getzon[i]+':checked').val() != undefined)
			zonaalerte = zonaalerte+$('#hck'+getzon[i]+':checked').val() + '; ';
	}
	callExternalInterface(zonaalerte);
	closeZonele();
	return false;
}  function resetzonealerte() {
	if(confirm('Deselectati toate zonele alese pana in acest moment?')) {
		var getzon = zoneleHarta.split(',');
		for(i=0;i<getzon.length;i++) {
			$('#hck'+getzon[i]).check('off')
		}
	}
	return false;
}


function dumpProps(obj, parent) {
	for (var i in obj) {
		// if a parent (2nd parameter) was passed in, then use that to
		// build the message. Message includes i (the object's property name)
		// then the object's property value on a new line
		if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
		// Display the message. If the user clicks "OK", then continue. If they
		// click "CANCEL" then quit this level of recursion
		if (!confirm(msg)) { return; }
		// If this property (i) is an object, then recursively process the object
		if (typeof obj[i] == "object") {
			if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
		}
	}
}


function addToFav(id, ADR) {
	$.post (
		ADR+'ajax/add_to_favorite.php?id='+id, {
			prof_pass:$('#prof_pass').val(), prof_repass:$('#prof_repass').val(), prof_name:$('#prof_name').val(),
			prof_phone:$('#prof_phone').val(), prof_state:$('#prof_state').val(), prof_city:$('#prof_city').val(),
			prof_address:$('#prof_address').val(), prof_bd_day:$('#prof_bd_day').val(), prof_bd_month:$('#prof_bd_month').val(),
			prof_bd_year:$('#prof_bd_year').val(), prof_newsletter:$('#prof_newsletter').val(),
			prof_signature:$('#prof_signature').val(), go_profile:$('#go_profile').val() },
		function(data){
			$('#butaddfavorit').fadeTo('slow',0.3);
			alert(data);
		}
	);
	return false;
}


/*
// by cosmin
function creareCont(){
	$('#submitcreare').hide();
	$.post (
		ADR+'ajax/crearecont.php', { 
		form:'crearecont',
		nume:$('#nume').val(),
		prenume:$('#prenume').val(),
		email:$('#email').val(),
		parola:$('#parola').val(),
		parola2:$('#parola2').val(),
		telefon:$('#telefon').val()
		},
		function(data){
			if(data == 'ok') {
				$('#creare_cont').hide();	
				$('#creare_cont_succes').show();	
			} else {
				alert(data);
				$('#submitcreare').show();				
			}
		}
	); return false;
}
function disableEnterKey(e) { var key; if(window.event) key = window.event.keyCode; else key = e.which; if(key == 13) return false; else return true; } */
