var selected_type = 0;
$(document).ready(function(){
	//var q = "?limit=10&sort_order=ASC"; order_direction=DESC & order= model_year
	
	$("#ff_maerke").siblings(".value").addClass("disabled");
	$("#ff_type").siblings(".value").addClass("disabled");
	
	var u = [];
	if(getParameterByName("s") == ""){
		u['maerke'] = "";
		u['model'] = "";
		u['type'] = "";
		u['gastype'] = "";
		u['geartype'] = "";
		u['year_from'] = "";
		u['year_to'] = "";
		u['distance_from'] = "";
		u['distance_to'] = "";
		u['price_from'] = "";
		u['price_to'] = "";
		u['engine_volume'] = "";
		u['model_variant'] = "";
		u['colors'] = "";
		u['free_text'] = "";
		u['afhentningstilbud'] = "";
	} else {
		u = url_b64decode(getParameterByName("s"));
	}
	var arr = [];
		arr['manufacture'] = (u['maerke'] == "" ? "" : u['maerke']);
		arr['model'] = (u['model'] == "" ? "" : u['model']);
		arr['type'] = (u['type'] == "" ? "" : u['type']);
		arr['colors'] = (u['colors'] == "" ? "" : u['colors']);
		arr['gastype'] = (u['gastype'] == "" ? "" : u['gastype']);
		arr['geartype'] = (u['geartype'] == "" ? "" : u['geartype']);
		arr['year_from'] = (u['year_from'] == "" ? "" : u['year_from']);
		arr['year_to'] = (u['year_to'] == "" ? "" : u['year_to']);
		arr['distance_from'] = (u['distance_from'] == "" ? "" : u['distance_from']);
		arr['distance_to'] = (u['distance_to'] == "" ? "" : u['distance_to']);
		arr['price_from'] = (u['price_from'] == "" ? "" : u['price_from']);
		arr['price_to'] = (u['price_to'] == "" ? "" : u['price_to']);
		arr['model_variant'] = (u['model_variant'] == "" ? "" : u['model_variant']);
		arr['engine_volume'] = (u['engine_volume'] == "" ? "" : u['engine_volume']);
		arr['free_text'] = (u['free_text'] == "" ? "" : u['free_text']);
		arr['afhentningstilbud'] = (u['afhentningstilbud'] == "" ? "" : u['afhentningstilbud']);
	if(u['maerke'] != ""){
		$("#ff_maerke").siblings(".value").text(u['maerke']);
		$("#ff_maerke").val(u['maerke']);
		$("#ff_model").siblings(".value").removeClass("disabled");
		get_models(u['maerke']);
		//get_models(u['maerke'], "", "");
	}
	if(u['model'] != ""){
		//get_models(u['maerke'], u['model'], "");
		//get_types(u['maerke'], u['model'], "");
		get_models(u['maerke']);
		get_types(u['maerke'], u['model']);
		$("#ff_model").siblings(".value").text(u['model']);
		$("#ff_model").val(u['model']);
		$("#ff_model").siblings(".value").removeClass("disabled");
	}
	//if(u['maerke'] == "" && u['model'] == ""){
	//	get_types("", "");
	//}
	if(arr['year_from'] != ""){
		$("#ff_aar_fra").siblings(".value").text(u['year_from']);
		$("#ff_aar_fra").val(u['year_from']);
	}
	if(arr['year_to'] != ""){
		$("#ff_aar_til").siblings(".value").text(u['year_to']);
		$("#ff_aar_til").val(u['year_to']);
	}
	if(arr['distance_from'] != ""){
		$("#ff_km_fra").siblings(".value").text(make_dotted_integer(u['distance_from']));
		$("#ff_km_fra").val(u['distance_from']);
	}
	if(arr['distance_to'] != ""){
		$("#ff_km_til").siblings(".value").text(make_dotted_integer(u['distance_to']));
		$("#ff_km_til").val(u['distance_to']);
	}
	if(arr['geartype'] != ""){
		$("#ff_gear").siblings("div[rel='"+u['geartype']+"']").css("background", "url(/files/images/layout/icon_radiobtn_silver_selected.png) left center no-repeat");
		$("#ff_gear").val(u['geartype']);
	}
	if(arr['gastype'] != ""){
		$("#ff_braendstof").siblings("div[rel='"+u['gastype']+"']").css("background", "url(/files/images/layout/icon_radiobtn_silver_selected.png) left center no-repeat");
		$("#ff_braendstof").val(u['gastype']);
	}
	if(arr['price_from'] != ""){
		$("#ff_pris_fra").siblings(".value").text(make_dotted_integer(u['price_from']));
		$("#ff_pris_fra").val(u['price_from']);
	}
	if(arr['price_to'] != ""){
		$("#ff_pris_til").siblings(".value").text(make_dotted_integer(u['price_to']));
		$("#ff_pris_til").val(u['price_to']);
	}
	if(arr['colors'] != ""){
		$("#ff_nuance").siblings(".value").text(u['colors']);
		$("#ff_nuance").val(u['colors']);
	}
	if(arr['afhentningstilbud'] == "true"){
		$("#ff_afhentningstilbud").siblings("div").css("background", "url(/files/images/layout/silver_checkbox_checked.png) left center no-repeat");
		$("#ff_afhentningstilbud").val("true");
		silver_checkbox_checked = true;
	}
	selected_type = u['type'];
	var get_manufactures = $.ajax({
		dataType:"jsonp",
		url:"http://mycar.accedo.dk/search/request/list_details/633/key:4752363d1f11340ba8f844cf082c46ec/results:handleResult_manufacture/version:0.1/manufacture:/model:/categories:/"
	});
	get_years("","","");
	get_types("","");
	get_distance("","","");
	get_price("","","");
	get_colors("","","");
	get_search_car_count(arr);
});
function get_models(manufacture){
	$.ajax({
		dataType:"jsonp",
		url:"http://mycar.accedo.dk/search/request/list_details/633/key:4752363d1f11340ba8f844cf082c46ec/results:handleResult_model/version:0.1/manufacture:"+ manufacture +"/model:/categories:/"
	});
}
function get_types(manufacture, model){
	$.ajax({
		dataType:"jsonp",
		url:"http://mycar.accedo.dk/search/request/list_categories/633/key:4752363d1f11340ba8f844cf082c46ec/results:handleResult_type/version:0.1/manufacture:"+ manufacture +"/model:"+ model +"/categories:/"
	});
}
function get_years(manufacture, model, type){
	$.ajax({
		dataType:"jsonp",
		url:"http://mycar.accedo.dk/search/request/list_years/633/key:4752363d1f11340ba8f844cf082c46ec/results:handleResult_year/version:0.1/manufacture:"+ manufacture +"/model:"+ model +"/categories:"+ type +"/"
	});
}
function get_distance(manufacture, model, type){
	$.ajax({
		dataType:"jsonp",
		url:"http://mycar.accedo.dk/search/request/list_mileage/633/key:4752363d1f11340ba8f844cf082c46ec/results:handleResult_distance/version:0.1/manufacture:"+ manufacture +"/model:"+ model +"/categories:"+ type +"/"
	});
}
function get_colors(manufacture, model, type){
	$.ajax({
		dataType:"jsonp",
		url:"http://mycar.accedo.dk/search/request/list_colors/633/key:4752363d1f11340ba8f844cf082c46ec/results:handleResult_colors/version:0.1/manufacture:"+ manufacture +"/model:"+ model +"/categories:"+ type +"/"
	});
}
function get_price(manufacture, model, type){
	$.ajax({
		dataType:"jsonp",
		url:"http://mycar.accedo.dk/search/request/list_price/633/key:4752363d1f11340ba8f844cf082c46ec/results:handleResult_price/version:0.1/manufacture:"+ manufacture +"/model:"+ model +"/categories:"+ type +"/"
	});
}
function get_search_car_count(arr){
	var manufacture = (arr['manufacture'] == "" ? "" : arr['manufacture']),
		model = (arr['model'] == "" ? "" : arr['model']),
		model_variant = (arr['model_variant'] == "" ? "" : arr['model_variant']),
		engine_volume = (arr['engine_volume'] == "" ? "" : arr['engine_volume']),
		geartype = (arr['geartype'] == "" ? "" : arr['geartype']),
		free_text = (arr['free_text'] == "" || arr['free_text'] == undefined ? "" : arr['free_text']),
		year_from = (arr['year_from'] == "" ? "" : arr['year_from']),
		year_to = (arr['year_to'] == "" ? "" : arr['year_to']),
		colors = (arr['colors'] == "" || arr['colors'] == undefined ? "" : arr['colors']),
		gastype = (arr['gastype'] == "" ? "" : arr['gastype']);
	var year = "";
	if(year_to != "" && year_from != ""){
		year = year_from + "-" + year_to;
	} else if(year_from != "" && year_to == ""){
		year = year_from + "-0";
	} else if(year_from == "" && year_to != ""){
		year = "1-" + year_to;
	} else {
		year = "";
	}
	
	var distance_from = (arr['distance_from'] == "" ? "" : arr['distance_from']),
		distance_to = (arr['distance_to'] == "" ? "" : arr['distance_to']);
	var distance = "";
	if(distance_to != "" && distance_from != ""){
		distance = distance_from + "-" + distance_to;
	} else if(distance_from != "" && distance_to == ""){
		distance = distance_from + "-0";
	} else if(distance_from == "" && distance_to != ""){
		distance = "1-" + distance_to;
	} else {
		distance = "";
	}
	
	var price_from = (arr['price_from'] == "" ? "" : arr['price_from']),
		price_to = (arr['price_to'] == "" ? "" : arr['price_to']);
	var price = "";
	if(price_to != "" && price_from != ""){
		price = price_from + "-" + price_to;
	} else if(price_from != "" && price_to == ""){
		price = price_from + "-0";
	} else if(price_from == "" && price_to != ""){
		price = "1-" + price_to;
	} else {
		price = "";
	}

	var category;
	if(arr['afhentningstilbud'] == true || arr['afhentningstilbud'] == "true"){
		// Dette er afhentningstilbudsflueben
		category = 1;
	} else {
		category = (arr['type'] == "" ? "" : arr['type']);
	}
	$.ajax({
		dataType:"jsonp",
		//url:"http://mycar.accedo.dk/search/request/cars/633/key:4752363d1f11340ba8f844cf082c46ec/version:0.1/results:handleResult_countcars/?manufacture="+ manufacture +"&freetext="+ free_text +"&model="+ model +"&categories="+ category +"&model_year="+ year+"&distance="+ distance+"&price="+ price +"&gastype="+gastype+"&geartype="+geartype+"&color="+color+""
		url:"http://mycar.accedo.dk/search/request/cars/633/key:4752363d1f11340ba8f844cf082c46ec/version:0.1/results:handleResult_countcars/?manufacture="+ manufacture +"&freetext="+ free_text +"&exterior_color="+ colors +"&model="+ model +"&categories="+ category +"&model_year="+ year +"&distance="+ distance +"&price="+ price +"&geartype="+ geartype +"&gastype="+gastype+"&model_variant="+model_variant+"&engine_volume="+engine_volume+""
	});
}
function handleResult_manufacture(jsonData) {
	var counter = 0;
	var options = "";
	if(jsonData.length!=0) {
		$.each(jsonData, function(key, value) {
			var maerke = value.car_manufacture;
			var rel = maerke.toLowerCase();
			rel = rel.replace(" ", "_");
			options += '<div class="option" rel="'+ maerke +'">'+ maerke +'</div>';
			counter++;
		});
		
		if($("#ff_maerke").siblings(".value").text() == "Henter..."){
			$("#ff_maerke").siblings(".value").text("Alle");
			$("#ff_maerke").val("");
		} else {
			//$("#ff_maerke").siblings(".value").text("Alle");
			//$("#ff_maerke").val("");
		}
		
		$("#ff_maerke").siblings(".options").append(options);
		
		$("#ff_maerke").siblings(".options").html(options);
		$("#ff_maerke").siblings(".options").prepend($("#ff_maerke").siblings(".options").find("div[rel='Mercedes']"));
		$("#ff_maerke").siblings(".options").prepend('<div class="option" rel="">Alle</div>');
		
		$("#ff_maerke").siblings(".value").removeClass("disabled");
	}
}
function handleResult_model(jsonData) {
	var counter = 0;
	//var options = '<div class="option" rel="">Alle</div>';
	var options = '';
	if(jsonData.length!=0) {
		$.each(jsonData, function(key, value) {
			if(value.car_model != ""){
				var model = value.car_model;
				var rel = model.toLowerCase();
				rel = rel.replace(" ", "_");
				options += '<div class="option" rel="'+ model +'">'+ model +'</div>';
				counter++;
			}
		});
		
		$("#ff_model").siblings(".options").append(options);
		$("#ff_model").siblings(".value").removeClass("disabled");
		$("#ff_model").siblings(".value").text("Vælg model");
	}
}
function handleResult_type(jsonData) {
	var counter = 0;
	var options = '';
	var selected = 0;
	var selected_string = "";
	if(jsonData.length!=0) {
		options += '<div class="option" rel="">Alle</div>';
		$.each(jsonData, function(key, value) {
			var type = value.name;
			var rel = value.id;
			if(rel == selected_type){
				selected = selected_type;
				selected_string = type;
				$("#ff_type").val(selected_type);
				$("#ff_type").siblings(".value").text(selected_string);
			}
			
			if (rel != 12) {
				options += '<div class="option" rel="'+ rel +'">'+ type +'</div>';
				counter++;
			}
		});
		
		$("#ff_type").siblings(".options").html(options);
		$("#ff_type").siblings(".value").removeClass("disabled");
		if($("#ff_type").siblings(".value").text() == "Henter..."){
			$("#ff_type").siblings(".value").text("Vælg type");
		}
	} else {
		//$("#ff_type").siblings(".value").addClass("disabled");
		$("#ff_type").siblings(".value").text("Vælg type");
		$("#ff_type").val("");
	}
}
function handleResult_colors(jsonData) {
	var counter = 0;
	var options = '<div class="option" rel="">Alle</div>';
	if(jsonData.length!=0) {
		$.each(jsonData, function(key, value) {
			var name = value.car_exterior_color;
			options += '<div class="option" rel="'+ name +'">'+ name +'</div>';
			counter++;
		});
		$("#ff_nuance").siblings(".options").html(options);
	}
}
function handleResult_countcars(jsonData) {
	if(jsonData.length!=0) {
		var bil = "";
		if(jsonData.length == 1) {
			bil = " bil";
		} else {
			bil = " biler";
		}
		//$(".adv_search_submit_con .count_search .car_count").text(jsonData.length + bil);
		$(".count_search .car_count").text(jsonData.length + bil);
	} else {
		//$(".adv_search_submit_con .count_search .car_count").text("0 biler");
		$(".count_search .car_count").text("0 biler");
	}
}
function handleResult_year(jsonData) {
	var counter = 0;
	var options = '<div class="option" rel="">-</div>';
	if(jsonData.length!=0) {
		$.each(jsonData, function(key, value) {
			var type = value.model_year;
			var rel = type.toLowerCase();
			rel = rel.replace(" ", "_");
			options += '<div class="option" rel="'+ rel +'">'+ type +'</div>';
			counter++;
		});

		$("#ff_aar_fra").siblings(".options").html(options);
		$("#ff_aar_til").siblings(".options").html(options);
	}
}
function handleResult_distance(jsonData){
	var counter = 0;
	var options = '<div class="option" rel="">-</div>';
	var minimum = 0;
	var maximum = 0;
	if(jsonData.length!=0) {
		//console.log(jsonData);
		$.each(jsonData, function(key, value){
			if(counter == 0){
				if(value.minimum != ""){
					minimum = value.minimum * 1000;
				}
				if(value.maximum != ""){
					maximum = Math.ceil(value.maximum / 100) * 100 * 1000;
					options += '<div class="option" rel="10000">10.000</div>';
					options += (maximum < 25000 ? "" : '<div class="option" rel="25000">25.000</div>');
					options += (maximum < 50000 ? "" : '<div class="option" rel="50000">50.000</div>');
					options += (maximum < 75000 ? "" : '<div class="option" rel="75000">75.000</div>');
					options += (maximum < 100000 ? "" : '<div class="option" rel="100000">100.000</div>');
					options += (maximum < 150000 ? "" : '<div class="option" rel="150000">150.000</div>');
					options += (maximum < 200000 ? "" : '<div class="option" rel="200000">200.000</div>');
					options += (maximum < 350000 ? "" : '<div class="option" rel="350000">350.000</div>');
					options += (maximum < 500000 ? "" : '<div class="option" rel="500000">500.000</div>');
				}
			}
			counter++;
		});
		//options += '<div class="option" rel="'+ maximum +'">'+ maximum +'</div>';
		$("#ff_km_fra").siblings(".options").html(options);
		$("#ff_km_til").siblings(".options").html(options);
	}
}
function handleResult_price(jsonData) {
	var counter = 0;
	var options = '<div class="option" rel="0">0</div>';
	if(jsonData.length!=0) {
		//console.log(jsonData);
		$.each(jsonData, function(key, value) {
			if(counter == 0){
				if(value.minimum != ""){
					var minimum = value.minimum * 1000;
				}
				if(value.maximum != ""){
					//maximum = Math.ceil(value.maximum / 100) * 100 * 1000; // 0 20 50 100 200 300 500 750 1m 2m
					var maximum = value.maximum;
					//console.log(value.maximum);
					maximum = maximum.split(".");
					maximum = maximum[0];
					//options += '<div class="option" rel="0">0</div>';
					options += (maximum < 20000 ? "" : '<div class="option" rel="20000">20.000</div>');
					options += (maximum < 50000 ? "" : '<div class="option" rel="50000">50.000</div>');
					options += (maximum < 100000 ? "" : '<div class="option" rel="100000">100.000</div>');
					options += (maximum < 200000 ? "" : '<div class="option" rel="200000">200.000</div>');
					options += (maximum < 300000 ? "" : '<div class="option" rel="300000">300.000</div>');
					options += (maximum < 500000 ? "" : '<div class="option" rel="500000">500.000</div>');
					options += (maximum < 750000 ? "" : '<div class="option" rel="750000">750.000</div>');
					options += (maximum < 1000000 ? "" : '<div class="option" rel="1000000">1.000.000</div>');
					options += (maximum < 2000000 ? "" : '<div class="option" rel="2000000">2.000.000</div>');
				}
			}
			//var type = value.model_year;
			//var rel = type.toLowerCase();
			//rel = rel.replace(" ", "_");
			//options += '<div class="option" rel="'+ rel +'">'+ type +'</div>';
			counter++;
		});

		$("#ff_pris_fra").siblings(".options").html(options);
		$("#ff_pris_til").siblings(".options").html(options);
	}
}
function animate_add_car(){
	//.css({"opacity": "0", display: "block"})
/*	$(".add_car_con .notification").animate({
			"top" : "20px"
		},
		1200,
		"easeOutElastic",
		function(){
			$(".add_car_con .notification").delay(2500).animate({
					"top" : "-60px"
				},
				500
			);
		}
	);*/
}

function base64_encode(data) {
    // Encodes string using MIME base64 algorithm
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/base64_encode
    // mozilla has this native - but breaks in 2.0.0.12!
    //if (typeof this.window['atob'] == 'function') {
    //    return atob(data);
    //}
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
        ac = 0,
        enc = "",
        tmp_arr = [];
    if (!data) {return data;}
    data = utf8_encode(data + '');
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);
        bits = o1 << 16 | o2 << 8 | o3;
        h1 = bits >> 18 & 0x3f;
        h2 = bits >> 12 & 0x3f;
        h3 = bits >> 6 & 0x3f;
        h4 = bits & 0x3f;
        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
    enc = tmp_arr.join('');
    var r = data.length % 3;
    return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
}
function base64_decode(data) {
    // Decodes string using MIME base64 algorithm
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/base64_decode
    // mozilla has this native - but breaks in 2.0.0.12!
    //if (typeof this.window['btoa'] == 'function') {
    //    return btoa(data);
    //}
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
        ac = 0,
        dec = "",
        tmp_arr = [];
    if (!data) {return data;}
    data += '';
    do { // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));
        bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
        o1 = bits >> 16 & 0xff;
        o2 = bits >> 8 & 0xff;
        o3 = bits & 0xff;
        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
    } while (i < data.length);
    dec = tmp_arr.join('');
    dec = utf8_decode(dec);
    return dec;
}
function utf8_encode(argString) {
    // Encodes an ISO-8859-1 string to UTF-8
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/utf8_encode
    if (argString === null || typeof argString === "undefined") {return "";}
    var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
    var utftext = "", start, end, stringl = 0;
	start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;
        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.slice(start, end);
            }
            utftext += enc;
            start = end = n + 1;
        }
    }
    if (end > start) {
        utftext += string.slice(start, stringl);
    }
    return utftext;
}
function utf8_decode (str_data) {
    // Converts a UTF-8 encoded string to ISO-8859-1
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/utf8_decode
    var tmp_arr = [],
        i = 0,
        ac = 0,
        c1 = 0,
        c2 = 0,
        c3 = 0;
    str_data += '';
    while (i < str_data.length) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if (c1 > 191 && c1 < 224) {
            c2 = str_data.charCodeAt(i + 1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i + 1);
            c3 = str_data.charCodeAt(i + 2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
    return tmp_arr.join('');
}
function make_dotted_integer(n, make_pointohhohh){
	var n_ = n + "";
	if(n_.indexOf(",")){
		n_ = n_.split(",");
		n_ = n_[0];
	}
	var r = n_.split("."),
		re = "", re1 = "", re2 = "", re3 = "";
	r = r[0] + "";
	if(r.length == 1 || r.length == 2 || r.length == 3){
		re = r;
	} else if(r.length == 4){
		re1 = r.substr(0,1);
		re2 = r.substr(1,3);
		re = re1 + "." + re2;
	} else if(r.length == 5){
		re1 = r.substr(0,2);
		re2 = r.substr(2,3);
		re = re1 + "." + re2;
	} else if(r.length == 6){
		re1 = r.substr(0,3);
		re2 = r.substr(3,3);
		re = re1 + "." + re2;
	} else if(r.length == 7){
		re1 = r.substr(0,1);
		re2 = r.substr(1,3);
		re3 = r.substr(4,3);
		re = re1 + "." + re2 + "." + re3;
	} else if(r.length == 8){
		re1 = r.substr(0,2);
		re2 = r.substr(2,3);
		re3 = r.substr(5,3);
		re = re1 + "." + re2 + "." + re3;
	}
	if(make_pointohhohh == true){
		re += ",00";
	}
	return re;
}
function getParameterByName(name){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null ) {
		return "";
	} else {
		return decodeURIComponent(results[1].replace(/\+/g, " "));
	}
}
