
var server_root = "/";

$(document).ready(function(){
	//google_maps_load();
	
	$("#route_s").hide();
	
	$("#basic_info_full").show();
	$("#contact_full").show();
	$("#product_full").show();
	$("#economic_full").hide();
	$("#persons_full").hide();
	$("#basic_info_img").attr("src", server_root + "images/" + "yk_arrw_d.gif");
	$("#contact_img").attr("src", server_root + "images/" + "yk_arrw_d.gif");
	$("#product_img").attr("src", server_root + "images/" + "yk_arrw_d.gif");
	$("#economic_img").attr("src", server_root + "images/" + "yk_arrw_r.gif");
	$("#persons_img").attr("src", server_root + "images/" + "yk_arrw_r.gif");
});

$(document).ready(function() {
	$("#last_cities").hide();
	$("#hide_last_cities").hide();
	
	$("#show_last_cities").click(function() {
		$("#show_last_cities").hide();
		$("#hide_last_cities").show();
		$("#last_cities").show();
	});
	
	$("#hide_last_cities").click(function() {
		$("#hide_last_cities").hide();
		$("#last_cities").hide();
		$("#show_last_cities").show();
	});
});


$(document).ready(function(){
	$("#show_all").click(function () {
		$("#basic_info_full").show();
		$("#contact_full").show();
		$("#product_full").show();
		$("#economic_full").show();
		$("#persons_full").show();
		$("#basic_info_img").attr("src", server_root + "images/" + "yk_arrw_d.gif");
		$("#contact_img").attr("src", server_root + "images/" + "yk_arrw_d.gif");
		$("#product_img").attr("src", server_root + "images/" + "yk_arrw_d.gif");
		$("#economic_img").attr("src", server_root + "images/" + "yk_arrw_d.gif");
		$("#persons_img").attr("src", server_root + "images/" + "yk_arrw_d.gif");
	});
	$("#hide_all").click(function () {
		$("#basic_info_full").hide();
		$("#contact_full").hide();
		$("#product_full").hide();
		$("#economic_full").hide();
		$("#persons_full").hide();
		$("#basic_info_img").attr("src", server_root + "images/" + "yk_arrw_r.gif");
		$("#contact_img").attr("src", server_root + "images/" + "yk_arrw_r.gif");
		$("#product_img").attr("src", server_root + "images/" + "yk_arrw_r.gif");
		$("#economic_img").attr("src", server_root + "images/" + "yk_arrw_r.gif");
		$("#persons_img").attr("src", server_root + "images/" + "yk_arrw_r.gif");
	});
});

$(document).ready(function(){
	$("#cities_full").hide();
	$("#cities_hide").hide();
	
	$("#cities_show").click(function() {
		$("#cities_show").hide();
		$("#cities_hide").show();
		$("#cities_full").toggle();
	});
	
	$("#cities_hide").click(function() {
		$("#cities_hide").hide();
		$("#cities_show").show();
		$("#cities_full").toggle();
	});
});

$(document).ready(function(){
	if (count_selected_companies() >= 100) {
		$(".qr_checkbox").attr("disabled", "disabled");
		$(".qr_checkbox:checked").removeAttr("disabled");
	}
	
	
	$(".qr_checkbox").click(function() {
		//alert(count_selected_companies());
		var value = $(this).val();
		if ($(this).is(":checked")) {
			addCompany(value);
			$("#add_" + value).hide();
			$("#remove_" + value).show();
		}
		else {
			removeCompany(value);
			$("#remove_" + value).hide();
			$("#add_" + value).show();
		}
		if (count_selected_companies() >= 100) {
			$(".qr_checkbox").attr("disabled", "disabled");
			$(".qr_checkbox:checked").removeAttr("disabled");
		}
		else {
			$(".qr_checkbox").removeAttr("disabled");
		}
		
	});
});

function map_click(element) {
	if (element == "route") {
		$("#map_s").hide();
		$("#route_s").show();
		$("#map_search").removeClass('tabs_s');
        $("#route_search").addClass('tabs_s');
	}
	else {
		$("#route_s").hide();
		$("#map_s").show();
		$("#route_search").removeClass('tabs_s');
        $("#map_search").addClass('tabs_s');
	}
}

$(document).ready(function(){
	$("#tender_full").show();
	$("#tender_img").attr("src", server_root + "images/" + "yk_arrw_d.gif");
});

function click(element) {
	$("#" + element + "_full").toggle();
	
	if ($("#" + element + "_img").attr("src") == server_root + "images/" + "yk_arrw_d.gif") {
		$("#" + element + "_img").attr("src", server_root + "images/" + "yk_arrw_r.gif");
	}
	else {
		$("#" + element + "_img").attr("src", server_root + "images/" + "yk_arrw_d.gif");
	}
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    if (str != null) {
    	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
    }
    else {
    	return null;
    }
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    if (str != null) {
    	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
    }
    else {
    	return null;
    }
}

function removeItems(array, item) {
	var i = 0;
	while (i < array.length) {
		if (array[i] == item) {
			array.splice(i, 1);
		} 
		else {
			i++;
		}
	}
	return array;
}

function addCompany(value) {
	if (jQuery.isFunction($.cookie) == true) {
		var webids = trim($.cookie("quotation_request_ids"));
		if (webids != null) {
			var webids_array = webids.split("|");
			if (jQuery.inArray(value, webids_array) == -1) {
				var new_webids = webids_array.join("|") + "|" + value;
			}
			$.cookie("quotation_request_ids", new_webids, { path: '/', expires: 1 });
		}
		else {
			$.cookie("quotation_request_ids", value, { path: '/', expires: 1 });
		}
		
	}
}

function removeCompany(value) {
	if (jQuery.isFunction($.cookie) == true) {
		webids = trim($.cookie("quotation_request_ids"));
		if (webids != null) {
			webids_array = webids.split("|");
			webids_array = removeItems(webids_array, value);
			new_webids = webids_array.join("|");
			$.cookie("quotation_request_ids", new_webids, { path: '/', expires: 1 });
		}
	}
}

function count_selected_companies() {
	if (jQuery.isFunction($.cookie) == true) {
		var webids = trim($.cookie("quotation_request_ids"));
		if (webids != null) {
			var webids_array = webids.split("|");
			var count = 0;
		
			for (i = 0; i < webids_array.length; i++) {
				if (webids_array[i] != "") {
					count++;
				}
			}
		
			return count;
		}
		else {
			return 0;
		}
	}
	else {
		return 0;
	}
	
}

function get_selected_companies() {
	if (jQuery.isFunction($.cookie) == true) {
		var webids = trim($.cookie("quotation_request_ids"));
		if (webids != null) {
			var webids_array = webids.split("|");
			var webids_new = new Array();
			var x = 0;
			for (i = 0; i < webids_array.length; i++) {
				if (webids_array[i] != "") {
					webids_new[x] = webids_array[i];
					x++;
				}
			}
		
			return webids_new;
		}
		else {
			return new Array();
		}
	}
	else {
		return new Array();
	}
	
}
