function isEmail(str){
    return /^[a-z]([a-z0-9-_\.]+)?\@[a-z-_=>0-9\.]+\.[a-z]{2,}$/i.test(str);
}

function isUrl(str){
    return /^(ftp|https?):\/\/[a-z0-9\-\.]{3,}(\.[a-z]{2,})?(\:[0-9]{2,5})?(\/(.+)?)?$/i.test(str);
}

function previewVideo(videoIn, fixinputonly) {
	videoOut = videoIn;
    if (videoOut.indexOf("object") > -1 || videoOut.indexOf("embed") > -1) {
       var matches = videoOut.match(/https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/gi);
       videoOut = matches[0];
    }
    if (videoOut.indexOf("watch") > -1) {
    	videoOut = videoOut.replace("watch?v=", "v/");
	}
	$("#video1").val(videoOut);
	return ( !fixinputonly
		? '<object height="120" width="170"><param name="movie" value="'+videoOut+'"/><param name="allowFullScreen" value="true"/><param name="allowscriptaccess" value="always"/><embed height="120" width="170" src="'+videoOut+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true"/></object>'
		: true
	);
}

function switchLang(inlang, nofocus) {
    if (!inlang) {
        return false;
    }
    $("a[id^='switchlang']").each(function(){
        $(this).removeClass('active');
    })
    $("#switchlang"+inlang).addClass('active');
    $("div[id^='descgroup']").each(function(){
        $(this).hide();
    })
    $("#descgroup"+inlang).fadeIn();
    $("#descgroupt"+inlang).fadeIn();
    if (!nofocus)
        $("#title_"+inlang).focus();
    return false;
}

function doTranslation(source_txt, target_txt, langin, langout, ok_res, ko_res) {
    var sourceText = $("#"+source_txt).val();
    $.translate(sourceText,langin,langout, {
        start: function(){$("#loadingtrans").show();},
        complete: function(translation){
            $("#"+target_txt).val(translation);
            $("#loadingtrans").html(ok_res);
            $("#loadingtrans").css({
                'padding-left':'35px',
                'background-color':'transparent',
                'background-image':'url(/web/images/ok.png)',
                'background-repeat':'no-repeat',
                'background-position': 'top left'
            });
        },
        error: function(){$("#loadingtrans").html(ko_res);}
    });
}

function doTranslationPreview(source_txt, target_txt, langin, langout) {
    var sourceText = $("#"+source_txt).val();
    $.translate(sourceText,langin,langout, {
        complete: function(translation){
			$("#"+target_txt).val(translation);
			$("#2"+target_txt).val(translation);
        }
    });
}

function doEvent(event_elem, city_elem, lang, selectedeventid) {
	$.ajax({
		url: "/web/ajax/get-events.php",
		global: false,
		type: "POST",
		data: ({
			lang:lang,
			city: $("#"+city_elem).val(),
			selectedeventid: selectedeventid
		}),
		dataType: "html",
		success: function(msg){
			$("#"+event_elem).replaceWith(msg);
		}
	});
}

/***** OBSOLETAS? *****/
function doZone(city_elem, zone_elem, lang, defaultoption, selectedzoneid) {
    $.ajax({
        url: "/web/ajax/get-zones.php",
        global: false,
        type: "POST",
        data: ({lang:lang,city_elem:city_elem,zone_elem:zone_elem,city_id:$("#"+city_elem).val(),defaultoption:defaultoption,selectedzoneid:selectedzoneid}),
        dataType: "html",
        success: function(msg){
            $("#"+zone_elem).fadeIn().replaceWith(msg);
        }
    });
}

function doZoneSEO(city_elem, zone_elem, lang, defaultoption, selectedzoneid) {
    $.ajax({
        url: "/web/ajax/get-zones-seo.php",
        global: false,
        type: "POST",
        data: ({lang:lang,city_elem:city_elem,zone_elem:zone_elem,city_id:$("#"+city_elem).val(),defaultoption:defaultoption,selectedzoneid:selectedzoneid}),
        dataType: "html",
        success: function(msg){
            $("#"+zone_elem).fadeIn().replaceWith(msg);
        }
    });
}

function doCity(city_elem, zone_elem, country, lang, defaultoption, selectedcityid, selectedzoneid) {
    if ($("#"+city_elem).val() != '') {
        doZone(city_elem, zone_elem, lang, defaultoption, selectedzoneid);
    }
    else {
        $.ajax({
            url: "/web/ajax/get-cities.php",
            global: false,
            type: "POST",
            data: ({country:country,lang:lang,city_elem:city_elem,zone_elem:zone_elem,defaultoption:defaultoption,selectedcityid:selectedcityid}),
            dataType: "html",
            success: function(msg){
                $("#"+city_elem).replaceWith(msg);
                doZone(city_elem, zone_elem, lang, defaultoption, selectedzoneid);
            }
        });
    }
}

function doCitySEO(city_elem, zone_elem, country, lang, defaultoption, selectedcityid, selectedzoneid) {
    if ($("#"+city_elem).val() != '') {
        doZoneSEO(city_elem, zone_elem, lang, defaultoption, selectedzoneid);
    }
    else {
        $.ajax({
            url: "/web/ajax/get-cities-seo.php",
            global: false,
            type: "POST",
            data: ({country:country,lang:lang,city_elem:city_elem,zone_elem:zone_elem,defaultoption:defaultoption,selectedcityid:selectedcityid}),
            dataType: "html",
            success: function(msg){
                $("#"+city_elem).replaceWith(msg);
                doZoneSEO(city_elem, zone_elem, lang, defaultoption, selectedzoneid);
            }
        });
    }
}
/***** OBSOLETAS? *****/

function translateForms(lang){
	if (lang=='') lang ='es';
    var curlang = lang;
    $("a[id^='switchlang']").each(function(){
        if ($(this).hasClass('active')) curlang = $(this).attr('id').substr(10,2);
    });
    if ($('#hi_title_'+curlang).val() != '') {
		if ($('#hi_title_es').val() == '')  doTranslationPreview('hi_title_'+curlang, 'hi_title_es', curlang, 'es');
        if ($('#hi_title_en').val() == '')  doTranslationPreview('hi_title_'+curlang, 'hi_title_en', curlang, 'en');
        if ($('#hi_title_fr').val() == '')  doTranslationPreview('hi_title_'+curlang, 'hi_title_fr', curlang, 'fr');
        if ($('#hi_title_de').val() == '')  doTranslationPreview('hi_title_'+curlang, 'hi_title_de', curlang, 'de');
        if ($('#hi_title_it').val() == '')  doTranslationPreview('hi_title_'+curlang, 'hi_title_it', curlang, 'it');
    }
    if ($('#hi_desc_'+curlang).val() != '') {
		if ($('#hi_desc_es').val() == '')  doTranslationPreview('hi_desc_'+curlang, 'hi_desc_es', curlang, 'es');
        if ($('#hi_desc_en').val() == '')  doTranslationPreview('hi_desc_'+curlang, 'hi_desc_en', curlang, 'en');
        if ($('#hi_desc_fr').val() == '')  doTranslationPreview('hi_desc_'+curlang, 'hi_desc_fr', curlang, 'fr');
        if ($('#hi_desc_de').val() == '')  doTranslationPreview('hi_desc_'+curlang, 'hi_desc_de', curlang, 'de');
        if ($('#hi_desc_it').val() == '')  doTranslationPreview('hi_desc_'+curlang, 'hi_desc_it', curlang, 'it');
    }
}

function checkFormCreateRoom(lang) {
    var status = true;

    // check city
    if ($("#newcity").is(':visible')) {
        if ($("#newcity").val() == '') {
            $("#newcity").addClass('required');
            status = status && false;
        }
        else {
            $("#newcity").removeClass('required');
            status = status && true;
        }
    }
    else {
        if ($("#city").val() == '') {
            $("#city").addClass('required');
            status = status && false;
        }
        else {
            $("#city").removeClass('required');
            status = status && true;
        }
    }

    // check zone
    if ($("#newzone").is(':visible')) {
        if ($("#newzone").val() == '') {
            $("#newzone").addClass('required');
            status = status && false;
        }
        else {
            $("#newzone").removeClass('required');
            status = status && true;
        }
    }
    else {
        if ($("#zone").val() == '') {
            $("#zone").addClass('required');
            status = status && false;
        }
        else {
            $("#zone").removeClass('required');
            status = status && true;
        }
    }

    // check price
    if ($("#price").val() == '' || $("#price").val() == '0') {
        $("#price").addClass('required');
        status = status && false;
    }
    else {
        $("#price").removeClass('required');
        status = status && true;
    }

    // check availability
    if ($("#avail_from").val() == '' && $("#avail_to").val() != '') {
        $("#avail_from").addClass('required');
        status = status && false;
    }
    else {
        $("#avail_from").removeClass('required');
        status = status && true;
    }

    // check title and desc
    if ($("#title_"+lang).val() == '') {
        $("#title_"+lang).addClass('required');
        status = status && false;
    }
    else {
        $("#title_"+lang).removeClass('required');
        status = status && true;
    }
    if ($("#desc_"+lang).val() == '') {
        $("#desc_"+lang).addClass('required');
        status = status && false;
    }
    else {
        $("#desc_"+lang).removeClass('required');
        status = status && true;
    }

    // check email
    if ($("#email").val() == '') {
        $("#email").addClass('required');
        status = status && false;
    }
    else if (!isEmail($("#email").val())) {
        $("#email").addClass('required');
        status = status && false;
    }
    else {
        $("#email").removeClass('required');
        status = status && true;
    }
    if ($("#email_check").val() == '0') {
        $("#email").addClass('required');
        status = status && false;
    }

    // check email sharing
    if ($("input[name='emailshare']:checked").val() == 3 && $("#phone").val() == '') {
        $("#phone").addClass('required');
        status = status && false;
    }
    else {
        $("#emailshare1").removeClass('required');
        $("#emailshare2").removeClass('required');
        $("#emailshare3").removeClass('required');
        $("#phone").removeClass('required');
        status = status && true;
    }

    // check conditions
    if (!$("#conditions").is(':checked')) {
        $("#conditions").addClass('required');
        status = status && false;
    }
    else {
        $("#conditions").removeClass('required');
        status = status && true;
    }

    if (!status) {
        $("#formerror").show();
        return false;
    }
    else {
        $("#gotostep2").attr('disabled', 'disabled');
        $("#formroom1").submit();
    }
}

function checkFormCreateEvent(lang) {
    var status = true;

    // check city
		if ($("#newcity").val() == '') {
				$("#newcity").addClass('required');
				status = status && false;
		}
		else {
				$("#newcity").removeClass('required');
				status = status && true;
		}

    // check event
		if ($("#event").val() == '') {
				$("#event").addClass('required');
				status = status && false;
		}
		else {
				$("#event").removeClass('required');
				status = status && true;
		}

    // check zone
    if ($("#newzone").is(':visible')) {
        if ($("#newzone").val() == '') {
            $("#newzone").addClass('required');
            status = status && false;
        }
        else {
            $("#newzone").removeClass('required');
            status = status && true;
        }
    }
    else {
        if ($("#zone").val() == '') {
            $("#zone").addClass('required');
            status = status && false;
        }
        else {
            $("#zone").removeClass('required');
            status = status && true;
        }
    }

    // check price
    if ($("#price").val() == '' || $("#price").val() == '0') {
        $("#price").addClass('required');
        status = status && false;
    }
    else {
        $("#price").removeClass('required');
        status = status && true;
    }

    // check availability
    if ($("#avail_from").val() == '' && $("#avail_to").val() != '') {
        $("#avail_from").addClass('required');
        status = status && false;
    }
    else {
        $("#avail_from").removeClass('required');
        status = status && true;
    }

    // check title and desc
    if ($("#title_"+lang).val() == '') {
        $("#title_"+lang).addClass('required');
        status = status && false;
    }
    else {
        $("#title_"+lang).removeClass('required');
        status = status && true;
    }
    if ($("#desc_"+lang).val() == '') {
        $("#desc_"+lang).addClass('required');
        status = status && false;
    }
    else {
        $("#desc_"+lang).removeClass('required');
        status = status && true;
    }

    // check email
    if ($("#email").val() == '') {
        $("#email").addClass('required');
        status = status && false;
    }
    else if (!isEmail($("#email").val())) {
        $("#email").addClass('required');
        status = status && false;
    }
    else {
        $("#email").removeClass('required');
        status = status && true;
    }
    if ($("#email_check").val() == '0') {
        $("#email").addClass('required');
        status = status && false;
    }

    // check email sharing
    if ($("input[name='emailshare']:checked").val() == 3 && $("#phone").val() == '') {
        $("#phone").addClass('required');
        status = status && false;
    }
    else {
        $("#emailshare1").removeClass('required');
        $("#emailshare2").removeClass('required');
        $("#emailshare3").removeClass('required');
        $("#phone").removeClass('required');
        status = status && true;
    }

    // check conditions
    if (!$("#conditions").is(':checked')) {
        $("#conditions").addClass('required');
        status = status && false;
    }
    else {
        $("#conditions").removeClass('required');
        status = status && true;
    }

    if (!status) {
        $("#formerror").show();
        return false;
    }
    else {
        $("#gotostep2").attr('disabled', 'disabled');
        $("#formroom1").submit();
    }
}
function checkFormCreateBarter(lang) {
    var status = true;

    // check city
    if ($("#newcity").is(':visible')) {
        if ($("#newcity").val() == '') {
            $("#newcity").addClass('required');
            status = status && false;
        }
        else {
            $("#newcity").removeClass('required');
            status = status && true;
        }
    }
    else {
        if ($("#city").val() == '') {
            $("#city").addClass('required');
            status = status && false;
        }
        else {
            $("#city").removeClass('required');
            status = status && true;
        }
    }

    // check zone
    if ($("#newzone").is(':visible')) {
        if ($("#newzone").val() == '') {
            $("#newzone").addClass('required');
            status = status && false;
        }
        else {
            $("#newzone").removeClass('required');
            status = status && true;
        }
    }
    else {
        if ($("#zone").val() == '') {
            $("#zone").addClass('required');
            status = status && false;
        }
        else {
            $("#zone").removeClass('required');
            status = status && true;
        }
    }

    // check availability
    if ($("#avail_from").val() == '' && $("#avail_to").val() != '') {
        $("#avail_from").addClass('required');
        status = status && false;
    }
    else {
        $("#avail_from").removeClass('required');
        status = status && true;
    }

    // check title and desc
    if ($("#title_"+lang).val() == '') {
        $("#title_"+lang).addClass('required');
        status = status && false;
    }
    else {
        $("#title_"+lang).removeClass('required');
        status = status && true;
    }
    if ($("#desc_"+lang).val() == '') {
        $("#desc_"+lang).addClass('required');
        status = status && false;
    }
    else {
        $("#desc_"+lang).removeClass('required');
        status = status && true;
    }

    // check email
    if ($("#email").val() == '') {
        $("#email").addClass('required');
        status = status && false;
    }
    else if (!isEmail($("#email").val())) {
        $("#email").addClass('required');
        status = status && false;
    }
    else {
        $("#email").removeClass('required');
        status = status && true;
    }
    if ($("#email_check").val() == '0') {
        $("#email").addClass('required');
        status = status && false;
    }

    // check email sharing
    if ($("input[name='emailshare']:checked").val() == 3 && $("#phone").val() == '') {
        $("#phone").addClass('required');
        status = status && false;
    }
    else {
        $("#emailshare1").removeClass('required');
        $("#emailshare2").removeClass('required');
        $("#emailshare3").removeClass('required');
        $("#phone").removeClass('required');
        status = status && true;
    }

    // check conditions
    if (!$("#conditions").is(':checked')) {
        $("#conditions").addClass('required');
        status = status && false;
    }
    else {
        $("#conditions").removeClass('required');
        status = status && true;
    }

    if (!status) {
        $("#formerror").show();
        return false;
    }
    else {
        $("#gotostep2").attr('disabled', 'disabled');
        $("#formroom1").submit();
    }
}

function checkFormCreateApartment(lang) {
    var status = true;

    // check city
    if ($("#newcity").is(':visible')) {
        if ($("#newcity").val() == '') {
            $("#newcity").addClass('required');
            status = status && false;
        }
        else {
            $("#newcity").removeClass('required');
            status = status && true;
        }
    }
    else {
        if ($("#city").val() == '') {
            $("#city").addClass('required');
            status = status && false;
        }
        else {
            $("#city").removeClass('required');
            status = status && true;
        }
    }

    // check zone
    if ($("#newzone").is(':visible')) {
        if ($("#newzone").val() == '') {
            $("#newzone").addClass('required');
            status = status && false;
        }
        else {
            $("#newzone").removeClass('required');
            status = status && true;
        }
    }
    else {
        if ($("#zone").val() == '') {
            $("#zone").addClass('required');
            status = status && false;
        }
        else {
            $("#zone").removeClass('required');
            status = status && true;
        }
    }

    // check price
    if ($("#price").val() == '' || $("#price").val() == '0') {
        $("#price").addClass('required');
        status = status && false;
    }
    else {
        $("#price").removeClass('required');
        status = status && true;
    }

    // check title and desc
    if ($("#title_"+lang).val() == '') {
        $("#title_"+lang).addClass('required');
        status = status && false;
    }
    else {
        $("#title_"+lang).removeClass('required');
        status = status && true;
    }
    if ($("#desc_"+lang).val() == '') {
        $("#desc_"+lang).addClass('required');
        status = status && false;
    }
    else {
        $("#desc_"+lang).removeClass('required');
        status = status && true;
    }

    // check email
    if ($("#email").val() == '') {
        $("#email").addClass('required');
        status = status && false;
    }
    else if (!isEmail($("#email").val())) {
        $("#email").addClass('required');
        status = status && false;
    }
    else {
        $("#email").removeClass('required');
        status = status && true;
    }
    if ($("#email_check").val() == '0') {
        $("#email").addClass('required');
        status = status && false;
    }

    // check email sharing
    if ($("input[name='emailshare']:checked").val() == 3 && $("#phone").val() == '') {
        $("#phone").addClass('required');
        status = status && false;
    }
    else {
        $("#emailshare1").removeClass('required');
        $("#emailshare2").removeClass('required');
        $("#emailshare3").removeClass('required');
        $("#phone").removeClass('required');
        status = status && true;
    }

    // check conditions
    if (!$("#conditions").is(':checked')) {
        $("#conditions").addClass('required');
        status = status && false;
    }
    else {
        $("#conditions").removeClass('required');
        status = status && true;
    }

    if (!status) {
        $("#formerror").show();
        return false;
    }
    else {
        $("#gotostep2").attr('disabled', 'disabled');
        $("#formroom1").submit();
    }
}

function checkFormCreateProfile(lang) {
    var status = true;

    // check city
    if ($("#newcity").is(':visible')) {
        if ($("#newcity").val() == '') {
            $("#newcity").addClass('required');
            status = status && false;
        }
        else {
            $("#newcity").removeClass('required');
            status = status && true;
        }
    }
    else {
        if ($("#city").val() == '') {
            $("#city").addClass('required');
            status = status && false;
        }
        else {
            $("#city").removeClass('required');
            status = status && true;
        }
    }

    // check zone
    if ($("#newzone").is(':visible')) {
        if ($("#newzone").val() == '') {
            $("#newzone").addClass('required');
            status = status && false;
        }
        else {
            $("#newzone").removeClass('required');
            status = status && true;
        }
    }

    // check availability
    if ($("#avail_from").val() == '' && $("#avail_to").val() != '') {
        $("#avail_from").addClass('required');
        status = status && false;
    }
    else {
        $("#avail_from").removeClass('required');
        status = status && true;
    }

    // check title and desc
    if ($("#title_"+lang).val() == '') {
        $("#title_"+lang).addClass('required');
        status = status && false;
    }
    else {
        $("#title_"+lang).removeClass('required');
        status = status && true;
    }
    if ($("#desc_"+lang).val() == '') {
        $("#desc_"+lang).addClass('required');
        status = status && false;
    }
    else {
        $("#desc_"+lang).removeClass('required');
        status = status && true;
    }

    // check email
    if ($("#email").val() == '') {
        $("#email").addClass('required');
        status = status && false;
    }
    else if (!isEmail($("#email").val())) {
        $("#email").addClass('required');
        status = status && false;
    }
    else {
        $("#email").removeClass('required');
        status = status && true;
    }
    if ($("#email_check").val() == '0') {
        $("#email").addClass('required');
        status = status && false;
    }

    // check email sharing
    if ($("input[name='emailshare']:checked").val() == 3 && $("#phone").val() == '') {
        $("#phone").addClass('required');
        status = status && false;
    }
    else {
        $("#emailshare1").removeClass('required');
        $("#emailshare2").removeClass('required');
        $("#emailshare3").removeClass('required');
        $("#phone").removeClass('required');
        status = status && true;
    }

    // check conditions
    if (!$("#conditions").is(':checked')) {
        $("#conditions").addClass('required');
        status = status && false;
    }
    else {
        $("#conditions").removeClass('required');
        status = status && true;
    }

    if (!status) {
        $("#formerror").show();
        return false;
    }
    else {
        $("#gotostep2").attr('disabled', 'disabled');
        $("#formprofile1").submit();
    }
}

String.prototype.cleanURL = function(){
    var tmp_this = this.toLowerCase();
    var arr_search = "áéíóúü".split("");
    var arr_replace = "aeiouu".split("");
    for(var i=0; i<arr_search.length; i++ ){
        tmp_this = tmp_this.replace(arr_search[i],arr_replace[i]);
    }
    return tmp_this.replace(/[^\\s\wñ\+]/g, "");
}

function doSearch(rooturl, city, zone, amenities, price, photos, videos, order, keywords, page) {
    var gotourl = rooturl;
    //parse params
    if (!amenities) amenities = 'all';
    if (!price) price = 'all';
    if (!photos) photos = 'no';
    if (!videos) videos = 'no';
    if (!order) order = 'date';
    keywords = keywords.replace(/ /g, '+');
    keywords = keywords.cleanURL();
    keywords = keywords.replace(/[^a-z0-9ñÑ\+]/g, "");
    if (!page) page = 1;

    gotourl += '-' + city;
    gotourl += (zone != '' ? '-' + zone : '');
    gotourl += '/' + amenities + '/';
    gotourl += 'price_' + price;
    gotourl += '-photos_' + photos;
    gotourl += '-videos_' + videos;
    gotourl += '-order_' + order;
    gotourl += (keywords != '' ? '/' + keywords : '');
    gotourl += '/' + page + '/';

    window.location.assign(gotourl);
    return false;
}

function doSearchApt(rooturl, city, types, amenities, price, meters, provider, contract, photos, videos, furniture, bedrooms, bathrooms, condition, order, keywords, page) {
    var gotourl = rooturl;

    if (!types) types = 'all';
    if (!amenities) amenities = 'all';
    if (!price) price = 'all';
    if (!meters) meters = 'all';
    if (!provider) provider = 'all';
    if (!contract) contract = 'all';
    if (!photos) photos = 'no';
    if (!videos) videos = 'no';
    if (!furniture) furniture = 'all';
    if (!bedrooms) bedrooms = 'all';
    if (!bathrooms) bathrooms = 'all';
    if (!condition) condition = 'all';
    if (!order) order = 'date';
    keywords = keywords.replace(/ /g, '+');
    keywords = keywords.cleanURL();
    keywords = keywords.replace(/[^a-z0-9ñÑ\+]/g, "");
    if (!page) page = 1;

    gotourl += '-' + city;
    gotourl += '/' + types;
    gotourl += '/' + amenities;
    gotourl += '/price_' + price;
    gotourl += '-meters_' + meters;
    gotourl += '-' + provider;
    gotourl += '-' + contract;
    gotourl += '-photos_' + photos;
    gotourl += '-videos_' + videos;
    gotourl += '-furniture_' + furniture;
    gotourl += '-bedrooms_' + bedrooms;
    gotourl += '-bathrooms_' + bathrooms;
    gotourl += '-' + condition;
    gotourl += '-order_' + order;
    gotourl += (keywords != '' ? '/' + keywords : '');
    gotourl += '/' + page + '/';

    window.location.assign(gotourl);
    return false;
}

function doSearchUniRoom(rooturl, amenities, price, photos, videos, order, keywords, page) {
    var gotourl = rooturl;
    //parse params
    if (!amenities) amenities = 'all';
    if (!price) price = 'all';
    if (!photos) photos = 'no';
    if (!videos) videos = 'no';
    if (!order) order = 'date';
    keywords = keywords.replace(/ /g, '+');
    keywords = keywords.cleanURL();
    keywords = keywords.replace(/[^a-z0-9ñÑ\+]/g, "");
    if (!page) page = 1;

    gotourl += '/' + amenities + '/';
    gotourl += 'price_' + price;
    gotourl += '-photos_' + photos;
    gotourl += '-videos_' + videos;
    gotourl += '-order_' + order;
    gotourl += (keywords != '' ? '/' + keywords : '');
    gotourl += '/' + page + '/';

    window.location.assign(gotourl);
    return false;
}
function doSearchEveRoom(rooturl, amenities, price, photos, videos, order, keywords, page) {
    var gotourl = rooturl;
    //parse params
    if (!amenities) amenities = 'all';
    if (!price) price = 'all';
    if (!photos) photos = 'no';
    if (!videos) videos = 'no';
    if (!order) order = 'date';
    keywords = keywords.replace(/ /g, '+');
    keywords = keywords.cleanURL();
    keywords = keywords.replace(/[^a-z0-9ñÑ\+]/g, "");
    if (!page) page = 1;

    gotourl += '/' + amenities + '/';
    gotourl += 'price_' + price;
    gotourl += '-photos_' + photos;
    gotourl += '-videos_' + videos;
    gotourl += '-order_' + order;
    gotourl += (keywords != '' ? '/' + keywords : '');
    gotourl += '/' + page + '/';

    window.location.assign(gotourl);
    return false;
}

function doSearchUniApt(rooturl, types, amenities, price, meters, provider, contract, photos, videos, furniture, bedrooms, bathrooms, condition, order, keywords, page) {
    var gotourl = rooturl;

    if (!types) types = 'all';
    if (!amenities) amenities = 'all';
    if (!price) price = 'all';
    if (!meters) meters = 'all';
    if (!provider) provider = 'all';
    if (!contract) contract = 'all';
    if (!photos) photos = 'no';
    if (!videos) videos = 'no';
    if (!furniture) furniture = 'all';
    if (!bedrooms) bedrooms = 'all';
    if (!bathrooms) bathrooms = 'all';
    if (!condition) condition = 'all';
    if (!order) order = 'date';
    keywords = keywords.replace(/ /g, '+');
    keywords = keywords.cleanURL();
    keywords = keywords.replace(/[^a-z0-9ñÑ\+]/g, "");
    if (!page) page = 1;

    gotourl += '/' + types;
    gotourl += '/' + amenities;
    gotourl += '/price_' + price;
    gotourl += '-meters_' + meters;
    gotourl += '-' + provider;
    gotourl += '-' + contract;
    gotourl += '-photos_' + photos;
    gotourl += '-videos_' + videos;
    gotourl += '-furniture_' + furniture;
    gotourl += '-bedrooms_' + bedrooms;
    gotourl += '-bathrooms_' + bathrooms;
    gotourl += '-' + condition;
    gotourl += '-order_' + order;
    gotourl += (keywords != '' ? '/' + keywords : '');
    gotourl += '/' + page + '/';

    window.location.assign(gotourl);
    return false;
}

function mycarousel_itemLoadCallback(carousel, state)
{
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }
    jQuery.get(
        '/web/ajax/dynamic_ajax_php_models.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};
function mycarousel_itemAddCallback(carousel, first, last, xml)
{
    carousel.size(parseInt(jQuery('total', xml).text()));
    jQuery('image', xml).each(function(i) {
        carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
    });
};
function mycarousel_getItemHTML(url)
{
    return '<img src="' + url + '" width="187" height="283" alt="Coompy.es" border="0" />';
};

// GOOGLE MAPS V3
var map;
function initialize(mapid, map_lat, map_lon, showstreetview, html) {
  // maps
  map = new google.maps.Map(document.getElementById(mapid), {
    center: new google.maps.LatLng(map_lat, map_lon),
    zoom: 15,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControl: true,
    mapTypeControlOptions: {
      style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
      },
    streetViewControl: showstreetview
  });
  infoWindow = new google.maps.InfoWindow;
  var point = new google.maps.LatLng(parseFloat(map_lat),parseFloat(map_lon));
  var marker = new google.maps.Marker({
    map: map,
    position: point
  });
  bindInfoWindow(marker, map, infoWindow, 'click', html);
  google.maps.event.addListener(map, 'click', function() {
    infoWindow.close();
  });
  google.maps.event.trigger(marker, 'click');

  // street view
  if( showstreetview ){
    var sview = new google.maps.LatLng(map_lat, map_lon);
    var panoramaOptions = {
      position:sview,
      pov: {
        heading: 0,
        pitch:0,
        zoom:1
      }
    };
    var myPano = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
    myPano.setVisible(true);
  }
}

function bindInfoWindow(marker, map, infoWindow, infoWindowtrigger, html) {
  google.maps.event.addListener(marker, infoWindowtrigger, function() {
    infoWindow.setContent(html);
    infoWindow.open(map, marker);
  });
}
