var SITE_PATH = "http://www.cri-irc.org/ngo_cso_database/";

function showListDocuments(name, year_of_creation, country_of_location, country_of_operation, type_of_actions, type_of_year, keyword) {
	document.getElementById("table_documents_google").innerHTML = "<img src='https://domainoo.com/style/images/wait_for_it.gif' alt='attente' />";
	
	var url=SITE_PATH+"form_rechercher.php?action=search";
	
	$.post(url,
		{ name: name, year_of_creation: year_of_creation, country_of_location: country_of_location, country_of_operation: country_of_operation, type_of_actions: type_of_actions, type_of_year: type_of_year, keyword: keyword },
		function(data){
			cssClassNames = {tableRow: 'tab-google-table-row', tableCell: 'tab-google-table-cell', selectedTableRow: 'tab-google-selected-row', hoverTableRow: 'tab-google-hover-row', oddTableRow: 'tab-google-over-row'};
			
			table = new google.visualization.Table(document.getElementById('table_documents_google'));
			donnees = new google.visualization.DataTable(data);
			
			var formatter = new google.visualization.TablePatternFormat('<a href="'+SITE_PATH+'vue_fiche.php?id_document={1}">{0}</a>');
			formatter.format(donnees, [0, 7]);
			
			/*formatter = new google.visualization.TablePatternFormat('<a href="'+LENOM_FORM_URL+'domains/{1}/id/update_domain">{0}</a>');
			formatter.format(donnees, [3, 7]);*/
			
			var view = new google.visualization.DataView(donnees);
  			view.setColumns([0, 1, 2]);
			
			table.draw(view, {allowHtml: true, cssClassNames: cssClassNames, page: 'enable', pageSize: 50});
		    document.getElementById("total_documents").innerHTML = donnees.getNumberOfRows()+" entries";
		},
		"json"
	);
	$("#table").fadeIn(1500);
}

function display_location(selection) {
    if( selection.value == "internet" ) {
    	document.getElementById("upload").style.display = "none";
        document.getElementById("internet").style.display = "block";
        document.getElementById("contact_details").style.display = "none";
    }
    else if( selection.value == "uploaded" ) {
    	document.getElementById("upload").style.display = "block";
        document.getElementById("internet").style.display = "none";
        document.getElementById("contact_details").style.display = "none";
    }
    else if( selection.value == "contact_details" ) {
        document.getElementById("upload").style.display = "none";
        document.getElementById("internet").style.display = "none";
        document.getElementById("contact_details").style.display = "block";
    }
    else {
    	document.getElementById("upload").style.display = "none";
        document.getElementById("internet").style.display = "none";
        document.getElementById("contact_details").style.display = "none";
    }
}

function validForm() {
	var erreur = 0;
	
	if(document.getElementById("name").value == '') {
		document.getElementById("lab_name").innerHTML = "Name : <span style=\"color:red;\">Name can't be empty</span>";
		erreur = 1;
	}
	else
		document.getElementById("lab_name").innerHTML = "Name : ";
	
	if(document.getElementById("country_of_location").value == '') {
		document.getElementById("lab_country_of_location").innerHTML = "Country of location : <span style=\"color:red;\">Country of location can't be empty</span>";
		erreur = 1;
	}
	else
		document.getElementById("lab_country_of_location").innerHTML = "Country of location : ";
		
	if(document.getElementById("country_of_operation").value == '') {
		document.getElementById("lab_country_of_operation").innerHTML = "Country of operation : <span style=\"color:red;\">Country of operation can't be empty</span>";
		erreur = 1;
	}
	else
		document.getElementById("lab_country_of_operation").innerHTML = "Country of operation : ";
		
	if(document.getElementById("type_of_actions").value == '') {
		document.getElementById("lab_type_of_actions").innerHTML = "Type of actions : <span style=\"color:red;\">Type of actions can't be empty</span>";
		erreur = 1;
	}
	else
		document.getElementById("lab_type_of_actions").innerHTML = "Type of actions : ";
		
	if(document.getElementById("htp_focus").value == '') {
		document.getElementById("lab_htp_focus").innerHTML = "HTP focus : <span style=\"color:red;\">HTP focus can't be empty</span>";
		erreur = 1;
	}
	else
		document.getElementById("lab_htp_focus").innerHTML = "HTP focus : ";
	
	if(document.getElementById("location").value == '') {
		document.getElementById("lab_location").innerHTML = "Location : <span style=\"color:red;\">Location can't be empty</span>";
		erreur = 1;
	}
	else
		document.getElementById("lab_location").innerHTML = "Location : ";
	
	if(erreur == 1)
		return false;
	
	return true;
	
}
