function col_details(id_colaborador)
{
	$("#col_details").load("../tools/components/colaboradores_details.php?id=" + id_colaborador);
	
	$("#sec_block").fadeTo(1, 0.60);	
	$("#sec_block_top_corners").fadeTo(1, 0.60);
	$("#sec_block_bottom_corners").fadeTo(1, 0.60);	
	$("#col_details").show();
	$("#col_details_top_corners").show();
	$("#col_details_bottom_corners").show();
}
function col_close()
{	
	$("#col_details").hide();
	$("#col_details_top_corners").hide();
	$("#col_details_bottom_corners").hide();
	$("#sec_block").fadeTo(1, 1);	
	$("#sec_block_top_corners").fadeTo(1, 1);
	$("#sec_block_bottom_corners").fadeTo(1, 1);		
}

function calc_slide(){
	if ($("#ip_calculator").position().left == 0)
		$("#ip_calculator").animate({ left: -400 }, 1200 );
	else
		$("#ip_calculator").animate({ left: 0 }, 1200 );
	$("#ip_calculator div.center").toggleClass("close");
}
function do_calc(lang){
	var modalidade = $("#selModalidade").val();
	var jurisdicao = $("#selJurisdicao").val();
	var datapedido = $("#txtDataPedido").val();
		
	if (validate_date(datapedido))
	{	
		$("#ip_calculator div#content").load("includes/ip-calculator.php?a=calc&m=" + modalidade + "&j=" + jurisdicao+ "&d=" + datapedido);
	}
	else
	{
		var strAlert = lang == "PT" ? "A data introduzida não está no formato correcto!" : "The inserted date is not in the right format!";
		alert(strAlert);		
	}
}
function validate_date(dateStr) {
	var format = "DMY";

    if (format.substring(0, 1) == "Y") { // If the year is first
       var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/;
       var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/;
    } else if (format.substring(1, 2) == "Y") { // If the year is second
       var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/;
       var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/;
    } else { // The year must be third
       var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/;
       var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
    }

    // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
    if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
    var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was

    // Check to see if the 3 parts end up making a valid date
    if (format.substring(0, 1) == "M") { var mm = parts[0]; } 
    else if (format.substring(1, 2) == "M") { var mm = parts[1]; } 
    else { var mm = parts[2]; }

    if (format.substring(0, 1) == "D") { var dd = parts[0]; } 
    else if (format.substring(1, 2) == "D") { var dd = parts[1]; } 
    else { var dd = parts[2]; }
    
    if (format.substring(0, 1) == "Y") { var yy = parts[0]; } 
    else if (format.substring(1, 2) == "Y") { var yy = parts[1]; } 
    else { var yy = parts[2]; }

    if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
    if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }

    var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
    if (parseFloat(dd) != dt.getDate()) { return false; }
    if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
    return true;
}
function calc_new_search(){
	$("#ip_calculator").load("includes/ip-calculator.php", function() { $("#ip_calculator div.center").toggleClass("close"); });
}

function data_pedido_focus(lang)
{
	var s = (lang == "PT") ? "DD/MM/AAAA" : "DD/MM/YYYY";
	if ($("#txtDataPedido").val() == s)
		$("#txtDataPedido").val("");	
}
function data_pedido_blur(lang)
{
	var s = lang == "PT" ? "DD/MM/AAAA" : "DD/MM/YYYY";
	if ($("#txtDataPedido").val() == "")
		$("#txtDataPedido").val(s);	
}
function change_data_label(lang)
{
	var modalidade = $("#selModalidade").val();
	var jurisdicao = $("#selJurisdicao").val();
	var data_label = "";

	var listOptions = "";
	listOptions = listOptions + (lang == "PT" ? "<option value=\"PT\">Portugal</option>" :  "<option value=\"PT\">Portugal</option>");
	listOptions = listOptions + (lang == "CE" ? "<option value=\"PT\">Comunidade Europeia</option>" :  "<option value=\"PT\">European Community</option>");
	listOptions = listOptions + (lang == "AO" ? "<option value=\"PT\">Angola</option>" :  "<option value=\"PT\">Angola</option>");
	listOptions = listOptions + (lang == "MZ" ? "<option value=\"PT\">Moçambique</option>" :  "<option value=\"PT\">Mozambique</option>");
	listOptions = listOptions + (lang == "MO" ? "<option value=\"PT\">Macau</option>" :  "<option value=\"PT\">Macao</option>");
	listOptions = listOptions + (lang == "CV" ? "<option value=\"PT\">Cabo Verde</option>" :  "<option value=\"PT\">Cape Verde</option>");
	listOptions = listOptions + (lang == "ST" ? "<option value=\"PT\">São Tomé e Príncipe</option>" :  "<option value=\"PT\">St. Thomas and Prince</option>"); 
		
	document.getElementById('selJurisdicao').disabled = false;
	switch(modalidade)
	{
		case "MCM":
			data_label = lang == "PT" ? "data do pedido" : "filing date";
			document.getElementById('selJurisdicao').selectedIndex = 1;
			document.getElementById('selJurisdicao').disabled = true;
			break;
		case "MIN":
			data_label = lang == "PT" ? "data do pedido" : "filing date";
			listOptions = (lang == "PT" ? "<option value=\"PT\">Portugal</option>" :  "<option value=\"PT\">Portugal</option>");
			listOptions = listOptions + (lang == "CE" ? "<option value=\"PT\">Comunidade Europeia</option>" :  "<option value=\"PT\">European Community</option>");
			listOptions = listOptions + (lang == "MZ" ? "<option value=\"PT\">Moçambique</option>" :  "<option value=\"PT\">Mozambique</option>");
			listOptions = listOptions + (lang == "ST" ? "<option value=\"PT\">São Tomé e Príncipe</option>" :  "<option value=\"PT\">St. Thomas and Prince</option>");
			break;
		case "LOG":
			data_label = lang == "PT" ? "data do pedido" : "filing date";
			break;
		case "PAT":
			data_label = lang == "PT" ? "data pedido" : "filing date";
			break;
		case "MNA":
		default:
			if (jurisdicao == "PT" || jurisdicao == "MO")
				data_label = lang == "PT" ? "data da concessão" : "date of grant";
			else 
				data_label = lang == "PT" ? "data do pedido" : "registration date";
			break;	
	}
	$("#selJurisdicao option").remove();
	$("#selJurisdicao").append(listOptions);	
	$("#data_label").html(data_label);	
}
function show_jurisdiction_label(j, l) {
	
	var juris = "";
	switch (j){
		case 1:
		default:
			juris = (l == "PT" ? "Portugal" : "Portugal");
			break;
		case 2:
			juris = (l == "PT" ? "Comunidade Europeia" : "European Community");
			break;
		case 3:
			juris = (l == "PT" ? "Angola" : "Angola");
			break;
		case 4:
			juris = (l == "PT" ? "Moçambique" : "Mozambique");
			break;
		case 5:
			juris = (l == "PT" ? "Cabo Verde" : "Cape Verde");
			break;
		case 6:
			juris = (l == "PT" ? "São Tomé e Príncipe" : "Sao Tome and Principe");
			break;
		case 7:
			juris = (l == "PT" ? "Macau" : "Macao");
			break;	
	}
	
	$("div#jurisdiction_label h1").html(juris);
	$("div#jurisdiction_label").css("visibility", "visible");
}
function hide_jurisdiction_label() {
	$("div#jurisdiction_label").css("visibility", "hidden");
}
function filter_letter_selector(target) {	
	if (target =="All")
	{
		$("#letter_selector_entries").children("div").show();
		return;		
	}	
	$("#letter_selector_entries").children("div").hide();
	$("." + target).show();
}
function fade_unexisting_letters() {
	if ($(".A").length == 0) $("#letter_selector_A").addClass("unexisting");
	if ($(".B").length == 0) $("#letter_selector_B").addClass("unexisting");
	if ($(".C").length == 0) $("#letter_selector_C").addClass("unexisting");
	if ($(".D").length == 0) $("#letter_selector_D").addClass("unexisting");
	if ($(".E").length == 0) $("#letter_selector_E").addClass("unexisting");
	if ($(".F").length == 0) $("#letter_selector_F").addClass("unexisting");
	if ($(".G").length == 0) $("#letter_selector_G").addClass("unexisting");
	if ($(".H").length == 0) $("#letter_selector_H").addClass("unexisting");
	if ($(".I").length == 0) $("#letter_selector_I").addClass("unexisting");
	if ($(".J").length == 0) $("#letter_selector_J").addClass("unexisting");
	if ($(".K").length == 0) $("#letter_selector_K").addClass("unexisting");
	if ($(".L").length == 0) $("#letter_selector_L").addClass("unexisting");
	if ($(".M").length == 0) $("#letter_selector_M").addClass("unexisting");
	if ($(".N").length == 0) $("#letter_selector_N").addClass("unexisting");
	if ($(".O").length == 0) $("#letter_selector_O").addClass("unexisting");
	if ($(".P").length == 0) $("#letter_selector_P").addClass("unexisting");
	if ($(".Q").length == 0) $("#letter_selector_Q").addClass("unexisting");
	if ($(".R").length == 0) $("#letter_selector_R").addClass("unexisting");
	if ($(".S").length == 0) $("#letter_selector_S").addClass("unexisting");
	if ($(".T").length == 0) $("#letter_selector_T").addClass("unexisting");
	if ($(".U").length == 0) $("#letter_selector_U").addClass("unexisting");
	if ($(".V").length == 0) $("#letter_selector_V").addClass("unexisting");
	if ($(".W").length == 0) $("#letter_selector_W").addClass("unexisting");
	if ($(".X").length == 0) $("#letter_selector_X").addClass("unexisting");
	if ($(".Y").length == 0) $("#letter_selector_Y").addClass("unexisting");
	if ($(".Z").length == 0) $("#letter_selector_Z").addClass("unexisting");
}
